Im trying to use the Adafruit Sd card with particle electron and I can’t make it work
Im using SDFat library and I can able to flash the code for TryMeFirst example, when I check through the Terminal, it said can’t access SD card Do not reformat. No card, wrong chip select pin, or SPI problem? SD errorCode: 0X1,0X0 ( it is from SDFat.cpp library )
But still not working with Particle electron
( connection CS A2 , SCK A3 , D0 A4 , D1 A5, 3V and GND )
I already checked with my Arduino Uno, it is working !
My goal is that getting the data from the sensor and storing the data to the SD card.
Also, I believe you should connect the 3V3 line of the Electron the 5V input, not the 3V line.
There's an onboard ultra-low dropout regulator that will convert voltages from 3.3V-6v down to ~3.3V (IC2). There's also a level shifter that will convert the interface logic from 3.3V-5V to 3.3V
I believe the 3V is intended to be an output, not an input.
#include "Particle.h"
// dependencies.SdFat=0.0.7
#include "SdFat.h"
// Primary SPI with DMA
// SCK => A3, MISO => A4, MOSI => A5, SS => A2 (default)
SdFat sd;
const uint8_t chipSelect = A2;
const unsigned long TEST_INTERVAL_MS = 10000;
unsigned long lastTest = 0;
void tryMeFirst();
void setup() {
Serial.begin();
}
void loop() {
if (millis() - lastTest >= TEST_INTERVAL_MS) {
lastTest = millis();
tryMeFirst();
}
}
void tryMeFirst() {
File myFile;
// Initialize the library
if (!sd.begin(chipSelect, SPI_FULL_SPEED)) {
Serial.println("failed to open card");
return;
}
// open the file for write at end like the "Native SD library"
if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
Serial.println("opening test.txt for write failed");
return;
}
// if the file opened okay, write to it:
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
myFile.printf("fileSize: %d\n", myFile.fileSize());
// close the file:
myFile.close();
Serial.println("done.");
// re-open the file for reading:
if (!myFile.open("test.txt", O_READ)) {
Serial.println("opening test.txt for read failed");
return;
}
Serial.println("test.txt content:");
// read from the file until there's nothing else in it:
int data;
while ((data = myFile.read()) >= 0) {
Serial.write(data);
}
// close the file:
myFile.close();
}
Im trying to use your code right now and it still said failed to open card from the terminal
It means sd card has problem? Do I need to do something for sd card?
when I tried with Arduino Uno, It doesn’t have issue for sd card…
I have both the sparkfun and adafruit version sdcards. I have followed the same pins and used the exact same code as you. The output continues to say “failed to open card” and no txt file is created. In the past, these cards have worked very sporadically. One day it will work, but the next it won’t, nothing changed. I think there might be a problem with the Particle itself…?