I have been using the Raspberry Pi 2 for quite some time and now have a project where I wanted to make it location aware through the addition of a GPS module. Since USB ports are limited, and i also had a UBlox NEO-6m-001 device I thought it made sense to connect this to the device through the inbuilt hardware UART pins to free up the USB ports.
Since i found information spread across a few places I thought it might be useful to include my workings within this document so that others may use this to set their system up if they want to emulate a similar thing. Beyond GPS location, I have also integrated the system with NTP (Network Time Protocol) to allow the device to update it's own time should there be no internet access which is handy given the raspberry pi does not have a real time clock.
*WARNING, this tutorial requires you to connect to the GPIO pins which can destroy your Raspberry pi, I take no responsibility for any damage that may occur*
By default, the Raspberry Pi is set to use the Hardware UART as a serial console output and if you connect the GPS to that pin then it will crash so first we need to disable the Console output to the hardware UART pins, this is done by the below;
- At the shell enter “sudo nano /boot/cmdline.txt”
- Find the line “dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait”
- Change this to remove console=serial0,115200 e.g.; “dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait”
- Since power can be an issue, I also recommend modifying the boot/cmdline to add “smsc95xx.turbo_mode=N” after rootwait, this may slow down the ethernet but does improve reliability.
- Save the file (Ctrl + O)
- At the shell enter “sudo nano /etc/inittab”
- Find the line “TO:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100” and put a # in front of it.
- Save the file (Ctrl + O)
- At the shell enter “sudo systemctl stop serial-getty@ttyAMA0.service && sudo systemctl disable serial–getty@ttyAMA0.service“
- Restart the Raspberry Pi
- We are now ready to install the GPS daemon and NTP, do this by “sudo apt-get update && sudo apt-get install gpsd gpsd-clients python-gps ntp”
- At the shell enter “sudo dpkg-reconfigure gpsd”
- At the shell enter “sudo nano /etc/default/gpsd”
- Change USBAUTO=true to false, in Devices enter “/dev/ttyAMA0”, in GPSD_OPTIONS enter “-n”
- Turn off the raspberry pi, and disconnect power. Now connect the raspberry pi Rx pin to the Tx pin of the uBLOX module, also connect the raspberry pi Ground pin to ground for the GPS, and the VCC to the raspberry pi 5v pin. (The website https://pinout.xyz/ gives great examples, BCM 15 (Rxd) is the recieve pin for the RPi Serial / UART, Pin 2 & 4 are 5v power, and Pin 6 is ground, just check the board is facing the right way!).
- Ensure no terminals are bridged, and then start back up the raspberry pi
- You may have to restart the raspberry pi, and at the shell hit “cgps -s”, if you see it update then it means the GPS is sucessfully set up.
- Next to setting up the NTP, at the shell enter “sudo nano /etc/ntp.conf”
- above the server line, enter this line “server 127.127.28.0 minpoll 4 maxpoll 4”
- Below that line, enter “fudge 127.127.28.0 time1 +0.350 refid GPS stratum 15“
- Save the file “Ctrl + O”
- At the terminal enter “sudo systemctl restart ntp”
- you should be able to now enter at the terminal “ntpq -pn” and if you see remote 127.127.28.0 and .GPS. all is working.
This was set up on Debian Jessie, so other operating systems and versions might behave differently. It was also run on a Raspberry Pi 2, these instructions will not work for a Raspberry Pi 3!. Another note, if you get errors on your Raspberry Pi about SysRq : HELP check to make sure you have removed the console references in the /boot/cmdline.txt file, and the /etc/inittab file and finally that the serial-getty service has been stopped and disabled.
Comments are closed.