Setting up the Raspberry Pi
- Download the New Out Of the Box Software (NOOBS) and place it on the SD card by following the directions here.
-
Get the Raspberry Pi running by following the official Quick Start Guide. Choose the (default) Raspbian operating system.
-
Get accurate internet time by running the following commands in the terminal window:
sudo apt-get install ntpdate sudo ntpdate -u ntp.ubuntu.com
- Update the operating system to the latest version:
sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade
- If you plan to use the WiFi, set it up. We used an Edimax EW-7811Un USB WiFi dongle and followed the instructions here. Note that this particular adapter has a power-saving feature that will cause it to go to sleep after a period of inactivity (about 10 hours in our experience). If you want to be able to connect to the Pi at all times, for example for debugging purposes, it is best to disable this feature by creating a file,
sudo nano /etc/modprobe.d/8192cu.conf
and adding the lines,
# Disable power management options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
Hit
Ctrl-X
to exit. See this thread for more details. -
If you haven’t done it during setup, run
sudo raspi-config
and enable the camera module. -
To disable the camera LED (which may scare the birds and produces artifacts in low-light pictures), run
sudo nano /boot/config.txt
and at the end of the file add a line (documentation),
disable_camera_led=1
Hit
Ctrl-X
to exit.
Setting up the bird feeder software
-
Get a copy of our code from GitHub to the Raspberry Pi. There are various ways to do this, but the simplest is to install git,
sudo apt-get install git
and then use the command,
git clone https://github.com/tpudlik/Birdfeeder.git
This will create a directory Birdfeeder in the current working directory containing a copy of the code.
-
Install
picamera
, the Python library for the Raspberry Pi camera, by typingsudo apt-get install python-picamera
- Install the pip Python package manager:
sudo apt-get install python-pip
- If you want to upload your photos to Dropbox, install the Python Dropbox API:
sudo pip install dropbox
- If you want to upload your photos to Twitter, install the Python Twitter API:
sudo pip install twython
- If you want to upload your photos to Flickr, install the Python Flickr API:
sudo pip install flickr-api
- Install the Python GPIO library:
sudo apt-get install python-dev sudo apt-get install python-rpi.gpio
- Install Pillow, an image processing library. This may take a while.
sudo pip install pillow
Currently, this package is only used if you tweet the pictures. If you intend to only store them locally, or to use Dropbox or Flickr, you can omit this dependency.
Configuring Dropbox, Flickr and Twitter
If you want your pictures automatically uploaded, rather than merely stored locally on the device, you will want to set up Dropbox, Flickr or Twitter integration. You can use any or all of them, and enable or disable their use at any time through configuration options. This section describes the initial, one-time setup.
Dropbox
You will need to register an application with Dropbox and save its
credentials.
- Go to Dropbox for Developers and click on the
Create app
button. - When asked “What type of app do you want to create?”, choose “Dropbox API App”. For storage, choose “Files and datastores”. It is OK, and in fact desirable, to limit the app’s permissions to its own folder. Finally, provide a name for the app.
- You will be taken to your new app’s dashboard. It lists two secret keys,
App key
andApp secret
. You will need them for the next step. - On the Pi, navigate to the
Birdfeeder
folder (where our code is located) and edit thedropbox_authentication.py
file:nano dropbox_authentication.py
Change the value of
app_key
andapp_secret
to the values you got from the dashboard. Exit nano usingCtrl-X
. -
Run,
python dropbox_authentication.py
and follow the prompts. You will have to go to the Dropbox website and enter your username and password. When you’re done, a file
access_tokens.py
will appear in the folder (if it wasn’t there already).
Flickr
The process is almost identical to the one for Dropbox. However, unlike with Dropbox, you may want to set up a separate Flickr account for your bird feeder. Otherwise, your carefully edited regular submissions will be drowned out by the bird feeder’s photo stream!
- Go to Flickr Services and apply for a (free) non-commercial API key. Fill out a short form.
- You will be taken to your new app’s dashboard. It lists two secret keys,
App key
andApp secret
. You will need them for the next step. - On the Pi, navigate to the
Birdfeeder
folder (where our code is located) and edit theflickr_authentication.py
file:nano flickr_authentication.py
Change the value of
app_key
andapp_secret
to the values you got from the app’s dashboard. Exit nano usingCtrl-X
. -
Run,
python flickr_authentication.py
and follow the prompts. You will have to go to the Flickr website and enter your username and password. When you’re done, the files
flickr_access_token.txt
andaccess_tokens.py
will appear in the folder (if they weren’t there already).
If you set up Dropbox or Flickr already, you will encounter no surprises here.
- Go to the Twitter App Console, log in, click on
Create New App
, and fill out the required fields. - On the application’s dashboard, under “Application Settings”, note the value of “Access level”. If it is not “Read and Write”, modify the app permissions.
- Also on the dashboard, select the Keys and Access Tokens tab and note the values of “API key” and “API secret key”. You will need these next.
- On the Pi, navigate to the
Birdfeeder
folder (where our code is located) and edit thetwitter_authentication.py
file:nano twitter_authentication.py
Change the value of
app_key
andapp_secret
to the values you got from the dashboard. Exit nano usingCtrl-X
. -
Run,
python twitter_authentication.py
and follow the prompts. You will have to go to the Twitter website and enter your username and password. When you’re done, a file
access_tokens.py
will appear in the folder (if it wasn’t there already).