[Solved]- Problem with Reading and Writing to SD card Photon

Hey,

I just wanted to preface this post by saying that I’m quite new to the particle ecosystem. Anyway, I’m attempting to read from and write to an SD card from the photon using the sd-card-library-photon-compat library. I’m using the example in the library folder titled Spark-ReadWrite.ino*. This is how i’ve wired the pins on the photon to the pins on the card module:

sdcs:A2
mosi:A5
miso:A4
sck:A3

I’m powering the photon via the micro usb cable connected to my laptop. The Vin pin on the photon is connected to the 5V pin on the card module(I’m powering the card module using the output voltage of the photon at Vin).

This is a picture of the card module I’m using:

and this is the sd card I’m using:

Anyway, when I try and flash the Spark-ReadWrite.ino example to my photon, I get the following output to serial:

Initializing SD card…Error: Read
Error: Sd2Card::waitStartBlock()
Error: Sd2Card::readData()
Error: SdVolume::init() Cache for read
Error: Read
Error: Sd2Card::waitStartBlock()
Error: Sd2Card::readData()
Error: SdVolume::init() Cache for read2
initialization failed!

I’m not sure why there’s an error reading from the SD card, and any help would be appreciated.

*Please note that I had to comment out the line while (!Serial.available());, since it was causing the photon to go idle when I would flash the binary file(I suspect it was causing an infinite loop, but I’m not sure why).

That looks like a normal configuration and should work. I’d guess it’s some sort of hardware or connection issue, but I thought I’d mention that I think most of us here use the SDFAT library on the Particle platform. It’s in the community libraries as [SDFAT] (https://build.particle.io/libs/57c0ad079c59cb36950005d3/) and [here on github] (https://github.com/greiman/SdFat-Particle).

3 Likes

Thank you so much! This library actually works!

3 Likes