Navigation

SKM53 to Ethernet+Sd Arduino logging

Functional:

 

limitations:
Cant use MMC cards.
Cant use old(ver.1 cards)- about before 2006.
Cant use HC sd cards(>2 GB)
/*
 Arduino Mega 
 RXD Arduino Pin 52
 TXD Arduino Pin 53
 RST Leave Open ? (Connect to a N/O momentary switch pulled low to reset?)
 NC Leave Open
 GND Ground
 VCC +5
 */
#include <SdFat.h>
#include <TinyGPS.h> 
#include <SoftwareSerial.h>

unsigned long fix_age;

SoftwareSerial GPS(53,52);
TinyGPS gps;
void gpsdump(TinyGPS gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;

bool line=false;
const uint8_t chipSelect = 53;
SdFat sd;
ArduinoOutStream cout(Serial);
#define error(s) sd.errorHalt_P(PSTR(s))

void setup(){
  GPS.begin(9600);
  Serial.begin(115200);
  delay(5000);
}

void loop(){
  long lat, lon;
  float tmp;
  unsigned long fix_age, time, date, speed, course;
  unsigned long chars;
  unsigned short sentences, failed_checksum;
  
//  String dataString ="";
  //char buf1[20];
  //char buf2[20]; 

  // retrieves +/- lat/long in 100000ths of a degree
  gps.get_position(&lat, &lon, &fix_age);

  getGPS();
  Serial.print("Latitude : ");
  tmp = (float)LAT/10000000;
Serial.println(lat);  
  Serial.print(LAT/100000,7);
  Serial.print(" :: Longitude : ");
  Serial.println(LON/100000,7);
  
  char name[] = "APPEND.TXT";
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
  ofstream sdout(name, ios::out | ios::app);
  if (!sdout) error("open failed");  
  //sprintf(buf1, "%f", lat);
  //sprintf(buf2, "%f", lon);  
//  dataString = buf1;
  sdout << lat;
  sdout << ",";
  sdout << lon;
  sdout << "|";  
  sdout.close();
  if (!sdout) error("append data failed");
}

void getGPS(){
  bool newdata = false;
  unsigned long start = millis();
  // Every 1 seconds we print an update
  while (millis() - start < 1000)
  {
    if (feedgps ()){
      newdata = true;
    }
  }
  if (newdata)
  {
    gpsdump(gps);
  }
}

bool feedgps(){
  while (GPS.available())
  {
    if (gps.encode(GPS.read()))
      return true;
  }
  return 0;
}

void gpsdump(TinyGPS gps)
{
  //byte month, day, hour, minute, second, hundredths;
  gps.get_position(&lat, &lon);
  LAT = lat;
  LON = lon;
  {
    feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
  }
}

http://maps.googleapis.com/maps/api/staticmap?center=49.7550201,13.4190502 &zoom=17&size=640x640&maptype=roadmap&markers=color:blue%7Plabel:S%7C49.7550201,13.4190502&sensor=false

Not functional:

//http://arduino.cc/forum/index.php?topic=130120.0
//http://www.circuitsathome.com/mcu/running-multiple-slave-devices-on-ardu...
/*
 * Append Example
 *
 * This sketch shows how to use open for append.
 * The sketch will append 100 line each time it opens the file.
 * The sketch will open and close the file 100 times.
 */
#include <SdFat.h>
#include <TinyGPS.h> 
#include <SoftwareSerial.h>

TinyGPS gps; 

SoftwareSerial skm53(53, 52);
bool line=false;

//http://www.ladyada.net/learn/arduino/ethfiles.html
// SD chip select pin
//const uint8_t chipSelect = SS;
const uint8_t chipSelect = 53;

// file system object
SdFat sd;

// create Serial stream
ArduinoOutStream cout(Serial);

// store error strings in flash to save RAM
#define error(s) sd.errorHalt_P(PSTR(s))
//------------------------------------------------------------------------------
void setup() {

  
  skm53.begin(9600);
  Serial.begin(9600);


}
//------------------------------------------------------------------------------
void loop() {
  // filename for this example
  char name[] = "APPEND.TXT";

  pinMode(53, INPUT);                       // set the SS pin as an output (necessary!)
  
  bool newData = false;
  for (unsigned long start = millis(); millis() - start < 1000;) 
  {
    while (skm53.available()) {
      char c = skm53.read();
      if (gps.encode(c)) newData = true;
    }
  } 
  
  Serial.println("1");
  
  if (newData) 
  { 
      Serial.println("New data");
    float lat, lon; 
    unsigned long age; 
    int year; 
    byte month, day, hour, minutes, second, hundredths; 
    
    String dataString ="";
    char buf1[20];
    char buf2[20];      
 
    gps.f_get_position(&lat, &lon, &age); 
    gps.crack_datetime(&year, &month, &day, &hour, &minutes, &second, &hundredths, &age); 
    Serial.print("Lat: "); 
    Serial.println(lat,6); 
    Serial.print("Lon: "); 
    Serial.println(lon,6); 
    if (line==true) 
    { 
      Serial.print("Speed: "); 
      Serial.println(gps.f_speed_kmph()); 
      Serial.print("Sat:"); 
      Serial.println(gps.satellites()); 
      Serial.print("Alt:"); 
      Serial.println(gps.f_altitude()); 
    } 
     
    if (line==false) 
    { 
      Serial.print("Date:"); 
      Serial.print(year); 
      Serial.print("-"); 
      Serial.print(month); 
      Serial.print("-"); 
      Serial.println(day); 
      Serial.print("Time:"); 
      Serial.print(hour); 
      Serial.print("-"); 
      Serial.print(minutes); 
      Serial.print("-"); 
      Serial.println(second); 
    } 
    line=!line; 
    
    // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
    // breadboards.  use SPI_FULL_SPEED for better performance.
    pinMode(53, OUTPUT);                       // set the SS pin as an output (necessary!)
    digitalWrite(53, HIGH);                    // but turn off the W5100 chip!
    if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

    cout << pstr("Appending to: ") << name;

    // open stream for append
    ofstream sdout(name, ios::out | ios::app);
    if (!sdout) error("open failed");

    sprintf(buf1, "%f", lat);
    sprintf(buf2, "%f", lon);  
    dataString = buf1;

    sdout << dataString;
    //sdout << " millis = " << millis() << endl;
    // close the stream
    sdout.close();

    if (!sdout) error("append data failed");
  }  
      Serial.println("loop");  
}

End