Our trail camera will depend on a Raspberry Pi for recording and storing our footage. The first step is to get it up and running.


Just joining us? Make sure you've got everything you need as listed in part one of this how-to guide.

 

Download and install the operating system

Just like any other computer our little Raspberry Pi needs an operating system (OS) to run everything. Rather than using a big hard-drive, the Pi stores its OS on a micro-SD card. This is very useful when you consider that swapping operating systems is as easy as changing the micro-SD card installed in the Raspberry Pi.

Starting afresh, we need to download 3 things to get going:

  • Grab the SD memory card formatter - this simply formats SD cards so we're sure they are clean and ready for our OS.
  • Download the latest version of Raspbian - the standard operating system. At the time of writing, this is Raspbian Stretch. There are usually two version available: 'with desktop' and 'lite'. I tend to use the Lite version since I don't intend on using the Raspberry Pi for anything else. This version saves space and takes less time to download and install.
  • Download Etcher - this program let's us 'flash' the operating system to the SD card.

While everything is downloading, attach your micro-SD card to your computer. If, like me, you only have an standard SD card slot you'll need an adapter and possibly a USB card reader. Once attached, install and open the SD card formatter. You should see the card's drive letter in the drive box. Before clicking format, be sure you have the correct drive selected, otherwise you could mess up another of your computer's drives. Once you're happy you have the correct drive, click Format.

Now your card is formatted we can copy the operating system to it. Raspbian comes zipped up in an archive so unzip it by double-clicking. While that's working away, install and open Etcher.

In Etcher:

  • Select the newly unzipped image file
  • Select your SD card drive
  • Click Flash

Writing to the SD can take a few minutes. Once complete you should now have a fresh installation of Raspbian Stretch on your micro-SD card. You should also see it appear in your list of drives connected to the computer either in Finder (macOS) or File Explorer (Windows).

There are just two more steps to set up in order to have the Raspberry Pi automatically join your wireless network.

 

Automatically join your wireless network

Previously, when setting up older Raspberry Pi models with older operating systems, we initially needed to hook up a monitor and keyboard in order to let the Pi connect to our wireless network and enable something called SSH so we could login from another computer. Now, however, this can all be done before we switch the Raspberry Pi on by creating two files and copying them to our micro-SD card.

  • Create an empty fil called 'ssh'. Make sure the file has no extension such as '.txt'.
    • On Windows on your desktop, right-click and select New->Text Document.
    • Rename the file 'ssh' removing any file extensions. If warned about changing the file extension, confirm you want to change it.
  • Create another file called 'wpa_supplicant.conf', again noting the file extension change. In this file, add the following lines, updating your country code, wireless network SSID and password respectively:

 

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev 
update_config=1 

network={ 
    ssid="ssid"
    scan_ssid=1
    psk="password"
    key_mgmt=WPA-PSK
}
  • Copy both files to the /boot partition of your newly flashed micro-SD card

Now, when we boot up the Raspberry Pi, it should automatically look for and connect to your wireless network. Of course, you'll have to be in range! We'll also be able to log into our Raspberry Pi via another computer.

 

Raspberry Pi - initial setup

Before we do anything trail camera related, let's tinker with the Raspberry Pi to make sure it's set up correctly.

With your micro-SD card plugged into the slot, power up your Raspberry Pi either using the power bank or a main power adapter if you have one. After a minute or so your Raspberry Pi should be fully booted up and connected to your wireless network. In order to access if from another computer, we need to know its IP address on the network. This is usually something like 192.168.x.x, however the Xs could be a value between 0 and 255 so guess is going to take a while! 

The best way to find out the IP address of the Raspberry Pi is to access your network's router. Do this be browsing to the IP address of your router. For example, mine is 192.168.1.1. A quick search for the default IP address of routers for your broadband provider should give you the answer. Once I'm logged into the router, you should be able to navigate to a screen that shows the devices connected to your network. It should be fairly obvious what is the Raspberry Pi. Once you find that, note down the IP address.

Now, on another computer connected to your wireless network we need to use an SSH client to access the Raspberry Pi. If you're using a Mac, you're in luck and SSH is available out of the box, otherwise there's an extra step.

macOS

  • On a Mac open the Terminal program (you can hit Cmd+Space and type Terminal or open the application via your Applications->Utilities folder).
  • At the prompt, type ssh ip-address-of-raspberry-pi

Windows

  • Download PuTTy - a free SSH client.
  • Once download, open the program and in the Host Name (or IP address) box, insert the IP of the Raspberry Pi.
  • Click Open

All being well you should be prompted for a username and password. The default values for these are pi and raspberry respectively. (Don't worry if you don't see any characters appearing when you type the password, that's just a Linus safety feature.) Once successfully connected via SSH, you should see something like this.

Through the Raspberry Pi Software Configuration Tool we can make a few changes essential for our trail camera to operate properly.

Let's start by expanding the file system to use as much of the storage as possible.

sudo raspi-config

Choose option 7 - Advanced Options and then option 1 Expand Filesystem. You should get a message explaining the filesystem will be expanded upon rebooting.

While in the Configuration Tool, let's enable the camera module by choosing option 5 Interfacing Options and the option 1 Enable/Disable connection to the Raspberry Pi Camera.

Next, let's update and upgrade our operating system to make sure we have the latest versions of all the packages contained within it. This is handy since it can improve reliability and increase performance of the Raspberry Pi. The trail camera should work without doing this but since we're leaving the camera in a remote place, it's good to know we've done all we can to make it as reliable as possible.

sudo apt-get update

And once this completes

sudo apt-get upgrade -y

The -y here just tells means we'll say yes to installing all the package updates and saves a bit of time. This process can take a few minutes so be patient.

Now we can add the various extra packages we'll need to fulfill the trail cam operation. Run each of these command separately. If you run into any errors, try running the command again and if that fails, try Googling the error to see if there are any solutions available.

sudo apt-get install python-pip

sudo pip install gpiozero picamera RPi.GPIO spidev

sudo apt install python-spidev python3-spidev python3-rpi.gpio

sudo apt install python-dev python3-dev python-gpiozero python3-gpiozero python-picamera gpac

We could stop here and reboot to attach the camera and check that all of this is working but while we're typing in commands, let's complete a couple more steps in the set up to save us going back to them later.

The footage that we record from our camera is going to be stored on a removeable drive (USB stick) separate to the operating system. This system has the obvious advantage of allowing us to remove the drive and plug in a fresh one without having to remove the camera from it's location however, in order for the drive to be 'seen' by the Raspberry Pi, we need to create a mount point.

sudo mkdir /mnt/usb

All we're doing here is creating a directory at the specified location. You can call it anything you want, but something fairly generic and easy to remember is useful as we'll be using it when it comes to the programming. Next, let's ensure we can write data to the location by setting some permissions.

sudo chmod 770 /mnt/usb

Great! We've gone a long way to getting the Raspberry Pi ready.

Summary

Well done in making it to this stage of the guide! If you're new to Raspberry Pis and computing the steps we've taken - flashing an operating system, connecting to computers over SSH, installing packages and giving basic command line instructions - are quite common to a lot of other projects so what you're learning can be applied elsewhere.

So far, we've got the pieces required for the project and completed the essential (but somewhat boring) set up steps. Next, we'll turn our attention to hooking up the hardware and writing the code for our trail cam.

If you have any questions about anything in this stage of the guide, feel free to ask in the comments below.