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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import feedparser
import time # for delays
import serial

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
def log(string):
    if logfile:
        f = open(logfile,'a')
        f.write(string)
        f.write("\n")
        f.close()
        print string
    else:
        print string
       
while 1: #loop forever retrieving new data ever delay seconds
    try:
        try:
            string = "<%s>Checking for new data: " % time.strftime('%x %X')
            feed = feedparser.parse('http://feeds2.feedburner.com/hackaday/LgoM')
            msg = feed.entries[0].title.encode('ascii', 'ignore') # get first post title and ensure its in proper ascii
            if msg == msgOld:
                string += "No new data."
        except:
            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"
            i=0
            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
                i+=1
               
        log(string) #print data to screen OR send to logfile
        time.sleep(delay)
    except KeyboardInterrupt:
        print '^C received, shutting down'
        exit()