Introduction: An Arduino RSS Feed Display

This Arduino project will display RSS feed headlines on an LCD via an Arduino and a USB cable. It works quite well, and lets you keep up with the world news while you're sitting at your desk. Many of the values in the code can be changed, and the system can be adapted to display Twitter and other information as well. It uses Python to interface with the Arduino.

All of the code and instruction provided is done so with no guarantee of success. I've bugtested the code to the best of my ability, and it should work in most cases, but certain things can throw it off. Details of such are within.

Step 1: Required Pieces/Parts for the Project

The project requires very few parts, generally things that most people with Arduinos will have lying around somewhere:

(1) Arduino Uno board
(1) Breadboard (I used a MakerShield prototyping shield instead, but a breadboard works just as well, albeit less compact)
(1) LED, your choice of color
(>12) Breadboard cables
(1) 16x2 Character LCD display, compatible with the LiquidCrystal library (works with larger LCD's with tweaking)
(1) Potentiometer, preferably 10K ohms.
(1) USB to USB-B cable (standard USB-to-Arduino cable)

Step 2: Wiring Up the LCD and the LED

The LCD should be wired up as is shown in this picture (given it's a 16x2 LCD that uses the HD44780 driver). Potentiometer controls the contrast. It should also be noted that most LCD's use pins 15 and 16 on the LCD as the +5v and GND for the backlight.

Picture is from http://arduino.cc/en/Tutorial/LiquidCrystal. Make sure you test it using the "Hello World!" program described. The screen may need to have the contrast turned all the way up for it to display properly.

The LED just goes in digital pin 13 and the GND pin next to it. Make sure the polarity is correct (Longer leg should be the + leg, short legs goes to ground).

Step 3: Getting the Required Software and Libraries

2 pieces of software and 2 Libraries/Extensions are needed for this project to work. The first library is an Arduino Library called LiquidCrystal440. It is available here: http://code.google.com/p/liquidcrystal440/. It is an updated version of the LiquidCrystal library, and helps deal with some issues when it comes to addressing memory that isn't currently visible on the screen.

Obviously to use the LiquidCrystal440 Library, you will need the first piece of software: The Arduino coding interface, which I assume all Arduino users have (if not, just check the Arduino.cc website)

The second piece of software you will need is Python. Python is an easy to learn programming language for the PC, Linux, or Mac. It is available for free here: http://www.python.org/.

The final thing you need is the extension that will let the Python computer program work with the Arduino itself, via the serial cable. The required extension is Pyserial, available here: http://pyserial.sourceforge.net/. Make sure you get the correct version of Pyserial to work with your version of Python (2.7 to 2.7, 3.1 to 3.1, etc).

Step 4: The Arduino Code

// This code is for the Arduino RSS feed project, by Fritter
// Read the comment lines to figure out how it works

int startstring = 0;     // recognition of beginning of new string
int charcount = 0;     // keeps track of total chars on screen
       
#include  <LiquidCrystal.h>  // import the LiquidCrystal Library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
         Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
         lcd.begin(16,2);            // Initialize the LCD size 16x2. Change if using a larger LCD
         lcd.setCursor(0,0);     // Set cursor position to top left corner
         pinMode(13, OUTPUT);
}

void loop() {
        char incomingByte = 0;   // for incoming serial data
       
         if (Serial.available() > 0) {        // Check for incoming Serial Data
                 digitalWrite(13, HIGH);
                 incomingByte = Serial.read();
                 if ((incomingByte == '~') && (startstring == 1)){            // Check for the closing '~' to end the printing of serial data      
                   startstring = 0;                                                                  // Set the printing to off
                   delay(5000);                                                                     // Wait 5 seconds
                   lcd.clear();                                                                         // Wipe the screen
                   charcount = 0;                                                                   // reset the character count to 0
                   lcd.setCursor(0,0);                                                          // reset the cursor to 0,0
                 }
                 if (startstring == 1){                                                             // check if the string has begun if first '~' has been read
                   if (charcount <= 30){                                                        // check if charcount is under or equal to 30
                     lcd.print(incomingByte);                                                // Print the current byte in the serial
                     charcount = charcount++;                                             // Increment the charcount by 1 yes I know it's awkward
                     }
                   }
                   if (charcount == 31){                                                         // if the charcount is equal to 31 aka the screen is full
                     delay(500);
                     lcd.clear();                                                                        // clear the screen
                     lcd.setCursor(0,0);                                                         // set cursor to 0,0
                     lcd.print(incomingByte);                                                // continue printing data
                     charcount = 1;                                                                 // set charcount back to 1
                   }
                  
                 if (incomingByte == '~'){                                                    // Check if byte is marker ~ to start the printing
                  
                   startstring = 1;                                                                  // start printing
                 }
         }
                 digitalWrite(13, LOW);
                 delay(10);                                                                            // 10ms delay for stability
             } 

Step 5: The Python Code

#import library to do http requests:
import urllib2
#import pyserial Library
import serial
#import time library for delays
import time

#import xml parser called minidom:
from xml.dom.minidom import parseString

#Initialize the Serial connection in COM3 or whatever port your arduino uses at 9600 baud rate
ser = serial.Serial("\\.\COM3", 9600)
i = 1
#delay for stability while connection is achieved
time.sleep(5)
while i == 1:
     #download the rss file feel free to put your own rss url in here
     file = urllib2.urlopen('http://news.sky.com/feeds/rss/world.xml')
     #convert to string
     data = file.read()
     #close the file
     file.close()
     #parse the xml from the string
     dom = parseString(data)
     #retrieve the first xml tag (<tag>data</tag>) that the parser finds with name tagName change tags to get different data
     xmlTag = dom.getElementsByTagName('title')[2].toxml()
     # the [2] indicates the 3rd title tag it finds will be parsed, counting starts at 0
     #strip off the tag (<tag>data</tag>  --->   data)
     xmlData=xmlTag.replace('<title>','').replace('</title>','')
     #write the marker ~ to serial
     ser.write('~')
     time.sleep(5)
     #split the string into individual words
     nums = xmlData.split(' ')
     #loop until all words in string have been printed
     for num in nums:
          #write 1 word
          ser.write(num)
          # write 1 space
          ser.write(' ')
          # THE DELAY IS NECESSARY. It prevents overflow of the arduino buffer.
          time.sleep(2)
     # write ~ to close the string and tell arduino information sending is finished
     ser.write('~')
     # wait 5 minutes before rechecking RSS and resending data to Arduino
     time.sleep(300)

Step 6: Getting It to Work.

Upload the Arduino Code to the Arduino itself. Put the Python code into a .py file. If all goes according to plan, if you run the .py file, you should see the text start appearing after about 10 seconds. Every time a word is outputted, the LED should flash as well.


If it doesn't work:

Check the port in the python file. Your Arduino may be labeled differently or be numbered differently.

Check that the RSS feed doesn't have a ~ in the data. That will throw things out of whack.

Try running the .py file from the command line as an administrator. Sometimes the script doesn't have proper permissions to access the COM ports.

Comments

author
RichardD79 (author)2016-02-01

I've hit a problem: "TypeError: unicode strings are not supported, please encode to bytes: '~'

-I'm very new to Arduino & Python but I believe the problem is the above code is Python 2, and I'm using Python 3. Can anyone please help? Thank you.

author
rikiris (author)RichardD792016-09-19

found it. looks like the lcd cannot support unicode (only support ascii) so in python script change line : ser.write(num) to ser.write(num.encode('UTF-8'))

and the rss url is also not valid anymore, be carefull. it's just prototype so you have to revise all code based on your needs.

Screen Shot 2016-09-20 at 1.52.49 PM.jpg
author
rikiris (author)RichardD792016-09-19

did you found that problem? im having same errors

author
russ_hensel (author)2016-01-23

I love the combination of Python and the Arduino. So I have created a collection about it. I have added your instructable, you can see the collection at: >> https://www.instructables.com/id/Arduino-and-Pytho...

author
ChristianV3 (author)2015-05-05

How would I make this display weather forecast?

author
surya raju (author)2015-02-12

Is the entire board really necessary, i.e. can't I get the results with a standalone arduino circuit?

author
Geeve George (author)2014-12-23

I got this error when I ran the code in phyton , please help me out!

Error.png
author
casey.lisak (author)2014-10-15

Can this be done with a LED matrix?

author
misadeks (author)2014-10-12

I made this!! It's so cool here's the photo.

temp_454638578.jpg
author
misadeks (author)2014-05-18

How can you use arduino code for a 20x4 LCD?

I tried changing the size in the code, but it does not work. When it comes to the second line it clears the lcd and the other part is displayed. Please help.

author
jkctech (author)2013-12-23

Is there way to use multiple lines? i use this feed: http://feeds.feedburner.com/p2000-regio-noord-holland-noord which is a feed of the 911 calls nearby my village. i tried changing the charcount, but im not very good with arduino. PLEASE HELP ME

author
tkadere (author)2013-11-17

I'm getting this error. What does this mean. Apologies I have never used python before.

line 39, in
ser.write(num)
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 283, in write
data = to_bytes(data)
File "C:\Python27\lib\site-packages\serial\serialutil.py", line 76, in to_bytes
b.append(item) # this one handles int and str for our emulation and ints for Python 3.x
TypeError: an integer or string of size 1 is required

author
tkadere (author)tkadere2013-11-18

I found a solution. I put this line num=str(num) just before ser.write(num) so python recognises num as a string

author
techno guy (author)2013-02-10

i also think that the settings for the ports have also been changed

author
techno guy (author)2013-02-10

i think you need to rewrite the python code because an update meshed urllib2 into urllib, i'm trying to debug it, but this is my first time seeing python, luckily programming is my thing

author
mshah9 (author)2012-09-22

great work!! But there is one problem I have came across after implementing this. What is news contents contains " 's " as part like in " that's " then this Python script is unable to parse it and send it to arduino via serial so any help on this ??

author
callemang (author)2012-09-18

Very cool. Thank you for posting. I have gotten it work but it doesn't use the second line of text, therefore words are not showing up. I think there is an error in the Arduino code because if I use Arduino's example serial display it works but it only prints one word then reprints the whole screen. Help? Please

author
fritterdonut (author)callemang2012-09-18

What size is your LCD display?

author
callemang (author)fritterdonut2012-09-19

Could it be a problem with the LiquidCrystal Library? I don't exactly understand that part of it. Am I supposed to put the .h file in a certain place?

author
callemang (author)fritterdonut2012-09-18

16x2. Hello World works with the second timer at the bottom.

author
zmashiah (author)2012-07-31

Very nice project.
I was wondering, if I do have the PC working on chewing up the web data, why do I need Arduino at all? I mean, I can have a much cheaper USB-to-Serial connecting the USB port of the PC to an LCD. As a matter of fact, CrystalFontz sell USB connected LCD screens, so the PC could simply manage the display too.

author
kd8bxp (author)zmashiah2012-08-05

I did something like this awhile ago using a beta-bright moving message sign, PHP script, and a home made serial cable, works quite well, I use it right now to display weather information and forecasts, but it can be used to do just about anything else that you would like displayed. In fact it works so well that I got myself a 2nd larger sign for the living room (Wife doesn't really like that one thou LOL) http://youtu.be/VoiIjmh4Qrg - Thought you might be interested thou because it just uses the computer and the beta-bright display protocol.

author
zmashiah (author)kd8bxp2012-08-05

Thanks kd8bxp (And I must admit is sounds like Radio Amateur code),
I did play with CrystalFontz a while back. Recently built few things where the micro-controller is basically standalone, connect to the Internet and display stuff on visual screen. See my Instructables. If the display is a small VGA one it has a higher wife-acceptance factor :-) The "old" 15" LCD display has now good use in the living room

author
fritterdonut (author)zmashiah2012-07-31

In this case the Arduino just manages the LCD and pieces together incoming words into proper, readable format. If you had a plain LCD with a USB connector and the proper software to interface with it via USB, then you could just use the screen.

I used the Arduino because I had it on hand and this was never meant to be a permanent build. I built it for fun, got it to work then took it apart and went onto the next Arduino project.

author
zmashiah (author)fritterdonut2012-07-31

I know about fun, and totally agree with that.

author
brndnlstr (author)2012-07-29

I could be wrong, but charcount=charcount++; won't do anything.

If you want to increment, you only need this:

charcount++;

That will increment by one.

author
fritterdonut (author)brndnlstr2012-07-29

It will in fact add 1 to the total, but it is redundant.

the ++ modifier essentially acts as variable = variable + 1

So in this case it says variable = variable = variable + 1

It works, but should simply say charcount++ for the sake of simplicity and easier reading. Thanks for pointing it out.

author
xenomachina (author)fritterdonut2012-07-30

Technically, the behavior is "undefined" which means it might do what you want, or it might not. The actual behavior is up to your C compiler, and *any* behavior is permitted, including not compiling the code, or producing code with wildly unexpected behavior.

In case you care: the reason it's undefined is that the C language spec says modifying the same variable multiple times within the same expression without an intervening "sequence point" is undefined. There are no sequence points in that expression, and charcount is being modified twice. This exact topic used to be a common question on the C programming groups on USENET. About once a week someone would ask why one compiler would behave differently than another when compiling "i = i++" (often the question was "which one is right?").

Here's a Stack Overflow question on this topic: http://stackoverflow.com/questions/949433/could-anyone-explain-these-undefined-behaviors-i-i-i-i-i-etc

author
fritterdonut (author)xenomachina2012-07-31

Thanks for the definitive answer. So while I can confirm it would work properly for me, it might not work properly if you use a different compiler. Really is playing a game of chance with your code, I guess.

author
reliason (author)2012-07-31

If you get a could not open port error try finding the correct port this way:

In terminal type: python -m serial.tools.list_ports
Find the port matching the one in the Arduino settings and copy paste into your python script.

author
palestinian-warrior (author)2012-07-29

this is really simple
and impressive
but the python language , this is the first time i see somebody using it in arduino
really really goooood

big thank you bro
even your project is simple but a new stuff has been learned today

author
knownware (author)2012-07-27

This is very cool. I like this a lot.

author
fritterdonut (author)2012-07-26

Fixed the code on the instructable. Thanks for pointing it out.

author
hankenstien (author)fritterdonut2012-07-27

no problem I'm glad Icould help, its little things like that that are usually the reason why something doesn't work.
Or in my case, I for get the ; or even just one space in the wrong place.
but I've dealt with this thru .html .php .pl /.cgi now a little C with the arduino, and Ive been noticing python gaining some ground again lately, so Ive been thinking about dabbling in it. any way good day and keep them coming.

author
hankenstien (author)2012-07-26

This is Pretty cool, and from the looks of the code it might be just simple, yet interesting enough to get me into python
Nice article thanks.

1. question though in the beginning of the arduino code.
Is the below lines a typo? shouldn't it include something?
or is it usingLiquidCrystal lcd(12, 11, 5, 4, 3, 2); as the include I no you said we need to download a new library but i never seen an include with pin assistants included, maybe it does not matter I'm just curious.

#include // import the LiquidCrystal Library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

About This Instructable

51,663views

142favorites

License:

Bio: Bugtesting from here to infinity and beyond.
More by fritterdonut:An Arduino RSS Feed Display
Add instructable to: