GPS with the Dragino LoRa Hat

Getting GPS to work on a Raspberry Pi 3 Model B

“My GPIO-connected UART device is broken on Pi 3, why?

The mini-uart is now routed to GPIO14/15 as the PL011 UART is now used for bluetooth communications. The mini-uart doesn’t have a separate clock divisor and uses the core clock frequency. Changes in core clock (e.g. through throttling or idle/load frequency changes) will result in arbitrary modification of the effective baud rate. There’s no easy way around this, but as a workaround there is a pi3-disable-bt devicetree overlay in latest rpi-update firmware which reverts this change.”

We will show you the operations in the next steps.


Connect the LoRa/GPS HAT to Rpi, use built-in patch GPS antenna.

Enable the UART

First we need to download and install a new device tree overlay.

The Raspberry Pi Engineer PhillE (forum username) has kindly made a custom overlay called pi3-miniuart-bt-overlay.dtb to remap the UART ports and this needs to be copied into the /boot/overlays folder on the SD card and we also copied it into the root / pi3-miniuart-bt-overlay.dtb of the card as well.

We have made a copy of the new boot overlay available to download from here and it will also be included in a future Raspbian Linux release. We have archived the overlay in zip format and it will need to be uncompressed and copied to your SD card.

Next we need to edit the /boot/config.txt file, open the file either on your desktop computer or using the Raspberry Pi via SSH

sudo nano /boot/config.txt

You need to add the following lines:


Then use Ctrl+O to save changes and use Ctrl+X to exit.

edit /boot/config.txt

Now edit /boot/cmdline.txt.

sudo nano /boot/cmdline.txt

Change the file to the following:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Exit and save your changes

If you have edited the cmdline.txt and config.txt files on your desktop put the SD card back in your Raspberry Pi 3 and boot to either a network SSH session or desktop and run the following in a shell window.

If you want to disable the built in bluetooth you need to stop hciattach trying to use the modem via uart0 which will disable the relevant systemd service

sudo systemctl disable hciuart

Now edit /lib/systemd/system/hciuart.server and replace ttyAMA0 with ttyS0 .

sudo nano /lib/systemd/system/hciuart.service

Replace “After=dev-serial1.device” with “After=dev-ttyS0.device”

Exit and save your changes

edit /lib/systemd/system/hciuart.server

You need to update the operating system with the latest patches with:

sudo apt-get update
sudo apt-get upgrade
sudo reboot

Once your Raspberry Pi 3 has rebooted you should now have access to the serial console via the GPIO header at 9600 baud.

If you just want to do a quick check to see what data is coming out of the GPS, you can enter the following command, following by CTRL+C to quit:

sudo cat /dev/ttyS0

cat /dev/ttyS0

Run the following two commands to stop and disable the tty service:

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



 sudo shutdown -r now


Install GPSD

You can always just read that raw data, but its much nicer if you can have some Linux software prettify it. We’ll try out gpsd which is a GPS-handling Daemon (background-helper)

To install gpsd, make sure your Pi has an Internet connection and run the following commands from the console:

 sudo apt-get install gpsd gpsd-clients python-gps

Raspbian Jessie systemd service fix

Note if you’re using the Raspbian Jessie or later release you’ll need to disable a systemd service that gpsd installs.  This service has systemd listen on a local socket and run gpsd when clients connect to it, however it will also interfere with other gpsd instances that are manually run (like in this guide).  You will need to disable the gpsd systemd service by running the following commands:

 sudo systemctl stop gpsd.socket
 sudo systemctl disable gpsd.socket

Should you ever want to enable the default gpsd systemd service you can run these commands to restore it (but remember the rest of the steps in this guide won’t work!):

 sudo systemctl enable gpsd.socket
 sudo systemctl start gpsd.socket

After disabling the gpsd systemd service above you’re ready to try running gpsd manually.

Run gpsd

GPSD needs to be started up, using the following command:

 sudo gpsd /dev/ttyS0 -F /var/run/gpsd.sock

Test gpsd

Now GPS doesn’t work indoors – as it needs a clear view of the sky so for this I’ve placed the PI on the window sill. Next I ssh into the pi and run cgps. There is a simple GPS client which you can run to test everything is working:

 cgps -s

The -s flag is there to tell the command not to write raw data to the screen as well as the processed data.

It may take a few seconds for data to come through, but you should see a screen like this:


If you have any problems and cgps always displays ‘NO FIX’ under status and then aborts after a few seconds, you may need to restart the gpsd service. You can do that via the following commands:

 sudo killall gpsd
 sudo gpsd /dev/ttyS0 -F /var/run/gpsd.sock

If here still shows ‘GPS timeout’ or ‘NO FIX’,edit /etc/default/gpsd as below:

 sudo nano /etc/default/gpsd

change it to look like this

# Default settings for gpsd.
# Please do not edit this file directly - use `dpkg-reconfigure gpsd' to
# change the options.

Then reboot. CGPS should work then.

NOTE:If the GPS receiver is new, or has not been used for some time, it may need a few minutes or so to receive a current almanac.You need 3 GPS satellites for a 2D fix (i.e. no height) or 4 satellites for a 3D fix. Once fixed,the LED ‘3D_FIX’ will blink.

You can view to get more info about gpsd.You can also try to use the following command:

* cgps

cgps and gpspipe should both just show curated data in the same way as your cat command did.


Try running gpsmon to get a live-streaming update of GPS data!

* gpsmon

The gpsmon real-time packet monitor and diagnostic tool. (This replaces the sirfmon tool in older versions.)

Calibrating the Magnometers on the Raspberry Pi Sense Hat



Taken from this forum post.

Install the necessary software and run the calibration program as follows:

sudo apt-get update
sudo apt-get install octave -y
cp /usr/share/librtimulib-utils/RTEllipsoidFit ./ -a
cd RTEllipsoidFit

You will then see this menu:

Options are:

  m - calibrate magnetometer with min/max
  e - calibrate magnetometer with ellipsoid (do min/max first)
  a - calibrate accelerometers
  x - exit

Enter option:

Press lowercase m. The following message will then show; press any key to start.

    Magnetometer min/max calibration
    Waggle the IMU chip around, ensuring that all six axes
    (+x, -x, +y, -y and +z, -z) go through their extrema.
    When all extrema have been achieved, enter 's' to save, 'r' to reset
    or 'x' to abort and discard the data.

    Press any key to start...

After it starts, you will see something similar to this scrolling up the screen:

Min x:  51.60  min y:  69.39  min z:  65.91
Max x:  53.15  max y:  70.97  max z:  67.97

Focus on the two lines at the very bottom of the screen, as these are the most recently posted measurements from the program. Now you have to move the Astro Pi around in every possible way you can think of. It helps if you unplug all non-essential cables to avoid clutter.

Try and get a complete circle in each of the pitch, roll and yaw axes. Take care not to accidentally eject the SD card while doing this. Spend a few minutes moving the Astro Pi, and stop when you find that the numbers are not changing anymore.

Now press lowercase s then lowercase x to exit the program. If you run the ls command now, you’ll see a new RTIMULib.ini file has been created.

In addition to those steps, you can also do the ellipsoid fit by performing the steps above, but pressing e instead of m.

When you’re done, copy the resulting RTIMULib.ini to /etc/ and remove the local copy in ~/.config/sense_hat/:

rm ~/.config/sense_hat/RTIMULib.ini
sudo cp RTIMULib.ini /etc

You are now done.

Raspberry Pi and the NEO 6M GPS


Original post here.

Intro: Raspberry Pi & the Neo 6M GPS

Previously I built a project where I connected a Neo-6M to an Arduino, but this time around, I wanted to show how to use a GPS with the Raspberry PI. Now there are several USB solutions, and apps that work with them, but I wanted to show how to use a $20 GPS module with a a serial UART, and Python code to decode the NMEA strings. Then you can write your own GPS interface, or combine the data with Google Maps.

Parts Needed:

Raspberry PI (any version)

Neo-6M GPS

Female to Female Jumpers

Step 1: Electrical Connection

Picture of Electrical Connection

The first step is to connect the GPS module to the Raspberry PI. There are only 4 wires (F to F), so it’s a simple connection.

Neo-6M RPI

VCC to Pin 1, which is 3.3v

TX to Pin 10, which is RX (GPIO15)

RX to Pin 8, Which is TX (GPIO14)

Gnd to Pin 6, which is Gnd

Step 2: Turn Off the Serial Console

By default, the Raspberry Pi uses the UART as a serial console. We need to turn off that functionality so that we can use the UART for our own application.

Open a terminal session on the Raspberry Pi.

The first thing we will do is backup the file cmdline.txt before we edit it.

sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt and press Enter.

The we need to edit cmdlint.txt and remove the serial interface.

Type in sudo nano /boot/cmdline.txt and press Enter.

Delete console=ttyAMA0,115200 and save the file by pressing Ctrl X, Y, and Enter.

Now type in sudo nano /etc/inittab and press enter.

Find ttyAMA0 by pressing Ctrl W and typing ttyAMA0 on the search line.

When it finds that line, press home, insert a # symbol to comment out that line, and Ctrl X, Y, Enter to save.

Type sudo reboot and press Enter to restart the Pi.

Step 3: Testing the GPS

Picture of Testing the GPS

Before we start writing our own code, let’s test the GPS by using some off the shelf programs.

Open a terminal session and type sudo apt-get install gpsd gpsd-clients and press Enter.

After that installs, let’s start the serial port:

Type stty -F /dev/ttyAMA0 9600 and press Enter.

Now start GPSD:

Type sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock and press Enter.

Now display by typing cgps -s and press Enter.