I have 2 Arduinos each with a Xbee Radio (XBee Pro 60mW Wire Antenna - Series 1 (802.15.4) - WRL-08742 - SparkFun Electronics) on a regulated board (SparkFun XBee Explorer Regulated - WRL-11373 - SparkFun Electronics) The one Ardunio is a MEGA, I have the Xbee connected on Serial2
On the Arduino Micro I have the Xbee connected to Serial 1. Basically what I am asking is how to change the baud rate correctly. When I run the Xbees with a baud of 9600 from the Arduino sketches they work beautifully. if I increase it to say 115200 all I get is 0's from one Arduino to the other. Does anyone have any idea what is going on here?
Does anyone have any idea what is going on here?
I'm going to guess that it's your code.
Is there anything else I need to change besides what is below on each Ardunio?
On Ardunio MEGA
Serial2.begin(9600); ---> Serial2.begin(115200);
On Ardunio Micro
Serial1.begin(9600); ---> Serial1.begin(115200);
by simply changing just this causes the code to not work correctly.
Is there anything else I need to change besides what is below on each Ardunio?
Yes. The baud rate that the Arduino talks to the XBee needs to match the baud rate that the XBee talks to the Arduino.
PaulS:
Is there anything else I need to change besides what is below on each Ardunio?
Yes. The baud rate that the Arduino talks to the XBee needs to match the baud rate that the XBee talks to the Arduino.
So how exactly do I go about configuring the Xbee to talk to the Ardunio at the correct Baud rate?
So how exactly do I go about configuring the Xbee
Using the X-CTU program from digi.com.
So basically I would remove the Xbee from the adapter that is connected to my Arduino, plug it into a USB xbee adapter and then configure the Xbee? Does the Xbee have some sort of internal memory that remembers the settings?
Does the Xbee have some sort of internal memory that remembers the settings?
Of course it does. That's how it remembers it's address, it's network, and who it's supposed to talk to.
I configured the Xbees to work with a 115200 baud rate. I set my code to connect with a baud of 115200. My original code does not work though. I put some debugging lines to send the Xbee data to the computer's serial monitor.
So on my Arduino Mega I have this
Serial2.write(1); Serial2.write(101);
On the Micro I have this
robotID_A = Serial1.read();
if(robotID_A == 1 )
{ delay(30); robotID_B = Serial1.read();}
On the micro it receives the 1 correctly but then for robotID_B I get -1 or about 1/10 times I get 1 ; What exactly do I have to do to my code to get it to work correctly? When I had the baud rates at 9600 all of my code worked beautifully.
I'm sure that the fine folks at http://snippets-r-us.com can help you with your snippets. Here, not surprisingly, we need to see ALL of your code.
I'd guess, though, that you are simply hoping that the two bytes arrive quickly enough. The time between two bytes is dependent on the baud rate.
I figured that no one would read my code mainly because it is huge and honestly quite messy.
But here it is. I am sorry if it is difficult to read.
I tried putting it into the code brackets but the Forum told me it exceeded the maximum allowed length of 9500 characters. I attached the two pieces of code as files.
Mega.ino (20 KB)
micro.ino (14.9 KB)
#include <SoftwareSerial.h>
On a Mega with 4 hardware serial ports?
You don't even create an instance of the class. Including the class definition is silly.
if(inches_1 < 6 || inches_1 > 13 ) {digitalWrite(ledPin_1,HIGH);}else{digitalWrite(ledPin_1,LOW);}
Rubbish. Spread this over multiple lines properly. You are not charged by the line.
This is what I suspected that you were doing:
if (Serial1.available())
{
int robotID_A = Serial1.read(); int robotID_B = 0; if(robotID_A == 1 ){ delay(30); robotID_B = Serial1.read(); }if(robotID_B == 101 )
{
int tempid = Serial1.read(); NoGo = 0;
If there is 1 byte available to read, you read 2 or 3 of them. Wrong. You must make sure that there is something to read, or wait for it, before EVERY read.