[SDFat] Logging data from sensor to sd card

I am trying to store data from an analog light sensor to an sd card at an interval. By referring to this tutorial (Particle electron SD card problem [SDFAT library]) I think I was able to get the sd card to work? I tested on the program tryMeFirst from the sdfat library, with the following output


So I think my sdcard works. But I don’t know how to approach logging the data from my light sensor (analog read from pin B5, 3.3V connection, and GND connection) onto the sd card. I looked at some other examples in the sdfat library, but it’s kind of overwhelming. In the loop, I’d like the sensor to gather data, then have it store the data to the sd card. then possibly introduce a delay for a period of time, and have the process repeat. This is what I’ve coded so far. The light sensor data is being read and outputted on the serial monitor, but no file is being created… Any advice?

P.S. For the following code, even the light data is not read on read

You could try @rickkas7’s SD card logger

1 Like

Can’t even compile the code. It says “Arduino.h: No such file or directory”

This suggests that you are targeting a too old device OS version.
It needs to be 0.6.2 or higher - currently 1.0.0 would be your best choice.

How would I do that?

Here is what I currently see:

You were right about my device. I updated it to 1.0.0. I tried to run the code, but still fails. The SdFat is updated as well.

How did you update?
Have you changed the target firmware in Web IDE?

Particle CLI in the command prompt I typed in particle update and it said updated successfully

Can you post a SHARE THIS REVISION link?


Dear lunchboxp,
This is my pin connection diagram for Photon with SD card…
I used digital pin for connection but analog pins can also be used…
Check with your pin connection…

I also faced error with storing data in SD with photon.