@jeremywmccarter, try what I suggested to see if it works
I have glanced at previous posts and may have missed something.
First, when you share SPI, you need to disable all devices before initializing any device.
For all devices except the first one to be initialized set CS high with code like this.
pinMode(CS_OTHER, OUTPUT);
digitalWrite(CS_OTHER, HIGH);
SdFat sets SPI speed, mode, and bit order each time it accesses the SPI bus.
Many older libraries do not restore SPI setting so you may need to set speed and mode before calls to these libraries.
@whg This is a really well written library, so much content. Thank you.
I cannot however get the remove() function to work, can you give an example of removing or deleting a file. If I use the followint
File Foo;
Foo.remove(āmyfile.txtā);
the compiler throws an error, I have tried other combinations but this seems to be what the documentation requires?
I can open, write, read, truncate but not delete it.
Thanks
Sorted. I had the file opened as O_READ it needs to be first opened as O_WRITE then erased, the following works
File Foo;
Foo.open(āmyFile.txtā,O_WRITE);
Foo.remove();
Thanks
May I also ask question about using this library. I have a photon with shield shield and Arduino Ethernet Shield with microSD card reader.
I tried Ethernet shield with regular arduino and it works well and read microSd cardā¦ ChipSelect pin for microsd reader is 4 on shield
But when I try example trymefirst without changing any other code then SPI configuration I only receive
Canāt access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X1,0X0
I try with SPI configuration 1 like below
// Pick an SPI configuration.
// See SPI configuration section below (comments are for photon).
#define SPI_CONFIGURATION 1
//------------------------------------------------------------------------------
// 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 = D6;
#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 => D3, MOSI => D2, SCK => D4, SS => D6
SdFatSoftSpi<D3, D2, D4> sd;
const uint8_t chipSelect = D5;
#endif // SPI_CONFIGURATION
//------------------------------------------------------------------------------
Since I use shield shield I use D6 as CS which is pin 4 on Ethernet shield. Anyone who can help me understand why I it doesnāt work?
EthernetS S_SHIELD PHOTON
SCLK 13 D4 // SPI_3 SCK
MISO 12 D3 // SPI_3 MISO
MOSI 11 D2 // SPI_3 MOSI
CARD_CS 4 D6
I was trying to use the SdFatSoftSpi library and can not get the code to recognize the device:.
Canāt access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X1,0XFF
We have the photon/electron mounted on another board that has the SDcard and none of the SPI mappings work as we used all of the pins for other functions, so I resorted to using the softwareSPI modeā¦ Have used an older library: https://github.com/head-labs/sd-card-library with software SPI and it works, .but I wanted to upgrade to a better library with long file names and what looks like a more active community for the Particle devices.
Anyone had any luck using softwarespi with this library? The example (SoftwareSpi) referenced in the html help file is not present in what I downloaded from git. I probably have some configuration file issue, but I have not found it yet. I am using the particle desktop IDE for building.
Any pointers appreciated
Hello, everyone.
I want to ask about Particleās library.
I have my code ready for upload in the photon.
But, it stuck at verifying. Here is the error. /workspace/test_button_semi.cpp:2:16: fatal error: SD.h: No such file or directory
How can I insert a library in Particle? Is it necessary?
I have bought two books about the particle photon by Simon Monk and Christopher Rush. But non-telling about how to insert a library in particleās library. I guess itās same with the Arduino, right?
Please help me to understand more about programming the particle photon. As for now, I just copy and paste every code that Iāve done in the Arduino IDE into Particle web IDE.
Here I attach my code on the above error.
**Noted that I used ( ) in # because to make it visible to you.
#include <SPI.h>
#include <SD.h>
#include <Wire.h> //I2C Library
#include <EEPROM.h>
const int CS_pin = 53;
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 5; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState5 = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
double ReadEEPROM; //Variable to store in EEPROM.
int C = 0; //Location we want the increment to be put.
File myFile;
void setup() {
Wire.begin();
Serial.begin(9600);
Serial.println("Initializing Card");
//CS Pin is an output
pinMode(CS_pin, OUTPUT);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
//button will Draw Power from Pin 5, so set it high
pinMode(buttonPin, INPUT);
//digitalWrite(buttonPin, HIGH);
while (!Serial);
Serial.print("Read the last number of button push in EEPROM : ");
EEPROM.get(C, buttonPushCounter);
Serial.println(buttonPushCounter);
//Initialize Card
if (!SD.begin(CS_pin))
{
Serial.println("Card Failure");
return;
}
Serial.println("Card Ready");
}
void loop() {
// read the pushbutton up input pin:
char fileName[10];
buttonState5 = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState5 != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState5 == HIGH)
{
buttonPushCounter++;
Serial.println(buttonPushCounter);
sprintf(fileName, "%d.txt", buttonPushCounter);
myFile = SD.open(fileName, FILE_WRITE);
Serial.println("File that will open :");
myFile.println("testing 1,2,3...");
digitalWrite(ledPin, HIGH);
Serial.println(fileName);
delay(2000);
digitalWrite(ledPin, LOW);
// close the file:
myFile.close();
delay(500);
}
else
{
myFile = SD.open(fileName);
Serial.println("File open :");
Serial.println(fileName);
Serial.write(myFile.read());
myFile.close();
}
}
// save the current number of button pushed as the last number value
lastButtonState = buttonState5;
EEPROM.put(C, buttonPushCounter);
}
I hope that you can help me to understand about Photon better.
Thank you.
You can add the library following this guide: https://docs.particle.io/guide/getting-started/build/electron/#using-libraries
Thank youā¦
What about this library, TryMeFirst?
Shouldnāt it be in the library?
Whereās that from?
You might need to give more information like which guide you are following and what libraries are required to remove the guesswork.
From this forum...
Sorry, Iām still trying to go there but I donāt know why Iām stuck hereā¦
When, I search in the library, there is no info like you give above.
Where can I find it? Is there any other library in the IDE?
Search for SDFat
In your right side screenshot it does tell
Showing the 10 most popular libraries,
search to find more
and at the top you have a textbox
[ Type to search ______ ]
where you can enter SDFat
Hi all,
I flashed the bench.cpp firware into my electron. However, i did not get any output when i ran particle serial monitor command in node.js command prompt. The electron went into safe mode right after bootloading. Did i miss out anything required to change or is it just a plug and play feature from the example in the library? I have provided a snapshot below regarding the output and the setup.
Thanks
Hi all,
first time poster, long time user. Iām trying to use the Adafruit Arduino SD Card shield with the photon. My goal is to sample analog signals (all 8 or as many as possible) at 100,000 sps and record the data onto the SD Card.
thoughts? sample codes? any help is greatly appreciated.
cheers,
Hooman
Iām not sure the Shield Shield will work well with the SD card shield as youāll have two sets of level shifters 3.3V Photon <-> 5V shields <-> 3.3V SD card.
Iād just go for a bare SD card holder as the voltage levels already fit together.
And sampling 8 channels at 100kHz will also proof difficult.
Sir,
I try to search SDFat, yes it shows the library.
I just donāt get it why I canāt get like @kennethlimcp give in his screenshot.
Because I try to learn about particle from an e-book.
@kennethlimcp maybe you can show me how you do it, like in the screenshot.
Thank you.