16x2 LCD Twitter Client – Tweet to my door (Arduino)
The end goal of this project is to build a device that will display tweets on a 16x2 character LCD screen. This screen is small and can therefore be mounted on a door or at the side of a desk. Along the way, the engineering student will learn how to program an Arduino microcontroller as well as write a Python script. They will get involved in the world of embedded Linux and understand how to use the Twitter OAuth API.
The Arduino microcontroller was chosen because of its ease of use. The Arduino has many features that appeal to beginners such as it's headers for easy wire connection, built-in crystal resonator, built-in voltage regulator and built-in FTDI chip.
Python was chosen as the programming language for the desktop program because it has a gentle learning curve. The beginner programmer does not need to know about pointers or other low level mechanics to make a program work. The tweepy library is available for Python so this makes it easier for the beginner programmer as they need not create the HTTP requests themselves.
A Linux distribution was chosen as the operating system because it has many features that appeal to programmers. Linux has the cron scheduler to make the Python script run on a given time interval to update with the latest tweets. Linux has the advantage of being cross-platform so that our software can be run on regular x86 computers as well as ARM computers such as the Raspberry Pi.
Description of project:
This project uses the OAuth API to get tweets from a users Twitter feed. It then sends them to a serial port where the data is read by an Arduino microcontroller and then displayed on a 16x2 character LCD display. The LCD is small in physical size and can be mounted in many places such as on a door. This is useful for a person who would want to leave a message on their door without actually going to their door. As long the person can access Twitter, they can change what their door says from anywhere in the world. An example would be if a person was in a meeting, they could update their door without leaving the meeting telling anyone who wants to visit the person that they are unavailable.
This could also be modified to follow somebody else's Twitter feed. One could follow a news feed on Twitter and the LCD display would give them live news updates right on their desk.
When the student completes the lab they will have learned about engineering design processes. They will understand how the project works and they will be inspired to make innovations. Knowing about how the hardware and software works, they will be able to adapt it to their own needs.
- Computer with Internet access â to get data from Twitter
- Arduino UNO microcontroller â reads data sent to it over USB-serial, interprets it and sends the appropriate commands to the LCD display
- 16x2 LCD display - receives commands from the Arduino and displays tweets for the user â http://canada.newark.com/lumex/lcm-s01602dsf-f/display-alphanumeric-16-x-2/dp/19J7638?MER=PPSO_N_P_EverywhereElse_None
- 5kÎ© trimmer -Â adjusts contrast by adjusting voltage at pin 3 (V0) on the LCD display
- Solderless breadboard â to hold trimmer and make connections.
- Wire â for connecting everything together
- Python 2.7 â To run our script to get tweets from twitter and send them to the LCD - http://www.python.org/
- Tweepy python library â to allow our python script to communicate with Twitter - https://pypi.python.org/pypi/tweepy/2.1
- Arduino IDE â To program the Arduino microcontroller â www.arduino.cc
- Linux distribution capable of running the above programs, such as Ubuntu - http://www.ubuntu.com/
- Soldering tool, solder and flux â for connecting wires to the LCD
- Wire stripper â for removing insulation from wires
- Create a Twitter account for this project.
- Go to www.twitter.com and fill in the sign-up form. Validate the account by clicking on the link sent to your email.
- Create a Twitter application for this project.
- Go to https://dev.twitter.com/apps/new and login.
- Give the application a name, description and website. The URL of the website is not important. Leave Callback URL blank.
- Accept the “Developer Rules of the Road”
- Complete the CAPTCHA and press next
- Get the OAuth keys
- Leave the Access Level to read-only
- Click on “Create my access token”
- Copy the Consumer key, Consumer secret, Access token and Access token secret into a place where they will be remembered.
- Add the application to your account
- Go to https://twitter.com/settings/applications and verify that the application has access
- Install tweepy â in Linux terminal type: sudo pip install tweepy and press enter
- Add the OAuth keys to the Python script.
- Open the file twitter_lab_test.py in an IDE such as Geany and complete the following lines:
- CONSUMER_KEY = '<Consumer key>'
- CONSUMER_SECRET = '<Consumer secret>'
- ACCESS_KEY = '< Access token>'
- ACCESS_SECRET = '< Access token secret>'
- Where <variable> are the keys from step 3
- Save the file
- Test out the application.
- Go to your Twitter page (https://twitter.com/<twitter username>
- Click on “compose new tweet” button on the top right corner and tweet something.
- Open the lab files directory in a terminal. Type: python twitter_lab_test.py and press enter. If your tweet is displayed in the terminal, everything is working.
- Solder wires the the LCD.
- For each wire do the following:
- Strip away about 0.5cm of insulation
- Twist the wire so that all the strands are together.
- Apply a small amount of flux to the wire.
- Feed the wire through the appropriate hole on the LCD.
- Apply a small amount of solder to the tip of a soldering tool and press the solder into the joint to secure the wire into the hole.
- Do this for LCD holes: 1,2,3,4,5,6,11,12,13 and 14.
- Connect the LCD to the Arduino
- Connect the wire from LCD pin 1 (Vss) to GND on the Arduino by going through the breadboard.
- Connect the wire from LCD pin 2 (VDD) to 5V on the Arduino by going through the breadboard.
- Connect the so that the two ends, pins 1 and 3, and connected to 5V and GND respectively.
- Connect the wire from LCD pin 3 (V0) to pin 2 on theÂ 5kÎ© trimmer.
- This should look as follows
- Connect the wire from LCD pin 4 (RS) to Arduino digital pin 12.
- Connect the wire from LCD pin 5 (R/W) to Arduino GND.
- Connect the wire from LCD pin 6 (E) to Arduino digital pin 11.
- Connect the wire from LCD pin 11 (D4) to Arduino digital pin 5.
- Connect the wire from LCD pin 12 (D5) to Arduino digital pin 4.
- Connect the wire from LCD pin 13 (D6) to Arduino digital pin 3.
- Connect the wire from LCD pin 14 (D7) to Arduino digital pin 2.
- This should look as follows:
- Upload Arduino sketch
- Plug the Arduino into the PC with a USB cable.
- Open the Arduino IDE.
- Open the file SerialDisplay_Twitterfeed.ino in the directoryÂ SerialDisplay_Twitterfeed.
- Press the Upload button
- With a flat-tip screwdriver turn the trimmer until the LCD display becomes readable. It should say, “Updating...”
- Make it display tweets.
- Open the file twitter_lcd.py in a programming IDE.
- Repeat the steps from step 5 for entering the keys.
- Open the directory where twitter_lcd.py is found in a terminal and type: python twitter_lcd.py
- If all is working, the first 26 characters of your latest tweet is displayed on the LCD along with the time that it was tweeted.
- Make it automatic.
- Copy the file twitter_lcd.py into your /home/<username> directory
- Make it executable. Right-click file, go to properties, permissions and check “Make the file executable”
- Alternatively, open the directory in a terminal and type: chmod 700 twitter_lcd.py, then press enter.
- In the terminal type: crontab -e , then press enter.
- Add the following line: */1 * * * * /home/<username>/twitter_lcd.py replacing username with your Linux username.
- Press Ctrl+O.
- Press enter.
- Press Ctrl+X
- The LCD will now be automatically updated every minute.
Areas for improvement:
This lab teaches the student many different concepts related to electrical and computer engineering. They will learn about the basics of these fields so that they will be able to learn more advanced concepts in these fields. With this new knowledge of electrical and computer engineering the student may wish to make the following modifications:
- The LCD screen only displays the first 26 characters of a tweet. With a bit of extra coding, the LCD screen could scroll the tweet so that the entire thing can be read.
- The LCD screen has support for an LED backlight. An improvement would be to make the backlight go on when it's dark by adding a photo-resistor.
- Adding a color and graphical LCD screen would be more aesthetically pleasing.
- Remove the solderless breadboard by soldering everything on a regular breadboard and use a header to plug into the Arduino.
This project would be appropriate for high school students in grades 11 and 12. Physics and computer science courses are available for these students so that they will be able to follow along with the concepts described in this lab.