Skip to content

Commit 2f32c88

Browse files
authored
Merge pull request #57 from arduino/sync/marqdevx/CatM1/gps-parsing
CatM1 GPS - adding how to parse NMEA data [PC-860]
2 parents 4991cde + 4eb60f6 commit 2f32c88

File tree

1 file changed

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

1 file changed

+54
-0
lines changed

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

+54
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ tags:
66
- Cat. M1
77
- NB IoT
88
- GNSS
9+
- NMEA
910
author: 'Pablo Marquínez'
1011
hardware:
1112
- hardware/04pro/shields/portenta-cat-m1-nb-iot-gnss-shield
1213
software:
1314
- ide-v1
1415
- ide-v2
1516
- web-editor
17+
- cli
18+
libraries:
19+
- name: 107-Arduino-NMEA-Parser
20+
url: https://github.com/107-systems/107-Arduino-NMEA-Parser
1621
---
1722

1823
![The Arduino® Portenta Cat. M1/NB IoT GNSS Shield](assets/featured.png)
@@ -256,6 +261,55 @@ Open the example by going to **Examples > GSM > GNSSClient**
256261
You will see the **NMEA** data in the Serial monitor.
257262
![NMEA log example Serial Monitor](assets/NMEA_output.png)
258263

264+
#### Parse NMEA GPS Sentences
265+
266+
Previously we went through how to show the GPS data in the Serial Monitor, but it was not possible to evaluate those messages (NMEA sentences).
267+
To do so you can use an **NMEA parser** this will convert the messages received from the GPS modem, parsing and saving them into variables. You can use the **107-Arduino-NMEA-Parser** library. This library can be found in the library manager inside the Arduino IDE.
268+
269+
This makes it possible to interact with the data that you need for your application, for example if you only want to get the latitude and longitude. You will be able to save those needed values into variables, instead of having the whole NMEA messages.
270+
271+
Open the example from the library at **Examples > 107-Arduino-NMEA-Parser > NMEA-Basic** and you need to add the following:
272+
273+
Include the needed libraries.
274+
275+
```cpp
276+
#include "GPS.h"
277+
#include "GSM.h"
278+
#include "ArduinoNmeaParser.h"
279+
#include "Arduino_secrets.h"
280+
281+
char pin[] = SECRET_PIN;
282+
char apn[] = SECRET_APN;
283+
char username[] = SECRET_LOGIN;
284+
char pass[] = SECRET_PASS;
285+
```
286+
287+
Inside the `setup()` initialize the GSM and GPS modules.
288+
289+
```cpp
290+
void setup(){
291+
Serial.begin(115200);
292+
while (!Serial) {}
293+
Serial.println("GSM...");
294+
GSM.begin(pin, apn, username, pass, CATNB);
295+
Serial.println("GPS...");
296+
GPS.begin();
297+
Serial.println("Success");
298+
}
299+
```
300+
301+
Edit the loop to parse the `GPS` readings instead of the `Serial1`.
302+
303+
```cpp
304+
void loop(){
305+
while(GPS.available()){
306+
parser.encode((char)GPS.read());
307+
}
308+
}
309+
```
310+
311+
***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.***
312+
259313
#### Low Power GPS
260314

261315
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)