Samik Saha
Published © GPL3+

Twitter Feed Display Using Raspberry Pi And 20x4 LCD

Build a Twitter feed display using Raspberry Pi and a 20x4 LCD to get updates continuously without bothering to check your phone or PC.

BeginnerProtip2 hours4,916
Twitter Feed Display Using Raspberry Pi And 20x4 LCD

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
SparkFun Standard LCD 20x4
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Male Header 40 Position 1 Row (0.1")
Male Header 40 Position 1 Row (0.1")
×1

Software apps and online services

Twitter
Twitter

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Connect 20x4 LCD to RPi

Shows the breadboard diagram how to connect the LCD display with Raspberry Pi 2. (Do not worry about the 16x2 LCD display shown here, it has the same pin configuration as a 20x4 LCD display)

Code

twitter-lcd-display.py

Python
Python code for starting the feed display
import twitter
from RPLCD import CharLCD
import time
import HTMLParser

lcd = CharLCD(pin_rs=26, pin_e=24, pins_data=[22, 18, 16, 12])

api=twitter.Api(consumer_key='YOUR_CONSUMER_KEY',
	consumer_secret='YOUR_CONSUMER_SECRET',
	access_token_key='YOUR_ACCESS_TOKEN_KEY',
	access_token_secret='YOUR_ACCESS_TOKEN_SECRET')

htmlParser = HTMLParser.HTMLParser()

try:
	while True:
		try:
			homeTimeline=api.GetHomeTimeline(count=1)
		except:
			lcd.clear()
			lcd.write_string(u'An Error occurred! Retrying')
			continue
		tweetUser = homeTimeline[0].user.screen_name
		tweetText = homeTimeline[0].text
		tweetText = htmlParser.unescape(tweetText) # convert HTML symbols like &
		tweetText = tweetText.replace('\n',' ') # replace newlines with space
		
		# Break the tweet into two parts as the LCD screen can display 
		# only 80 characters at a time
		
		seg1_len = 80 - len(tweetUser) - 2 
		tweetText1 = tweetUser+": "+tweetText[:seg1_len]
		tweetText2 = tweetText[seg1_len:]
		lcd.clear()
		lcd.write_string(tweetText1)	
		if tweetText2:
			for i in range(7):
				time.sleep(8)
				lcd.clear()
				lcd.write_string(tweetText2)
				time.sleep(8)
				lcd.clear()
				lcd.write_string(tweetText1)
		else:
			time.sleep(60)
except KeyboardInterrupt:
	pass
finally:
	lcd.clear()
	lcd.write_string(u'Twitter feed stopped')

Credits

Samik Saha
1 project • 1 follower
Carbon based bipedal lifeform

Comments