I have been trying for a few days to get a MicroSD card to work with my Particle Photon. With no success. I am currently almost to the point of bashing my head through a wall or something… But that would be expensive to fix. So I will opt to post on here for help.
Anywho, I purchased a MicroSD shield and am using the First SPI configuration with the Pins as such:
SCK - A3
MISO - A4
MOSI - A5
SS - A2
Gnd - Gnd (Obviously…)
VCC - 3.3v (I tried Vin As well.)
I am also using Particle.publish as a way to debug.
All that I get as published is:
Starting
Fail
I used the code from the TryMeFirst.cc code on Github:
#include "SdFat.h"
// Pick an SPI configuration.
// See SPI configuration section below (comments are for photon).
#define SPI_CONFIGURATION 0
//------------------------------------------------------------------------------
// Setup SPI configuration.
#if SPI_CONFIGURATION == 0
// Primary SPI with DMA
// SCK => A3, MISO => A4, MOSI => A5, SS => A2 (default)
SdFat sd;
const uint8_t chipSelect = SS;
#elif SPI_CONFIGURATION == 1
// Secondary SPI with DMA
// SCK => D4, MISO => D3, MOSI => D2, SS => D1
SdFat sd(1);
const uint8_t chipSelect = D1;
#elif SPI_CONFIGURATION == 2
// Primary SPI with Arduino SPI library style byte I/O.
// SCK => A3, MISO => A4, MOSI => A5, SS => A2 (default)
SdFatLibSpi sd;
const uint8_t chipSelect = SS;
#elif SPI_CONFIGURATION == 3
// Software SPI. Use any digital pins.
// MISO => D5, MOSI => D6, SCK => D7, SS => D0
SdFatSoftSpi<D5, D6, D7> sd;
const uint8_t chipSelect = D0;
#endif // SPI_CONFIGURATION
//------------------------------------------------------------------------------
File myFile;
void setup() {
Serial.begin(9600);
// Initialize SdFat or print a detailed error message and halt
// Use half speed like the native library.
// Change to SPI_FULL_SPEED for more performance.
Particle.publish("print", "Starting");
delay(2000);
if (!sd.begin(chipSelect, SPI_FULL_SPEED)) {
Particle.publish("print", "Fail");
sd.initErrorHalt();
}
Particle.publish("print", "SD Card Works!!");
// open the file for write at end like the "Native SD library"
if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt("opening test.txt for write failed");
}
// if the file opened okay, write to it:
myFile.println("testing 1, 2, 3.");
myFile.printf("fileSize: %d\n", myFile.fileSize());
// close the file:
myFile.close();
// re-open the file for reading:
if (!myFile.open("test.txt", O_READ)) {
sd.errorHalt("opening test.txt for read failed");
}
// read from the file until there's nothing else in it:
int data;
while ((data = myFile.read()) >= 0) {
Particle.publish("print", data);
}
// close the file:
myFile.close();
Particle.publish("print", "Made it to the end");
}
void loop() {
// nothing happens after setup
}
Thanks for the Help in advance!