This guide explains how to set up your Raspberry Pi to take a photo that is precisely synchronized with a GPS time pulse (PPS), and then embed the GPS coordinates into the photo’s EXIF data.
You will need a Raspberry Pi, a Pi Camera Module, and a GPS module that has a PPS (or 1PPS) output pin.
VCC to a 3.3V pin on the Pi and GND to a Ground pin.TX (Transmit) pin to the Pi’s RX (Receive) pin (GPIO 15).RX (Receive) pin to the Pi’s TX (Transmit) pin (GPIO 14).PPS output pin to GPIO 17 on the Raspberry Pi.Pinout Summary (Physical Pins on Pi Header):
| GPS Pin | Pi Pin (Physical) | Pi Pin (BCM) | Purpose |
|---|---|---|---|
| VCC | 1 (3.3V Power) | - | Power for GPS |
| GND | 6 (Ground) | - | Common Ground |
| TX | 10 (GPIO 15) | GPIO 15 | GPS data to Pi (RXD) |
| RX | 8 (GPIO 14) | GPIO 14 | Pi commands to GPS (TXD) |
| PPS | 11 (GPIO 17) | GPIO 17 | 1 pulse-per-second signal |
sudo raspi-configpicamera2 and gpiod libraries have deep integration with the OS, so they should be installed globally using apt.
sudo apt update
sudo apt install -y python3-picamera2 python3-gpiod
capture_with_gps.py is saved.python3 -m venv venv
source venv/bin/activate
Your prompt will now start with (venv).
venv active, install the remaining libraries using pip. They will be installed safely inside your project’s venv folder.
pip install pyserial pynmea2 piexif
The script capture_with_gps.py has been created for you. Here is a brief explanation of how it works:
gpiochip4). If you use a Pi 4 or older, you must change Chip('gpiochip4') to Chip('gpiochip0').Get a GPS Fix: Take your Raspberry Pi somewhere with a clear view of the sky. The GPS module’s indicator light should start blinking, signifying it has a satellite lock. This can take a few minutes.
cat /dev/ttyS0
You should see lines starting with $GPRMC, $GPGGA, etc. Press Ctrl+C to stop.
source venv/bin/activate
python capture_with_gps.py
gps_photos directory.Ctrl+C to stop the script gracefully. When you are done, you can leave the environment by typing deactivate.You can then view the photos in the gps_photos folder and check their properties/details to see the embedded GPS coordinates.