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. (Newer PiTFT variants already have all the buttons installed by default.)

Load 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. The Raspbian “Lite” edition is recommended for this project.

With the Raspberry Pi powered off, install the Pi camera with its ribbon connector, install the PiTFT display atop the GPIO header, connect an HDMI monitor and USB keyboard and go through the normal first-boot procedure.

After logging in, run sudo raspi-config for some basic configuration…

The following settings are useful and recommended:

  • Under Internationalization Options, change the keyboard layout to match your region. If your keyboard is producing unexpected characters, this is usually the reason why.
  • Also in International, if planning to use wireless networking, change the WiFi country setting for your location. Then you can go back to the main menu and Network Options to set up a WiFi connection.

The following are optional:

  • Under Interfacing Options, enable SSH if you’d prefer to log in remotely and finish the system configuration over a 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.

Select “Finish” and then 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. If raspi-config doesn’t handle the options you need, 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.

Install & Test PiTFT

Our PiTFT installation guide covers the basic setup (see notes below for specific options):

When running the PiTFT installer script, select the #1 configuration option: “PiTFT 2.4", 2.8" or 3.2" resistive (240x320)”. This project can work with any of the resistive touch 320x240 PiTFT displays. It will not work with capacitive displays or the 3.5" PiTFT.

For rotation, select the #1 option: “90 degrees (landscape)”. This covers most situations, but if you find the screen is oriented 180° from what you need, just re-run the adafruit-pitft.sh script and select the #3 option instead (“270 degrees (landscape)”). You do not need to re-run the camera installer script we’ll show later, just the PiTFT installer.

When asked about having the text console on the PiTFT, answer “y”. Then reboot when prompted.

Make sure you've got the Raspberry Pi booting with the Text Console 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

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 https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/pi-touch-cam.sh >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.

This guide was first published on Jan 14, 2014. It was last updated on Oct 17, 2018. This page (Pi Setup) was last updated on May 23, 2018.