Skip to content

Commit 9730a6d

Browse files
authored
Merge pull request #401 from manchoz/add_gps_library
Add GPS to exported libraries
2 parents 38b1f98 + dafb45b commit 9730a6d

File tree

4 files changed

+117
-83
lines changed

4 files changed

+117
-83
lines changed

.github/workflows/compile-examples.yml

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
additional-libraries: |
6565
- name: lvgl
6666
version: 7.11.0
67+
- name: MicroNMEA
6768
additional-sketch-paths: |
6869
- libraries/PDM
6970
- libraries/doom
@@ -80,6 +81,7 @@ jobs:
8081
- libraries/USBHOST
8182
- libraries/USBMSD/examples/AccessFlashAsUSBDisk
8283
- libraries/WiFi
84+
- libraries/GSM
8385
- board:
8486
fqbn: arduino:mbed:nanorp2040connect
8587
additional-sketch-paths: |

libraries/GSM/examples/GNSSClient/GNSSClient.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include <GPS.h>
22
#include <GSM.h>
33

4-
REDIRECT_STDOUT_TO(Serial);
5-
64
#include "arduino_secrets.h"
75
char pin[] = SECRET_PIN;
86
char apn[] = SECRET_APN;
@@ -26,6 +24,8 @@ void setup() {
2624
}
2725

2826
void loop() {
27+
// Print out raw NMEA strings.
28+
// For parsed output look at the MicroNMEA_integration example.
2929
if(GPS.available()){
3030
Serial.print((char) GPS.read());
3131
delay(1);
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,124 @@
1+
#include <GPS.h>
12
#include <GSM.h>
23
#include <MicroNMEA.h>
34

45
#include "arduino_secrets.h"
5-
char pin[] = SECRET_PIN;
6-
char apn[] = SECRET_APN;
7-
char username[] = SECRET_USERNAME;
8-
char pass[] = SECRET_PASSWORD;
9-
10-
void mycallback(char * output);
11-
12-
void setup() {
13-
Serial.begin(115200);
14-
while (!Serial) {}
15-
//GSM.debug(Serial);
16-
Serial.println("\nStarting connection to server...");
17-
GSM.begin(pin, apn, username, pass, CATNB);
18-
Serial.println("\nStarting connection ...");
19-
20-
Serial.println("\nEnable GNSS Engine...");
21-
GSM.beginGNSS(mycallback);
22-
GSM.startGNSS();
23-
}
6+
constexpr auto pin { SECRET_PIN };
7+
constexpr auto apn { SECRET_APN };
8+
constexpr auto username { SECRET_USERNAME };
9+
constexpr auto pass { SECRET_PASSWORD };
2410

2511
char nmeaBuffer[100];
2612
MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer));
2713

28-
void loop() {
29-
30-
delay(1000);
31-
32-
// Output GPS information from previous second
33-
Serial.print("Valid fix: ");
34-
Serial.println(nmea.isValid() ? "yes" : "no");
35-
36-
if (nmea.isValid()) {
37-
38-
Serial.print("Nav. system: ");
39-
if (nmea.getNavSystem())
40-
Serial.println(nmea.getNavSystem());
41-
else
42-
Serial.println("none");
43-
44-
Serial.print("Num. satellites: ");
45-
Serial.println(nmea.getNumSatellites());
46-
47-
Serial.print("HDOP: ");
48-
Serial.println(nmea.getHDOP() / 10., 1);
49-
50-
Serial.print("Date/time: ");
51-
Serial.print(nmea.getYear());
52-
Serial.print('-');
53-
Serial.print(int(nmea.getMonth()));
54-
Serial.print('-');
55-
Serial.print(int(nmea.getDay()));
56-
Serial.print('T');
57-
Serial.print(int(nmea.getHour()));
58-
Serial.print(':');
59-
Serial.print(int(nmea.getMinute()));
60-
Serial.print(':');
61-
Serial.println(int(nmea.getSecond()));
62-
63-
long latitude_mdeg = nmea.getLatitude();
64-
long longitude_mdeg = nmea.getLongitude();
65-
Serial.print("Latitude (deg): ");
66-
Serial.println(latitude_mdeg / 1000000., 6);
67-
68-
Serial.print("Longitude (deg): ");
69-
Serial.println(longitude_mdeg / 1000000., 6);
70-
71-
long alt;
72-
Serial.print("Altitude (m): ");
73-
if (nmea.getAltitude(alt))
74-
Serial.println(alt / 1000., 3);
75-
else
76-
Serial.println("not available");
77-
78-
Serial.print("Speed: ");
79-
Serial.println(nmea.getSpeed() / 1000., 3);
80-
Serial.print("Course: ");
81-
Serial.println(nmea.getCourse() / 1000., 3);
82-
}
14+
// Keep track of NMEA string processing
15+
auto nmeaProcessStatus { false };
16+
17+
// Check for valid fix every checkValidInterval ms
18+
constexpr unsigned long checkValidInterval { 5000 };
19+
unsigned long checkValidNow {};
20+
21+
void setup()
22+
{
23+
Serial.begin(115200);
24+
for (const auto timeout = millis() + 2500; !Serial && millis() < timeout; delay(250))
25+
;
26+
27+
// GSM.debug(Serial);
28+
delay(1000);
29+
30+
Serial.println("Starting Carrier Network registration");
31+
if (!GSM.begin(pin, apn, username, pass, CATNB)) {
32+
Serial.println("The board was not able to register to the network...");
33+
// do nothing forevermore:
34+
while (1)
35+
;
36+
}
37+
Serial.println("Enable GNSS Engine...");
38+
// GPS.begin() start and eanble the GNSS engine
39+
GPS.begin();
40+
Serial.println("GNSS Engine enabled...");
41+
Serial.println("Waiting for a valid fix.");
42+
43+
checkValidNow = millis();
8344
}
8445

85-
void mycallback(char * output)
46+
void loop()
8647
{
87-
for (size_t i = 0; i < strlen(output); i++) {
88-
nmea.process(output[i]);
89-
}
90-
nmea.process('\0');
91-
//Serial.println(output);
48+
while (GPS.available()) {
49+
char c = GPS.read();
50+
// process is true when a valid NMEA string has been processed
51+
nmeaProcessStatus = nmea.process(c);
52+
}
53+
54+
if (nmeaProcessStatus && millis() > checkValidNow) {
55+
checkValidNow = millis() + checkValidInterval;
56+
57+
// Output GPS information from previous second
58+
Serial.print("Valid fix: ");
59+
Serial.println(nmea.isValid() ? "yes" : "no");
60+
61+
if (!nmea.isValid())
62+
return;
63+
64+
String navSystem;
65+
switch (nmea.getNavSystem()) {
66+
case 'N':
67+
navSystem = "GNSS";
68+
break;
69+
case 'P':
70+
navSystem = "GPS";
71+
break;
72+
case 'L':
73+
navSystem = "GLONASS";
74+
break;
75+
case 'A':
76+
navSystem = "Galileo";
77+
break;
78+
default:
79+
break;
80+
}
81+
Serial.print("Nav. system: ");
82+
Serial.println(navSystem);
83+
84+
Serial.print("Num. satellites: ");
85+
Serial.println(nmea.getNumSatellites());
86+
87+
Serial.print("HDOP: ");
88+
Serial.println(nmea.getHDOP() / 10., 1);
89+
90+
Serial.print("Date/time: ");
91+
Serial.print(nmea.getYear());
92+
Serial.print('-');
93+
Serial.print(int(nmea.getMonth()));
94+
Serial.print('-');
95+
Serial.print(int(nmea.getDay()));
96+
Serial.print('T');
97+
Serial.print(int(nmea.getHour()));
98+
Serial.print(':');
99+
Serial.print(int(nmea.getMinute()));
100+
Serial.print(':');
101+
Serial.println(int(nmea.getSecond()));
102+
103+
long latitude_mdeg = nmea.getLatitude();
104+
long longitude_mdeg = nmea.getLongitude();
105+
Serial.print("Latitude (deg): ");
106+
Serial.println(latitude_mdeg / 1000000., 6);
107+
108+
Serial.print("Longitude (deg): ");
109+
Serial.println(longitude_mdeg / 1000000., 6);
110+
111+
long alt;
112+
Serial.print("Altitude (m): ");
113+
if (nmea.getAltitude(alt))
114+
Serial.println(alt / 1000., 3);
115+
else
116+
Serial.println("not available");
117+
118+
Serial.print("Speed: ");
119+
Serial.println(nmea.getSpeed() / 1000., 3);
120+
Serial.print("Course: ");
121+
Serial.println(nmea.getCourse() / 1000., 3);
122+
nmea.clear();
123+
}
92124
}

portenta.variables

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export FLAVOUR="portenta"
22
export VARIANTS=("PORTENTA_H7_M7 PORTENTA_H7_M4")
33
export FQBNS=("envie_m7 envie_m4")
4-
export LIBRARIES=("doom Ethernet MRI Portenta_SDRAM SPI WiFi ea_malloc openamp_arduino Portenta_System ThreadDebug Himax_HM01B0 PDM Portenta_Video USBAudio KernelDebug Portenta_Audio RPC USBHID Wire Portenta_lvgl Portenta_Camera rpclib USBHOST mbed-memory-status Portenta_SDCARD Scheduler USBMSD SocketWrapper GSM")
4+
export LIBRARIES=("doom Ethernet MRI Portenta_SDRAM SPI WiFi ea_malloc openamp_arduino Portenta_System ThreadDebug Himax_HM01B0 PDM Portenta_Video USBAudio KernelDebug Portenta_Audio RPC USBHID Wire Portenta_lvgl Portenta_Camera rpclib USBHOST mbed-memory-status Portenta_SDCARD Scheduler USBMSD SocketWrapper GSM GPS")
55
export BOOTLOADERS=("PORTENTA_H7")

0 commit comments

Comments
 (0)