Well I have been trying to think of a useful application of my freshly built 32×8 LED Matrix display. I am not always the most creative individual when it comes to applying my skills so nothing was really popping into my head, until I checked the hack-a-day website for the 5th time again in one day just to see that it hadn’t been updated yet. So I wrote a quick python program that will fetch an RSS feed from hackaday.com and send the most current title over serial to my Arduino that drives the 32×8 Matrix. Now all I need to do to check if there is an update and if it sounds interesting is glance up.
For the arduino code you can refer to my last entry here http://dredx.com/electronics/?p=114
You will need to install the python libraries feedparser and setuptools as well but they will literally take 30secs to install. Just a quick note on the isntall of setuptools the easiest method is to download the easy_setup.py script from that link which is located under the “Installation Instructions” header not Downloads
import time # for delays
logfile = "RSS_log.txt" #0=disabled, set to filename for writing the logdata to(lines normally printed to console) useful for running script from pythonw so its hidden
delay = 300 #Ammount of time to delay in seconds between update checks
arduino = serial.Serial(2,115200,timeout = 1) # 2=Com3 on windows
print "Initalizing Serial port..."
time.sleep(2) #wait for initialize
msgOld = ' ' #initialize old message variable
f = open(logfile,'a')
while 1: #loop forever retrieving new data ever delay seconds
string = "<%s>Checking for new data: " % time.strftime('%x %X')
feed = feedparser.parse('http://feeds2.feedburner.com/hackaday/LgoM')
msg = feed.entries.title.encode('ascii', 'ignore') # get first post title and ensure its in proper ascii
if msg == msgOld:
string += "No new data."
pass #ignore all errors(may not be a good idea but ensures script keeps running)
if msg != msgOld: # do stuff if the message changed
string += "New data found.\n"
msgOld = msg
# write leading spaces(so it scrolls nice rather than the end touching the begining) and
# trailing newline(newline is important because it lets arduino know when we are done sending data)
string += "<%s>Wrote: %s" % (time.strftime('%x %X'),msg)
msg = " " + msg + "\n"
while i != len(msg):
arduino.write(msg[i]) #send message one character at a time so we dont hit 64 byte buffer limit of arduino
log(string) #print data to screen OR send to logfile
print '^C received, shutting down'