Interfacing a GPS Module With the Raspberry Pi: Dashcam Part 2

Introduction: Interfacing a GPS Module With the Raspberry Pi: Dashcam Part 2

About: #BnBe is a platform to help teach electronics no matter what the age or skill level. We’re currently designing a wide range of products from beginner level kits to industry-standard microcontroller platforms.

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.

https://www.instructables.com/id/Making-a-DashCam-Using-the-Raspberry-Pi-Zero-pt1/

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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 serial port 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.

  • sudo systemctl stop serial-getty@ttyS0.service
  • sudo systemctl disable serial-getty@ttyS0.service

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 contents from the following file and paste it in the script as seen in the video.

https://www.bitsnblobs.com/wp-content/media/diy/e29/e29-dashcam.py

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.

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.

YouTube: https://www.youtube.com/channel/UCbWiK1A5RqAugSquBHuyBdA?sub_confirmation=1

Thank you for reading!

Be the First to Share

    Recommendations

    • LED Strip Speed Challenge

      LED Strip Speed Challenge
    • Sculpting Challenge

      Sculpting Challenge
    • Clocks Contest

      Clocks Contest

    Discussions