Skip to main content

How to Make a Raspberry Pi RSS News Ticker

Raspberry Pi RSS News Ticker
(Image credit: Tom's Hardware)

Keeping up to date with the latest news is tough and sometimes we need a little help. RSS feeds provide a great way to quickly digest lots of news quickly. Sure you could visit an RSS feed or have an RSS reader on your computer, but what if you could have a simple, dedicated device that only shows the headlines?

Here’s a Raspberry Pi project that will use Python code to read an RSS feed, the Tom’s Hardware feed for example, and display the top five headlines on an LCD screen.

To build this project you will need:

  • Any model of Raspberry Pi with Raspberry Pi OS and GPIO Pins
  • An I2C LCD screen such as this one
  • 4 x Female to female jumper wires

1. Install Python libraries to use LCD screens and work with RSS feeds by entering the following commands:

sudo pip3 install rpi-lcd feedparser

2. Enable the I2C interface via Preferences >> Raspberry Pi Configuration

(Image credit: Tom's Hardware)

3. Connect the I2C LCD screen as per the diagram. 

(Image credit: Tom's Hardware)

4. Launch Thonny. You can find it on the start menu under Programming.

5. In a new file import libraries of Python code to use the LCD screen, control the pace of the project, read the RSS feed and finally manipulate text into chunks. 

from rpi_lcd import LCD
from time import sleep
import feedparser
import textwrap

6. Create an object, called “tom” which will store the RSS feed data from Tom’s Hardware. 

tom = feedparser.parse("https://www.tomshardware.com/uk/feeds/all")

7. Create a connection to the LCD and then pause the code for 1 second. 

lcd = LCD()
sleep(1)

8. Use a for loop to repeat code five times. If you want more than 5 headlines, change the (5) to a higher number. 

for i in range(5):

9. Print the entries from the Tom’s Hardware RSS feed. The value of i is incremented each time the for loop goes round, to a maximum of five. 

          print(tom['entries'][i]['title'])

10. Create an object called split and use that to save 16 character chunks of the RSS feed. The chunk size is set by the 16 character screen size of the LCD. 

split = textwrap.wrap(text, 16)

11. Create an object called split and use that to save 16 character chunks of the RSS feed. The chunk size is set by the 16 character screen size of the LCD.

split = textwrap.wrap(text, 16)

12. Print “Tom’s Hardware” (or the name of your news source) to the first line of the LCD screen. 

lcd.text("Tom's Hardware", 1)

13. Create another for loop to print the contents of the split object to the LCD screen.

        for i in range(len(split)):
    	lcd.text(split[i], 2)
    	sleep(0.5)

14. Add a one second pause before clearing the LCD screen.

     sleep(1)
lcd.clear()

15. Save the code as TomsRSSFeed.py 

16. Check your code against our complete code listing. 

from rpi_lcd import LCD
from time import sleep
import feedparser
import textwrap
tom = feedparser.parse("https://www.tomshardware.com/uk/feeds/all")

lcd = LCD()
sleep(5)
for i in range(5):
	print(tom['entries'][i]['title'])
	text = tom['entries'][i]['title']
	split = textwrap.wrap(text, 16)
	lcd.text("Tom's Hardware", 1)
	for i in range(len(split)):
    	lcd.text(split[i], 2)
    	sleep(0.5)
	sleep(1)
lcd.clear()

17. Click on Run to start the code. 

(Image credit: Tom's Hardware)