logo elektroda
logo elektroda
X
logo elektroda

Code for GPS NEO 6M with TinyGPSPlus, display of latitude and longitude

CC_PL 957 15
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 20566891
    CC_PL
    Level 13  
    I have the following code:

    
    #include <TinyGPSPlus.h>
    #include <SoftwareSerial.h>
    
    static const int RXPin = 4, TXPin = 3;
    static const uint32_t GPSBaud = 4800;
    
    TinyGPSPlus gps;
    SoftwareSerial ss(RXPin, TXPin);
    
    void setup()
    {
      Serial.begin(115200);
      ss.begin(GPSBaud);
    }
    
    
    char buffer[25];
    
    void showData()
    {
    
      if (gps.location.isValid() && (gps.location.age() < 2000))
       {
       sprintf(buffer, "LATITUDE-%f", gps.location.lat());
       Serial.println(buffer);
    
       sprintf(buffer, "LONGITUDE-%f", gps.location.lng());
       Serial.println(buffer);
    }
    
      if (millis() > 5000 && gps.charsProcessed() < 10)
      {
        Serial.println(F("No GPS detected: check wiring."));
        while(true);
      }
    }
    


    But firing the ShowData(); function does not have the desired effect. What could be the reason for this? I don't get the GPS coordinates...

    Thanks in advance for the hints!
  • ADVERTISEMENT
  • #2 20566935
    JacekCz
    Level 42  
    CC_PL wrote:
    But firing the ShowData(); function does not produce the desired effects.



    It is not anyone's responsibility to wonder what you think the "desired effects" are. - and what those "undesirable effects" are
    You have some diagnostics, but we are supposed to guess.

    CC_PL wrote:
    I have the following code:



    This formula usually means "I plucked the code from the net somewhere". Thanks for the honesty.

    ps. I don't see f. loop()
  • ADVERTISEMENT
  • #3 20566948
    CC_PL
    Level 13  
    The desired effects are to display the LATNG coordinates :) And the example is simply an example for the library.

    loop() is not there because I only pasted part of the code. When I fire up the example from Git Hub it still gets:

    No GPS detected: check wiring.


    I have checked the wiring many times :) .
  • ADVERTISEMENT
  • Helpful post
    #4 20566991
    khoam
    Level 42  
    CC_PL wrote:
    When I fire up the example from Git Hub it still gets:
    It's still you have to choose different pins for SoftwareSerial in the case of ESP32, because 3 and 4 are the wrong choice. Link
    Beyond that, ESP32 has more than one HardwareSerial (Serial, Serial1, Serial2), so using SoftwareSerial is such a bit pointless.
  • #5 20567002
    CC_PL
    Level 13  
    #include <TinyGPSPlus.h>
    
    #define RXD2 16
    #define TXD2 17
    static const uint32_t GPSBaud = 9600;
    
    
    TinyGPSPlus gps;
    
    void setup() {
      Serial.begin(115200);
      Serial2.begin(GPSBaud, SERIAL_8N1, RXD2, TXD2);
    }
    
    void loop()
    {
    
      while (Serial2.available() > 0)
    
        if (gps.encode(Serial2.read()))
    
          displayInfo();
    
     
    
      if (millis() > 5000 && gps.charsProcessed() < 10)
    
      {
    
        Serial.println(F("No GPS detected: check wiring."));
    
        while(true);
    
      }
    
    }
    
    void displayInfo()
    
    {
    
      Serial.print(F("Location: "));
    
      if (gps.location.isValid())
    
      {
    
        Serial.print(gps.location.lat(), 6);
    
        Serial.print(F(","));
    
        Serial.print(gps.location.lng(), 6);
    
      }
    
      else
    
      {
    
        Serial.print(F("INVALID"));
    
      }
    
      Serial.print(F("  Date/Time: "));
    
      if (gps.date.isValid())
    
      {
    
        Serial.print(gps.date.month());
    
        Serial.print(F("/"));
    
        Serial.print(gps.date.day());
    
        Serial.print(F("/"));
    
        Serial.print(gps.date.year());
    
      }
    
      else
    
      {
    
        Serial.print(F("INVALID"));
    
      }
    
      Serial.print(F(" "));
    
      if (gps.time.isValid())
    
      {
    
        if (gps.time.hour() < 10) Serial.print(F("0"));
    
        Serial.print(gps.time.hour());
    
        Serial.print(F(":"));
    
        if (gps.time.minute() < 10) Serial.print(F("0"));
    
        Serial.print(gps.time.minute());
    
        Serial.print(F(":"));
    
        if (gps.time.second() < 10) Serial.print(F("0"));
    
        Serial.print(gps.time.second());
    
        Serial.print(F("."));
    
        if (gps.time.centisecond() < 10) Serial.print(F("0"));
    
        Serial.print(gps.time.centisecond());
    
      }
      else
    
      {
        Serial.print(F("INVALID"));
    
      }
    
      Serial.println("OK");
    
    }
    

    Also not working :( .
  • Helpful post
    #6 20567038
    khoam
    Level 42  
    What voltage are you supplying the NEO with, 5V or 3.3V?
  • ADVERTISEMENT
  • #7 20567048
    CC_PL
    Level 13  
    I supply 3.3V. I have two modules (NEO6M and SAM M8Q), I soldered the cables and nothing

    Still GPS not detected, check wiring.
  • Helpful post
    #8 20567054
    khoam
    Level 42  
    I'm going to ask a bit of a stupid question, but I want to make sure. Did you connect the TX from the Neo to the RX in the ESP, and the RX from the Neo to the TX in the ESP?
  • #9 20567064
    CC_PL
    Level 13  
    Yes, as it is in the UART,

    Added after 7 [hours] 56 [minutes]:

    I tried this code:

    Quote:
    #include
    #include

    HardwareSerial GPSSerial (2);
    TinyGPSPlus gps;

    void setup()
    {
    Serial.begin(9600);
    GPSSerial.begin ( 9600, SERIAL_8N1, 16, 17 ); // begin GPS hardware serial
    }

    void loop()
    {

    Serial.begin(9600);
    // This sketch displays information every time a new sentence is correctly encoded.
    while (GPSSerial.available() > 0)
    if (gps.encode(GPSSerial.read()))
    displayInfo();

    if (millis() > 10000 && gps.charsProcessed() < 10)
    {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
    }
    }

    void displayInfo()
    {
    Serial.print(F("Location: "));
    if (gps.location.isValid()))
    {
    Serial.print(gps.location.lat(), 9);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 9);
    }
    else
    {
    Serial.print(F("INVALID"));
    }
    }


    and same error: Check wiring

    I still used the "echo" test:
    Quote:

    #define RXDATA 16 //pin where data from GPS is received, default for Serial2, but can be changed
    #define TXDATA 17 //pin where data is sent to GPS, default for Serial2, but can be changed

    void loop()
    {
    while (Serial2.available())
    {
    Serial.write(Serial2.read());
    }
    }

    void setup()
    {
    Serial2.begin(9600, SERIAL_8N1, RXDATA, TXDATA); //serial for GPS

    Serial.begin(115200);
    Serial.println();
    Serial.println("GPS_Echo Starting");
    }


    I get:

    Quote:

    08:19:15.815 ->
    08:19:15.815 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    08:19:15.815 -> configsip: 0, SPIWP:0xee
    08:19:15.815 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    08:19:15.849 -> mode:D IO, clock div:1
    08:19:15.849 -> load:0x3fff0030,len:1344
    08:19:15.849 -> load:0x40078000,len:13924
    08:19:15.849 -> ho 0 tail 12 room 4
    08:19:15.849 -> load:0x40080400,len:3600
    08:19:15.849 -> entry 0x400805f0
    08:19:15.948 ->
    08:19:15.948 -> GPS_Echo Starting
    08:19:15.948 ->


    Added after 2 [hours] 33 [minutes]:

    On the ESP32 forum I got the answer that PIN 17 cannot be used.... Are they writing the truth? From the pinout of this board, it appears that this is the TX from UART2.
  • #10 20567380
    khoam
    Level 42  
    CC_PL wrote:
    From the pinout of this board, it appears that this is the TX from UART2.

    Detailed and you are using Serial2 (UART2).

    Code for GPS NEO 6M with TinyGPSPlus, display of latitude and longitude
    Link

    CC_PL wrote:
    On the ESP32 forum I got the answer, that PIN 17 cannot be used..

    Unbelievable stories. What is this "ESP32 forum"?
  • #11 20567402
    CC_PL
    Level 13  
    Thanks for the tables

    This is the main Esspressif forum. I think the guy was referring to some rare PSRAM memory board.
  • #12 20567405
    khoam
    Level 42  
    On Serial2 it should fire up from the first boot. I have no idea at the moment what could be wrong. You say all connections are OK, so maybe the module itself has a problem. Remotely it's a bit like fortune telling. I provide a link to a project where this is done using Serial2, but the code there doesn't seem particularly different from what you've posted. Link


    What specifically is this board with ESP32?
  • #14 20567457
    khoam
    Level 42  
    The module from ESP32 is the "standard" one. What, on the other hand, are the GPS modules from NEO?
  • #15 20567561
    CC_PL
    Level 13  
    I have a Neo 6M and two SAM M8Q.

    Added after 52 [minutes]:

    I have a new set of cables. The power is working at last (the red LED on the GPS is on). The blue one should still be on.

    In the serial monitor I have: "coordinates wrong". - Location Invalid.
  • #16 20567737
    khoam
    Level 42  
    This means only that and only that the GPS module has not caught the signal from the spy satellites. Sometimes it takes many minutes and sometimes it helps to reposition the module.

Topic summary

The discussion revolves around issues with a GPS NEO 6M module using the TinyGPSPlus library for Arduino. The user is attempting to display latitude and longitude coordinates but encounters a "No GPS detected: check wiring" error. Various responses suggest checking wiring connections, using appropriate pins for SoftwareSerial on ESP32, and ensuring the correct voltage supply (3.3V). The user confirms connections are correct and mentions using two GPS modules (NEO 6M and SAM M8Q). Despite troubleshooting, the GPS module fails to acquire a signal, leading to invalid location readings. Suggestions include repositioning the module for better satellite signal reception.
Summary generated by the language model.
ADVERTISEMENT