Pi Setup

The optional tactile buttons on the PiTFT are not required for this project. You can install the buttons for other things if you like, but the camera software is entirely touchscreen-based.

Install & Test PiTFT Operating System

To ensure that all the software interdependencies work, it’s best to start with a clean installation.

Format a 4GB or larger SD card and load it up with the Raspbian operating system. This guide explains how to prepare a card for the Raspberry Pi.

You’ll save a ton of setup time by using one of our pre-built Raspbian images with PiTFT support already included. The Raspbian “Lite” edition is recommended for this project. You’ll find links to download PiTFT-ready Raspbian Lite images here:

Make sure to download the correct Raspbian image for your screen type. The first link is for resistive touch screens, second is for capacitive screens. They won’t work the other way ’round!

IMPORTANT: performing an 'apt-get upgrade' on a working system will BREAK PiTFT SUPPORT. Don't do this. We'll update links for newer images as they’re available.

Make sure you've got the Raspberry Pi booting with the Text mode display on the PiTFT before you continue. You'll need to have that PiTFT stuff all working!

Once you have it working, log in and then shutdown with sudo shutdown at the command line

Install Camera

With the Raspberry Pi powered off, install the Pi camera ribbon connector, install the PiTFT display atop the GPIO header, connect a USB keyboard, power the Raspberry Pi, and work through the usual first-time boot configuration.

Run sudo raspi-config after logging in to run through the configuration

The raspi-config menu is a bit scrunched on the PiTFT, but the vital options are all present.

The following option is required:

  • Expand Filesystem

The following are very useful and recommended:

  • Under Internationalization Options, select Change Timezone and Change Keyboard Layout to match your region. If your keyboard is producing unexpected characters, this is usually the reason why.

The following are optional:

  • Under Advanced Options, select Hostname to give this Pi a unique name (such as “picam”) to distinguish it from other Raspberry Pi’s on the network.
  • Other settings can be configured to your liking.

The following should not be used:

  • Overclock. This is a portable, battery-operated project and an overclocked Pi will draw more current. Overclocked systems don’t always play well with the PiTFT and are more likely to corrupt the SD card filesystem. Do not enable this option.

Reboot when prompted, then more configuration awaits…

Even if you don’t plan to use the Dropbox functionality of this project, it’s necessary to get the Raspberry Pi on your network at least temporarily to download additional software. This can be done using the wired Ethernet jack (no additional configuration needed), or over WiFi using either a USB WiFi adapter or the Pi 3’s built-in wireless networking. This guide may be helpful for setting that up.

Do not continue until the Pi is successfully on the network. You can log in and try “ping adafruit.com” from the command-line to test.

Easy Install

Our camera software requires a complex set of software dependencies. We’ve written a script that takes care of all the ugly parts. You can download and run with these three lines (this is easiest if you login via ssh and copy-and-paste these lines):

cd ~
curl -O https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/pi-touch-cam.sh
sudo bash pi-touch-cam.sh

The script explains what it’s about to do and prompts for a “Y” before continuing; any other input will cancel.

It may take 10 minutes or so to run. Afterward, you’ll be prompted to reboot the system again. If this all works, skip ahead to the “Testing” section below.

Used the “Easy Install” route? Skip ahead to “Testing” below!

Complex Install From Scratch

If you used the “Easy Install” directions above, you can ignore this section and skip ahead to “Testing” below.

These are the steps taken by the pi-cam-install.sh script, if for some reason you need to perform any or all of these steps manually…

System Tweaks

The file /boot/config.txt is modified to enable the camera (if not already active via raspi-config) and also boost the speed of the PiTFT display (changing the “speed” and “fps” values). These lines are usually at the bottom of the file.

dtoverlay=pitft28c,rotate=90,speed=80000000,fps=60
start_x=1
gpu_mem=128

Install Prerequisite Software

Our code relies on a few libraries for handling the camera and screen output. One of these, it’s necessary to intentionally downgrade, in order for the touchscreen to interoperate correctly. It’s complicated. These lines in the script set that up (but don’t actually perform the downgrade yet):

# Enable Wheezy package sources
echo "deb http://archive.raspbian.org/raspbian wheezy main
" > /etc/apt/sources.list.d/wheezy.list

# Set stable as default package source (currently jessie)
echo "APT::Default-release \"stable\";
" > /etc/apt/apt.conf.d/10defaultRelease

# Set priority for libsdl from wheezy higher then the jessie package
echo "Package: libsdl1.2debian
Pin: release n=jessie
Pin-Priority: -10
Package: libsdl1.2debian
Pin: release n=wheezy
Pin-Priority: 900
" > /etc/apt/preferences.d/libsdl

Update the APT package index files and install Python libraries:

sudo apt-get update
sudo apt-get -y --force-yes install python-picamera python-pygame python-imaging

Now we perform the actual SDL library downgrade (it has to follow the “apt-get update” above):

apt-get -y --force-yes install libsdl1.2debian/wheezy

Download the Camera and Dropbox Scripts

Just a couple more steps to download and uncompress these…

cd ~pi
wget https://github.com/andreafabrizi/Dropbox-Uploader/archive/master.zip
unzip master.zip
rm master.zip
mv Dropbox-Uploader-master Dropbox-Uploader

wget https://github.com/adafruit/adafruit-pi-cam/archive/master.zip
unzip master.zip
rm master.zip

Modify /etc/rc.local for auto-start (but don’t enable)

These lines are added to /etc/rc.local — the second is intentionally commented out by default. It’s a good idea to test the camera software manually before throwing the switch. These are inserted just before the final “exit 0” line that’s normally present.

# Enable this line to run camera at startup:
# cd /home/pi/adafruit-pi-cam-master ; sudo python cam.py

Testing

Now give it a try. The software must be run as root (using the sudo command) in order to access the TFT display:

cd adafruit-pi-cam-master
sudo python cam.py

If all goes well, after a few seconds’ initialization you should see a live viewfinder preview on the screen, as well as two onscreen buttons.

If this doesn’t happen, an error message should give some sort of troubleshooting guidance; missing library or driver, etc.

There’s still some work to be done if we want to use Dropbox, so quit the camera program for the time being…tap the gear icon (settings), the left arrow and then the confirmation button. You’ll be back at the command line now.

Standalone mode

You can have the Pi boot straight into the camera software at startup by editing /etc/rc.local (this must be done as root, so “sudo” your text editor of preference):

sudo nano /etc/rc.local

If you use the Easy Install script, the following line is already present, but commented out. Delete the initial “#” character on the line, save changes and reboot.

Otherwise, if doing this the long way, add the following line just before the final “exit 0”:

cd /home/pi/adafruit-pi-cam-master; python cam.py

Next time you reboot you should see the text console for a few seconds and then it will start the cam.py software.

Last updated on 2016-12-02 at 12.53.46 PM Published on 2014-01-14 at 04.54.19 PM