Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th

So I'm using two Arduinos sending sensor data (3axis accel, 3axis gyro) over two XBees to another XBee + USB shield which is then piping the data into Max/MSP.

At first I was using something similar to the built-in 'VirtualColorMixer' patch, by sending the data, then a ",", then more data.I added to that tags for each arduino (1 or 2) and then for each sensor type (Ax, Ay, Az),

But then I realized that I have two Arduinos piping data in at the same time, and it's conceivable that I could 'cross the streams' and break all the tagging. (if one device sends its data value before a line break from the next device it would break the parsing side of things).

Then after a suggestion from Grumpy Mike I used a hex byte to label the device (rather than the 4 bytes I'm using there). So 0x11 would be device one, sensor1, 0x24 would be deice two, sensor4 etc...

I also moved all of the read functions to the start of the void loop to avoid printing in the middle of reading and delaying when the analog data is sampled from (using some software filtering that compares previous positions, so I would imagine this would improve accuracy).

The problem I'm having is that I don't seem to be getting the hex value in serial monitor (or Max/MSP). In Max after grouping and parsing things a bit I'm getting the 6 sensor values in a row, but nothing in front of each... In serial monitor I'm getting something similar.

Is there something wrong with my serial.print code there? Is this the most thorough way to avoid 'crossing the streams' from two devices sending serial data? (my println is on a separate line, and I guess that's my footer value at the moment, should I remove that and presume that everything before a hex character is the full data?)

0x11, in ASCII, is Device Control 1. Serial Monitor doesn't know how to print "Device Control 1", so it doesn't. If you want to send the characters "0x11" then just println("0x11 " + aAccX);

Note that 0x11 is one byte, while "0x11" is 4 bytes ("11" is 2 bytes).

Also, if you have 2 devices that are both piping in data (I don't know how that works...), it's entirely possible that they'll both send data at the same time, so you could get "00xx1112 9587" with all of the data mashed together.

Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th

Hmm. So how do I send single bytes? (Can I just use higher values like 0x44 as device1, sensor4, and 0x54 as device2, sensor4).

As if I'm sending "0x11" I might as well send my original "1 ax " as I can parse it easier.

As far the last part, I'm not sure how it works either (yet). I have the XBees and everything else but I forgot to buy a voltage booster so I've not test driven the full setup yet. I was assuming (rather hopefully) that the XBee protocol handled how that worked and one XBee receiving data from multiple XBees would just send the data clumped together how it came in. I could be wrong there....

Serial.print(char(0x11) + AccX);This is not concatenating output the way that you think it will. It is ADDING the two values, which is most certainly not what you want. There are no shortcuts for sending to values to the serial port. You must either stuff the data in an array or use multiple Serial output statements.

Sending AccX using print() is not the best way, either. For speed, you want to send data in binary. Serial.write() would be useful, but note that it is for byte-sized data. To send an int requires sending two bytes.

Whatever you do, you STILL run the risk of two Arduinos/XBees sending data at the same time, unless you implement some form of handshaking (Hey, 1, what's new? (#1 replies). Hey, 2, what's up? (#2 replies)).

Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th

Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th

Without reading your middle comment I would worry that this would break apart the message again, but I guess that's a non issue here. So my code would be that serial.write thing for each sensor value. Would I still use a println as my 'footer'?

Quote

And how do I concat the header and data into one message?

So it doesn't matter if I print them at the same time or separately, they travel over serial as pieces regardless?

The USB shield/XBee is connected to the computer indeed. So would that mean i would be doing the handshaking thing from the computer? Unless I misunderstood what you meant.

Quote

Is it possible to implement a handshake if the receiving side doesn't have an arduino? I just have an XBee and a USB shield

What is the XBee/USB Shield doing? I thought that the device was connected to the PC, which was getting the serial data.[/quote]

Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th

Without reading your middle comment I would worry that this would break apart the message again, but I guess that's a non issue here.So my code would be that serial.write thing for each sensor value. Would I still use a println as my 'footer'?

Yes. The serial data is a collection of bytes, sent in the order specified. Note that the receiving end must expect binary data, now, not ascii data.

Quote

So it doesn't matter if I print them at the same time or separately, they travel over serial as pieces regardless?

True, where the pieces are bytes.

Quote

The USB shield/XBee is connected to the computer indeed. So would that mean i would be doing the handshaking thing from the computer?

Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th

Rodrigo Constanzo is a performer and composer living in Manchester, England. He is an avid improviser and performs regularly using home made electro acoustic, and modified electronic instruments. He is currently working towards a PhD in Composition at th