Arduino/LCD tests
I got this cool LCD from Adafruit. It has a tutorial for connecting it to an Arduino.
I wrote a tiny driver with web.py and spawning. Spawning has the cool feature of being able to use eventlet to handle multiple simultaneous requests in one process, in one thread. This helps me share my single USB port with all the requests; I didn't have to write any special queuing stuff. I would have gotten that property for free with twisted, too, but twisted.web and nevow are more complicated to use.
My code is essentially this:
import web, serial
ser = serial.Serial(port='/dev/ttyUSB1', baudrate=9600, timeout=1,
xonxoff=0, rtscts=0)
class index(object):
def POST(self):
ser.write("\xff" + web.data() + "\x00") # I made up this protocol and implemented it on the arduino side
return "ok"
urls = (r'/', 'index')
app = web.application(urls, globals())
application = app.wsgifunc()
# spawn --port=9017 --threads=0 host.application
This is probably more than one needs just to connect an LCD to a computer, but I intend to run several other sensors and light controls off the same Arduino, so my web server will be getting more elaborate.
In the meantime, I can run unix shell commands onto the LCD:
% forever { date | curl -d @- http://dash:9017/; sleep 1 }
Or I can do a live search on twitter and display its results on the LCD:
import sys, restkit, jsonlib, urllib
login = "...", "..."
keyword = sys.argv[1]
response = restkit.request(
"http://stream.twitter.com/1/statuses/filter.json?track=%s" %
urllib.quote(keyword), filters=[restkit.BasicAuth(*login)])
for out in response.body_stream():
text = jsonlib.read(out)['text']
print text
restkit.request(method="post", url="http://dash:9017/", body=text)