Introduction: Tweeting Webcam Photos From Your ZYBO
This Instructable is going to over how to tweet pictures from a Webcam on a ZYBO, when everything is finished, you'll be able to turn the ZYBO on and start tweeting immediately.
For this instructable you will need:
- ZYBO that has been successfully booted with Linaro
- USB Splitter
- Internet Connection to ZYBO
Step 1: Signing Up for Twitter
If you don't have a Twitter account, fill out your credentials and log in. In order for us to tweet, we need to create a Twitter application. We're gonna do this before we start working on the ZYBO, you can do this on the ZYBO, or a computer.
Step 2: Going Into Settings
On the top right-hand corner, there will be a green button with an egg in the middle. Click on the egg button, then when the drop-down menu appears, click on the Settings option, this will take us to the use options of your Twitter account.
Step 3: Adding Your Mobile Phone
In order for us to create a Twitter App, we have to register a mobile phone number on Twitter (and confirm it). After you've created your app, you may unregister your phone number.
Step 4: Creating Your Twitter App
Go to apps.twitter.com.
Click on the Create New App button.
Step 5: Getting Your Twitter App License
Now you can create your App License!
- Name your App
- Create your Description
- Add your website (you need http:// or https:// to be recognized as a valid URL)
- You may leave the Callback URL blank
Before you can continue there is a license agreement at the bottom of the page. Accept the agreement and your App License will be created!
Step 6: Generating Your Tokens
In order for us to Tweet with our account, we need to get our Application and Access tokens.
Click on the Key and Access Tokens button.
You'll see the Application Settings, there will be a Consumer Key (API Key) and a Consumer Secret (API Secret). Scroll down and generate your Access Tokens, these will have an Access Token and an Access Token Secret.
You will need these to Tweet anything. In order to find them again go to apps.twitter.com.
Step 7: Installing Apache
In order for us to be able to send Tweets out of the ZYBO, we need to install Apache. You don't have to everything, but if you want to work with websites it is advised.
To open your terminal hit ctrl+alt+t, most of the following steps will be done in the terminal.
First, enter the command: sudo apt-get update, this will update our install lists.
Next, enter the command:sudo apt-get install apache2, this may take a few minutes.
Step 8: Installing Pip
At this point, you want to be using the ZYBO, we are going to install Tweetpony, which is an API that allows us to Tweet. Before this, we need to install pip, which is going to assist us in Tweetpony installation.
Enter the command sudo apt-get install python-pip python-dev build-essential, this is going to install pip.
Step 9: Installing TweetPony
TweetPony is a Python API that will allow us to communicate with Twitter. There are other APIs that have similar functionality, but this one had install instructions that were easy to understand.
Enter the command:sudo pip install tweetpony, this will install TweetPony.
Step 10: Installing Motion
Next, we're going to install Motion. Motion is the image capture software that we're going to be using.
Enter the command: sudo apt-get install motion
At this point you can run motion, but it will save a file every 1/4 second or so, which isn't what we want for this project. We are going to change the configuration file of motion to continually overwrite one image (temp.jpg) in our www folder.
Step 11: Download Motion.config and Picpytweet.py
Download the zip file, in there we have the motion.config file and picpytweet.py files.
The main difference between the motion.config currently being used and the motion.config file downloaded is how/where images are saved.
The picpytweet.py file a python file that we are going to use to Tweet.
Once this is done downloading, extract the tweet folder and place it in the Documents folder.
Step 12: Adding Your Access Keys
Remember the Keys and Tokens we created way long ago? Well, now it's to use them!
If you didn't record them you can go to apps.twitter.com and find them again
- Click on your app
- Click on the Keys and Access Tokens button
Once you have the Tokens, open picpytweet.py. You can do this using the command gedit Documents/tweet/picpytweet.py or right-clicking and opening with gedit.
Add your tokens and save. (You can also change the text your tweeting by going to the line with api.update_status_with_media("YOUR TEXT HERE " + value, ['/var/www/temp.jpg'])
Step 13: Replacing Motion.config
Now that the tweet folder has been downloaded, we can replace the auto-generated motion.conf folder with the one updated for tweeting.
Enter the command: sudo rsync -a Documents/tweet/motion.config /etc/motion/motion.conf
Now we can run motion by using the command sudo motion, this will re-write temp.jpg at 30 FPS in our /var/www folder.
Step 14: Copying Picpytweet.py Into Www
Enter the command: sudo cp Documents/tweet/picpytweet.py /var/www/picpytweet.py
This is going to create a copy of picpytweet.py and place it into /var/www.
Now enter the command: sudo chmod +x /var/www/picpytweet.py
The chmod +x command makes picpytweet.py an executable application.
Step 15: Tweeting!
Now we're almost done!
- Open up a new terminal by pressing ctrl+alt+t on the keyboard
- In the new terminal enter the command sudo motion, this will start motion.
- On the other terminal, enter the command /var/www/./picpytweet.py
Now you can tweet images using the t on the keyboard!
We have a be nice policy.
Please be positive and constructive.