Arduino to Arduino XBee Serial Communication

I have two Arduinos hooked up to XBee modules. One is sending temperature data from a DS18B20 temperature sensor. The other arduino is collecting that data and displaying it on an LCD. Does anyone know how to get it to work? I got the transmitting Arduino to work and it is sending data properly if I connect the receiving xbee to my computer and looking at the X-CTU Terminal but when I receive the data on the Arduino, it is a bunch of random numbers… They are both running at 57600 Baud as well as the Arduinos. Please somebody help… I really need to finish this project fast and basically cannot move forward without solving this problem first.

I made this example program:

Send:

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

void loop()
{
Serial.print(80.87);
delay(1000);
}

Receive:

#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);

void setup()
{
Serial.begin(57600);
lcd.begin(20,4);
}

void loop()
{
if (Serial.available()) {
lcd.write(Serial.read());
delay(1000);
}
}

The result of this program is: http://www.flickr.com/photos/tabchas/4878403671/

Serial.print(80.87);

What do you want this to do? Could it be that you wanted this?

Serial.print("80.87");

Fast usually hinders reading. I suffer from that two sometimes. ;)

Jeroen

I want it to display whatever number I put in. I tried adding the quotation marks just like you put it but it still gave the same result with all the random characters and symbols...

Thanks anyway...

I'd like to see you change the receiver code a bit:

void loop()
{
  if (Serial.available() > 0)
  {
    lcd.write("Serial data received: ");
    while(Serial.available() > 0)
    {
      lcd.write(Serial.read());
    }
    delay(1000);
  }
}

This will help us determine if the problem is with the LCD or the serial data.

Does changing lcd.write to lcd.print have any effect?

I put the code that you wanted but it would not accept lcd.write("Serial received: ").... I changed it to lcd.print and it worked. It printed the words "Serial Received" Properly but it did not display the number properly from lcd.write(Serial.read());

Thanks

What does lcd.print(Serial.read()); do?

Output: http://www.flickr.com/photos/tabchas/4878874063/

I have to ask: Why the new thread for the same question you already asked? It makes it a lot harder to follow and people have to ask the same questions over again. Even worse, now, we are going backwards.

lcd.write is correct.

The numbers you are getting are not random. How many times do you think the numbers 56, 46, 48, 194 would appear in a truly random series. Those are the ASCII codes for 8, ., 0, [ch9516], and considering that it appears that your workspace is 80.8ºF, The question becomes why the other garbage is in your communications.

Is there anything else connected to your serial lines (including the USB)? Any strong sources of RF interference?

Sorry… I just thought because my post was going to the lower end of the stack I needed to repost… Did you see the pictures that I posted? It was giving these random characters… I dont think there are any interferences…

Any time there is a new post it will move back to the top. If it drops off the front page and you still need an answer it is better to “bump” the post. i.e. post a reply in the same thread yourself (perhaps only with “bump” in the text) and it will move to top of the heap. Just don’t abuse it by bumping often and it is better to write something along the lines of “Hey Guys, I tried this and that and this other thing, but I still need help.”

So, are both USB cables unplugged?

Let’s try Hello World from the sending unit. So, change the sending Arduino to use:

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup()
{
 Serial.begin(57600);
 sensors.begin();
}

void loop()
{ 
  Serial.println("Hello World. ");  
}

While you are doing as Ted suggests, change the receiver to lcd.print a space after each lcd.write, so that you can see each character separately.

It is always being powered by USB...

This is what happens with lcd.write - http://www.flickr.com/photos/tabchas/4879142679/

This is what happens with lcd.print - http://www.flickr.com/photos/tabchas/4879751232/

I'm thinking your USB connection may be the problem. USB uses pins 0 & 1, the same pins that the Arduino uses to communicate serially with the Xbee.

If your PC sends any serial data to the USB connection when the Arduino is communicating with the XBee, the data will be corrupted.

Well, clearly the lcd.print picture looks more reasonable. However, there are no spaces between the individual bytes being written, so it’s hard to tell which numbers go together.

There is no text, either.

Make the sender send “ABCDEF : 1234567890” once. Make it send the float val 12.34.

float val = 12.34;
Serial.print(val);

Have the receiver lcd.print the received data. Show the code and the lcd picture.

I hope this helps! I think I did what you asked. If there are any problems just ask!

Thanks!

Sender:

void setup()
{
Serial.begin(57600);
Serial.print(“ABCDEF : 1234567890”);
}

void loop()
{
float val = 12.34;
Serial.print(val);
}

Receive:

#include <LiquidCrystal.h>

LiquidCrystal lcd(2,3,4,5,6,7);

void setup ()
{
Serial.begin(57600);
lcd.begin(20,4);
}

void loop()
{
if (Serial.available() > 0)
{
lcd.print(Serial.read());
delay(500);
}
}

Output Video: http://www.flickr.com/photos/tabchas/4879467283/

Oh and by the way Tim Williams, I got two 9 volt batteries and I powered my Arduinos from the battery and it sill produced the same results...

Try this on the sender:

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

void loop()
{
 float val = 12.34;
 Serial.print("ABCDEF : 1234567890");
 Serial.print(val);
 for(;;){} // Wait forever
}

And this on the receiver:

#include <LiquidCrystal.h>

LiquidCrystal lcd(2,3,4,5,6,7);

void setup ()
{
 Serial.begin(9600);
 lcd.begin(20,4);
}

void loop()
{
 if (Serial.available() > 0)
 {
   lcd.print(Serial.read());
   lcd.print(" ");
 }
}

Note, especially the reduced baud rate.

Hope this helps!!!

Output: http://www.flickr.com/photos/tabchas/4880165913/

65 is the ASCII code for 'A'. 66 is B. 70 is F. 32 is space. 58 is the ':'. 54 is the ASCII code for '1'.

The data on your LCD starts on line 1, goes to line 3, then line 2 and, finally line 4.

So, the data IS being sent correctly from the sender to the receiver, via the XBees. The issue is this statement:

lcd.print(Serial.read());

The Serial.read() function's return type is byte. While it is the same size as char, the lcd.print() function handles bytes and chars differently. chars are printed as characters '1', '2', 'A', etc. whereas bytes are written as strings '54', '52', '65', etc.

The key then is to cast the value returned by Serial.read90 a char in the call to lcd.print:

lcd.print((char)Serial.read());

Try this, please.

This looks right… But I dont know for sure…

Output: http://www.flickr.com/photos/tabchas/4880957888/