I'm using four XBee series 1 radios, three of them are connected to three Lilypad Arduinos. Each one is running a program that is reading and printing values collected from pressure sensors that are attached to analog pins 0 and 2 (see attached code). I have a 4th XBee configured as the coordinator and is plugged into my computer which is running a processing program (see attached). I was expecting this program to sort through the multiple values coming from the three arduinos and stream them into 6 columns (sensor 0 through to sensor 6). I have lifted both codes from Tom Igoes tutorial on serial communication Lab: Two-way (Duplex) Serial Communication using an Arduino and Processing – ITP Physical Computing. My teacher suggested that his punctuation method should work with the radios and that I do not need to be in API mode. I'm clearly missing something. I'm new at this and I've tried to provide you with info as succinctly as possible but please bear with me if I have neglected to include something important. Any feedback would be greatly appreciated.
Here's what's happening when I run the program:
- radios are communicating with coordinator and transmitting data
- all the data is streaming through two columns only, sensor 0 and sensor 1.
- I can see the data values change when I apply pressure to the different sensors but it's all messy.
- If I run only one radio and turn off the other two, the program runs beautifully.
Arduino code
void setup() {
// configure the serial connection:
Serial.begin(9600);}
void loop() {
// read the sensor:
int sensorValue = analogRead(A0);
// print the results:
Serial.print(sensorValue);
Serial.print(",");// read the sensor:
sensorValue = analogRead(A2);
// print the results:Serial.println(sensorValue);
}
Processing Code
import processing.serial.*; // import the Processing serial library
Serial myPort; // The serial portvoid setup() {
// List all the available serial ports
println(Serial.list());// I know that the first port in the serial list on my mac
// is always my Arduino module, so I open Serial.list()[0].
// Change the 0 to the appropriate number of the serial port
// that your microcontroller is attached to.
String portName = Serial.list()[0];
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
}
void draw() {
// twiddle your thumbs
}void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
if (myString != null) {
myString = trim(myString);// split the string at the commas
// and convert the sections into integers:
int sensors[] = int(split(myString, ','));// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();}
}