HI,
I am moving my project from an ESP32 S3 to a RP2040 feather to save on battery power. The issue I have, has stumped me. The GPS stream is not been recieved correctly and hence i am unable to parse the data when calling the gps routines.
However, the gps data stream is recieved correctly if I access the gps data stream from the main loop? which points to issue with my gps routine, buts it looks ok and does work fine on the ESP32 S3.
The gps outputs at 9600 baud at 1hz. I Only need to transmit $GNRMC and $GNGGA so the gps is set up for this.
I have created a stripped out code out to replicate and try and see what going wrong but I am stuck.
#include <Arduino.h>
#include <MicroNMEA.h>
#include "gnssmodule.h"
GNSSModule gnss;
void setup() {
Serial2.setRX(9); // setup UART1 RX
Serial2.setTX(8); // setup UART1 TX
Serial.begin(115200);
gnss.initialize();
}
void loop() {
// while(Serial2.available()) {
// Serial.write(Serial2.read()); // check we are reading gps data stream
// outputs the correct and expected gps sentences
//$GNGGA,103503.000,,,,,0,00,3.9,,,,,,*46
//$GNRMC,103503.000,V,,,,,,,190125,,,N,V*23
//$GNGGA,103504.000,,,,,0,00,3.9,,,,,,*41
//$GNRMC,103504.000,V,,,,,,,190125,,,N,V*24
//}
gnss.readGNSS();
// calling gps parse from gnssmodule produces only the $GNGGA up to the 8th field??????
//$GNGGA,104217.000,,,,,0,00,25.5$GNGGA,104218.000,,,,,0,00,25.5$GNGGA,104219.000,,,,,0,00,25.5$GNGGA,104220.000,,,,,0,00,25.5$GNGGA,
}
gnssmodule.h
#ifndef _GNSSMODULE_H
#define _GNSSMODULE_H
#include "Arduino.h"
#include "MicroNMEA.h"
class GNSSModule {
public:
MicroNMEA nmea;
GNSSModule();
bool readGNSS();
void initialize();
bool step();
uint8_t getHour();
uint8_t getMinute();
double getLatitude();
double getLongitude();
private:
long _lastUpdateTime;
};
#endif
gnssmodule.cpp
#include "gnssmodule.h"
GNSSModule::GNSSModule() {};
void GNSSModule::initialize() { // initialise the gps module
Serial2.begin(9600); //map GPS on uart1 to pin 8 and 9
while(!Serial2.available()) { // if serial2 available do stuff
// add uirenderer screen to here if gpas is availabe
}
// set a flag here to indicate init has worked
}
// Returns true if new data was read.
bool GNSSModule::readGNSS() {
if((millis() - _lastUpdateTime) > 1000) { // 1 hz update so make sure we only read after 1000ms
while(Serial2.available()) { // is serial ready?
Serial.write(Serial2.read()); // check we are reading gps data stream
// nmea.process(Serial2.read()); precess gps into usable data
}
_lastUpdateTime = millis(); // set update conter back to curent millis
return true; // set flag to true if we have success
} else {
return false; // else return false no data
}
}
uint8_t GNSSModule::getHour() {
return nmea.getHour();
}
uint8_t GNSSModule::getMinute() {
return nmea.getMinute();
}
double GNSSModule::getLatitude() {
Serial.print(nmea.getLatitude());
return (double) nmea.getLatitude();
}
double GNSSModule::getLongitude() {
return (double) nmea.getLongitude();
}
bool GNSSModule::step() {
return readGNSS();
}
Any pointers/help will be most welcome
regards
jeremy