Hi I have an arduino mega which is meant to log data from a gps (EM406A) and write it to a SD-card (Sandisk 2GB SD)
And also if possible dump the files on the sdcard trough the usb cable if connected to a Computer/phone with a serial terminal open. 8)
For now I have only made the part that logs from GPS to SD-card.
And im using a program that reads from the sdcard onto the pc (SD Dumpfile in arduino examples)
But...
Its not working ![]()
Its nothing wrong with the GPS because i get a nice clean NMEA output when i use my DIRECT
GPS-ARDUINIO-PC program.
Can you figure out what I am doing wrong?
Thanks ![]()
DIRECT tranfer program:
/*
Example 17.1
Display any data coming out of the GPS receiver in the serial monitor box
tronixstuff.com/tutorials > Chapter 17
*/
// as the GPS module sends data out serially, we just pick it up character by
// character and repeat it to the serial output
void setup()
{
Serial.begin(9600);
Serial1.begin(4800);
}
void loop()
{
byte a;
if ( Serial1.available() > 0 )
{
a = Serial1.read(); // get the byte of data from the GPS
Serial.write(a);
}
}
DIRECT transfer output:
Via SD-card write program:
#include <SPI.h> //Made for Arduino Mega 2560
#include <SD.h>
File myFile;
const int chipSelect = 53;
void setup() {
Serial1.begin(4800); // Setting up baud for GPS
if (SD.exists("DATALOG.txt")) { // If there is a log on the SD-card:
SD.remove("DATALOG.txt"); // Remove any previous logs on SD-card
myFile = SD.open("DATALOG.txt", FILE_WRITE); // Create new log on SD-card
myFile.close(); // Close log on SD-card
} else { // If the SD-card is empty:
myFile = SD.open("DATALOG.txt", FILE_WRITE); // Creating new file on SD-card
myFile.close(); // Closing file on SD-card
}
}
void loop() {
byte a;
if ( Serial1.available() > 0 ) { // If GPS has sent data:
File dataFile = SD.open("DATALOG.txt", FILE_WRITE); // Open Log file on SD-card
a = Serial1.read(); // get the byte of data from the GPS // Read byte from Serial port
dataFile.write(a); // Write into SD-card
dataFile.close(); // Close log file on SD-card
}
}
VIA SD-card read program:
#include <SPI.h>
#include <SD.h>
const int chipSelect = 53;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
// 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:
return;
}
Serial.println("card initialized.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt");
// if the file is available, write to it:
if (dataFile) {
while (dataFile.available()) {
Serial.write(dataFile.read());
}
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
void loop() {
}
VIA SD-card output: