Raspberry Pi 3 setup for NMEA GPS module

Table of Contents

Set up device and network connection

  1. Flash Raspberry Pi OS on SD card

    1. Download light image from the official site of Raspberry Pi Foundation
    2. Use sudo dd if=<path-to-image> of=/dev/<SD-card-device>
  2. Enable SSH

    1. Make directory to mount SD card to with sudo mkdir /mnt/sdcard
    2. Mount device with sudo mount /dev/<SD-card-device>p1 /mnt/sdcard
    3. Do cd /mnt/sdcard then make file "ssh" with sudo touch ssh
  3. Insert the SD card and power on Raspberry Pi

  4. Connect Raspberry Pi using network cable

  5. Find and connect to the device using PC terminal

    1. Use nmap -sn <network-ip>/<network-bits> and copy the IP that corresponds to the MAC address of a "Raspberry Pi Foundation" device
    2. Connect to the device using ssh pi@<device-IP>
  6. Do basic setup

    1. Login as pi, enter password raspberry
    2. Do sudo passwd to change the password for user pi
    3. Do echo '<hostname>' > sudo tee /etc/hostname to change hostname
  7. Connect to WiFi hotspot

    1. Do rfkill unblock wlan to unblock wlan
    2. Edit the files below using vi or nano


      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
      # Example network configuration
      # Add any additional networks


      # Add these lines to the bottom of the file
      interface wlan0
      arping <router-ip-1>
      arping <router-ip-n>
      profile <router-ip-1>
      static ip_address=<static-ip>/<host-bits>
      static routers=<router-ip>  # Typically .1
      static domain_name_servers=<DNS1>,<DNS2>
      profile <router-ip-n>
      # Repeat for any additional networks

  8. Reboot the device using sudo reboot and remove network cable

    1. Repeat step 1.5 using WiFi hotspot network address
    2. In case of major interference, do echo sudo iwconfig wlan0 power off >> ~/.bash_profile to disable power savings for interface wlan0

Enabling GPS hardware

  1. Enable the serial interface and connect the GPS module

    1. Edit the files below using vi or nano


      # Add these lines to the bottom of the file


      dwc_otg.lpm_enable=0 <all existing args> plymouth.ignore-serial-consoles

    2. In order to disable console login for serial ports, enter sudo systemctl mask serial-getty@ttyAMA0

    3. By default, Raspberry Pi echoes data back to the device. To reduce the noise, do echo '/bin/stty -F /dev/ttyAMA0 -echo' >> ~/.bash_profile
    4. Shut down using sudo shutdown now, wait for the green light to blink a few times and disconnect from power after the long glow
    5. Connect the GPS module — connect VCC to Pin 1 (+3.3V), GND to Pin 6 (GND), TXD to Pin 10 (RXD) and (optionally) RXD to Pin 8 (TXD)
  2. Testing operation

    1. Connect Raspberry Pi to power
    2. Execute cat /dev/ttyAMA0 — if it displays serial data, it's working
    3. Wait until $GNGGA supplies data — if comma-separated fields are not empty/the indication LED starts blinking, a location is captured

Using GPS data

  1. Capture and save data

    1. Start a screen session using screen, then enter cat /dev/ttyAMA0 > nmea_data
    2. Detach from session using Ctrl+A then d
    3. Exit the shell and gather data remotely
    4. When you want to end the capture, reconnect to device SSH
    5. Find running screen sessions using screen -ls
    6. Reattach to the existing one using screen -r <session>, then kill using Ctrl+A, k then y to confirm
    7. Exit remote shell, copy data from device using scp pi@<device-IP>:/home/pi/nmea_data .
    8. Install gpsbabel, convert the file to gpx using gpsbabel -i nmea -f nmea_data -o gpx -F nmea_data.gpx
  2. Display data

    1. Have QGIS installed on main PC
    2. Download a QML style set compatible with Geofabrik shapefile extracts such as mkoenigb's OSM Geofabrik Universal QML Style and extract it
    3. Download a OSM shapefile extract from Geofabrik and extract it to the Geofabrikdata subdirectory of the previous extraction
    4. Open the ExampleProject.qgs file using QGIS
    5. Do Ctrl+Shift+V or Layer > Add Layer > Add Vector Layer, specify location of nmea_data.gpx in Vector Dataset(s) > Add

Capturing and displaying live GPS data

  1. Set up gpsd

    1. Install gpsd on Raspberry Pi
    2. Edit the configuration and socket file


      # Find this line and add ttyAMA0 path


      # Enables listening to LAN

    3. Reload services using sudo systemctl daemon-reload, then enable service using sudo systemctl enable gpsd and start using sudo systemctl start gpsd

  2. Display data in QGIS

    1. In QGIS, in the existing project, create a new layer using Layer > Create Layer > New Temporary Scratch Layer > select Point in Geometry type
    2. Show the GPS Information panel using View > Panels > GPS Information
    3. In the Options pane, select gpsd under Connection and fill in the required data
    4. Under Track, enable Automatically add points
    5. Let it gather data. When you want to end tracking, click the Toggle Editing button and confirm saving the changes done to the layer