Let's Make Robots!

processing and arduino help


Hello, my question is what should i do if i want to send multiple variables from processing/arduino to arduino and vice-versa

I think you put it in a long string but how do you decode it. I think its like this not sure 123,456,789,100 with commas seperating them. I want to send values from different sensors from one arduino to another with xbee like shown here.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

...or your baud rates don't match...

Weird values are actually kinda common in a situation like this. It would take a really long time to explain the specific ins and outs of serial data transfer, so I will hit the bullet points. You will have to play around a bit and do some googling.

Put simply, serial.print and serial.write are different. Also, take a look at the ASCII chart and you will find that all 256 combinations of a byte can be written 4 or 5 different ways --I.e. 65 0x43 101 @#65 and regular ol' "A". Your funny values are probably due to the fact that an "A" is being sent and a "65" is being recieved (or any other combination). I am not going to lie to you, it gets really confusing and the more you learn, the more you seem to be confused --At least it did with me.

After I while, I just accepted the fact that I was going to have to play with the "serial.print"s and the "serial.write"s until I found a combination that worked. You should also play with adding BYTE() to your sends, serial.write(BYTE(yourVariableToSend). --Yeah, I seem to remember that "BYTE" thing working in the past, try that one for sure.

I am sorry I don't have better answers for you on this one, it has been quite a while since I have done this. --and when I did, I really did just play with it until it worked. I am sure I wrote down the right way to do it, but damned if I would ever be able to find it.

thnks for the help ill try it for sure ;)

Alright, here is what I would do:

On the processing side, write a sketch that goes like this:

byte i=0;

  mySerial.print(i);      **I can't really remember how the serial.print command looks like in processing



Now you have a little count spitting out of processing. It is 3 bytes, the count, count+1 and count+2. Your first data will be 0,1,2, the second batch will be 1,2,3, the next one will be 2,3,4, and so on. Just let this run, it will do a "send" of 3 bytes, first-second-third, once a second. When we get up to our 255 limit for a byte, each count should simply overflow and start again.

Using this system, we can test to see that the proper data is coming through, and we can also easily see if it is in the correct order.


Now on the arduino side, we are simply waiting to catch 3 bytes as they come in:




From there, you can do anything you want to see if your data is being read right. You can blink leds, send the data out to a LCD, add another FTDI and SoftSerial and send it back to the computer to serial monitor, whatever. But the above is about as simple as it can be, just send three bytes in order, and receive them in the same order. That's it.


Its not really working I tried writing the values to leds since i cant open the terminal to debug.

So i made the arduino recieve the values from processing andthen send them back to processing's terminal to debug but i get some weird values.

So the standard firmata is the only way i guess but what if I need to send arduino to arduino.

im kind of confused what order is it in and since i am starting for my first time im using processing to send values then i will use those values and turn them into pwm or something.

What you di im guessing is for the xbee and 2 arduinos

thank you for heling and putting the effort

I kind of made some code on this subject 

the processing part takes x position and y position of mouse and writes it to the port of the arduino.

heres processing code.

import processing.serial.*;

 Serial port;


 void setup() {

 size(180, 180);


 println("Available serial ports:");



 // Uses the first port in this list (number 0).  Change this to

 // select the port corresponding to your Arduino board.  The last

 // parameter (e.g. 9600) is the speed of the communication.  It

 // has to correspond to the value passed to Serial.begin() in your

 // Arduino sketch.

 port = new Serial(this, Serial.list()[0], 9600);  


 // If you know the name of the port used by the Arduino board, you

 // can specify it directly like this.

 //port = new Serial(this, "COM1", 9600);



 void draw() {

 // draw a gradient from black to white

 for (int i = 0; i < 180; i++) {


 line(i, 0, i, 180);



 // write the current X-position of the mouse to the serial port as

 // a single byte





the x and y goes in this form 120,120


the arduino side kind of decodes it i think it uses serial.parseint got it here http://arduino.cc/en/Tutorial/ReadASCIIString

here is the adino code 


#include <Servo.h>

Servo servo;

Servo servo1;

void setup()


  // initialize the serial communication:







void loop() {

  int brightness;

  int brightness1;


  // check if data has been sent from the computer:

  if (Serial.available()) {

    // read the most recent byte (which will be from 0 to 255):

    int brightness = Serial.parseInt();

    int brightness1 = Serial.parseInt();

    // set the brightness of the LED:






Well, "confused" does not really exist in a robot brain, it is either coded correctly or not. You can however, loose data or receive crap data --and there are ways to fix this.

When sending a given number of bytes, it is sometimes a good idea to use qualifiers and terminators. These are simply two numbers sent at the beginning and/or end of your sends to help keep things "in sync". The most common example of this is to send a CR or LF (13 or 10) at the end of your sends to say, "this send is done". Data sent without this last byte can be ignored --something did not come in right...

Another option which is fairly fail-safe is to use a checksum. Put simply, you take all the bytes you are going to send and add them up. This total gets sent at the end. Your receiver gets the data, adds all the bytes and compares it to the checksum number. If they don't match, it ignores the data (or does whatever you tell it to do when this happens) and waits for another clean packet to come by.


All-in-all, if you are just sending a few bytes worth of data, and not trying to do it at incredible baud rates, you should rarely if ever have bad data using X-bees.


One more because I think this might get you...  You can not send an int, long, etc. Everything must be sent as bytes. If you have a number smaller than 0 or bigger than 255, it will have to be "broken up" into its component bytes, sent, then "reassembled" on the other side.