Saturday, February 26, 2011

Arduino to Chumby to UDP

So after getting Chumby Python + PySerial on a USB stick, I hooked up a USB hub to the Chumby One, hooked up the USB stick to the hub (which ends up at /mnt/usb on the Chumby), and also hooked up the Arduino to the USB hub:

Then I wrote this program on the Chumby:

from socket import *
import serial
from time import sleep

while 1:
data =
if len(data) > 0:
print "Got:",data
s.sendto(data,('[my server IP addr]',10001))
print "not blocked"

Note that this program is not blocked waiting for Serial input from the Arduino. On my Internet server, I wrote:

from socket import *
s=socket(AF_INET,SOCK_DGRAM) # create UDP socket
s.bind(('[my server IP addr',10001)) # bind to port 10001

while 1:
[msg,addr]=s.recvfrom(256) # receive packet of up to 256 bytes
print "addr:",addr," message:",msg

Then everything that the Arduino sends out on Serial to the Chumby goes over UDP to my Internet server.

This is easy!

No comments: