Hello everybody,
In previous post, I have presented autonomous boat based on the Pixhawk. Currently I am troubleshooting the connection between my Garmin intelliducer and Adafruit GPS datalogger, as was done previously by Thomas J Coyle III and Burkhard rieck. I'm having some troubles with the ultimate Adafruit GPS Datalogger. I have a Garmin Sonar connected to Ultimate GPS datalogger and Arduino 1. The Garmin sonar sends strings with information about the depth, which are read as strings by the datalogger. The shield is able to read/write both the GPS position and string.
However, the problem is that after a couple of readings stops. Sometimes after 10 readings, sometimes after 3 readings. During the last reading, the shield logs first the reading from the sonar and then stops at the moment when it should read the GPS signal. What surprises me most is that if I reset the datalogger, without any problem it starts logging again, and stops after a seemingly random number of good strings. However, when I try to log only the GPS signal, with another code, there is no problem.
Anyone encountered similar problem with Adafruit Ultimate GPS Datalogger? Can it be that my Arduino UNO hasn't sufficient capacity to run the code? In case anyone has experience with logging string coming out from the sonar, your advice would be highly appreciated.
Thanks beforehand,
Esteban Caligaris,
Asuncion, Paraguay
P.D.: This is the code I'm using, provided by Thomas J Coyle III:
[code]
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>
SoftwareSerial sonar(6,5); // RX, TX
SoftwareSerial gps(8,7);
#define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
String inputString1 = "";
String inputString2 = ""; // a string to hold incoming data
const int chipSelect = 10;
File dataFile;
boolean stringComplete = false; // whether the string is complete
int a=0;
void setup()
{
//Serial.begin(57600); // Xbee
Serial.begin(115200); // Terminal
sonar.begin(4800);
gps.begin(9600);
inputString1.reserve(200);
inputString2.reserve(200);
gps.println(PMTK_SET_NMEA_OUTPUT_RMCONLY);
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(SS, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1) ;
}
Serial.println("card initialized.");
// Open up the file we're going to log to!
dataFile = SD.open("datalog.txt", FILE_WRITE);
if (! dataFile) {
Serial.println("error opening datalog.txt");
// Wait forever since we cant write data
while (1) ;
}
}
void loop() {
sonar.listen();
while(a==0){
while (sonar.available()) {
char inChar = (char)sonar.read();
inputString1 += inChar;
if (inChar == '\n') {
stringComplete = true;
}
}
if (stringComplete) {
if (inputString1.startsWith("$SDDBT")){
a=1;
dataFile.println(inputString1);
Serial.print(inputString1);
dataFile.flush();
}
inputString1 = "";
stringComplete = false;
}
}
gps.listen();
while(a==1){
while (gps.available()) {
char inChar = (char)gps.read();
inputString2 += inChar;
if (inChar == '\r') {
stringComplete = true;
}
}
if (stringComplete) {
if (inputString2.startsWith("$GPRMC")){
dataFile.println(inputString2);
Serial.print(inputString2);
dataFile.flush();
a=0;
}
inputString2 = "";
stringComplete = false;
}
}
}
[/code]
Replies
Hi all,
I've managed to solve this problem with some coding reviewing and tests. This is the code that worked for me:
//Make sure to install the adafruit GPS library from https://github.com/adafruit/Adafruit-GPS-Library
#include <Adafruit_GPS.h> //Load the GPS Library. Make sure you have installed the library form the adafruit site above
#include <SPI.h> //ACACAC
#include <SD.h> //ACACAC
#include <SoftwareSerial.h> //Load the Software Serial Library. This library in effect gives the arduino additional serial ports
SoftwareSerial mySerial(8, 7); //Initialize SoftwareSerial, and tell it you will be connecting through pins 8 and 7
SoftwareSerial sonar(6, 5); //ACACAC
Adafruit_GPS GPS(&mySerial); //Create GPS object
const int chipSelect =10; //ACACAC
File dataFile;
//float sensorPin = A0; // select the input pin for the sensor
//float sensorValue = 0; // variable to store the value coming from the sensor
//double sensorVoltage = 0.0000;
//double aux = 0.0000;
//double sensorTemp = 0.0000;
String NMEA1; //We will use this variable to hold our first NMEA sentence
String NMEA2; //We will use this variable to hold our second NMEA sentence
char c; //Used to read the characters spewing from the GPS module
String inputString1=""; //ACACAC
boolean stringComplete = false; //ACACAC
int a=0; //ACACAC
void setup()
{
Serial.begin(115200); //Turn on the Serial Monitor
sonar.begin(4800); //ACACAC
GPS.begin(9600); //Turn GPS on at baud rate of 9600
inputString1.reserve(200); //ACACAC
GPS.sendCommand("$PGCMD,33,0*6D"); // Turn Off GPS Antenna Update
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY); //Tell GPS we want only $GPRMC and $GPGGA NMEA sentences
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
delay(1000); //Pause
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(SS, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1) ;
}
Serial.println("card initialized.");
// Open up the file we're going to log to!
dataFile = SD.open("datalog.txt", FILE_WRITE);
if (! dataFile) {
Serial.println("error opening datalog.txt");
// Wait forever since we cant write data
while (1) ;
}
}
void loop() // run over and over again
{
a=0;
readGPS(); //This is a function we define below which reads two NMEA sentences from GPS
sonar.listen(); //ACACAC
while(a==0){
while (sonar.available()){
char inChar = (char)sonar.read();
inputString1 += inChar;
if (inChar == '\n'){
stringComplete = true;
}
}
if (stringComplete){
if (inputString1.startsWith("$SDDBT")){
a=1;
dataFile.println(inputString1);
Serial.print(inputString1);
dataFile.flush();
}
inputString1 = "";
stringComplete = false;
}
}
}
void readGPS(){ //This function will read and remember two NMEA sentences from GPS
clearGPS(); //Serial port probably has old or corrupt data, so begin by clearing it all out
while(!GPS.newNMEAreceived()) { //Keep reading characters in this loop until a good NMEA sentence is received
c=GPS.read(); //read a character from the GPS
}
GPS.parse(GPS.lastNMEA()); //Once you get a good NMEA, parse it
NMEA1=GPS.lastNMEA(); //Once parsed, save NMEA sentence into NMEA1
//while(!GPS.newNMEAreceived()) { //Go out and get the second NMEA sentence, should be different type than the first one read above.
// c=GPS.read();
// }
//GPS.parse(GPS.lastNMEA());
//NMEA2=GPS.lastNMEA();
a=0;
Serial.println(NMEA1);
//Serial.println(NMEA2);
Serial.println("");
dataFile.println(NMEA1);
//dataFile.println(NMEA2);
dataFile.flush();
}
void clearGPS() { //Since between GPS reads, we still have data streaming in, we need to clear the old data by reading a few sentences, and discarding these
mySerial.listen();
while(!GPS.newNMEAreceived()) {
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
while(!GPS.newNMEAreceived()) {
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
}
Thanks and regards,
Esteban Caligaris
OK_Sonar_GPS.ino
Hi Esteban,
Have you give it a try yet? What are the results?
And do you have any wired external i2c communications? As of my previous experiences, they can lead to such an issue.
Kind regards,
Fatih.
Esteban Caligaris said:
Hi Guy,
Thanks for the reply. I have actually bought the Arduino Mega and I'm going to give it a try.
Regards,
Esteban Caligaris
Hello Esteban
Use an arduino mega. It has 4 uarts so you don't have to use SoftwareSerial. Or hard wire your sd shield to the uart and forget the serial output to your PC.
Guy