A library for interfacing the Melopero SAM-M8Q Multi GNSS breakout board with Arduino.
If you were looking for the Python3 library for the Raspberry Pi click HERE
Melopero SAM-M8Q | Description |
---|---|
3V3 | Input power pin. Apply 3.3V to this pin |
SCL | I2C Serial CLock pin |
SDA | I2C Serial DAta pin |
GND | Ground pin |
INT | External Interrupt pin (INPUT) |
SAF | SAFEBOOT_N pin, for future service, updates and reconfiguration |
RST | RESET pin, INPUT, Active Low |
PPS | Pulse Per Second pin, OUTPUT, connected to the Blue LED |
VBA | V_BACKUP pin, INPUT. This pin accepts a voltage in the 3.3V-6V range. By applying a voltage to this pin, you will automatically disable the coin cell battery and avoid the installation of the optional CR1220 battery holder, while still allowing a warm start of the GNSS module. |
At the top of the board you'll find the pinout for connecting a FTDI cable (only FTDI cables with 3.3V data and power line!)
You will need:
- Arduino IDE, you can download it here: download Arduino IDE
- the Melopero SAM-M8Q Multi GNSS breakout: buy here
Use only 3.3V power and logic Arduino boards, such as the Arduino MKR.
DO NOT connect this board directly to 5V. You'll need a level converter to use it with an Arduino UNO.
This sensor communicates over I2C.
I2C connections:
Melopero SAM-M8Q | Arduino |
---|---|
3V3 | VCC |
SCL | SCL |
SDA | SDA |
GND | GND |
Alternatively, use the onboard Sparkfun's Qwiic compatible connectors to make a quick I2C connection without soldering
This library can be installed directly from the Library manager of the Arduino IDE.
Open the Arduino IDE, select Sketch-->Include Library-->Manage Libraries.
Type "melopero sam-m8q", select the library and click on "Install".
The installation will include some examples, available under File-->Examples-->Melopero SAM-M8Q.
This breakout board is compatible only with 3.3V power and logic board, such as the Arduino MKR.
You'll need a level converter to use this breakout board with an Arduino UNO.
//Author: Leonardo La Rocca
#include <Melopero_SAM_M8Q.h>
#include <Wire.h>
Melopero_SAM_M8Q gps;
int lastUpdate;
void setup() {
Serial.begin(9600);
//First set up the gps to use only UBX messages
//Many functions in the library return a Status
//You can get a description of the status with:
//gps.getStatusDescription(status);
//(This function returns a String)
Serial.println("Setting comunication to ubx only...");
Status stat = gps.setCommunicationToUbxOnly();
Serial.println(gps.getStatusDescription(stat));
//Check if there was an error
if (stat != Status::NoError){
Serial.println("Something went wrong... (check connections and restart script)");
while (true);
}
//After a configuration message is sent the device will
//send an acknowledge or a not acknowledged message.
//After having sent a configuration message you can
//wait for the acknowledge with:
//gps.waitForAcknowledge(MSG_CLASS, MSG_ID);
//Where MSG_CLASS and MSG_ID are the class and id of the
//message you are waiting an acknowledge for.
bool ack = gps.waitForAcknowledge(CFG_CLASS, CFG_PRT);
Serial.print("acknowledged : ");
Serial.println(ack);
lastUpdate = millis();
}
void loop() {
int curTime = millis();
if (curTime - lastUpdate > 1000){
lastUpdate = millis();
//Update the PVT data contained in gps.pvtData
//with gps.updatePVT(polling , timeoutMillis)
//by default polling is true and timeoutMillis = 1000
Status stat = gps.updatePVT();
if (stat == Status::NoError){
//Print out the data
printDate();
Serial.print("Gnss fix : ");
Serial.println(getGNSSFixType(gps.pvtData.fixType));
if (gps.pvtData.fixType != NO_FIX){
printCoordinates();
printHeight();
}
}
else {
Serial.println(gps.getStatusDescription(stat));
}
}
}
void printDate(){
Serial.print("[");
Serial.print(gps.pvtData.year);
Serial.print(" - ");
Serial.print(gps.pvtData.month);
Serial.print(" - ");
Serial.print(gps.pvtData.day);
Serial.print("] ");
Serial.print(gps.pvtData.hour);
Serial.print(" : ");
Serial.print(gps.pvtData.min);
Serial.print(" : ");
Serial.println(gps.pvtData.sec);
}
void printCoordinates(){
Serial.print("Longitude : ");
Serial.print(gps.pvtData.longitude);
Serial.print(" Latitude : ");
Serial.print(gps.pvtData.latitude);
Serial.println(" Scale: 1e-7 Unit: degrees");
}
void printHeight(){
Serial.print("Heigth: ");
Serial.print(gps.pvtData.height);
Serial.print(" Height MSL: ");
Serial.print(gps.pvtData.hMSL);
Serial.println(" Unit: millimeters");
}