I was wondering how to go about programming my Xbee module (XB24, version 1084) in C/C++ without using the API.
I will be attaching the XBIB-R-DEV REV4 RS232 board to a mini-ITX computer that will be running embedded linux on it called iMedia. This module will mostly be receiving data from the other XB24 unit that is contained in a circuit connected to a PIC.
I really just don’t know where to start as far as gathering information from the other Xbee to the one connected to the RS232 board, and then transmitting that data via a serial cable to my mini-ITX computer. Any pointers or docs would be helpful, as I have already looked through this entire forum for something similar to what I am trying to accomplish, but to no avail. I have also looked through the Xbee manual, but couldn’t find what I was looking for. Please Help!
First and most notably, I will likely be using the USB dev board since our Alix computer automatically recognizes the driver for the USB, but not the RS232 (I would have to load modules into the kernel, which I don’t want to mess with at this point). Which brings me to the next thing that I changed…
I switched from iMedia to an embedded Debian version called Voyage. It works very well for my purposes. I was also able to get Python on there, and pyserial, so communicating with the Xbee was a snap.
However, now I have run into a bit of a larger issue. When I am trying to do quick python scripts to the Xbee module, I will start with the following:
>>> import serial
>>> ser = serial.Serial(‘/dev/ttyUSB0’,9600,timeout=1)
>>> ser.write(‘+++’)
Right here I enter to command mode, and it appears to work, because then I will do:
>>> ser.read(10)
And it returns with:
‘OK\r’
But, as soon as I try any other AT commands, such as:
>>> ser.write(‘ATID3434’)
and then read it back:
>>> ser.read(10)
It will respond with:
‘’
So, for one reason or another it won’t ever send the OK/r that I am waiting for. I checked and the firmware is completely up to date. Anyone have any ideas? Any help would be appreciated.
Thanks for your quick response. I think that may have been part of the problem. My code now looks like this after much tinkering:
/////////
-- coding: utf-8 --
Python program to test connection to xbee
Uses serial.py from sourceforge
import serial # Import Serial class from pyserial
import time # Import time class for delays
#Create a serial instance called ser. This also opens the serial port at /dev/ttyUSB0, which is standard using the FTDI driver on linux
ser = serial.Serial(“/dev/ttyUSB0”,9600,8,‘N’,1,0,1,1,1)
#Enter into AT command mode:
ser.write(“+++”)
#Delay for 1.5 seconds to wait for ‘OK\r’
time.sleep(1.5)
print “IN AT MODE, SLEPT FOR 1.5 SEC”
#Change the PAN ID to 3434, just as a test for now
ser.write(“ATID3434\r”)
ser.write(“ATWR\r”)
print “WROTE TO MEM”
print ser.read(10) #Should return with ‘OK\r’
ser.write(“ATCN\r”)
print “ENDING COMMAND MODE”
#Close the serial (USB) port:
ser.close()
////////////
And now I seem to be getting the right output. It was also hanging up when I tried to do just ser.write(“ATID\r”). It would kill command mode here every time.
I guess my next question would be, how do I know if the PANID changed to 3434? Is there a real easy way to check that?
Thanks so much in advance. You have been a major help thus far.