Dear friends of Adafruit,
first of all I want to congratulate your company, amazing!
I am working in a project using the ultimate GPS breakout (which is really nice). The GPS works fine and I reach all the data I need. I am using the GPS module over an Arduino Wireless SD shield. I do not understand (I have tried many different solutions) why after getting for example the number of satellites I can not begin the SD access, I get always the initialization failed message......:-( .......there is something from the GPS that avoid the normal work of those 2 lines for the SD.... please, any idea of what is going? (the SD code works also really fine without going through the GPS).
if (GPS.fix) {
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
//________________________________________________________________
pinMode(SS, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
many thanks
Marc
adafruit ultimate GPS
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: adafruit ultimate GPS
Does your code call SD.begin(chipSelect) more than once? You can only call it once. It should be called in setup(), not in your loop.
- marcvo
- Posts: 12
- Joined: Wed Jan 15, 2014 5:41 am
Re: adafruit ultimate GPS
Dear friends of Adafruit,
many thanks for your answer, but I have checked your suggested point and it is not the problem.....
anyway I have been checking again every instruction in order to find which GPS sentence was avoiding the normal access to the SD file and I finally found it! :-)
It is the GPSsend command: "GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);"
If I remove that sentence everything works fine again! it a surprise because I thought that the GPS.send.... was absolutely necessary in order to setup what kind of
data will the GPS send to each request......do you remember? in your ULTIMATE GPS tutorial, you talk that we have two options: total data or minimum data. I suppose that the GPSsend command is only necessary for the raw data....and if I only need parse data (lat and Long) I do not need the GPSsend command? but what about the rate (1Hz or 5Hz or 10Hz)? so, finally, why does the GPSsend..... command blocks the SD acces?
we are working in an amazing project to use UAV to measure Pollution. We are working in collaboration with the Barcelona Municipal Environment department and the CSIC (one the bigger research LABs of Europe: http://www.csic.es/web/guest/home) and also the ICREAL (environmental research center: http://www.creal.cat/en_index.html). That is the reason we are preparing an Arduino+RasPi device to collect data from an UAV. I am a Master of Science in Robotics and Advanced Control (UAV specialisation). I will let you know how the project is going.
In addition, I am looking forward a job position in a firm like Adafruit, where to continue my career, improving my knowledge and experience. Could you please send some career adafruit link to me?
many many thanks for your help, time, service, products and people!
kind regards
many thanks for your answer, but I have checked your suggested point and it is not the problem.....
anyway I have been checking again every instruction in order to find which GPS sentence was avoiding the normal access to the SD file and I finally found it! :-)
It is the GPSsend command: "GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);"
If I remove that sentence everything works fine again! it a surprise because I thought that the GPS.send.... was absolutely necessary in order to setup what kind of
data will the GPS send to each request......do you remember? in your ULTIMATE GPS tutorial, you talk that we have two options: total data or minimum data. I suppose that the GPSsend command is only necessary for the raw data....and if I only need parse data (lat and Long) I do not need the GPSsend command? but what about the rate (1Hz or 5Hz or 10Hz)? so, finally, why does the GPSsend..... command blocks the SD acces?
we are working in an amazing project to use UAV to measure Pollution. We are working in collaboration with the Barcelona Municipal Environment department and the CSIC (one the bigger research LABs of Europe: http://www.csic.es/web/guest/home) and also the ICREAL (environmental research center: http://www.creal.cat/en_index.html). That is the reason we are preparing an Arduino+RasPi device to collect data from an UAV. I am a Master of Science in Robotics and Advanced Control (UAV specialisation). I will let you know how the project is going.
In addition, I am looking forward a job position in a firm like Adafruit, where to continue my career, improving my knowledge and experience. Could you please send some career adafruit link to me?
many many thanks for your help, time, service, products and people!
kind regards
- marcvo
- Posts: 12
- Joined: Wed Jan 15, 2014 5:41 am
Re: adafruit ultimate GPS
SORRY!!!!!! it still doesn't work!!!
if the SD part of the script is in the "void setup" and the GPS is in the "void loop", everything works, but how I could concatenate a loop of: read SD > read GPS > read SD > read GPS.....etc.... if I can not move the "GPS get data" to the void setup or I also can not move the "SD open file and read" to the void loop???? ideas?
thanks again
Marc
if the SD part of the script is in the "void setup" and the GPS is in the "void loop", everything works, but how I could concatenate a loop of: read SD > read GPS > read SD > read GPS.....etc.... if I can not move the "GPS get data" to the void setup or I also can not move the "SD open file and read" to the void loop???? ideas?
thanks again
Marc
- marcvo
- Posts: 12
- Joined: Wed Jan 15, 2014 5:41 am
Re: adafruit ultimate GPS
details of my problem with the ULTIMATE GPS:
File myFile = SD.open("TEST.TXT", FILE_READ); That sentence must be at the setup because I do not want to open my SD file in each iteration (that is exactly what happens if I put it in the void loop), just because if I open-close the SD file every time, I will always access to the first data of the SD file list every time, and I want to go further in that list.
File myFile = SD.open("TEST.TXT", FILE_READ);
for (int id = 0; id<108; id++) {
if (myFile) {
lat = myFile.readStringUntil(',');
lon = myFile.readStringUntil('\n');
}
I would like to proceed with that path:
0. Open SD file list (void setup)
1. Get GPS lat-lon (void loop)
2. Read lat1, lon1 from the SD file list (how could I do that in the void loop if myFile is created in the void setup? I have typical error myFile not declared here)
3. Compare lat1,lon1 from SD lat,lon readed in the GPS (void loop)
repeat 2-3 steps n times.....
many thanks again
Marc
File myFile = SD.open("TEST.TXT", FILE_READ); That sentence must be at the setup because I do not want to open my SD file in each iteration (that is exactly what happens if I put it in the void loop), just because if I open-close the SD file every time, I will always access to the first data of the SD file list every time, and I want to go further in that list.
File myFile = SD.open("TEST.TXT", FILE_READ);
for (int id = 0; id<108; id++) {
if (myFile) {
lat = myFile.readStringUntil(',');
lon = myFile.readStringUntil('\n');
}
I would like to proceed with that path:
0. Open SD file list (void setup)
1. Get GPS lat-lon (void loop)
2. Read lat1, lon1 from the SD file list (how could I do that in the void loop if myFile is created in the void setup? I have typical error myFile not declared here)
3. Compare lat1,lon1 from SD lat,lon readed in the GPS (void loop)
repeat 2-3 steps n times.....
many thanks again
Marc
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: adafruit ultimate GPS
It would be easier to advise you if you would post the entire sketch. Use the '</>' button above the reply window to insert code tags, and paste your sketch between them.
- Franklin97355
- Posts: 23910
- Joined: Mon Apr 21, 2008 2:33 pm
Re: adafruit ultimate GPS
Could you post your code and a description or drawing of your connections between it all?
Please use the code button as shown below.
Please use the code button as shown below.
- marcvo
- Posts: 12
- Joined: Wed Jan 15, 2014 5:41 am
Re: adafruit ultimate GPS
Thanks,
that is my last version of the script. At least it works, but it only allows to read the first line of the stored file into the SD, just because the loop close the file in each iteration, so it always goes to the first line of the gps positions stored into the SD file. If I change the SD read instruction <\File myFile = SD.open("TEST.TXT", FILE_READ);\> all the SD read gets an error. I have tried to move it to the setup and also at the beginning of the void loop creating a new loop after.
thanks
that is my last version of the script. At least it works, but it only allows to read the first line of the stored file into the SD, just because the loop close the file in each iteration, so it always goes to the first line of the gps positions stored into the SD file. If I change the SD read instruction <\File myFile = SD.open("TEST.TXT", FILE_READ);\> all the SD read gets an error. I have tried to move it to the setup and also at the beginning of the void loop creating a new loop after.
thanks
Code: Select all
//================================================================================
//Marc Viader Juny 2014 Net.Butterfly script. SPERANZA-VIADER urban design & computing
//================================================================================
#include <SPI.h>
#include <SD.h>
#include <string.h>
#include <LiquidCrystal.h>
#include <math.h>;
//_________________________________GPS VARIABLES________________________________
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO false
boolean usingInterrupt = false;
void useInterrupt(boolean);
//_______________________________ SD READ VARIABLES________________________________
const int chipSelect = 4; // Arduino UNO
String lat = "";
String lon = "";
int id = 0;
//============================= VOID SETUP =======================================
void setup()
{
//___________________________SD CHECKING_ ______________________________________
Serial.begin(9600);
pinMode(SS, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
//_______________________________________GPS START SETUP________________________
Serial.println("Adafruit GPS library basic test!");
GPS.begin(9600);
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
//GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
//GPS.sendCommand(PGCMD_ANTENNA);
useInterrupt(true);
delay(1000);
mySerial.println(PMTK_Q_RELEASE);
}
// _________________GPS FUNCTIONS_________________________________________________
SIGNAL(TIMER0_COMPA_vect) {
char c = GPS.read();
#ifdef UDR0
if (GPSECHO)
if (c) UDR0 = c;
#endif
}
void useInterrupt(boolean v) {
if (v) {
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
uint32_t timer = millis();
//============================= FUNCTION VOID LOOP=====================================
void loop()
{
//_________________GPS__________________________________________________________
if (! usingInterrupt) {
char c = GPS.read();
if (GPSECHO)
if (c) Serial.print(c);
}
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA()))
return;
}
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out the current stats
//_________________________________________________________________GPS parse
if (millis() - timer > 2000) {
timer = millis(); // reset the timer
Serial.print("\nTime: ");
Serial.print(GPS.hour, DEC); Serial.print(':');
Serial.print(GPS.minute, DEC); Serial.print(':');
Serial.print(GPS.seconds, DEC); Serial.print('.');
Serial.println(GPS.milliseconds);
Serial.print("Date: ");
Serial.print(GPS.day, DEC); Serial.print('/');
Serial.print(GPS.month, DEC); Serial.print("/20");
Serial.println(GPS.year, DEC);
Serial.print("Fix: "); Serial.print((int)GPS.fix);
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
if (GPS.fix) {
Serial.print("Location: ");
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
Serial.print(", ");
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
Serial.print("Angle: "); Serial.println(GPS.angle);
Serial.print("Altitude: "); Serial.println(GPS.altitude);
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
//________________________________________________________________SD file read
File myFile = SD.open("TEST.TXT", FILE_READ);
if (myFile) {
//id++;
lat = myFile.readStringUntil(',');
lon = myFile.readStringUntil('\n');
Serial.print("id = "); Serial.print(id); Serial.print(",");
Serial.print("lat = "); Serial.print(lat); Serial.print(",");
Serial.print("lon = "); Serial.print(lon); Serial.print("\n");
}
else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
myFile.close();
//_________________________________________________________________SD end
}
}
//___________________________________________________________________
//Serial.print ("it is over.......finished"); // data saved
//delay(10000);
}
// close void loop
- marcvo
- Posts: 12
- Joined: Wed Jan 15, 2014 5:41 am
Re: adafruit ultimate GPS
wire:
ULTIMATE GPS connected to pins 2 and 3 for data
and ground and 5v for power.
I use pins 12 and 13 for sensors (still not connected) and 5 until 11 for the LCD (also still not connected).
ULTIMATE GPS connected to pins 2 and 3 for data
and ground and 5v for power.
I use pins 12 and 13 for sensors (still not connected) and 5 until 11 for the LCD (also still not connected).
- marcvo
- Posts: 12
- Joined: Wed Jan 15, 2014 5:41 am
Re: adafruit ultimate GPS
Another conflict is related to the Serial speed. In theory, reading your tutorial, the GPS should go at 115200, and the SD read at 9600....
at the moment everything is setup at 9600.....and reading only one line from the SD seems to be right....
as you can see at the screen shot, the script shows the lat,lon from the GPS and just after, it reads the lat lon from the SD, changing the id, but always same value because its the same first line of the file in the SD....
best regards
at the moment everything is setup at 9600.....and reading only one line from the SD seems to be right....
as you can see at the screen shot, the script shows the lat,lon from the GPS and just after, it reads the lat lon from the SD, changing the id, but always same value because its the same first line of the file in the SD....
best regards
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: adafruit ultimate GPS
GPS runs at 9600 by default.
You need to make myFile a global variable so that you can open it in setup and read it in loop
this fooled me for a long time. It turns out that the main problem you were having was running out of SRAM. Please see this tutorial for a discussion of SRAM:
https://learn.adafruit.com/memories-of-an-arduino
I made myFile global, and applied some changes to free up a little more SRAM. It works now. But you will have SRAM problems in the future when you start adding more things to the sketch. You should consider going with a different Arduino, like a Leonardo or a Mega, which will have more SRAM
You need to make myFile a global variable so that you can open it in setup and read it in loop
this fooled me for a long time. It turns out that the main problem you were having was running out of SRAM. Please see this tutorial for a discussion of SRAM:
https://learn.adafruit.com/memories-of-an-arduino
I made myFile global, and applied some changes to free up a little more SRAM. It works now. But you will have SRAM problems in the future when you start adding more things to the sketch. You should consider going with a different Arduino, like a Leonardo or a Mega, which will have more SRAM
Code: Select all
//================================================================================
//Marc Viader Juny 2014 Net.Butterfly script. SPERANZA-VIADER urban design & computing
//================================================================================
#include <SPI.h>
#include <SD.h>
//#include <string.h>
#include <LiquidCrystal.h>
#include <math.h>;
//_________________________________GPS VARIABLES________________________________
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO false
boolean usingInterrupt = false;
void useInterrupt(boolean);
//_______________________________ SD READ VARIABLES________________________________
const int chipSelect = 4; // Arduino UNO
String lat = "";
String lon = "";
int id = 0;
File myFile;
//============================= VOID SETUP =======================================
void setup()
{
//___________________________SD CHECKING_ ______________________________________
Serial.begin(9600);
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println(F("initialization failed!"));
while (1); //loop here forever
}
Serial.println(F("initialization done."));
myFile = SD.open("test.txt", FILE_READ);
if (!myFile)
{
// if the file didn't open, print an error:
Serial.println(F("error opening test.txt"));
// while (1); //loop here forever
}
lat.reserve(10); //reserve the maximum size strings lat and lon will ever see.
lon.reserve(10); // this makes String objects use memory more efficiently
//_______________________________________GPS START SETUP________________________
Serial.println(F("Adafruit GPS library basic test!"));
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPS.sendCommand(PGCMD_ANTENNA);
useInterrupt(true);
delay(1000);
mySerial.println(PMTK_Q_RELEASE);
}
// _________________GPS FUNCTIONS_________________________________________________
SIGNAL(TIMER0_COMPA_vect) {
char c = GPS.read();
#ifdef UDR0
if (GPSECHO)
if (c) UDR0 = c;
#endif
}
void useInterrupt(boolean v) {
if (v) {
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
uint32_t timer = millis();
//============================= FUNCTION VOID LOOP=====================================
void loop()
{
//_________________GPS__________________________________________________________
if (! usingInterrupt) {
char c = GPS.read();
if (GPSECHO)
if (c) Serial.print(c);
}
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA()))
return;
}
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out the current stats
//_________________________________________________________________GPS parse
if (millis() - timer > 2000) {
timer = millis(); // reset the timer
Serial.print(F("\nTime: "));
Serial.print(GPS.hour, DEC); Serial.print(F(":"));
Serial.print(GPS.minute, DEC); Serial.print(F(":"));
Serial.print(GPS.seconds, DEC); Serial.print(F("."));
Serial.println(GPS.milliseconds);
Serial.print(F("Date: "));
Serial.print(GPS.day, DEC); Serial.print(F("/"));
Serial.print(GPS.month, DEC); Serial.print(F("/20"));
Serial.println(GPS.year, DEC);
Serial.print(F("Fix: ")); Serial.print((int)GPS.fix);
Serial.print(F(" quality: ")); Serial.println((int)GPS.fixquality);
if (GPS.fix) {
Serial.print(F("Location: "));
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
Serial.print(F(", "));
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
Serial.print(F("Speed (knots): ")); Serial.println(GPS.speed);
Serial.print(F("Angle: ")); Serial.println(GPS.angle);
Serial.print(F("Altitude: ")); Serial.println(GPS.altitude);
Serial.print(F("Satellites: ")); Serial.println((int)GPS.satellites);
//________________________________________________________________SD file read
id++;
lat = myFile.readStringUntil(',');
lon = myFile.readStringUntil('\n');
Serial.print(F("id = ")); Serial.print(id); Serial.print(F(","));
Serial.print(F("lat = ")); Serial.print(lat); Serial.print(F(","));
Serial.print(F("lon = ")); Serial.print(lon); Serial.print(F("\n"));
//_________________________________________________________________SD end
}
}
//___________________________________________________________________
//Serial.print (F("it is over.......finished")); // data saved
//delay(10000);
}
// close void loop
- marcvo
- Posts: 12
- Joined: Wed Jan 15, 2014 5:41 am
Re: adafruit ultimate GPS
Dear Rick,
many many thanks,
I was really close of jumping through the window....5 full days&nights with the same issue...:-O hahaha.....I have check maybe 25 different versions...time to enjoy a glass of red wine!
the dark side is that I am aware that i would never find the origin of the problem without your help.... SRAM! it was totally out of my thoughts related to the issue origin... :-(
positive side:
1. I have learned that I must be careful with SRAM collapse (interesting tutorial).
2. I can have while loops into the setup!!!!! = setup loops non stop setuping in parallel with the main loop! very interesting!
3. I can pass flash-memory based strings to Serial.print() by wrapping them with F()! that means I am saving flash memory? very interesting and important again....
Final question:
At the final scrip, I wont use the serial port to see lats or lon. I currently have used just for debuging....But on the field with the battery I will use the LCD 16x2 to follow how is going.
Do you have any recommendation (like the Serial.print(F(String))) but in the LCD.print(String) ? will every LCD.print(String) spend memory flash like a normal Serial.print without F ? is there any solution to clean memory after each time I send to the LCD a LCD.print(String) ?
have a good day
best regards
MArc
many many thanks,
I was really close of jumping through the window....5 full days&nights with the same issue...:-O hahaha.....I have check maybe 25 different versions...time to enjoy a glass of red wine!
the dark side is that I am aware that i would never find the origin of the problem without your help.... SRAM! it was totally out of my thoughts related to the issue origin... :-(
positive side:
1. I have learned that I must be careful with SRAM collapse (interesting tutorial).
2. I can have while loops into the setup!!!!! = setup loops non stop setuping in parallel with the main loop! very interesting!
3. I can pass flash-memory based strings to Serial.print() by wrapping them with F()! that means I am saving flash memory? very interesting and important again....
Final question:
At the final scrip, I wont use the serial port to see lats or lon. I currently have used just for debuging....But on the field with the battery I will use the LCD 16x2 to follow how is going.
Do you have any recommendation (like the Serial.print(F(String))) but in the LCD.print(String) ? will every LCD.print(String) spend memory flash like a normal Serial.print without F ? is there any solution to clean memory after each time I send to the LCD a LCD.print(String) ?
have a good day
best regards
MArc
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: adafruit ultimate GPS
You should be able to use F() with lcd print.
Please be positive and constructive with your questions and comments.