We’ve been playing with Arduinos for the last few weeks. Yesterday I bought a Freetronics Dot Matrix Display (DMD) from Jaycar for $30 or so, and I’ve cobbled together a couple of scripts to drive some RSS content to it. It works 🙂
I have a SainSmart Mega 2560, but there’s no reason this shouldn’t work with any Uno compatible. Note – this DMD doesn’t work with the Mega unless you overwrite a couple of files (Thanks @TheRevva for sharing)
Before starting, two ruby gems are needed – SerialPort and FeedJira -thanks @johndagistino [protected] for the steer. It’s also worth spending time going through the code samples Freetronics have made available on github – linked at the bottom their product page
Note – I still have a problem with serial comms in that it doesn’t work unless I have the Serial Monitor open.
gem install serialport gem install feedzilla
This is the ruby test script that I’ve used to grab two rss feeds, and pass the headlines in one at a time into to Arduino over the serial port.
require "serialport" require "feedjira" def showfeed(feedurl) #params for serial port port_str = "/dev/tty.usbmodem621" #NB port may be different for you, copy this from port selected in Arduino IDE baud_rate = 9600 data_bits = 8 stop_bits = 1 parity = SerialPort::NONE sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity) feed = Feedjira::Feed.fetch_and_parse(feedurl) sp.write feed.title puts feed.title sp.write " " sleep(8) feed.entries.each do |entry| sp.write entry.title puts entry.title sp.write " " sleep(8) end end showfeed('http://feeds.smh.com.au/rssheadlines/top.xml') showfeed('http://www.theverge.com/rss/frontpage')
And lastly, the Arduino sketch to drive the rss feed onto the display:
// dmd-rss.ino #include "SPI.h" #include "DMD.h" #include "TimerOne.h" #include "Arial_black_16.h"<arial_black_16.h> // you can remove the fonts if unused #include "SystemFont5x7.h" #define DISPLAYS_ACROSS 1 #define DISPLAYS_DOWN 1 /* change these values if you have more than one DMD connected */ DMD dmd(DISPLAYS_ACROSS,DISPLAYS_DOWN); void ScanDMD() { dmd.scanDisplayBySPI(); } void drawText(String dispString, int scrollspeed) { dmd.clearScreen( true ); dmd.selectFont( SystemFont5x7 ); char newString[256]; int sLength = dispString.length(); dispString.toCharArray( newString, sLength+1 ); dmd.drawMarquee(newString,sLength,( 32*DISPLAYS_ACROSS )-1 , 0 ); long start=millis(); long timer=start; long timer2=start; boolean ret=false; while(!ret){ if ( ( timer+1000-scrollspeed ) < millis() ) { ret=dmd.stepMarquee( -1 , 0 ); timer=millis(); } } } void setup() { Serial.begin(9600); Timer1.initialize( 5000 ); /*period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.*/ Timer1.attachInterrupt( ScanDMD ); /*attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()*/ dmd.clearScreen( true ); /* true is normal (all pixels off), false is negative (all pixels on) */ } void loop() { String content = ""; char character; while(Serial.available()) { character = Serial.read(); content.concat(character); Serial.println(content); } if (content != "") { drawText(content,980); delay(1000); dmd.clearScreen( true); delay(500); } else { delay(500); } }