Raspberry Pi USB GPS

This simple Python script reads the NMEA data from GPS receiver connected to Raspberry Pi via USB and sends the data into CAN-Bus network.

Note:

This is most simple way to get some basic GPS data at the rate of 1 message per second using default NMEA protocol. It is very generic and should work with almost all USB GPS units. Most GPS units can do MUCH more but the code should be a bit more specific. Stay tuned for that. 🙂

You can download the most recent source code from GitHub: https://github.com/ExperimentalAvionics/Direct_GPS

Installation instructions:

Most likely the Python (and Python3) are already installed on your Raspberry Pi

Login to your RPi console using your favourite terminal software. I use PuTTY.

If you have not done it yet, install geomag Python library

pip3 install geomag

Create a folder for your GPS script:

mkdir gps
cd gps

Copy the “direct_gps.py” from GitHub: https://github.com/ExperimentalAvionics/Direct_GPS into this directory

Start the script from inside /home/pi/gps to make sure it works

python3 direct_gps.py

You should see something like this:

Bring up CAN0....
CAN is Ready
Receiving GPS data

Exit by pressing Control-C

Configure automatic start-up for this Python script (run the script as a service)

First create a brand-new config file:

sudo nano /etc/systemd/system/direct_gps.service

Copy-paste the following text into the file

[Unit]
Description=Get direct_gps service running at boot
After=CAN_Listener.service

[Service]
ExecStart=/usr/bin/python3 /home/pi/gps/direct_gps.py
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=Direct_GPS
User=pi
Group=pi

[Install]
WantedBy=multi-user.target

Enable the service:

sudo systemctl enable direct_gps.service

Start the service

sudo systemctl start direct_gps.service

Check the status:

sudo systemctl status direct_gps.service

If the service is running correctly you should see something like this:

direct_gps.service - Get direct_gps service running at boot
Loaded: loaded (/etc/systemd/system/direct_gps.service; enabled; vendor prese
Active: active (running) since Tue 2018-11-06 21:47:55 AEDT; 24min ago
Main PID: 1364 (python3)
CGroup: /system.slice/direct_gps.service
ââ1364 /usr/bin/python3 /home/pi/gps/direct_gps.py

Nov 06 21:47:55 FDR systemd[1]: Started Get direct_gps service running at boot.
lines 1-8/8 (END)