Skip to content
PekawayPekaway
Add GPS (Basics)

Add GPS (Basics)

Knowing and monitoring the current position of the van provides peace of mind and of course enables further automation. That's why this tutorial will cover the basic setup of a GPS module in our system.

GPS SERIAL Module

To add GPS, you usually use ready-made modules that evaluate the GPS signals and then make the data available via an interface. This usually happens via a serial connection (UART) or via a "USB" serial connection.

In the picture you can see a GPS module with the NEO-6m chip from U-Blox. This module is very common and we used it for our test. In principle, however, other modules should work the same way.

These modules only need power and a serial connection. You've probably already noticed the pins in the middle of our relay board.

Use on the relay board

These pins are there to solder exactly such modules directly onto the relay board. We have therefore routed the I2C bus and two UARTs in different pin assignments for different boards.

Since the Raspberry PI has 4 - 5 UARTS, i.e. serial interfaces, we can use them perfectly for this purpose. ATTENTION, this does not work with the PI3 .

Here, as an example, a U-Blox module is connected to the UART4. Unfortunately, we didn't have a "blue" module left; the pin assignment would have been exactly right and we could have soldered it on directly. At the moment, we're also having problems with the connection of the GPIOS on our image due to the use of wiringPI. That's why only UART1 (display) and UART5 (multiuart) are currently working. We'll therefore use UART5 in the rest of the tutorial. (to the left of the pins in the image and on the JST connector on the back)

Enable UARTS

In order to use the UARTs on the Raspberry PI, we first have to activate them. This is done via the Config.txt on the boot partition of the SD.

There we can use the command:

dtoverlay=uart5

Activate the additional UART and use it later. The UART becomes the serial interface /dev/ttyAMA1 in the system. This is the second port in the system. /dev/ttyAMA0 (=/dev/ttyS0) is used to communicate with the display.

If you activate more interfaces they will be made available under AMA2, AMA3 etc.

Now that we have activated the serial interface and connected our module, we need to receive the data in Node-Red.

Connect Node-Red

To receive the data from the GPS module, we simply use a "serial node". Take a look at our connections flow, there are many of them there. By default, the interface /dev/ttyAMA1 should also be found there, since we have already activated the UART5.

For the sake of simplicity, please delete everything that starts with AMA1. Otherwise we would have to make the tutorial much more extensive.

Then you take a "serial-node-in" and configure it with the following settings.

/dev/ttyAMA1 baud rate 9600 8N1

and select that the data should be separated after 100ms of idle time.

Under Windows with a connected USB GPS receiver you would simply select the corresponding COM.

Node-RED data analysis

The data that comes through the UART port is not immediately meaningful to us. That's why we use the parse-gps plugin.

https://www.npmjs.com/package/node-red-contrib-parse-gps

However, we cannot find this plugin in the Node-RED palette, but have to install it manually with npm (Node Package Manager). To do this, we log into our system via SSH and then change to the Node-RED directory with

" cd ~/.node-red/"

and install the parse-gps module with

"npm install node-red-contrib-parse-gps"

Then we restart Node-RED so that we can use the node in the editor:

"sudo systemctl restart nodered.service".

If that worked so far, we convert the data received from the GPS module to a string in a function node. (Or you can set it directly in the "serial node" if it is not already set there)

After that we can hang the installed parse-gps plugin. If no GPS signal is received we will see the following:

As soon as we receive a signal, we get msg.payload.lat and msg.payload.lon are displayed and thus have our location.

Please note that this can take up to 10 minutes when starting the modules for the first time. It should be quicker next time. The modules have a small battery to store the last values ​​and can be used for evaluation for a faster start.

What you do with the data is currently up to you. :) Display weather data, automatically switch off all relays when parked in the garage or whatever else you can imagine.

We will soon integrate the whole thing into our IOT bridge. Then you will be able to locate your vehicle relatively easily. We will also build an API endpoint to easily retrieve the data from our system.

Leave a comment

Your email address will not be published..

more tutorials

Open Source needs support

become Patron now

More projects, more tutorials and more supported devices. Our community is growing and would appreciate your support. So become a patron now to always receive the latest content and support the VAN PI project at the same time.

Become a Patron
Cart 0

Your cart is currently empty.

Start Shopping