/* 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:
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
@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.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
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]
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
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/
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
ok here's an improved version of my code
/* 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 */ // Include required libraries #include <TinyGPS++.h> #include <SoftwareSerial.h> #include <SPI.h> #include <SD.h> // 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; }
@madmike970 Ok. Is that DroneBot's code? Now remind me what the problem is.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
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:
gps pins:
rx-d4
tx-d3
sd pins:
cs-d8
sck-d5
mosi-d7
miso-d6.
@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.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
@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.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
@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
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
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 😛
@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.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
@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.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
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 ?
Experience is what you get when you don't get what you want.
@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.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting