Here is a quick note on using USB serial with Python. I hooked up a Sparkfun explorer board with a Xbee series 1.
|Sparkfun Xbee Explorer|
First you need to install the Serial library:
apt-get install python-serial
The Sparkfun adapter uses FTDI so it shows up as
I found this, it works really well.
Simple TCP/IP bridge
I started with this link:
I couldn't get it to show data from the Xbee at first so I used Minicom to test:
Somehow it started working once I saw data using Minicom.
Here is the final code to test read from serial with Python
#!/usr/bin/python import serial ser = serial.Serial('/dev/ttyUSB0', 9600) ser.open() try: while 1 : result = ser.readline() print result except KeyboardInterrupt: ser.close()
Now I don't need to use my desktop as a Serial-TCP/IP gateway and I can use Python to process the data from the Smart Outlet or anything else. Or talk directly to my robots.
This raspberry Pi is becoming more helpful by the day.
Now I am not sure if multiple devices can use the serial at the same time, have to look into that or combine a the TCP/IP server with extra later for processing data. Maybe I could make all my Python script use the TCP/IP gateway instead of Serial. I might use API mode on the xbee to talk to multiple xbees or have packet headers to know which device they come from.
Update: The first time I did this it worked, then while writing this I couldn't get it to work again. I will have to try again later with a powered USB hub, but I am pretty sure that isn't the problem. It is the same problem I have originally where there isn't any output from the Xbee. Now Minicom just exits instead of showing the data from the Xbee.
08/28/2012 Update 2: I ended up connecting the Xbee to the UART. You need to disable getty first which you can find here: http://www.irrational.net/2012/04/19/using-the-raspberry-pis-serial-port/
After I got it working on the UART minicom still wouldn't work. Then I realized it has to be run with SUDO! D'oh! Now I might try the USB again, but reading it via Python didn't work over USB anyway, which I did run with Sudo. At least now I freed up a USB port. I have to at least try USB again.
08/28/2012 Update 3: I tired again with USB and it works but only if you run Minicom first using sudo. Once you do that then the Python script will work. I am going to stick with using the UART which works perfectly.
If you get it to work reliably let me know in the comments.