Skip to content

Commit d5a75a3

Browse files
committed
Add NMEA parsing section
1 parent 4991cde commit d5a75a3

File tree

1 file changed

+47
-0
lines changed
  • content/hardware/04.pro/shields/portenta-cat-m1-nb-iot-gnss-shield/tutorials/cheat-sheet

1 file changed

+47
-0
lines changed

content/hardware/04.pro/shields/portenta-cat-m1-nb-iot-gnss-shield/tutorials/cheat-sheet/cheat-sheet.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,53 @@ Open the example by going to **Examples > GSM > GNSSClient**
256256
You will see the **NMEA** data in the Serial monitor.
257257
![NMEA log example Serial Monitor](assets/NMEA_output.png)
258258

259+
#### Parse NMEA GPS Sentences
260+
261+
Previously we shown how to show the GPS data on the Serial Monitor, but it was not possible to evaluate those messages (NMEA sentences).
262+
To do so you can use an **NMEA parser** that will convert the messages received from the GPS modem and it will parse and save them into variables, you can use the **107-Arduino-NMEA-Parser** library.
263+
264+
Open the example from the library at **Examples > 107-Arduino-NMEA-Parser > NMEA-Basic** and you need to add the following:
265+
266+
Include the needed libraries.
267+
268+
```cpp
269+
#include "GPS.h"
270+
#include "GSM.h"
271+
#include "ArduinoNmeaParser.h"
272+
#include "Arduino_secrets.h"
273+
274+
char pin[] = SECRET_PIN;
275+
char apn[] = SECRET_APN;
276+
char username[] = SECRET_LOGIN;
277+
char pass[] = SECRET_PASS;
278+
```
279+
280+
Inside the `setup()` initialize the GSM and GPS modules.
281+
282+
```cpp
283+
void setup(){
284+
Serial.begin(115200);
285+
while (!Serial) {}
286+
Serial.println("GSM...");
287+
GSM.begin(pin, apn, username, pass, CATNB);
288+
Serial.println("GPS...");
289+
GPS.begin();
290+
Serial.println("Success");
291+
}
292+
```
293+
294+
Edit the loop to parse the `GPS` readings instead of the `Serial1`.
295+
296+
```cpp
297+
void loop(){
298+
while(GPS.available()){
299+
parser.encode((char)GPS.read());
300+
}
301+
}
302+
```
303+
304+
***You will see the output data as various "-1" until the GPS has enough visible satellites to get the correct data, make sure the GPS antenna is somewhere that can see the sky.***
305+
259306
#### Low Power GPS
260307

261308
The GPS antenna is active, that means that it needs power to function as it has electronics inside of it.

0 commit comments

Comments
 (0)