NeoGPS Library Compatibility

Post here first, or if you can't find a relevant section!
Post Reply
jim_patrick
Posts: 10
Joined: Tue Jul 07, 2020 12:23 pm

NeoGPS Library Compatibility

Post by jim_patrick »

Hi everyone,

I'm using an STM32F103C series board and have been trying and failing to get the NeoGPS library to work on it. I've got it working on an Arduino Nano, and so far I've never had an issue running Arduino Nano code on my STM32, but this one doesn't seem to like it.

Code: Select all

//  Description:  This program only parses an RMC sentence for the lat/lon.
// When uploading remove Tx line of GPS from Rx of Nano, 
// Can print Lat & Long to screen in 1.4mS

#include <NMEAGPS.h>


#define gpsPort Serial
#define GPS_PORT_NAME "Serial"
#define DEBUG_PORT Serial

int32_t Lat, Long;
static NMEAGPS  gps; // This parses the GPS characters


void setup()
{
  DEBUG_PORT.begin(38400);
  while (!DEBUG_PORT);

  DEBUG_PORT.println( F("Looking for GPS device on " GPS_PORT_NAME) );
  DEBUG_PORT.flush();

  gpsPort.begin(38400);
}


void loop(){
  //
  while (gps.available(gpsPort)) {
    
    gps_fix fix = gps.read();
    
    if (fix.valid.location) {
      DEBUG_PORT.print(fix.latitudeL());
      DEBUG_PORT.print(", ");
      DEBUG_PORT.println(fix.longitudeL());
      //DEBUG_PORT.print( fix.speed_mph(), 2 );
      }
    }
}
This code is from the example folder NMEAloc.ino and I've stripped it back a bit. Like I said this works fine on the Nano but nothing comes through on the STM32. I know the GPS is working because when I reset the STM32, I get 1 packet of GPS data through the Serial monitor before the code has full booted up. Then the initialising statement is printed then nothing else. I tried moving the GPS to Serial2 with no luck.

If anyone had any ideas I could try or places to look that would be really useful!

Many thanks.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: NeoGPS Library Compatibility

Post by stevestrong »

Please be aware that Serial is the acronym for USB serial.
If you want to use the hardware USART1 interface, then you should use "Serial1" in your code, for USART2 Serial2, and so on.
jim_patrick
Posts: 10
Joined: Tue Jul 07, 2020 12:23 pm

Re: NeoGPS Library Compatibility

Post by jim_patrick »

I tried using Serial1 and got no repsonse. It seems to only print data back to the monitor when it is Serial.print etc .
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: NeoGPS Library Compatibility

Post by stevestrong »

Back to the monitor yes, it goes over USB serial, but to the GPS module you have to use Serial1 (pins PA9/PA10).

Code: Select all

#define gpsPort Serial1
jim_patrick
Posts: 10
Joined: Tue Jul 07, 2020 12:23 pm

Re: NeoGPS Library Compatibility

Post by jim_patrick »

So I tried that and what happens is the GPS data is sent to the Serial Monitor while the STM32 is booting up then it stops.

I cant upload a photo for some reason it thinks a 0.3Mb png is "too large".

So my print statements to the monitor are just using Serial, but as you suggested I'm using Serial1 for the GPS. It will print the NMEA strings to the monitor for the second or so before its fully booted but after that it just prints the setup print statement then nothing else...
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: NeoGPS Library Compatibility

Post by fredbox »

I installed that library and get this warning:

Code: Select all

WARNING: library NeoGPS claims to run on avr, samd, sam, esp8266, arc32, esp32 architecture(s) and may be incompatible with your current board which runs on stm32 architecture(s).
Looking at the complexity of that library, it may be more trouble than it is worth to make it work.

TinyGPS works without any issues.
jim_patrick
Posts: 10
Joined: Tue Jul 07, 2020 12:23 pm

Re: NeoGPS Library Compatibility

Post by jim_patrick »

I had seen the warning but was hoping it would either work or there could be a little workaround. So far anything I've run on a Nano has then subsequently worked on my STM32.

Thanks, I'll try TinyGPS, hopefully thatll work with a NEO M8N.
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: NeoGPS Library Compatibility

Post by fredbox »

mrburnette wrote in this post:
Honestly, decoding the serial NMEA is so easy a library is not required; simple state machine.
Example in C for PSoC4:
Here is his example to display the GPS time converted to STM32 (1.9.0):

Code: Select all

#define mySerial SerialUSB
HardwareSerial gpsSerial(PA10, PA9);
void setup() {
  mySerial.begin(9600);
  gpsSerial.begin(9600);
}
void loop() {
  if (gpsSerial.available())
  {
    char ch = gpsSerial.read();
    if (ch == '$')
    {
      char nmea[120];
      uint32_t k = 0;
      do
      {
        while (!gpsSerial.available());
        ch = gpsSerial.read();
        nmea[k++] = ch;
      } while ((ch != '*') && (k < 120));
      if (strstr(nmea, "GPRMC"))
      {
        //mySerial.println(nmea);
        char *p = nmea;
        p = strchr(p, ',') + 1;   // time is at 1st comma
        uint32_t time = atoi(p);
        //mySerial.println(time);
        for (uint32_t n = 0; n < 8; n++)  // date is at 8th comma
        {
          p = strchr(p, ',') + 1;
        }
        uint32_t date = atoi(p);
        //mySerial.println(date);
        char buf[32];
        sprintf(buf, "20%02d/%02d/%02d %02d:%02d:%02d",
                date % 100, ((date % 10000) / 100), date / 10000,
                time / 10000, ((time % 10000) / 100), time % 100);
        mySerial.println(buf);
      }
    }
  }
}
Output:

Code: Select all

2020/07/08 00:33:20
2020/07/08 00:33:21
2020/07/08 00:33:22
2020/07/08 00:33:23
2020/07/08 00:33:24
2020/07/08 00:33:25
jim_patrick
Posts: 10
Joined: Tue Jul 07, 2020 12:23 pm

Re: NeoGPS Library Compatibility

Post by jim_patrick »

Thanks for all your help everyone. I was looking at the code for Joop Brokking's YMFC 32 Quadcopter as he also used the STM32 with a GPS and noticed in his code the Serial monitor output is initialised as Serial.begin, then the GPS is initialised on PA2/PA3 as Serial1.begin.

I had wrongly assumed that TX1, RX1 would be Serial1 and TX2, RX2 would be Serial2.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: NeoGPS Library Compatibility

Post by stevestrong »

jim_patrick wrote: Wed Jul 08, 2020 11:52 am I had wrongly assumed that TX1, RX1 would be Serial1 and TX2, RX2 would be Serial2.
Well, that assumption is actually right.
I think PA2/PA3 is Serial3 or Serial1 remapped. Or maybe Serial1 is defined as Serial3 at the beginning of the code.
Post Reply

Return to “General discussion”