NEO-6M is one of the most popular GPS modules used among hobbyists, you can get them for around 5…10 euros in Ebay.
The module is using the serial protocol for communication.
Raspberry PI
Before you proceed any further, you need to sort out the serial port mess associated with RPI. Please read this.
Connect the module as shown:
NEO-6M | RASPBERRY |
VCC | 3V3 |
GND | GND |
RX | GPIO 14 (TX) |
TX | GPIO 15 (RX) |
I assume a Jessie version newer than May 2016.
If you issue cat /dev/serial0 (remember serial0 ia an alias always pioints to GPIO serial) you should start
receiveing raw NMEA messages. If so, the hardest part of the setup is done. If you don’t want to use a port alias
you can always use ttyAMA0 or ttyS0 (depends on your HW setup)
Raw message decoding can be done with gpsd
apt–get install gpsd gpsd–clients python–gps
On Jessie the above will also install a service for auto starting gpsd.
Run sudo dpkg-reconfigure gpsd (or manually edit /etc/default/gpsd if you feel confident)
When asked if you want gpsd to start automatically answer Yes
When asked if gpsd should handle attached USB GPS receivers automatically answer No
When promped for device enter /dev/serial0
Leave everything else to defaults
Your /etc/default/gpsd should now look like:
# Default settings for gpsd.
# Please do not edit this file directly – use `dpkg-reconfigure gpsd’ to
# change the options.
START_DAEMON=”true”
GPSD_OPTIONS=”-n”
DEVICES=”/dev/serial0″
USBAUTO=”false”
GPSD_SOCKET=”/var/run/gpsd.sock”
…reboot…
If you want to be able to manually start/stop gpsd you first have to disable the service that
was automatically installed with gpsd
sudo systemctl stop gpsd.socket
sudo systemctl disable gpsd.socket
To start gpsd:
sudo gpsd /dev/serial0 –F /var/run/gpsd.sock
To stop gpsd
sudo killall gpsd
To re-enable automatic start/stop
sudo systemctl enable gpsd.socket
sudo systemctl start gpsd.socket
Now that you have gpsd up and running you may use any of the installed gps tools
cgps -s
or
gpsmon
You have to be outdoors to get a descent fix. If you can’t get a fix, restart gpsd or move outdoors ๐
Arduino
Connectivity for arduino is similar to that for RPi.
NEO-6M | ARDUINOY |
VCC | 5V |
GND | GND |
RX | SoftSerial TX |
TX | SoftSerial RX |
The only difference is that since the HW UART is
usually occupied for sketch uploading and/or serial monitoring we will have to use a different set of pins
for the GPS communication. SoftwareSerial is an Arduino library that will allow you to just do that.
The following simple sketch can be used for raw NMEA message reception.
#include <SoftwareSerial.h>
// Define two pins (Rx,Tx) that will be used for serial commuication
//between the Arduino and the GPS module
SoftwareSerial ssgps(4, 3);
byte gpsWord;
void setup()
{
//Initialise both serial ports
Serial.begin(9600);
ssgps.begin(9600);
}
void loop()
{
//As long as there are GPS data available on SW serial port send them to
//the HW serial for display purposes
while (ssgps.available() > 0)
{
gpsWord = ssgps.read();
Serial.write(gpsWord);
}
}
Regarding the SoftwareSerial there are some limitations that need to be addressed:
-If using multiple software serial ports, only one can receive data at a time.
-The current maximum RX speed is 57600bps
-RX doesn’t work on Pin 13
Raw message decoding can be accomplished with TinyGPS++ library by Mikal hart.
You can get it here: TinyGPS++
There is a number of examples on the github page, you can get a lot more on the internet
but the basic principle has as follows:
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
// Define two pins (Rx,Tx) that will be used for serial commuication
//between the Arduino and the GPS module
SoftwareSerial ssgps(4, 3);
byte gpsWord;
//Define the TinyGPS++ object
TingGPSPlus gpsPlus;
void setup()
{
//Initialise both serial ports
Serial.begin(9600);
ssgps.begin(9600);
}
void loop()
{
//As long as there are GPS data available on SW serial port send them to
//the HW serial for display purposes
while (ssgps.available() > 0)
{
gpsWord = ssgps.read();
if (gpsPlus.encode(gpsWord))
{
Serial.write(gpsWord);
Serial.println(gpsPlus.location.lat(),6);
Serial.print(F(“,”));
Serial.print(gpsPlus.location.lng(),6);
}
}
}