Go Down

Topic: ESP32 and GPS Neo-6m, problem on reading data  (Read 2319 times) previous topic - next topic

GuilhermeVolker

HI!
I'am trying to read data from the Neo-6m GPS on ESP32, using arduino IDE. But all i got now its a baunch of zeros, is there some exemple out there for me to understand why i have this problem? Thanks in advance.


Code: [Select]
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial serial1(3, 1); //rx,tx

void setup() {
 Serial.begin(115200);
  serial1.begin(9600); //gps baud

}

void loop() {
 bool recebido = false;
  while (serial1.available()) {
     char cIn = serial1.read();
     recebido = gps.encode(cIn);
  }
Serial.print(gps.date.value());
Serial.print(" | ");
Serial.print(gps.altitude.feet());
Serial.print(" | ");
Serial.println(gps.satellites.value());
delay(500);
}

Idahowalker

Why use Software Serial with an ESP32?

Whiles I am using an AdaFruit Ultimate GPS the principle is the same.

I load up the #include <TinyGPS++.h> library.

I load #include <HardwareSerial.h>

I declare a TinyGPSPlus GPS; and HardwareSerial GPSSerial ( 1 );

In setup I do these things
Code: [Select]
GPSSerial.begin ( GPS_DataBits, SERIAL_8N1, 2, 15 ); // begin GPS hardware serial
xTaskCreatePinnedToCore( fGPS_Parse, "fGPS_Parse", TaskStack10K3, NULL, Priority5, NULL, TaskCore0 ); // assigned to core 0
  sema_GPS_Gate = xSemaphoreCreateMutex();
  xSemaphoreGive( sema_GPS_Gate );


This is the defined task to get the GPS data:
Code: [Select]
////////////////////////////////////////////////////////////////////////////
void fGPS_Parse(  void *pvParameters )
{
  int iBit = 1;
  for (;;)
  {
    xEventGroupWaitBits (eg, evtGPS_Parse, pdTRUE, pdTRUE, portMAX_DELAY) ;
    if ( xSemaphoreTake( sema_GPS_Gate, xTicksToWait0 ) == pdTRUE )
    {
      //query GPS: has a new complete chunk of data been received?
      if ( GPSSerial.available() > 1 )
      {
        if ( GPS.encode(GPSSerial.read()) )
        {
          if (  GPS.location.isValid())
          {
            if ( xSemaphoreTake( sema_Posit, xSemaphoreTicksToWait ) == pdTRUE )
            {
              xPosit.Lat = GPS.location.lat();// store data into structure
              xPosit.Lon = GPS.location.lng();
              xSemaphoreGive( sema_Posit );
            }
          } // if (  GPS.location.isValid())
          if (GPS.speed.isValid())
          {
            if ( xSemaphoreTake( sema_Posit, xSemaphoreTicksToWait ) == pdTRUE )
            {
              xPosit.MPH = GPS.speed.mph();
              xPosit.KPH = GPS.speed.kmph();
              xSemaphoreGive( sema_Posit );
            }
          } //  if (GPS.speed.isValid())
          if (GPS.time.isValid())
          {
            if ( xSemaphoreTake( sema_Time, xSemaphoreTicksToWait ) == pdTRUE )
            {
              xTime.iSeconds = GPS.time.second();
              xTime.iMinutes = GPS.time.minute();
              xTime.iHours = GPS.time.hour();
              xSemaphoreGive( sema_Time );
            }
          } // if (GPS.time.isValid())
          if (GPS.date.isValid())
          {
            if ( xSemaphoreTake( sema_Date, xSemaphoreTicksToWait ) == pdTRUE )
            {
              xDate.iMonth = GPS.date. month();
              xDate.iDay = GPS.date.day();
              xDate.iYear = GPS.date.year();
              xSemaphoreGive( sema_Date );
            }
          } // if (GPS.date.isValid())
          if (  GPS.altitude.isValid() )
          {
            if ( xSemaphoreTake( sema_Posit, xSemaphoreTicksToWait ) == pdTRUE )
            {
              xPosit.Alti = GPS.altitude.meters();
              xSemaphoreGive( sema_Posit );
            }
          } //  if (  GPS.altitude.isValid() )
          if ( GPS.course.isUpdated() )
          {
            if ( xSemaphoreTake( sema_Posit, xSemaphoreTicksToWait ) == pdTRUE )
            {
              xPosit.Hdg = GPS.course.deg();
              xSemaphoreGive( sema_Posit );
            }
          } // if ( GPS.course.isUpdated() )
          if ( xSemaphoreTake( sema_Posit, xSemaphoreTicksToWait ) == pdTRUE )
          {
            xQueueOverwrite( xQ_Posit, (void *) &xPosit );
            xSemaphoreGive( sema_Posit );
          }
        } // if ( GPS.encode(GPSSerial.read()))
      } // if ( GPSSerial.available() > 0 )
      xSemaphoreGive( sema_GPS_Gate );
    }
  } // for (;;)
  vTaskDelete( NULL );
} // void fGPS_Parse(  void *pvParameters )
////////////////////////////////////////////////////////////////////////////////



GPS Parsing is triggered by a 1mS hardware timer. Works great.
1/18/2018, got my first Arduino Uno.

GuilhermeVolker

I just bought one esp32, so i'am still learning. I'll try your code, thanks a lot!

srnet

#3
Jun 14, 2019, 10:04 pm Last Edit: Jun 14, 2019, 10:05 pm by srnet
Have you realised that every time a character arives from the GPS, you go off and print to the serial console a whole lot of information that has almost certainly not been updated ?

You should keep sending stuff to the gps.encode function until a fix is updated, then you can print the lat and long stuff to the serial monitor.
No PMs please, they dont get answered.

srnet

This is what I would do;

Code: [Select]
void loop()
{

  while (serial1.available())
  {
    char cIn = serial1.read();
    recebido = gps.encode(cIn);
  }

  if (gps.location.isUpdated() && gps.altitude.isUpdated())
  {

    Serial.print(gps.date.value());
    Serial.print(" | ");
    Serial.print(gps.altitude.feet());
    Serial.print(" | ");
    Serial.println(gps.satellites.value());
  }
}
No PMs please, they dont get answered.

GuilhermeVolker

Now, with all the modifications on the code:

Code: [Select]
#include <HardwareSerial.h>
//#include <SoftwareSerial.h>

#include <TinyGPS++.h>


TinyGPSPlus gps;

// The serial connection to the GPS device
//HardwareSerial Serial1(3, 1); //rx,tx

void setup() {
 Serial.begin(115200);
 Serial1.begin(9600, SERIAL_8N1, 3, 1); //gps baud
}

void loop() {
 bool recebido = false;
  while (Serial1.available()) {
     char cIn = Serial1.read();
     recebido = gps.encode(cIn);
  }
   if (gps.location.isUpdated() && gps.altitude.isUpdated())
  {
Serial.print(gps.date.value());
Serial.print(" | ");
Serial.print(gps.altitude.feet());
Serial.print(" | ");
Serial.println(gps.satellites.value());
delay(500);
  }
}



On the Serial port i'am receiving this mensage, without any data from the gps  :smiley-eek: :


ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9232
load:0x40080400,len:6412
entry 0x400806a8




Idahowalker

Code: [Select]
Serial1.begin(9600, SERIAL_8N1, 3, 1); //gps baud

The ESP32 does NOT have a Serial0 or Serial1 or Serial2. The ESP32, for serial ports has (0), (1), (2).

What you are seeing on Serial is normal boot stuff.
1/18/2018, got my first Arduino Uno.

GuilhermeVolker

#7
Jun 15, 2019, 05:48 pm Last Edit: Jun 15, 2019, 05:49 pm by GuilhermeVolker
Well, i finally was able to read the gps data, the code that  made it possible is bellow:

Code: [Select]
/*some obs:
 *  * There are three serial ports on the ESP known as U0UXD, U1UXD and U2UXD.
 *
 * U0UXD is used to communicate with the ESP32 for programming and during reset/boot.
 * U1UXD is unused and can be used for your projects. Some boards use this port for SPI Flash access though
 * U2UXD is unused and can be used for your projects.
 * on the code, i use the u2uxd. Dont forget to invert the rx/tx with the sensor ;)
 */

#include <HardwareSerial.h>
#include <TinyGPS++.h>

#define RXD2 16
#define TXD2 17

TinyGPSPlus gps;

void setup() {
 Serial.begin(115200);
 Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2); //gps baud
}

void loop() {
 bool recebido = false;
  while (Serial1.available()) {
     char cIn = Serial1.read();
     recebido = gps.encode(cIn);
  }
   if (gps.location.isUpdated() && gps.altitude.isUpdated())
  {
    Serial.print("D/M/A: ");
Serial.print(gps.date.value());
Serial.print(" | alt: ");
Serial.print(gps.altitude.feet());
Serial.print(" | satellites: ");
Serial.println(gps.satellites.value());
delay(500);
  }
}

Go Up