This is part 2 of the dashcam project and in this post, we will learn how to interface a GPS module to the Raspberry Pi. We will then use the GPS data and add it to the video as a text overlay. Please read part 1 by using the link below, before you continue with this post.
The video below gives you more information about GPS modules, communication along with an overview of how everything comes together. I would recommend watching it first before continuing.
Step 1: Enable Serial Port
We first need to SSH into the board and then enable the serial port. This can be done by running the following command:
- sudo raspi-config
This will open up the configuration tool and you can use the arrows to navigate to the interfacing options, and then serial. Select NO to the console and then YES to the hardware serial port. Use the TAB key to navigate to the Finish option and then select NO when it asks you if you want to reboot. This will take you back to the terminal. Enter the following command so that we can shut down the board:
- sudo shutdown -h now
Once the board has shut down, we can connect the GPS module to the board using the reference image.
Step 2: Test the GPS Module
We will now test the GPS module to make sure it is working correctly. That can be done by running the following command:
- sudo cat /dev/serial0
You should be able to see some text output starting with “$GP….” as seen in the image. This is data from the GPS module and it means that the serial communication is working as it should. You can press “CTRL+Z” to stop the output.
We then need to disable the “getty” service as it might interfere with the serial communication. This can be done by running the following commands.
Step 3: Write the Final Script
Before we write the final script, we need to run a few commands. First, we need to install the python-serial module which can be done by running the following command:
- sudo apt install python-serial
We will be using the pynmea2 module to make sense of the GPS data and that can be installed by running the following command:
- sudo pip install pynmea2
We also need to install psutil for the root user and this can be done by running the following command:
- sudo pip install psutil
Finally, we can create a new script file using the following command:
- sudo nano dashcam2.py
You can then copy the following contents and paste it in the script as seen in the video.
Running The Final Script
Once this is done, save the file by typing “CTRL+X”, then Y, then ENTER. You can then test the script by running the following command:
- sudo python dashcam2.py
The script will then run as it should and you can use FileZilla to obtain the video files like last time. The video files will contain an overlay with the GPS data along with the CPU usage.
Video With GPS Overlay
The dashcam project is not yet over and there will be a follow-up post to continue this series. Do consider subscribing to our YouTube channel as this help support us.
This is the GPS test script that was mentioned in the video:
Thank you for reading!