Core and SD Library not working

Hi,

I have tried to use my core with an SD card. Therefor I wired an SD card directly like here and I have also used my Adafruit Micro SD Breakout board plus.
I used the example sketches in the online IDE but it does not do anything. I checked the wiring multiple times and it is correct.

The web IDE highlights clock of clockPin in cyan. Could this be the problem?

Kind regards,
Tom

I’m not sure what your issues might be, but I have this library working with a sainsmart sd board. I don’t recall if I made any changes to the sd-card-library. I have not tried this in the web IDE, but it does work when compiling with Spark/Particle Dev via the cloud.

Below is my code:

/******************************************************************************/
    /**
        @file     application.ino
        @author   Author Name
        @brief    logs data to local sd card

    **/
/******************************************************************************/

/*----------------------------------INCLUDES----------------------------------*/
#include "sd-card-library.h"


/*-------------------ENUM, TYPE AND CONSTANT DEFINITIONS----------------------*/    
const uint8_t chipSelect    = A2;    // Also used for HARDWARE SPI setup
const uint8_t mosiPin       = A5;
const uint8_t misoPin       = A4;
const uint8_t clockPin      = A3;

/*---------------------------VARIABLE DEFINITIONS-----------------------------*/


/*---------------------------FUNCTION DECLARATION-----------------------------*/


/******************************************************************************/
    /**
        @name     setup
        @brief    setup code to only run once
        @return   void

    **/
/******************************************************************************/
void setup() {
    if(!Spark.connected()){     // if ! connected to spark cloud,
        Spark.connect();        // try to connect
    }

    Serial.begin(9600);

    while(!Serial.available()){
        SPARK_WLAN_Loop();
    }

    // Initialize SOFTWARE SPI
    if (!SD.begin(mosiPin, misoPin, clockPin, chipSelect)) {
        Serial.println("Card failed, or not present");
        return;
    }

    File testFile = SD.open("asdf.txt", FILE_WRITE);

    if(testFile){
        testFile.println("Testing... 1, 2, 3...");
        testFile.close();
        Serial.println("file write successful.");
    }else{
        Serial.println("file write error");
        return;
    }    
}


/******************************************************************************/
    /**
        @name     loop
        @brief    main program code to loop continuously
        @return   void

    **/
/******************************************************************************/
void loop() {

}

I hope this helps,

Brent

Hi Brent,

thank you very much for your help! I have tried your code (reimportet the sd library in the web IDE) but I had no luck.
Is the IDE also highlighting the “clock” of “clockPin” in cyan?

@hl68fx, can you post a picture of your wiring? The IDE does not highlight any pin so the cyan you see is the online/offline indicator I believe.

Hi peekay123,

here is the picture of my wiring:

and a picture of my code where “clock” is highlighted:

Kind regards,
Tom

I found out why your code does not work for me @bpryer
while(!Serial.available()){
SPARK_WLAN_Loop();
}

These three lines were blocking my code :smile: I don’t know why the sample from the library does not work. But now I can use your code.
Thank you all very much for your help!

The reason that the web IDE is highlighting your code is due to “clock” being a key word. Anytime you use a keyword as the first portion of a variable name (clockPin) the IDE’s syntax parser isn’t robust enough to catch that this is a variable name and not a key word. This should also be the same for the “time” keyword. If you have a variable named “timer” the time will be cyan.

As for your other problem… I have not tried writing directly to an sd card. I have been using a breakout board writing to a micro sd card. I would recommend trying to use your adafruit micro sd.

Brent

Glad to hear you got it working! I will have to try writing directly to an SD card. I have a ton of old ones setting around.

cheers,

Brent

The code now also works with my Adafruit Breakout board without any further modification :smile:

1 Like