Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Serial communication with two sensors / + weird output in oF

$
0
0

@ABel wrote:

Hi oF forum,

I am trying to figure out how to set up serial communication between an Arduino with two sensors attached (CapSense and Ultrasonic) and openFrameworks. How can I differentiate between the two sensor input in openFrameworks?

Firmata didn’t work with CapSense, and I tried to arrange the incoming data in a “comma-separated” vector but I couldn’t make it work. Unfortunately, I don’t have that much experience with programming.

As a way of circumventing this, I have currently 2xArduinos (one for each sensor) and then just made two ofSerial objects in oF. But my readings are totally off now, I no longer understand what is going on. In openFrameworks I am constantly getting a value of 254 from the Ultrasonic, and with the CapSense I am either getting a 0 but then sometimes low 10s to 50s - with no response when I touch (usually the values are 0 to 700). But I am getting correct values in the Arduino IDE serial monitor.

My code is:

Arduino
It’s very simple code, it does what it needs to do and then I use Serial.write(exampleVariable). I use the example code from CapSense and the NewPing lib for the ultrasonic.

oF

void ofApp::setup(){
	serial1.setup("COM3", 9600); 
	serial2.setup("COM4",9600);
}

void ofApp::update(){

	if (serial1.available() < 0)  {
		msg = "Arduino Error";
	}
	else {
		//While statement looping through serial messages when serial is being provided.
		while (serial1.available() > 0) {

			//byte data is being writen into byteData as int.
			byteDataPing = serial1.readByte();
	
		}
	}
	 if(serial2.available() < 0) { msg = "Arduino Error"; }
	 else {
		 while (serial2.available() > 0) {

			 byteDataCapSense = serial2.readByte();
		 }
	 }

Can anyone help me figure out how to control the data coming from the two sensors in openFrameworks?
Any help is appreciated.

  • Anne

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles