Xbee communicating with Arduino - please help

I have an arduino and it is reading data from a series of sources - accelerometer, tilt switches, compass and an ultrasonic sensor - for height. the thing is, i am saving these values into intergers but i need to then transmit these values to a second xbee board - connected to an arduino board (minus arduino) which is then interfaced into maxMSP. From their the data is read from it serially and stuff is done.

What i am having trouble with is finding out how to transmit the data through the xbee in the first place.

I have a series of xbee shields from nkc and i was thinking it was as simple as it was with picaxe microcontrollers - where you say

serialout 7,n1900(data one,data 2,data3,...);

but alas this is not the case.

I have googled it and looked at the few sites about xbee and the arduino, but i dont quite understand what is required in just sending data strings.

Can anyone add assistance?

Please help :smiley:

Nat :-/

Hey, Nat,

It's not too much harder than that. Assuming your data is all integer and you want to send it out the serial port in string form, you could just do:

Serial.begin(19200);
Serial.print(data1);
Serial.print(data2);
Serial.print(data3);
Serial.print(data4);
...

If you need newline delimiters between each one, use Serial.println instead of Serial.print. If you need something else as a delimiter, print it directly, like:

Serial.print(data1); Serial.print(",");
Serial.print(data2); Serial.print(",");
...
Serial.println(data5);

Mikal

Thank you Mikal!

I have nw got an accelerometer sending data! thank you.

The next thing, i have it sending over xbee to the recieving arduino, on the serial screeen of the arduino programmer, it doesnt display the correct data im sending - is this because its ascii characters?
This is my code so far:

int accPinY = 0; // input pin for the accelerometer Y
int accPinX = 1; // input pin for the accelerometer X
int val1 = 1; // values norm 0, but set as demo numbers
int val2 = 2; //

void setup() {
Serial.begin(9600);
}

void loop() {
//val1 = analogRead(accPinY); // read the value from the sensor
//val2 = analogRead(accPinX); // read the value from the sensor
//Serial.print("I read: ");
Serial.print(val1, DEC);
//Serial.print("a");
//Serial.println(val2, DEC);
delay(100);
}

on the recierving serial screen, i just get a huge list of '?' (question marks) looking at the ascii table, this doesnt represent 1,2 or any other number vaguly like this.

i tried BYTE and its the same

can you help with this problem?
thanks so far!

nat :slight_smile:

It might very well be. Without knowing the specifics of your projects, I can tell you that a common mistake is to send ASCII data when binary data is expected and vice versa. Just know that:

byte b = 49;
int i = 49;

Serial.print(b); // This sends a single binary byte 49
Serial.print(i); // This sends ASCII '4' followed by ASCII '9'
Serial.print(b, DEC); // This is how to force ASCII printing of bytes
Serial.print(i, BYTE); // This is how to force binary "printing" of integers

Mikal

again thankyou for the quick reply.

I shall describe my project to help.

basically i am trying to build a sort of controller using different sensors, which communicates wirelesly to a mac with maxMSP.
the first test is using an accelerometer (2way - X and Y)
I am trying to read the analogue values - connected to analogue inputs 0 and 1, and then send using xbee to an xbee recieving board - an arduino board without chip but with an xbee board connected.

the code im using currently is above in my previous post.
the data is being sent and i can recieve it on the serial screen of the arduino programmer, but it just displays a series of '?' characters, or other odd characters. looking at the ascii table, ? doesnt seem to be a character to expected - whilst using val = 1 and 2 for testing, as 1 or 2 is
bin oct dec hex
011 0001 061 49 31 1
011 0010 062 50 32 2

so i dont get anything that resembles that.

please help :slight_smile:

nat

Nat, if you are seeing "?" or "other odd characters", you are almost certainly trying to interpret binary data as if it were ASCII. I haven't played with XBee, but I'll bet it is using binary bytes that can't be easily interpreted in text form. To use your example, if I write an Arduino program that sends a binary 1 to the Serial console, it draws a little square box, because binary 1 doesn't have a representable ASCII value. I think you were expecting too see an ASCII '1', which is decimal 49.

Mikal