XBee S2 Arduino RC Car

Let me start off by saying that I’m a newb.

I am taking an introduction to robotics class and for my final project I am turning my currently lego-Arduino Uno robot into a remote control. Simultaneously, I’m working on a project for another class where we will eventually be required to set up a ZigBee network using XBee Series 2 modules. I decided, "hey, why not kill two birds with one stone by familiarizing myself with these early–while making a cool RC car for my project?’ Now, about 48 sleepless hours later, I’m regretting not going with the “plug-and-play” XBee S1 chips for this project that is due next Thursday.

Here is my hardware:

~The two XBee S2 modules are: https://www.sparkfun.com/products/10414

~I’m using an XBee Serial USB: https://www.sparkfun.com/products/8687

~I was using the Explorer Regulated (https://www.sparkfun.com/products/11373) but had a bit of a soldering incident, so now I am using a Seeed Studio:http://www.seeedstudio.com/depot/xbee-shield-p-419.html.

~I have access to two Arduino Uno’s: https://www.sparkfun.com/products/11021

~The two motors are Lego XL motors (http://shop.lego.com/en-US/LEGO-Power-F … Motor-8882) driven from an ArduMoto board: https://www.sparkfun.com/products/9896

Here are my questions/problems.

FIRST: A question about the XBee Serial USB Board:

After I initially fried my Explorer Regulated board, I tried simply hardwiring BOTH XBees into my Arduino Unos using the 3.3V output, ground, RX and TX, and hardwiring in the reset pin to ground on the Unos. This worked great! I was able to make one XBee set to Router AT mode, talk to another XBee set to Coordinator AT using the terminal in the X-CTU program. I then tried hooking one of the XBees–into the remaining Serial USB board–into the Arduino Uno in the same fashion (5V (I also tried the 3.3V pin), ground, RX and TX), so I could monitor the boards LED for transmission confirmation. When I used the Serial USB board WITH the Uno, X-CTU would not recognize it. Not sure what’s up with that… I’d like to be able to have the LED confirmation lights, while still using the Arduino to power the XBee.

SECOND: Those… strange… data packets/no data transmission:

I decided to go buy the Seeed Studio shield from RadioShack, and was quickly able to get that working so I could see the LED showing connectivity between the two, from one unit at least. Using the LED’s on this for connectivity and my two Arduino Uno’s as serial adapters, I was able to transmit data from one Arduino Uno to the other and display it on the Serial Monitor (still with one as a Router in AT mode, and another as a Coordinator in AT mode). Then, I tried to do this tutorial: http://www.youtube.com/watch?v=CzH146rR-7I where he uses an Arduino Uno connected to an XBee in Coordinator API mode, wirelessly talking to an XBee set in Router AT mode to turn an LED connected to the XBee Router on and off simultaneously making the LED on the transmitting (coordinator end) Uno turn on and off. I followed his example thoroughly, made the LED on the Arduino turn on and off, the transmission light on the Seed shield tell me it was transmitting, but nothing happened on the other end… After doing hours of research, I’m GUESSING it has something to do with knowing nothing about the data packages, addresses and all. However, I did set my modules up exactly as he did, and wrote my code to perfectly match his, so I don’t know where I could be going wrong.

My end goal, hopefully before next week is to get the two XBees to communicate, allowing me to drive the car forward, backwards, turn right and left using my laptop, via either X-CTU or the Arduino compiler, but without being able to get my XBees to work I have ABSOLUTELY no idea where to start. :o

API data packets (Frames) have the address of the target with a Checksum at the end. If you change the address, from an example to an address of a board you have, then the Checksum must also change. If this check sum is wrong at the receiving end then the entire packet is silently ignored. This sounds like what may be happening.

If you just need a wireless serial link then just run both XBees in AT mode.

When you get to the class with networking the XBee you can then learn how to use the API mode.

FYI: there have been a number of threads on using XBee S3’s in AT and API mode in this forum. I think these can be helpful to you so search for them and read.

good luck and have fun

Running it in AT mode definitely seems like it could work. I set my two UNO’s up with the two XBee’s and had them sending Serial.print statements. However I ran into some other issues:

FIRST:

While it would send a Serial.print from one XBee to the other, I cannot seem to make it allow me to manually enter a character to send using the Serial Monitor. Maybe something to do with the number of serial ports on the UNO? (I’m using RX and TX for the XBee’s). Here is my code:

The Arduino hooked up to the Router:

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

void loop()  { 
  if (Serial.available() > 0)  {
    Serial.write(Serial.read());

  }
}

The Arduino hooked up to the Coordinator:

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

void loop()  { 
  while(Serial.available() == 0);
  
  int val = Serial.read();
  
  Serial.println(val);
//  
//  Serial.println("hi");
//  
//  delay(1000);
}

The commented out Serial.println(“hi”); was sending hi from the coordinator to the router and printing out on the router’s monitor, but I cannot seem to send an inputted variable.

SECOND:

Is there some way to press keys on my computer for live command other than typing a character and hitting enter? I was hoping to drive this thing through the a,w,d,s keys by holding w down to go forward, etc… I guess I could do it by wiring in buttons, I was just hoping for a more elegant software solution.

I really do not know the UNO board so can’t help on that part.

To make things easier to troubleshoot, connect the UNO’s Serial prots to the PC without the XBees, with the proper level translation for TTL to RS232. Or use the Explorer board for the UNO to PC interface without the XBee.

Now get the UNO code serial working. Once it is working put the XBees (in AT mode which will just pass any serial data from one XBee to the other).

If you use a terminal program on you PC any character type will be sent out the PC’s serial port.

X-CTU’s terminal tab will do this and also check these other terminal programs:

TeraTerm Pro

HyperTerm

RealTerm

Putty

I have used S2 XBees for status and control of a small robot I built. It worked just like you want. I type characters on the PC keyboard that are sent to the Bot over the XBees to stop, turn, etc.

Thank you for your help! I’m getting much closer. waltr, I took your suggestion and got the Arduino’s talking using this example http://yayrobots.com/wordpress/?p=119 and then switched it out to work with the two XBee’s, the sender is in router AT mode, the receiver is in coordinator AT mode.

Here is my code:

//This is the sender
//Plug XBee tx into I/O 2, XBee rx into I/O 3

#include <SoftwareSerial.h>

#define rxPin 2      //Set up pin 2 and 3 as new serial pins
#define txPin 3

//enable these pins using the SoftwareSerial library
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void setup()
{
 pinMode(rxPin, INPUT);    //rx is set to input
 pinMode(txPin, OUTPUT);   //tx is set to ouput
 mySerial.begin(9600);      //begin communications
 Serial.begin(9600); // set up Serial library at 9600 bps
}

void loop()
{  
  //if there is no user input, it stays stuck in this while loop
  
  while(Serial.available() == 0);
  int val = Serial.read() - '0';  //read in from keyboard (in serial monitor)
  delay(500);
  mySerial.print(val);    //print it to the new serial pins
  delay(500);
  Serial.print(val);
}
//This is the receiver
//TX to RX, RX to TX

char recievedChar = 'a';
void setup()
{
 Serial.begin(9600); // set up Serial library at 9600 bps
 Serial.println(recievedChar); //Check to see if Monitor is working
}

void loop()
{
 if (Serial.available()){
   recievedChar = Serial.read();
   Serial.print(recievedChar);
   delay(100);
 }
}

The issue: The buffer within the XBee does clear. I prints out something like this:

a

a1

a12

a123

a1423

a14235

a14235

Where 'a' is the initialized character, 1 is the first character sent, 2 is the second character, etc...

I have tried Serial.flush(), but it dos nothing. I think it is the XBee has it’s own buffer that is not getting cleared out. I tried downloading this XBee library https://code.google.com/p/xbee-arduino/, but none of the commands within the library seem to work (like XBee.flush() ) but Arduino claims there are none of those commands in the library (I can’t seem to find any tutorials or instructions for the library). Am I correct in thinking it’s the buffer in the XBee? And if so, has anybody used the library? Or is there another clever way to get around this?

The XBees do have FIFO buffers but are really only used if the RTS/CTS lines are enabled for flow control.

Check the XBee setup parameters for the RTS/CTS to be disabled. Or tei these XBee pins to logic low (ground).

Where exactly is the print out from?

Another test is to disconnect the UNO serial lines from the remote XBee. Then connect the XBee Dout to Din to ‘loop-back’ the serial data. Now when you type at the PC the character should go out the PC port to the XBee, to the other XBee, out the XBee Dout pin, in the Din pin and sent back the the PC.