Introduction: How to Send Tweets From Your Raspberry Pi

Picture of How to Send Tweets From Your Raspberry Pi

In this rapidly growing moment of Internet of Things. People are using tweeter to send tweets form their pet dish, bird feeder, switch, power meter, pot, thermostat and what not, I even saw an instructable that was about tweeting pregnancy. I have been working on raspberry pi lately and I thought it would be great to send tweets from raspberry pi, this could help folks to use this instructable and make interesting tweeting stuff using raspberry pi.

Lets get started.

Step 1: Quick Video

Here is a small 5 min video that tells it all.

Click here to watch on youtube

Step 2: Things Needed

Picture of Things Needed

Following is the list of things needed for this mini-project-

  1. Raspberry Pi (any version will do),
  2. Ethernet cable (for connecting to internet) (quantity = 2) - one for Raspberry Pi and another for PC/laptop (if you are using wifi on raspberry pi and your PC/laptop this component can be avoided),
  3. SD card (with raspbian installed in it),
  4. Wall adapter to power Raspberry Pi and
  5. PC/laptop with linux installed in it (we will use it to remote login in to our Raspberry Pi) (No worries if you don't have linux, you can use software called PUTTY to perform same tasks that we will do with linux terminal on your windows machine).

For anyone who is not familiar with raspberry pi, you can follow THIS to familiarize and setup your raspberry pi for this mini-project. HERE is the helping videos for Raspberry Pi.

Step 3: Register Your App With Apps.twitter.com

Picture of Register Your App With Apps.twitter.com

Following are steps to register an app with apps.twitter.com. We need to perform these steps in order to allow a machine to access twitter on your behalf.

  1. Open your web browser,
  2. goto apps.twitter.com,
  3. Once this page loads click on 'Create new app' button, (Remember to make an account on twitter before doing this)
  4. You will be asked to give application name, description, website and callback URL (optional); Provide appropriate details, and
  5. Scroll down this page and click on 'Create your Twitter application' button.

Once application is created, the next step is to note down the 4 important keys.

Step 4: Get Keys

Picture of Get Keys

To allow Raspberry Pi to access twitter on your behalf, you need to provide Raspberry Pi with the 4 keys namely-

  1. Consumer Key (API key)
  2. Consumer Secret (API Secret)
  3. Access Token
  4. Access Token Secret

To get these keys, on successful creation of Twitter Application, click on 'Keys and Access Token' tab. Note down first two keys, scroll down and click on 'Create my access token' and note down remaining two keys.

Step 5: Plug in Your Raspberry Pi

Picture of Plug in Your Raspberry Pi

Get your Raspberry Pi (any version will do), insert SD card with Raspbian installed in it (To install raspbian on SD card). Connect Raspberry Pi on the internet enabled network using Ethernet cable and make sure that your laptop/PC is also connected to same network using another Ethernet cable. Finally power on the Raspberry Pi using its power supply.

Step 6: Find IP Address of Raspberry Pi Connected on Your Network

Picture of Find IP Address of Raspberry Pi Connected on Your Network

To remote login to your Raspberry Pi from your PC/laptop, first step is to find its IP address. Open Linux terminal on your PC/laptop and type 'sudo nmap -sn <your network subnet with astrisk(*) in place of host address>'. (This is to avoid the struggle of connecting display, keyboard and mouse to find Raspberry Pi's IP address)

On typing this command you will get list of all devices on your network with their IP address and details of their manufacturer. Note down IP address of device with manufacturer as 'Raspberry Pi foundation'. This is the IP of your Raspberry Pi that we will use to remote login to it.

Step 7: Install Twython on Raspberry Pi

Picture of Install Twython on Raspberry Pi

Twython is python package of twitter APIs. To install it on your Raspberry pi first remote login to it, using IP address obtained in previous step.

To remote login to Raspberry Pi from PC/laptop, open terminal and type 'ssh pi@IP address of your raspberry pi'. Once logged into your Raspberry Pi, update list of available packages and their version, to do this type 'sudo apt-get update' in remote logged terminal.

Next we need to install python package manager on Raspberry Pi, to do this type 'sudo apt-get install python-pip'. Now finally install twython using 'sudo pip install twython'.

Step 8: Python Code to Send Tweets

Picture of Python Code to Send Tweets

I am attaching code for sending tweets. You need to fill in your keys at commented places in order to get a working code.

To execute this file type- 'python '

That's all for this instructable; I hope you guys come up with useful application that uses this instructable. Thanks for reading.

Comments

About This Instructable

3,396views

83favorites

License:

More by victoryking:Speaking Alarm ClockConvert Speakers to Bluetooth-speakersLED Panel With a Dimmer
Add instructable to: