0

I am on a project with a group to create a device that will retrieve tweets and display them on an LCD on a Raspberry Pi platform. We are using a Raspberry Pi 3 model with a Cobbler T and breadboard. We are using the code below and have been trying to implement a button that will either refresh and retrieve new tweets to the LCD or to dim or sleep the display for a time. We have been having trouble with the GPIO working with the LCD. We have set up a button that accesses the RPi via the breadboard and tried coding the button to dim the screen or retrieve new tweets, but we keep receiving error messages about a GPIO Warning or there is no feedback whatsoever. Any suggestions or advice is greatly appreciated.

UPDATED CODE We are still having trouble implementing a button on the breadboard to run all this code (i.e. fetch recent tweets and display them on the LCD) when pushed, and to have a small LED light up when either the button is pushed or the LCD writes the string.

Any help is very appreciated.

import twitter
from RPLCD import CharLCD
import RPi.GPIO as GPIO
import time
from html.parser import HTMLParser

lcd = CharLCD(cols=24,rows=2,pin_rs=26, pin_e=24, pins_data=[22, 18, 16,     12],numbering_mode=GPIO.BCM)
api = twitter.Api(consumer_key = 'jGuhu2M0luIBw7B713re7EGNp',
consumer_secret = 'YGazMMJbE0RzHBUy0zOhU9QbBtKLYLFcz5PiWDkYYulEq5pOKE',
access_token_key = '788782390873391104-DAykFUDPkj0lO3rMGln3F2D5ZT1auro',
access_token_secret = '9WiJeEbOYeEGMkGh6jr8UKsOt0aXAyUarH1Qzhjp74Qba')

#htmlParser = html.parser.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
        tweetText = tweetText[12:]
        # 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 = 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'

========================= UPDATE ===================================== The problems we are trying to overcome are: 1. Implement a method to search for a specific hashtag 2. Display the tweet with the hashtag on the LCD 3. Light up the LED when a new tweet is retrieved 4. When a button is pushed brighten or dim the display 5. When a button is pushed retrieve new tweets with the specified hashtag

I am trying to figure out how to write the code to search for the hashtag and how to display it on the LCD. The current code only seems to retrieve and display tweets from my Twitter account via the Twitter API defined in the code. I am also unsure of where to put the GPIO input or output within the code to get new tweets when a button is pushed or how to light up the LED when something is received.

LED is connected to GPIO(5) Button 1 is connected to GPIO(20) Button 2 is connected to GPIO(21)

I will upload a better image of the breadboard setup.

enter image description here

Working on drawing up the design on the breadboard in an outline online.

Babeeshka
  • 105
  • 1
  • 4
  • 21

0 Answers0