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.

There is no magic bullet here, you are going to simply have to learn how to deal with strings. Its a really good thing to know -for RC stuff as well as a lot of other stuff.

I would forget for a moment, how this relates to this particular problem and instead just start doing some searches for info on manipulating strings. There are even a lot of libraries that will help you with this. Gotta learn how the zero-thing works, how to split them, remove whitespace, all-caps, all-lower, adding them, etc...

It should be said though, that at the end of the day, you are just sending bytes here. No real reason they have to be in the form of a string. Any reason you don't just break up your int's into bytes and just simply send them as "numbers"?

But what if I want to send data from 4 sensors from one arduino to another using xbee.

wouldnt the recieving arduino get confused with so many bytes.

How would it know which belongs to what so i thought for 4 sensors it could be like

sensor 1 sensor 2   sensor 3 sensor 4

123        ,     456    ,     789    ,     100

If im asking a stupid question i am sorry.

also any sites for me to understand manipulating strings.

I kind of know what strings are since we are learning c++ in my school.

The difficulty lies in picking one that is easy to use and reasonably efficient.

Here are some questions that you need to answer first:

 - Will you allways be sending the same values?

 - Will you send them all at the same time and in the same order?


When you ask the first question do you mean will I kepp sending a 250 on and on its a no. If you mean will I send the same type of data yes. And for the second question yes I will send them at the same time .

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.

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:






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

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