XBee perfboard hooked up to the Raspberry Pi |
The RasPi is running on Debian wheezy and the perfboard is connected via two row header sockets to the GPIO pins.
The 3.3V for the XBee is directly coming from Pin 1 of the GPIO-Header (GND from Pin 6), DOUT is connected to Pin 10 (GPIO RXD) and DIN to Pin 8 (GPIO TXD). I didn't test it with a XBee Pro attached, this will certainly draw too much current from the RasPi. The 3.3V supply only delivers 50mA as per this wiki . This is fine with the normal XBee which has 40mA max. current demand as per datasheet. If you need more current (XBee PRO needs 295mA@3.3V when transmitting with maximum output power) you could use the 5V power source with a subsequent voltage regulator as mentioned in the blog entries before. Be careful to use a voltage regulator with enough capabilities to deliver ample current.
Still enough legroom for the Raspberry Pi |
To get the whole thing working you have to modify some settings in Debian wheezy. There is a nice walkthrough in this blog.
If you want to communicate via Python you have to get pyserial (sudo apt-get install python-serial or sudo apt-get install python3-serial for Python3). Example code for Python2 to send a value to the Arduino would look like this:
import serial
xbee=serial.Serial(port='/dev/ttyAMA0',baudrate='9600')
xbee.write('8')
For Python3 you would have to change the last line to:
xbee.write(b'8')
to send as a String.
On the Arduino side you could read the incoming data with Serial.read().
Connecting the whole thing together gives a huge amount of opportunities for future projects as one can use the combined cpu power/ linux system/ graphic abilities of the Raspberry Pi and the microcotroller skills and shields of the Arduinos - everything wirelessly connected in a mesh network.
Interesting tutorial XBee for Raspberry Pi http://www.cooking-hacks.com/index.php/documentation/tutorials/raspberry-pi-xbee
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI found that your post is very impressive to understand XBee module with using Xbee tutorial. Can you tell me about more the working process of Xbee in Linux?
DeleteThanks, nice post. My issue is send AT commands to change MY, ID or whatever programming python, I'm using PySerial. ¿Do you know something about that?
ReplyDelete