Go Down

Topic: SD.remove() won't work (Read 404 times) previous topic - next topic

zack2321

In my sketch, i have my SD.remove() in my void setup() so I can start with a fresh set of data every time. I have a troubleshooting statement right after that in the void setup() that says, "ultra not working" so this is telling me that the SD.remove is not deleting that file before moving onto the void loop(). Any help?

Code: [Select]

#include <NewPing.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <SPI.h>
SoftwareSerial mySerial(3,2);
Adafruit_GPS GPS(&mySerial);

char c;
String NMEA1;
String NMEA2;

#define TRIGGER_PIN 6
#define ECHO_PIN 7
#define MAX_DISTANCE 200
#define pingSpeed 1000
#define chipSelect 4
unsigned long pingTimer1, pingTimer2, pingTimer3;
NewPing sonar(6,7,65);

File myFile;

void setup() {
  Serial.begin(115200);
  pingTimer1 = millis() + pingSpeed;
  pingTimer2 = pingTimer1 + (pingSpeed/2);
  pingTimer3= pingTimer2 + pingSpeed;
  GPS.begin(9600);
  GPS.sendCommand("$PGCMD,33,0*6D");
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);

  if(!SD.begin(4)) {
    Serial.println(F("not beginning"));
    return;
  }
  Serial.println(F("its working"));
  pinMode(10,OUTPUT);
 
  SD.remove("ultrad.txt");
  if(! SD.remove("ultrad.txt")){
    Serial.println(F("ultra not working"));
    return;
  }
  SD.remove("gps.txt");
  if(!SD.remove("gps.txt")){
  Serial.println(F("gps not working"));
  return;
  }
}

void loop() {

if(millis()>= pingTimer1) {
  pingTimer1 += pingSpeed;
  Ping();
}

if (millis() >= pingTimer2) {
  pingTimer2 = pingTimer1 + (pingSpeed/2);
  GPSdata();
}

if (millis() >= pingTimer3) {
  pingTimer3 = pingTimer2 + pingSpeed;
  SDCARD();
}
}

void Ping(){
 delay(50);
 int uS=sonar.ping();
// Serial.print(F("Ping: "));
// Serial.print(uS/US_ROUNDTRIP_CM);
// Serial.println(F("cm"));
}

void GPSdata() {
   
  clearGPS();
  while(!GPS.newNMEAreceived()) { //loop until you have a good NMEA sentence
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA()); //parse that last good NMEA sentence
  NMEA1=GPS.lastNMEA();

  while(!GPS.newNMEAreceived()) { //loop until you have a good NMEA sentence
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA()); //parse that last good NMEA sentence
  NMEA2=GPS.lastNMEA();

//  Serial.print(GPS.latitude);
//  Serial.print(F(","));
//  Serial.println(GPS.longitude);
//  Serial.print(GPS.hour, DEC);Serial.print(':');
//  Serial.println(GPS.minute, DEC);

 
 
}

void clearGPS() {

   while(!GPS.newNMEAreceived()) { //loop until you have a good NMEA sentence
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA()); //parse that last good NMEA sentence
  while(!GPS.newNMEAreceived()) { //loop until you have a good NMEA sentence
    c=GPS.read();
  }
  GPS.parse(GPS.lastNMEA()); //parse that last good NMEA sentence
   while(!GPS.newNMEAreceived()) { //loop until you have a good NMEA sentence
    c=GPS.read();
}
}

void SDCARD(){
  int uS=sonar.ping();
  myFile = SD.open("ultrad.txt", FILE_WRITE);
  myFile.print(uS/US_ROUNDTRIP_CM);
  myFile.print(",");
  myFile.print("cm");
  myFile.print(",");
  myFile.print(GPS.hour, DEC);myFile.print(':');
  myFile.println(GPS.minute, DEC); 
  myFile.close();

 
 
  myFile = SD.open("gps.txt", FILE_WRITE);
  myFile.print(GPS.latitude);
  myFile.print(",");
  myFile.print(GPS.longitude);
  myFile.print(",");
  myFile.print(GPS.hour, DEC);myFile.print(':');
  myFile.println(GPS.minute, DEC); 
  myFile.close();
}

PaulS

Code: [Select]
  SD.remove("ultrad.txt");
  if(! SD.remove("ultrad.txt")){
    Serial.println(F("ultra not working"));
    return;
  }

Same stupid code as in your other post.

Go Up