Help with SdFat Library

Hi Team,

I have read through a lot of discussion regarding the SdFat library. I couldn’t write or read any data from the sdcard. Here is the step by step process followed:

  1. Flashed the sdcard with Fat32 using windows.
  2. Connected the pins of the shield as follows,
    CS -> A2
    SCK -> A3
    MISO -> A4
    MOSI -> A5
    VCC -> 3V3
    GND -> GND
  3. Now flashed the photon with the example firmwares in the sdfat library but nothing works.
    The shield used is this. Is there anything I am missing?
    Thanks for the help!

I'd say yes - have a look at the link you posted
image

Have you tried with VCC -> VIN yet?

You also need to keep the wires from the Photon pins to the module short - best if you use a breadboard and the shortest wire links possible. Lastly, are you able to see what pull up resistors there are on the module for the MOSI, MISO and CS?

@ScruffR I thought the specifications said it will support the 3.3v, then I should throw this shield and buy a new one?
@armor No I am not.
I am using a breadboard with jumper wires.
I don’t know about the pull up registers. Let me get back to you on this

You need to read carefully :wink:
The description states that the logic (interface) levels can be 5V or 3.3V due on-board regulator and level shifters. But for these to function the supply needs to be >4.5V.

Not necessarily. When you have your Photon powered off a 5V source you can use Vin instead of 3v3 (as @armor already stated above).

I have connected the Vin to Vcc and still nothing. Adding the image of the shield below.

.
I noticed the device went from breathing cyan to breathing green several seconds after I flashed the firmware. This is the firmware I am using.

I suggest that you use the example application versions for Particle and not Arduino.

Did you see any output on the serial monitor?

#include <SPI.h>

This isn’t required. Instead I would include #include “Particle.h” to avoid possible compile issues.

Also the chipselect variable in the firmware you are using is not set to pin A2 that you have wired to.

@armor Thanks for the help! Let me fix those issues and update here with the findings.

Just for the record: On Photon (and other Gen2 devices) A2 is the same thing as SS - both macros will be substituted with 12.

As pointed out by @armor in order to get "new" hardware going it's always advisable to start with a minimal test code and one baby-step at a time :wink:

There are many infinite loops that may trap your code and hence will probably starve the cloud process off controler timer.
To know which, where and why you need to look at the serial output - we can't do that for you.

2 Likes

@ScruffR @armor Thanks for the guidance. Now I am trying to use a simple logger firmware uses SdCardLogHandlerRK. This is to test the log files are created and the shield is working fine.

This is the example firmware I am using. Writing to the sdcard still fails. Is there anything I am missing.

Send a photo of how it is wired up - easiest way to rule out any connection issues


Is the image visible? The pin details are in the above image of this thread.

There is no SD card in the holder :wink:

BTW, since you are free to use your jumper wires wherever you want, so it would be preferable to adhere to common colour codes (Vcc red, GND black, the rest as you see fit).

You also still haven't provided us with any info about the debug output your code should produce

I just removed it for some other purpose.

Ok this looks ok - please post the code you are testing with?

it would be preferable to adhere to common colour codes (Vcc red, GND black, the rest as you see fit).

I didn't know that, thanks.
@ shanevanj The firmware I am testing now is:

#include "Particle.h"

#include "SdCardLogHandlerRK.h"

SYSTEM_THREAD(ENABLED);

// The SD card CS pin on the Adafruit AdaLogger FeatherWing is D5.
const int SD_CHIP_SELECT = A2;
SdFat sd;

SdCardPrintHandler printToCard(sd, SD_CHIP_SELECT, SPI_FULL_SPEED);

size_t counter = 0;

void setup() {
	Serial.begin();
}

void loop() {
	printToCard.printlnf("testing counter=%d", counter++);
	delay(1000);
}

I am using a empty microsd card formatted with FAT32.

Can you add the basic SDFAT library (in webIDE) and try the SdInfo.ino app to validate if the card is functional. this is a simpler way to test for functionality. Dont forget to change the SS value to A2 for your card

1 Like

This is helpful. Let me get back to you on this.

Now the status LED changed to breathing green from cyan. I will try replacing the photon or sdcard and try again.

And did you get valid card information the serial output?