So here are a few notes on getting a Chumby to talk to an Arduino using PySerial (and Python). It’s pretty easy, but I’ll document it to make it obvious. As the Chumby is sometimes a bit slow with a few of these steps, it’s good to know it will work in the end.
First you’ll want Python on the Chumby. At the time the latest version already compiled for the Chumby is Python 2.6, so it’s pretty up-to-date.
Once you’ve got Python installed and on a USB stick you’ll also want to download PySerial – I picked the latest version PySerial-2.5-rc2.
With PySerial expanded and on the USB stick (alongside Python) you’ll want to put the USB stick in the Chumby and connect to it via SSH.
Change to the directory for the USB stick (e.g.
You should see (at least) two directories, one for Python and one for PySerial:
chumby:/mnt/usb-EC5C-3D0A# ls -l drwxr-xr-x 6 root root 4096 Jun 26 21:15 pyserial-2.5-rc2 drwxrwxrwx 4 root root 4096 Jan 10 13:51 python2.6-chumby
You’re first instinct may be to try and install PySerial via the usual call to
python setup.py install. However this appears not to work.
All is not lost though – just manually copy the relevant directory (serial) from PySerial to the python site-packages directory, e.g.:
cp -r pyserial-2.5-rc2/serial python2.6-chumby/lib/python2.6/site-packages/
Know to check that’s worked open a python prompt and try to import the serial library:
chumby:/mnt/usb-EC5C-3D0A# python2.6-chumby/bin/python Python 2.6.2 (r262:71600, May 23 2009, 22:28:43) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import serial >>>
If you don’t see any errors (as above) then everything has installed ok.
Next step is to try out connecting an Arduino.
So first off you’ll want to ensure the Arduino has a program that can read from the serial port – to show that everything is working ok. In my case I picked my Morse Code program. This will read bytes from the serial port and toggle the built-in LED (on pin 13), so it’s handy for verifying the serial port is working.
So now you have a program loaded on the Arduino, connect it to the Chumby. The Arduino should get enough power from the Chumby to start up ok.
You need to work out which serial port the Arduino is using on the Chumby. List the tty’s in /dev and pick the most likely looking one (should have USB in it’s name):
chumby:/mnt/usb-EC5C-3D0A# ls /dev/tty* /dev/tty /dev/ttyS00 /dev/ttyS02 /dev/ttyS1 /dev/ttyS3 /dev/ttyS0 /dev/ttyS01 /dev/ttyS03 /dev/ttyS2 /dev/ttyUSB0
On my Chumby the serial port was
Now open up a python prompt again and try talking to the Arduino. You’ll need to configure the baud-rate of the serial port to match the program on the Chumby. In my case this was 9600.
chumby:/mnt/usb-EC5C-3D0A# python2.6-chumby/bin/python Python 2.6.2 (r262:71600, May 23 2009, 22:28:43) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import serial >>> ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1) >>> ser.write('sos') 3
If you are using the same morse code program you should see the LED blink out ‘DOT-DOT-DOT DASH-DASH-DASH DOT-DOT-DOT’ – confirming that the serial port works.
This is really quite handy, as the Chumby is a small low-power Linux server. Coupled with Python this means it’s really easy to get any Arduino based project online, without needing a “normal” computer constantly running. Not quite as self-contained as using an Ethernet Shield, but the Chumby is fairly small, so it and an Arduino will easily sit on a window ledge (for example).