Computer to Arduino XBee using C?

Greetings all!  I've been searching everywhere and I'm just needing that push in the right direction.

I have two series 1 XBee's and I would like to plug one XBee in to my computer via USB and the other will sit on an Arduino board on the wireless shield.  My computer is running Slackware Linux and I would like to use C to send and receive data with the arduino.  Does anyone have any insight to this type of problem?


txrx5 years ago

Assuming you are using an XBee Explorer http://www.sparkfun.com/products/8687 or similar to connect the XBEE to your PC

When you plug in the USB cable, your computer will see the XBEE as a regular serial port. so you should see a /dev/ttyUSBx device show up. The /dev/ttyUSBx works just like any other file.

So you could send a command over the xbee, by doing something like this

echo "hello world" > /dev/ttyUSB0

or you can watch for incoming data with

tail -f /dev/ttyUSB0

The fopen() is C's stdio would be able to open this file. for more info see this forum post: http://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-read-and-write-to-dev-ttyusb0-in-c-675382/ 

mal10c (author) 5 years ago
Hey Joshnuss,

That worked!! I was able to take what you said and make the receiving end too on the Aruino board. I was definitely making that more difficult than it should have been.

In the end, on the Arduino board, I created a standard serial reader using Serial.read() and I switched the little switch on the arduino shield from USB to micro. Then uploaded the sketch.

On the linux side, I just did the echo command that you recommended and probably woke up most of my neighbors from the excitement.

Thanks so much!