Notifications
Clear all

tried to copy/paste the gps logger code over to an esp12-e an 8266 no luck

80 Posts
4 Users
6 Likes
5,542 Views
(@madmike970)
Member
Joined: 3 years ago
Posts: 31
Topic starter  

/* GPS Position Logger gps-position-logger.ino Read GPS data from BN-220 or any serial GPS sensor Requires TinyGPS++ Library Save to SD or microSD card DroneBot Workshop 2021 https://dronebotworkshop.com */ // Include required libraries #include <tinygps++.h> #include #include #include // GPS Connections static const int RXPin = 4, TXPin = 3; // GPS Baud rate (change if required) static const uint32_t GPSBaud = 9600; // SD Card Select pin const int chipSelect = 8; // Write LED //const int recLED = 7; // String to hold GPS data String gpstext; // GPS write delay counter variables // Change gpsttlcount as required int gpscount = 0; int gpsttlcount = 30; // TinyGPS++ object TinyGPSPlus gps; // SoftwareSerial connection to the GPS device SoftwareSerial ss(RXPin, TXPin); void setup() { // Set LED pin as output //pinMode(recLED, OUTPUT); // Start Serial Monitor for debugging Serial.begin(115200); // Start SoftwareSerial ss.begin(GPSBaud); // Initialize SD card if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); //don't do anything more: while (1); } Serial.println("card initialized."); // Blink LED so we know we are ready // digitalWrite(recLED, HIGH); // delay(500); // digitalWrite(recLED, LOW); // delay(500); // digitalWrite(recLED, HIGH); // delay(500); // digitalWrite(recLED, LOW); // delay(500); // digitalWrite(recLED, HIGH); // delay(500); // digitalWrite(recLED, LOW); } void loop() { // Turn off LED // digitalWrite(recLED, LOW); // See if data available while (ss.available() > 0) if (gps.encode(ss.read())) // See if we have a complete GPS data string if (displayInfo() != "0") { // Get GPS string gpstext = displayInfo(); // Check GPS Count Serial.println(gpscount); if (gpscount == gpsttlcount) { // LED On to indicate data to write to SD card // digitalWrite(recLED, HIGH); //Open the file on card for writing File dataFile = SD.open("gpslog.csv", FILE_WRITE); if (dataFile) { // If the file is available, write to it and close the file dataFile.println(gpstext); dataFile.close(); // Serial print GPS string for debugging Serial.println(gpstext); } // If the file isn't open print an error message for debugging else { Serial.println("error opening datalog.txt"); } } // Increment GPS Count gpscount = gpscount + 1; if (gpscount > gpsttlcount) { gpscount = 0; } } } // Function to return GPS string String displayInfo() { // Define empty string to hold output String gpsdata = ""; // Get latitude and longitude if (gps.location.isValid()) { gpsdata = String(gps.location.lat(), 6); gpsdata += (","); gpsdata += String(gps.location.lng(), 6); gpsdata += (","); } else { return "0"; } // Get Date if (gps.date.isValid()) { gpsdata += String(gps.date.year()); gpsdata += ("-"); if (gps.date.month() < 10) gpsdata += ("0"); gpsdata += String(gps.date.month()); gpsdata += ("-"); if (gps.date.day() < 10) gpsdata += ("0"); gpsdata += String(gps.date.day()); } else { return "0"; } // Space between date and time gpsdata += (" "); // Get time if (gps.time.isValid()) { if (gps.time.hour() < 10) gpsdata += ("0"); gpsdata += String(gps.time.hour()); gpsdata += (":"); if (gps.time.minute() < 10) gpsdata += ("0"); gpsdata += String(gps.time.minute()); gpsdata += (":"); if (gps.time.second() < 10) gpsdata += ("0"); gpsdata += String(gps.time.second()); } else { return "0"; } // Return completed string return gpsdata; }</tinygps++.h>

wasnt sure about the LED's being compatible so i just disabled all the led blinks. i get this from the serial monitor:

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)
 
wdt reset
load 0x4010f000, len 3460, room 16 
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4 
tail 4
chksum 0xc9
csum 0xc9
v0004c730
~ld

gps pins:

rx-d4

tx-d3

sd pins:

cs-d8

sck-d5

mosi-d7

miso-d6.

I apologize if my description/post isnt up to par.... please forgive me i'm just a dumbass construction worker trying to learn to code. thanks


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6930
 

@madmike970 Is that sketch one of the examples? It woulod be easier to read if you posted it as code. Instructions for that are somewhere, but I don't remember where. You can also experiment on the 'Test Forum' it's the last one.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6930
 

In the IDE under Edit is 'Copy For Forum' I just did that now I will click the <> code icon above

[code]
#include <TinyGPS++.h>
/* 
   This sample sketch should be the first you try out when you are testing a TinyGPS++
   (TinyGPSPlus) installation.  In normal use, you feed TinyGPS++ objects characters from
   a serial NMEA GPS device, but this example uses static strings for simplicity.
*/

// A sample NMEA stream.
const char *gpsStream =
  "$GPRMC,045103.000,A,3014.1984,N,09749.2872,W,0.67,161.46,030913,,,A*7C\r\n"
  "$GPGGA,045104.000,3014.1985,N,09749.2873,W,1,09,1.2,211.6,M,-22.5,M,,0000*62\r\n"
  "$GPRMC,045200.000,A,3014.3820,N,09748.9514,W,36.88,65.02,030913,,,A*77\r\n"
  "$GPGGA,045201.000,3014.3864,N,09748.9411,W,1,10,1.2,200.8,M,-22.5,M,,0000*6C\r\n"
  "$GPRMC,045251.000,A,3014.4275,N,09749.0626,W,0.51,217.94,030913,,,A*7D\r\n"
  "$GPGGA,045252.000,3014.4273,N,09749.0628,W,1,09,1.3,206.9,M,-22.5,M,,0000*6F\r\n";

// The TinyGPS++ object
TinyGPSPlus gps;

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

  Serial.println(F("BasicExample.ino"));
  Serial.println(F("Basic demonstration of TinyGPS++ (no device needed)"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();

  while (*gpsStream)
    if (gps.encode(*gpsStream++))
      displayInfo();

  Serial.println();
  Serial.println(F("Done."));
}

void loop()
{
}

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();
}
[/code]

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6930
 

I just used the Test Forum to experiment. There is a second source code paste, check it out at

https://forum.dronebotworkshop.com/postid/27560/

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@madmike970)
Member
Joined: 3 years ago
Posts: 31
Topic starter  

   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6930
 

@madmike970 Ok. Is that DroneBot's code? Now remind me what the problem is.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@madmike970)
Member
Joined: 3 years ago
Posts: 31
Topic starter  

wasnt sure about the LED's being compatible so i just disabled all the led blinks. i get this from the serial monitor after i upload to esp12-e:

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)
 
wdt reset
load 0x4010f000, len 3460, room 16 
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4 
tail 4
chksum 0xc9
csum 0xc9
v0004c730
~ld

gps pins:

rx-d4

tx-d3

sd pins:

cs-d8

sck-d5

mosi-d7

miso-d6.

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6930
 

@madmike970 Ok, so it compiles clean then you upload to the board. I don't have that board in my board manager, so I have no idea what is happening. I have loaded those type of sketches onto my GPS board and it works.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6930
 

@madmike970 There is nowhere in that sketch where that stuff is printed, it's just normal GPS stuff. Those are pins. Has the GPS had time to discover where it's located yet, if it's a new GPS from China, it will takle many hours becasue it has to start searching from it's last known position in China before it finds where you are at. I am talking hours, maybe a good part of the day.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6930
 

@madmike970 You may want to read the following for a better explanation of what I was giving you. I think I left mine on overnight but not sure how long before or after before I got 'synched'

https://en.wikipedia.org/wiki/Time_to_first_fix

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@madmike970)
Member
Joined: 3 years ago
Posts: 31
Topic starter  

ive already gotten some successful results from the gps using an arduino uno.... i wanted to use a nano but the code and libraries wont fit... im trying to make a collar to track where my cat goes when she goes on adventure.. so an uno isnt really gonna work... i read some stuff about the pins not being the same label to the pin numbers in the code but like i said im a construction worker.... this is my maiden voyage and im not all that bright anyways 😛


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6930
 

@madmike970 What do you mean "won't fit", the information I am looking at basically says it should work. Just wire it the same using the same pin numbers.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6930
 

@madmike970 Ok, that starts to make sense. 

Yes, you will need to understand what pins the original used then figure out what pins on the Nano to use. If I am right, it means reading the silk screen labels on the UNO then finding the same label on the NANO. Now adjust the code where it assigns pin numbers. 

Going back to your original post, what do you mean by copy paste etc, if you had it working on the uno, just go into the Tools menu select Board Manager then click on your ESP board or whichever one you choose, compile and then upload to that board after wiring it the same of course. There is no need to copy paste in this case. Very confusing.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 
Posted by: @madmike970

ive already gotten some successful results from the gps using an arduino uno.... i wanted to use a nano but the code and libraries wont fit... im trying to make a collar to track where my cat goes when she goes on adventure.

Both the Arduino Uno and Arduino Nano have 32K of SRAM. What made you think the code and libraries wouldn't fit on the Nano ?

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6930
 

@madmike970 AFAIK this is what you need in terms of wiring on the NANO. I am leaving out Grounds and +5V as they should be obvious.

LED

Pin 7 to a Led thru a 200ish ohm Resistor

GPS

Pin 3 to the GPS TX

Pin 4 to the GPS RX

SD Card adapter

Pin 5 to CS

Pin 11 to MOSI

Pin 12 to MISO

Pin 13 to SCK

Other than G and +5V that's it.

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 1 / 6