The first thing we will do is set up the two pieces of hardware and verify that they are working correctly before moving on to the software.
The first (and the most important) piece of hardware we need is the camera board. Firstly, start by connecting the camera board to the Pi.
The camera is connected to the Pi via a 15-pin flat, flex ribbon cable, which can be physically connected to two connectors on the Pi. However, the connector it should be connected to is the one nearest to the Ethernet jack; the other connector is for display.
Firstly, we need to enable support for the camera in the operating system itself by performing the following steps:
raspi-config
utility from a terminal (either locally or over SSH). Enter the following command:sudo raspi-config
This command will open the following configuration page:
This will load the configuration utility. Scroll down to the Enable Camera option using the arrow keys and select it using Enter.
Once this is done, you will be taken back to the main raspi-config
menu. Exit raspi-config
, and reboot the Pi to continue.
Both of these installations can be done with the following two commands:
sudo rpi-update sudo apt-get install python-picamera
sudo reboot
python-picamera
library we just installed.To do this, create a simple test script using nano
:
nano canera_test.py
import sys import time import picamera with picamera.PiCamera() as cam: cam.resolution = (1280, 1024) cam.start_preview() time.sleep(5) cam.capture(sys.argv[1]) cam.stop_preview()
python camera_test.py image.jpg
image.jpg
. It is worth downloading the image using SFTP to verify that the camera is working properly.Before connecting the GPS module to the Pi, there are a couple of important modifications that need to be made to the way the Pi boots up.
By default, Raspbian uses the on-board serial port on the GPIO header as a serial terminal for the Pi (this allows you to connect to the Pi and run commands in a similar way to SSH). However, this is of little use to us here and can interfere with the communication between the GPS module and the Pi if the serial terminal is left enabled. This can be disabled by modifying a couple of configuration files:
sudo nano /boot/cmdline.txt
ttyAMA0
(the name for the on-board serial port). In my case, there was a single entry of console=ttyAMA0,115200
, which had to be removed. Once this is done, the file should look something like what is shown in the following screenshot:sudo nano /etc/inittab
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Once this is done, the file should look like what is shown in the following screenshot:
sudo shutdown -h now
Next, we need to connect the GPS module to the Pi GPIO port. One important thing to note when you do this is that the GPS module must be able to run on 3.3 V or at least be able to use a 3.3 V logic level (such as the Adafruit module I am using here).
Next, connect the GPS module to the Pi, as shown in the following diagram. If you are using the Adafruit module, then all the pins are labeled on the PCB itself. For other modules, you may need to check the data sheet to find which pins to connect:
Once this is completed, the wiring to the GPS module should look similar to what is shown in the following image:
After the GPS module is connected and the Pi is powered up, we will install, configure, and test the driver and libraries that are needed to access the data that is sent to the Pi from the GPS module:
gpsd
is the daemon that managed data from GPS devices connected to a system, gpsd-clients
contains a client that we will use to test the GPS module, and python-gps
contains the Python client for gpsd
, which is used in the time-lapse capture application:sudo apt-get install gpsd gpsd-clients python-gps
gpsd
to work in the way we want. To do this, use the following command:sudo dpkg-reconfigure gpsd
raspi-config
. First, you will be asked whether you want gpsd
to start on boot. Select Yes here:/dev/ttyAMA0
here:gpsd
, when it is executed. Here, we will enter -n -G
. -n
, which tells gpsd
to poll the GPS module even before a client has requested any data (this has been known to cause problems with some applications) and -G
tells gpsd
to accept connections from devices other then the Pi itself (this is not really required, but is a good debugging tool):cgps -s
This should give output similar to what is shown in the following screenshot, if everything works:
If the status indication reads NO FIX, then you may need to move the GPS module into an area with a clear view of the sky for testing. If cgps
times out and exits, then gpsd
has failed to communicate with your GPS module. Go back and double-check the configuration and wiring.
3.138.117.75