0

I want to save the file as date and time and I want to open the file mySensorData = SD.open(filename, FILE_WRITE); in the set up. It shows "insert SD card" when I try to open the file in setup.

The data is not being written into the SD card. It is creating the file but not writing into file.

3
  • and the first line "Pressure, Temperature, Depth,Altitude" is in the file? – Juraj Jun 25 '18 at 21:11
  • in setup you open "sensor1.txt" and in loop filename. test if (!mySensorData), not if (mySensorData==0) – Juraj Jun 25 '18 at 21:12
  • Sorry! I just upload the new code. I want to save the file as date and time . and i want to open the file mySensorData = SD.open(filename, FILE_WRITE); in the set up. It shows insert SD card when i try to open the file in setup . – brar_kev Jun 25 '18 at 21:46
1

You start logging set to LOW and then test if it is high, since it isn't you go to the else clause, you call exit(0) and kill your processor, hence your code never gets executed!

volatile boolean logging = LOW;

...

void loop() 
{ 
   if(logging == HIGH) // starts low
   {
    ... // never executed
   }
   else 
   {
    ... // 
    exit(0); // now your Arduino is dead!
   }
}

The ellipses (...) are where i snipped your code out.

exit(0) turns off interrupts and loops forever with while(1); which has the effect of a full, power-consuming halt; exit(0) should have a sleep call in it, because what exit(...) does isn't very useful for an Arduino!

11
  • Sorry, I didn't get your answer. Would you please explain it to me . – brar_kev Jun 26 '18 at 16:12
  • @brar_kev I had stripped down the code to the structure so you can see; the first thing your loop does is check if (logging == HIGH) it was initialized it to LOW so flow goes to else clause, you do some stuff then you call exit(0) which halts the proccessor, the uC will not execute anymore instuctions until it is reset. so everything else never gets called. – esoterik Jun 26 '18 at 19:11
  • But in the interrupts logging = ! logging .. so i'm making it low .. The code was working fine but when i added the RTC module then it stopped writing into the file. I checked when try to open the file in the set up the it shows iNSERT sd CARD AND if i comment the open file section then it works . I'm new to programming and don't know how should i change it now .Thank for help – brar_kev Jun 26 '18 at 19:41
  • 1
    @brar_kev exit(0) disables interrupts, so your interrupt handler can't be executed either. – esoterik Jun 26 '18 at 20:51
  • 1
    @brar_kev start with the sample, and add pieces to it until it works or something breaks, whatever breaks may tell you what is broken, or a better question to ask – esoterik Jun 28 '18 at 18:37
0

The problem was related to memory . So i commented some Serial.print commands and then it worked perfectly fine . I edit this part of my code .

else { // Serial.print(mySensorData); // Serial.println("Insert SD card for logging"); digitalWrite(led_pin, LOW); lcd.clear(); lcd.print("Insert SD card"); delay(1000); //
}

1
  • Please list the lines that you had to comment out. Your answer may help someone with the same problem. – Greenonline Jul 5 '18 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.