|
6 | 6 | - Cat. M1
|
7 | 7 | - NB IoT
|
8 | 8 | - GNSS
|
| 9 | + - NMEA |
9 | 10 | author: 'Pablo Marquínez'
|
10 | 11 | hardware:
|
11 | 12 | - hardware/04pro/shields/portenta-cat-m1-nb-iot-gnss-shield
|
12 | 13 | software:
|
13 | 14 | - ide-v1
|
14 | 15 | - ide-v2
|
15 | 16 | - web-editor
|
| 17 | + - cli |
| 18 | +libraries: |
| 19 | + - name: 107-Arduino-NMEA-Parser |
| 20 | + url: https://github.com/107-systems/107-Arduino-NMEA-Parser |
16 | 21 | ---
|
17 | 22 |
|
18 | 23 | 
|
@@ -256,6 +261,55 @@ Open the example by going to **Examples > GSM > GNSSClient**
|
256 | 261 | You will see the **NMEA** data in the Serial monitor.
|
257 | 262 | 
|
258 | 263 |
|
| 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 | + |
259 | 313 | #### Low Power GPS
|
260 | 314 |
|
261 | 315 | The GPS antenna is active, that means that it needs power to function as it has electronics inside of it.
|
|
0 commit comments