I have
Arduino Uno
sparkfun SD shield
Garmin LVC 18x GPS
NMEA 0183 intelliducer depth sounder
Powering these I have
2 6V 1.5AH lead batteries
Cheap charge controller
18W solar panel
When I plug in the setup to my computer, everything reads fine, and the SD card records the data marvelously, but when I plug into the actual power I need it to be connected to (ie. the batteries) I get whack numbers, no numbers, whack text files, etc. I have tried plugging everything into the batteries alone and still I get the same problem. I have read other threads concerning this Here and Here but they all think it is the program. My program works flawlessly when plugged into the computer.
Batt Volt = 12.45V
Solar V = 12.5V
Wall V = 12.32V
Do I need to upgrade my batteries, or switch around the loads, or change the program, or ??? Below is code if necessary.
/*
*
* Wiring
*
* GPS <=> Arduino
* Wht <=> D3
* Grn <=> D2
* Red <=> 5V
* Blk <=> G
*
* Sonar <=> Arduino
* Wht(+) <=> D5
* Blu(-) <=> D4
* Red <=> 12V
* Blk <=> G(12V)
*
*/
// Libraries to include
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>
// Begin serial ports for the GPS and Sonar
SoftwareSerial gps(3, 2, 1); // RX, TX
SoftwareSerial sonar(5, 4, 1);
// Declare constants, strings, etc.
String Depth = ""; // A string to output Depth
String inputString1 = ""; // a string to hold incoming data
String inputString2 = ""; // a string to hold incoming data
const int chipSelect = 10; // Required for the SD shield to talk with the Uno
File dataFile; // Prepares a file for writing to SD card
boolean stringComplete = false; // whether the string is complete
int a = 0; // is a test to see if gps/sonar has been heard
int com1; // Finding first comma in sonar output, float values can change, so need to select data between commas
int com2; // finding second comma in sonar output
void setup()
{
Serial.begin(115200); // Terminal window begin rate
gps.begin(4800);
sonar.begin(4800);
inputString1.reserve(200);
inputString2.reserve(200);
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(chipSelect, 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;
com1 = inputString1.indexOf(','); // finds location of first ,
com2 = inputString1.indexOf(',', com1 + 1 ); //finds location of second ,
Depth = inputString1.substring(com1 + 1, com2); //captures second data String
Serial.print("Depth: ");
Serial.print(Depth);
Serial.print("m ");
dataFile.print(Depth); // Prints depth to the SD card
dataFile.print(",");
dataFile.flush();
}
inputString1 = "";
stringComplete = false;
}
}
gps.listen();
while (a == 1) {
//Serial.println("while a = 1");
while (gps.available()) {
//Serial.println("while gps available");
char inChar = (char)gps.read();
inputString2 += inChar;
if (inChar == '\n') {
stringComplete = true;
delay(10);
}
}
if (stringComplete) {
if (inputString2.startsWith("$GPRMC")) {
char lat_deg_str[3]; // begin char with length 3 to stor latitude degree
char lat_min_str[8];
char lon_deg_str[4];
char lon_min_str[8];
inputString2.substring(16, 18).toCharArray(lat_deg_str, sizeof(lat_deg_str)); // appends data from inputstring2 to latitude degree string from locations 16 through 18
inputString2.substring(18, 25).toCharArray(lat_min_str, sizeof(lat_min_str));
inputString2.substring(28, 31).toCharArray(lon_deg_str, sizeof(lon_deg_str));
inputString2.substring(31, 37).toCharArray(lon_min_str, sizeof(lon_min_str));
int lat_deg = atof(lat_deg_str); // Turns the degree string into a degree integer/float
float lat_min = atof(lat_min_str);
int lon_deg = atof(lon_deg_str);
float lon_min = atof(lon_min_str);
float latitude = lat_deg + lat_min / 60; // converting from DDMM.ffff to decimal degrees lat/long
float longitude = lon_deg + lon_min / 60;
Serial.print("Latitude: ");
Serial.print(latitude, 6);
Serial.print(" Longitude: -");
Serial.println(longitude, 6);
dataFile.print(latitude, 6);
dataFile.print(",-");
dataFile.println(longitude, 6);
dataFile.flush();
latitude = 0;
longitude = 0;
a = 0;
}
inputString2 = ""; // Clearing all the strings just in case of relicts
char lat_min_str = "";
char lon_min_str = "";
stringComplete = false;
}
}
}