GPS with ESP8266

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ridanleffell
 
Posts: 6
Joined: Sun Jan 12, 2020 10:51 pm

GPS with ESP8266

Post by ridanleffell »

Hello all,

I have a student who is using the GPS adafruit breakout successfully with an Arduino, but when she switched to a NodeMCU (ESP8266) we don't get any readings. e.g. "Time: ******".
Is there anything we are not realizing about the ESP/GPS interaction?... HELP!

Thanks!

User avatar
Franklin97355
 
Posts: 23902
Joined: Mon Apr 21, 2008 2:33 pm

Re: GPS with ESP8266

Post by Franklin97355 »

What code is she running and how is it connected?

User avatar
ridanleffell
 
Posts: 6
Joined: Sun Jan 12, 2020 10:51 pm

Re: GPS with ESP8266

Post by ridanleffell »

Thank you for your help! I am using a NodeMCU, ESP8266 and an ultimate GPS Breakout v3 board. When uploading my code, the GPS bored receives a FIX. Yet, the GPS coordinates are not printing on the consul. However, when using an Arduino, instead of a NodeMCU, the code seems to work. Do you have any advice or suggestions in order to solve this problem?

TX -> Pin 8
RX -> Pin 7
GND -> GND
VIN -> 3v3

Thank you

Code: Select all

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/* Create object named bt of the class SoftwareSerial */
SoftwareSerial GPS_SoftSerial(8, 7);/* (Rx, Tx) *
//SoftwareSerial GPS_SoftSerial(2, 3);/* (Rx, Tx) *
/* Create an object named gps of the class TinyGPSPlus */
TinyGPSPlus gps;              

volatile float minutes, seconds;
volatile int degree, secs, mins;

void setup() {
 Serial.begin(115200);   /* Define baud rate for serial communication */
 //Serial.begin(9600);   /* Define baud rate for serial communication */
 GPS_SoftSerial.begin(9600); /* Define baud rate for software serial communication */
}

void loop() {
       smartDelay(1000);     /* Generate precise delay of 1ms */
        unsigned long start;
        double lat_val, lng_val, alt_m_val;
        uint8_t hr_val, min_val, sec_val;
        bool loc_valid, alt_valid, time_valid;
       lat_val = gps.location.lat();     /* Get latitude data */
       loc_valid = gps.location.isValid();     /* Check if valid location data is available */
       lng_val = gps.location.lng();     /* Get longtitude data */
       alt_m_val = gps.altitude.meters();      /* Get altitude data in meters */
        alt_valid = gps.altitude.isValid();     /* Check if valid altitude data is available */
       hr_val = gps.time.hour();   /* Get hour */
       min_val = gps.time.minute();      /* Get minutes */
       sec_val = gps.time.second();      /* Get seconds */
       time_valid = gps.time.isValid();  /* Check if valid time data is available */
        if (!loc_valid)
       {        
         Serial.print("Latitude : ");
         Serial.println("*****");
         Serial.print("Longitude : ");
         Serial.println("*****");
        }
        else
        {
         DegMinSec(lat_val);
         Serial.print("Latitude in Decimal Degrees : ");
         Serial.println(lat_val, 6);
         Serial.print("Latitude in Degrees Minutes Seconds : ");
         Serial.print(degree);
         Serial.print("\t");
         Serial.print(mins);
         Serial.print("\t");
         Serial.println(secs);
         DegMinSec(lng_val); /* Convert the decimal degree value into degrees minutes seconds form */
         Serial.print("Longitude in Decimal Degrees : ");
         Serial.println(lng_val, 6);
         Serial.print("Longitude in Degrees Minutes Seconds : ");
         Serial.print(degree);
         Serial.print("\t");
         Serial.print(mins);
         Serial.print("\t");
         Serial.println(secs);
        }
        if (!alt_valid)
        {
         Serial.print("Altitude : ");
         Serial.println("*****");
        }
        else
        {
         Serial.print("Altitude : ");
         Serial.println(alt_m_val, 6);  
        }
        if (!time_valid)
        {
         Serial.print("Time : ");
         Serial.println("*****");
        }
        else
        {
         char time_string[32];
         sprintf(time_string, "Time : %02d/%02d/%02d \n", hr_val, min_val, sec_val);
         Serial.print(time_string);  
        }
}

static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do
  {
    while (GPS_SoftSerial.available())    /* Encode data read from GPS while data is available on serial port */
     gps.encode(GPS_SoftSerial.read());
/* Encode basically is used to parse the string received by the GPS and to store it in a buffer so that information can be extracted from it */
  } while (millis() - start < ms);
}

void DegMinSec( double tot_val)           /* Convert data in decimal degrees into degrees minutes seconds form */
{
  degree = (int)tot_val;
  minutes = tot_val - degree;
  seconds = 60 * minutes;
  minutes = (int)seconds;
  mins = (int)minutes;
  seconds = seconds - minutes;
  seconds = 60 * seconds;
  secs = (int)seconds;
}
Attachments
leeg.jpg
leeg.jpg (87.47 KiB) Viewed 2714 times

Locked
Please be positive and constructive with your questions and comments.

Return to “For Educators”