Logging data to sd card

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
kabary
 
Posts: 14
Joined: Thu Dec 05, 2013 1:53 am

Logging data to sd card

Post by kabary »

hello ,

I have the ultimate gps logger shield https://www.adafruit.com/products/1272 and i also have the barometric sensor BMP085 also from adafruit.

So the problem i am facing is that i can't get the sd card attached the gps logger shield to get data from both the gps and the barometric sensor at the same time .

I can get it to work only with the gps , and for the barometric sensor i attach an sd card to an ethernet shield and it works , but both separately.

Whenever i try to do both the program freezes and won't let the sd card initalization begin

here is my code

Code: Select all

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <avr/sleep.h>
///
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>

Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

SoftwareSerial mySerial(8,7);

Adafruit_GPS GPS(&mySerial);
// If using hardware serial (e.g. Arduino Mega), comment
// out the above six lines and enable this line instead:
//Adafruit_GPS GPS(&Serial1);


// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences. 
#define GPSECHO  false

#define chipSelect 10
#define ledPin 13

File logfile;
// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
long startTime; 

int cutterPin = 9;
boolean flag = false;

void setup()  
{

  startTime= millis(); 
    
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  Serial.begin(115200);
 
 // pinMode(cutterPin,OUTPUT);
  Serial.println("Adafruit GPS library basic test!");

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  pinMode(ledPin, OUTPUT);

  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  if (!SD.begin(chipSelect)) 
  { 
    Serial.println("Card init. failed!");
    while(1);
  }
      logfile = SD.open("sen.txt", FILE_WRITE);
      
       if(!bmp.begin())
  {
    /* There was a problem detecting the BMP085 ... check your connections */
    Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
    

    
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // Request updates on antenna status, comment out to keep quiet
  GPS.sendCommand(PGCMD_ANTENNA);

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  useInterrupt(true);

  delay(1000);
  // Ask for firmware version
  mySerial.println(PMTK_Q_RELEASE);
}


// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
#ifdef UDR0
  if (GPSECHO)
    if (c) UDR0 = c;  
    // writing direct to UDR0 is much much faster than Serial.print 
    // but only one character can be written at a time. 
#endif
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    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(millis()-startTime > 300000 && flag == false)
  {
    cutter();
    flag = true;
  }
  
  // in case you are not using the interrupt above, you'll
  // need to 'hand query' the GPS, not suggested :(
  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()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
  
    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) { 
    Serial.println("hello");
    timer = millis(); // reset the timer
    gps();
  
  }
}

void gps()
{
    
    if(logfile.print("\nTime: "))
    {
      Serial.println("yes");
      logfile.flush();
    }
    logfile.print(GPS.hour, DEC); logfile.print(':');
    logfile.print(GPS.minute, DEC); logfile.print(':');
    logfile.print(GPS.seconds, DEC); logfile.print('.');
    logfile.println(GPS.milliseconds);
    logfile.print("Date: ");
    logfile.print(GPS.day, DEC); logfile.print('/');
    logfile.print(GPS.month, DEC); logfile.print("/20");
    logfile.println(GPS.year, DEC);
    logfile.print("Fix: "); logfile.print((int)GPS.fix);
    logfile.print(" quality: "); logfile.println((int)GPS.fixquality); 
    if (GPS.fix) 
    {
      Serial.println("we have a fix");
      logfile.print("Location: ");
      logfile.print(GPS.latitude, 4); logfile.print(GPS.lat);
      logfile.print(", "); 
      logfile.print(GPS.longitude, 4); logfile.println(GPS.lon);
      logfile.print("Speed (knots): "); logfile.println(GPS.speed);
      logfile.print("Angle: "); logfile.println(GPS.angle,4);
      float altitude = GPS.altitude;
     /* if(int(altitude) > 2000 && flag == false)
      {
        cutter();
        flag = true;
      }
      */
      logfile.print("Altitude: "); logfile.println(GPS.altitude,4);
      logfile.print("Satellites: "); logfile.println((int)GPS.satellites);
    }
}

void bar()
{
  
}

void cutter()
{
  Serial.println("cut");
  digitalWrite(cutterPin,HIGH);
  delay(120000);
  digitalWrite(cutterPin,LOW);
}
it wouldn't work , however if icommented the barometric sensor bmp.begin and comment the libraries of the barometric sensor ii will log data normally (gps only ) Any idead how to get the barometric data to the sd card on the gps logger shield
Last edited by adafruit_support_mike on Mon Mar 31, 2014 11:23 pm, edited 1 time in total.
Reason: added CODE tags to preserve the formatting

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Logging data to sd card

Post by adafruit_support_mike »

To calrify, are you trying to use two SD cards at once, or just a single SD card as a repository for more than one kind of information?

kabary
 
Posts: 14
Joined: Thu Dec 05, 2013 1:53 am

Re: Logging data to sd card

Post by kabary »

hello , i am using one sd card that is sitting on the gps logger sheild , and trying to log both gps and barometric data to it ?

it's not working , is it even possible to do it ?

User avatar
engineercarl
 
Posts: 56
Joined: Fri Nov 22, 2013 6:47 pm

Re: Logging data to sd card

Post by engineercarl »

Sound like an SRAM crash. The GPS and SD libraries use alot of memory, so you don't have alot of room to run other boards. You may wish to look at this thread. http://forums.adafruit.com/viewtopic.php?f=31&t=50509

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”