Button Press Recorded to Twitter

30 Sep 2016

I did this project as part of my "documenting applications for Raspberry Pi" work as an Intern for Ensemble Tech. All code/work is not original and based on this work by Ahmad Khattab. I have learnt the "how- to" from his documentation of Buidling a doorbell and have implemented and documented the small part of tweeting the time. Check it out!

  • Hardware Requirements
    1. Raspberry Pi
    2. 16x02 LCD module
    3. Push button
    4. A 1k Resistor to act as Pull-Down for the button's ground connection
    5. LCM1602 I2C module(uses PCF8574T) for LCD

  • Create an ‘App’
  • The first thing you have to do is create an app for the twitter API. Sounds scary, but it’s not. Just go to https://apps.twitter.com/ and log in with your twitter account id and password. Once logged in, hover over your avatar and click My Applications, then click Create a new Application

    Then you’ll have to complete four fields in the form. Name, Description, website and callback URL. The last two don’t much matter for what we’re doing here. Then you have to tick the box agreeing to their terms and then complete the CAPTCHA. Then click Create Your Twitter Application.

  • Find Your App
  • Hover over your avatar and click on “My Applications”.
    You should now see a page with all your created twitter apps. Click on your new app.
    You should then see something like this.

    1. Setting up Twitter App 1
    2. It creates a “Read only” app by default. You can change that later if you want (by clicking the OAuth tab) but we’ll leave it as is for now because we only need read-only access for this program. Further down the page it looks like this.

    3. Setting up Twitter app 2
    4. Create Access Token. In order for your program to talk to twitter, it needs a way of authenticating. The system used is called OAuth, and it uses access tokens (codes). So you need to click the “Create My Access token” button…

    5. Setting up Twitter app 3
    6. …to make this happen. Soon after that, you should have an additional section at the bottom of the page (you might need to refresh the page (F5) to see it)…

    7. Setting up Twitter app 4
    8. Keep this page open. You will need to copy these codes into your program.
      Install tweepy
      Before you can use tweepy, you need to get it onto your Pi. Fortunately, it’s a Python extension, so easy to install.

      sudo apt-get update updates Raspbian package lists
      sudo apt-get install python-dev python-pip

      Install pip and dev (You may not need python-dev for pip and tweepy, but I installed it anyway.) You could try to install tweepy and sometimes it fails. The reason appears to be an older version of pip in the Raspbian repo. You can get round this with…

      sudo pip install -U pip

      (this will uninstall pip and replace it with a version that works). …before you install tweepy. sudo pip install tweepy install tweepy itself You now have all you need to make your Python script talk to twitter.

  • Pin to Pin Connections:
  • PCF8574T Module Raspberry Pi Pin
    GND Pin 6 (GND)
    Vcc Pin 4(5V)
    SDA Pin 3(SDA1)
    SCL Pin 5(SCL1)
    Pin 1-16 of LCM1602 module is connected with Pin 1-16 LCD module
    Button Raspberry Pi Pin
    One end Pin 13(GPIO 27)
    Other end Pin 6(GND)

  • Code:
  • Click on the Script-Names to view and download them!

  • Output: