I'm trying to temporarily save two values into an array. One value is a latitude (from my GPS), and another one that I made up. So far, I am able to load the latitude value into the array with no problem, but when I try to load the second value (it is commented out in the code below), the output that I get goes haywire (i.e.: I start to get all sort of weird characters zooming by the serial monitor screen).
Could I have missed something in the syntax?
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO false
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
int counter = 0; // set the counter to zero
char* products[][2]= { };
void setup()
{
Serial.begin(9600);
Serial.println("Adafruit GPS library basic test!");
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
GPS.sendCommand(PGCMD_ANTENNA);
useInterrupt(true);
delay(1000);
mySerial.println(PMTK_Q_RELEASE);
}
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 {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
uint32_t timer = millis();
void loop() // run over and over again
{
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) Serial.print(c);
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out the current stats
if (millis() - timer > 2000) {
timer = millis(); // reset the timer
// Print GPS info
if (GPS.fix) {
////Set counter
counter = counter + 1; // Then, start the line counter
Serial.print(counter);
Serial.print(" ");
//////////// Print the Latitude & speed
Serial.print(GPS.latitude, 5); //Lat number
Serial.print(" ");
Serial.print(GPS.longitude, 5); //Lon number
Serial.println(" ");
// Creating the array of subset data
if (counter == 5) {
Serial.println();
Serial.print("Line number ");
Serial.print(counter);
Serial.println(" will go into the array");
//Load the latitude into an array (example lat value: 1118.33544)
char lat1[12]; //This will account for potential "negative" latitutdes
dtostrf(GPS.latitude, 6, 5, lat1); //convert float to string
strncat (lat1, '\0', 12); // add a NULL terminator at the end of the variable "lat1" (just in case)
strcpy(products[0][0], lat1); //add "lat1" value to the "products" array in position [0][0]
//Now, let's try loading a second element into the array
//strcpy(products[0][1], "5555.55555");
//Lets print what I have in my array
Serial.println("Below is what I have in my array:");
char array1[50] = {};
snprintf(array1, sizeof(array1), "%s %s", products[0][0], products[0][1]);
Serial.println(array1);
Serial.println();
}
}
}
}