Introduction: Twitter Colour Sniffer Lamp
Have you ever wondered which colour people are tweeting in their tweets??
No, right? I expected.
But still, it's a pretty cool thing to do. So, go ahead and do this thing.
This instructable tells you how to build a lamp ( fine, it's just assembling a strip of RGB leds inside a lamp ) which changes its colour whenever someone tweets with a hashtag ( you can select any hashtag and work on it ) and the tweet has a colour name in it. The lamp changes it's colour to the colour in the tweet.
Pretty cool stuff right? Wait till you finish this project yourself and see the colour change by "Magic".
Step 1: Go Out and Get the Stuff You Need...
To get this setup up and running, sniffing colour( or color if you prefer American English ) in tweets and making your day( OK, at least your lamp) a colourful one, you will need all of the below things (yes, ALL. Don't be cheap and skip things, it won't work).
1. Raspberry Pi 1 / B+ / 2.
2. WiFi module ( compatible with Raspberry ).
3. Any Arduino board (I've used Nano).
4. Adafruit NeoPixel Strip 144 LEDs (Of course, the number of LEDs doesn't really make a difference. Just have sufficient number of LEDs to light up a considerable amount of surface area).
5. 2 Power Adapters. One for Raspberry Pi, One for the LEDs.
6. MicroSD card loaded with Raspbian ( SDCard if you are using RaspberryPi 1).
7. USB Cable type-B (or whichever fits into your arduino).
8. A twitter account ( Duh, who doesn't have one. )
Step 2: Twitter Credentials
For all who know how to get a twitter app credentials and OAuth tokens, sprint ahead and get them and store them in a safe ( yes, an actual safe made up of metal!! Sarcasm intended). Also, you can skip this step if you got the twitter credentials.
This step will show you how to get the twitter app credentials.
1. Go to apps.twitter.com
2. Sign in if you aren't signed in to twitter. ( If you don't have a twitter account, create one. Obviously. )
3. Now select Create App.
4. Fill in all the details required and move ahead.
5. After you agree to the terms and create your application, you will see an application page.
6. Move to the "Keys and Acces Tokens" tab in the page.
7. Select "Generate Access Tokens" after scrolling down.
8. Your access tokens will be generated. Now, select the test OAuth button on top right.
9. You need to note down the first four values.
10. These are what you need to note down :
Access token secret
Now, move to the next step.
Step 3: Get the Repo
Clone the repository from github using this link
If you don't know what cloning a repository is ( Like Seriously?? Good, you'll learn it now and here )
in your terminal.
You should see three files :
1. A python file.
2. An arduino .ino file.
3. A launcher.sh file.
Step 4: Set Up the RaspberryPi
This step will teach you setting up the RaspberrryPi for this instructable to work.
This step assumes that you have Raspbian or some debian based image loaded and running on your RaspberryPi. If this makes no sense to you, then please read about how to load an image onto a RaspberryPi here.
The step also assumes that you have connected a keyboard to your RaspberryPi and that you are not using it headless ( i.e that a monitor is also connected ). If you have neither, read this.
You will need the following installed in your RaspberryPi:
1. Python 2.7
Check if python is installed by simply typing python in the terminal of Pi. It should also show you the python version.
Install Twython from sudo pip install Twython
3. Setup Wifi
Setup WiFi access to your RaspberryPi ( enough, I'll be calling it Pi from now ) with the Pi compatible WiFi module you gathered in the second step. Learn how to setup WiFi access from here. Although Internet through ethernet will also do, it's better to work with WiFi if you want to use your Pi for an application far from the router or modem.
Now, follow these steps to setup the Pi.
These steps are for creating a python script :
1. Create a new folder and name it twitterlamp.
mkdir twitterlamp && cd twitterlamp
2. Create a python script named twitter.py
3. Copy the code from the python file which was in the github repo and paste it here.
4. You need to do some edits in the python file.
5. Recall the credentials you took from twitter and add the codes in the file where it is indicated.
6. Save and exit.
These steps will help you create a launcher script and make it run continously :
1. Move to your home directory by typing cd.
2. Create a new file
3. Copy the contents of the file launcher.sh from the repository to this file.
4. Save and exit.
Now, you need to create a crontab. Type in the following commands in the terminal one by one and it should do the work for you :
mkdir logs && cd logs
sudo crontab -e
It should now give you a choice of text editor. Select nano (option 2). I recommend it.
Type the following inside the file
@reboot sh /home/pi/launcher.sh >/home/pi/logs/cronlog 2>&1<br>
Now restart the Pi
You are good to go to the next step.
Step 5: Setting Up Arduino & Hardware Connections.
You will need a library from Adafruit installed. The library is Adafruit Neo-pixel. You can download it from here.
Installing the library :
1. Download the .zip file from Github link given above.
2. Open your Arduino IDE. (I'll recommend you update the IDE to version 1.6.5 if you haven't already done it)
3. Install the library from Sketch>Include Library > Add .zip library.
Now, open the .ino file from the repository and upload it to your Arduino via the IDE. ( Of course choose the correct board, CPU, baud rate, port number blah blah before uploading).
You will need to connect the DIN pin of the Neo-pixels to the D6 pin of your Arduino.
Connect the ground of the Arduino to the ground of Neo-pixel.
Solder a connector ( called DC connector female ) like the one shown in Image . Solder the red wire to the VCC of the Neo-pixel and the Black wire to the GND of Neo-pixel. ( If your connector doesn't have colour coding, find out which wire is positive and which is gnd by using a multimeter. )
Make sure that the ground of Arduino and Neo-pixel are connected to each other.
Step 6: Integration of All the Steps
Now, you need to connect your Arduino and RaspberryPi together so that all of this can work.
Take a USB cable that fits into your Arduino and then plug it into RaspberryPi and into Arduino.
Now, connect the DC power adapter to the Neo-pixel strip.
Now, you can power on the Pi and all will work smooth...
Enjoy tweeting with Colours.
Step 7: Troubleshooting
Here are a list of errors you might get
1. Errors in Arduino IDE :
Adafruit_NeoPixel.h: No such file or directory
compilation terminated. Error compiling.
You haven't installed the library ( don't skip the steps man... not cool ). Or it's not properly installed. Install again.
2. Errors in RaspberryPi
Traceback (most recent call last):
File "", line 1, in ImportError: No module named twython
The module isn't installed. Install it again (duh!).
serial.serialutil.SerialException: could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: '/dev/ttyUSB0'
The USB serial port is a different one. Run dmesg and check which usb port is the Arduino connected to. Just change the number after USB to that number and it should do.
Participated in the
Make It Glow! Contest