Go Down

Topic: how to know if println fails to sd card? (Read 484 times) previous topic - next topic

benjaminhoey

Hi,

I am using an LC-TECH 5v SD card module. Using the code and wiring from this tutorial:

sd-card-module-and-temperature-sensor\

I didnt have trouble initializing the sd card, but I had trouble writing to the file. I found out that I needed to use an external power supply because there wasn't enough current. Now everything is working fine.

This setup will be used on a moving vehicle, and what I would like to do, is figure out some way of letting me know if the arduino is not writing to the file - so for example light an LED.

I know it is possible to know if the sd cards hasn't initialized, but I dont know how to find out if println() to the file has failed or not.

Is this possible?

pert

The first place to look for an answer to this sort of question is the reference page for the library:
https://www.arduino.cc/en/Reference/SD
If you look at the documentation of println() linked from that page:
https://www.arduino.cc/en/Reference/FilePrintln
Quote
Returns

byte
println() will return the number of bytes written, though reading that number is optional
So if println() returns 0 you know the write failed. For example:
Code: [Select]

if(myFile.println((float)DHT11.humidity, DEC)) == 0) {
  digitalWrite(errorLED, LOW);
}


Go Up