Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!





GPS Data logger on ...
 
Share:
Notifications
Clear all

GPS Data logger on Heltec ESP32 WiFi Board  

  RSS

 tvr4
(@tvr4)
Estimable Member
Joined: 3 months ago
Posts: 107
July 16, 2020 3:39 PM  

I was able to get the GPS data logger working. I was using PIN 16 for GPS TX and PIN 17 for GPS RX but I could not get readable data from the GPS,

I then moved the GPS TX to PIN 23 and I immediately started receiving quality data from the GPS module.

Everything seems to be working but there is an issue.
When powering on the ESP32 there is no display. If I press the RST button the display appears and the code seems to be working
Any idea why this is happening?

Wiring is as follows (VCC on all modules to 5V, GND to Ground)
GPS module (ublox 6M)
RX - ESP32 PIN 23
TX - ESP32 PIN 17

SD Card Module
CS - ESP32 PIN 26
SCK - ESP32 PIN 27
MOSI - ESP32 PIN 14
MISO - ESP32 PIN 13

Code is attached
Any help is greatly appreciated

#include <Wire.h>
#include "SSD1306AsciiWire.h"
#include "SSD1306Ascii.h"

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

const int cs_sd=26;

TinyGPSPlus gps;

int maxspeed = 0, speed1 = 0;
int maxhigh = 0, high1 = 0;
int maxsatelite = 0, satelite1 = 0;

SSD1306AsciiWire oled;
#define I2C_ADDRESS 0x3C
#define RST_PIN 16


void setup() {
   Serial.begin(115200);

    Serial1.begin(9600, SERIAL_8N1, 23, 17);

  Wire.begin(4, 15);
  Wire.setClock(400000L);
  #if RST_PIN >= 0
    oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
  #else // RST_PIN >= 0
    oled.begin(&Adafruit128x64, I2C_ADDRESS);
  #endif // RST_PIN >= 0

  oled.setCursor(20,2); 
  oled.setFont(utf8font10x16);
  oled.print("GPS DATA LOGGER");
  oled.setCursor(50,4); 
  oled.print("BY ME");
  delay(4000);
  oled.clear();

    if (!SD.begin(26, 14, 13, 27))
  {
   oled.clear();
   oled.print("    NO SD Card");
   delay(2000);
   oled.clear();
   return;
  } 
   oled.print("  SD Card OK");
   delay(2000);
   oled.clear();
    
   File data = SD.open("GPS-data.txt",FILE_WRITE);        //Open the file "GPS-data.txt"
   data.println(""); data.println("Start Recording");    // Write to file
   data.close(); 
}


void loop() {   

    satelite1 = (abs(gps.satellites.value()));

    oled.setFont(Verdana12_bold); 
    oled.setCursor(0,0);
    oled.print("Vmax     ");
    oled.print("Hmax   ");
    oled.print("SAT  ");
    
   speed1 = (gps.speed.mph());
  if ( speed1 > maxspeed) {
    maxspeed = speed1;
  }

  oled.setFont(Arial_bold_14);
  oled.setCursor(10 , 2); 
  oled.clearToEOL();
  oled.print(maxspeed);
  
  high1 = (gps.altitude.feet());
  if ( high1 > maxhigh) {
    maxhigh = high1;
  }
  
  oled.setCursor(50 , 2);  //prev 50,1
  oled.print(maxhigh);

  oled.setCursor(100 , 2);  //prev 100,1
  oled.print(satelite1);

  oled.println(" ");
  oled.println(" ");

  oled.setFont(Verdana12_bold);

  oled.setCursor(0 , 4.5);
  oled.print("LAT    ");
  oled.println(gps.location.lat(),6);
  oled.print("LNG  ");
  oled.println(gps.location.lng(),6);
  
//-4 is eastern time offset
  String Temps=String(gps.time.hour()-4)+(":")+(gps.time.minute())+(":")+(gps.time.second());
  String Date=String(gps.date.month())+("/")+(gps.date.day())+("/")+(gps.date.year());

  if (satelite1 > 1)  {
    File data=SD.open("GPS-data.txt",FILE_WRITE);
    data.println(Date + " " + Temps + " " + String(gps.location.lat(), 6)+" "+String(gps.location.lng(), 6)+(" ")+String(gps.altitude.feet(),0)+(" ")+String(gps.speed.mph(),0)+(" ")+String(satelite1)); 
    data.close();  
   }
    DelayGPS(100);
  }


  static void DelayGPS(unsigned long ms)
{
  unsigned long start = millis();
  do
  {
    while (Serial1.available())
      gps.encode(Serial1.read());
  } while (millis() - start < ms);
}

ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 7 years ago
Posts: 1521
July 17, 2020 5:37 AM  

Having seen this with one of my projects: give the ESP a slight delay in it's startup.
By lack of really knowing what is going on, I think the ESP at times may be too fast.

Something like the change below.
This may not be the best location, so you may have to try a different location and/or time amount - I've also noticed with one of my LED projects that "delay(0);" sometimes already seem to do the trick.

 void setup() {
  Serial.begin(115200);

  Serial1.begin(9600, SERIAL_8N1, 23, 17);

  Wire.begin(4, 15);
  Wire.setClock(400000L);
delay(100); #if RST_PIN >= 0 oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN); #else // RST_PIN >= 0 oled.begin(&Adafruit128x64, I2C_ADDRESS); #endif // RST_PIN >= 0 oled.setCursor(20,2); oled.setFont(utf8font10x16); oled.print("GPS DATA LOGGER"); oled.setCursor(50,4); oled.print("BY ME"); delay(4000); oled.clear(); if (!SD.begin(26, 14, 13, 27)) { oled.clear(); oled.print(" NO SD Card"); delay(2000); oled.clear(); return; } oled.print(" SD Card OK"); delay(2000); oled.clear(); File data = SD.open("GPS-data.txt",FILE_WRITE); //Open the file "GPS-data.txt" data.println(""); data.println("Start Recording"); // Write to file data.close(); }

 

 


ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 3 months ago
Posts: 107
July 17, 2020 10:18 AM  

I have tried delay up to 1000 and still can't get it to work.  It appears to be a display issue of some kind

I inserted a line within setup to write "setup" on the serial monitor and another line in the main loop to send "loop" to the serial montor.

1) If I power up the ESP32 I see nothing on the serial monitor and nothing on the display. 
2) If I press the reset button the display works and the sketch starts operating properly.  But nothing appears on the serial monitor
I have to close and reopen the serial monitor for it to operate

3) At this point the serial monitor shows "main loop"

So the code is running but the display is not showing anything

 


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 7 years ago
Posts: 1521
July 18, 2020 6:30 AM  

Could it be a conflict between serial port for the serial monitor and the pin's you have used for you GPS/SD ?
It "feels" like the serial port (for the serial monitor and/or GPS) is somehow conflicting.

From what you wrote, I'd say "no", but it may be worth inspecting.

From this article I see that these pins should be avoided:

  • GPIO 6 (SCK/CLK)
  • GPIO 7 (SDO/SD0)
  • GPIO 8 (SDI/SD1)
  • GPIO 9 (SHD/SD2)
  • GPIO 10 (SWP/SD3)
  • GPIO 11 (CSC/CMD)

None of them you seem to be using ... 🤔 


ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 3 months ago
Posts: 107
July 18, 2020 8:31 AM  

I found the problem with the display not working.  I looked at some of the examples that were included in Heltec.h library, which the manufacturer listed to install for the board.  There was one line that all the OLED examples started with:

#include "heltec.h"

Heltec.begin(true /*DisplayEnable Enable*/, false /*LoRa Enable*/, true /*Serial Enable*/);

 

This second line is what fixed the display.  No delay or other modification needed.
When you plug the board in to the USB for power (I don't have an external power source yet) the program quickly displays that start screen

 


ReplyQuote



 Hans
(@hans)
Noble Member Admin
Joined: 7 years ago
Posts: 1521
July 19, 2020 5:39 AM  

Nice find! Just a little sad that it is needed haha.
But I'm glad to hear that you found a fix. 👍 


ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 3 months ago
Posts: 107
July 19, 2020 9:22 AM  

@hansI agree.  Seems to be a waste to include the heltec library for one statement.  That lib also does sisplay control but it is poorly implemented and comfusing.  Plus it only works on that board.

At least the SSD1306Ascii will work on the Uno, Nano and the ESP32


ReplyQuote
Share: