1

This super simple code, that saves data to a csv file, works perfectly fine on my Arduino Uno (I am using the default SPI pins).

However, for my project I need to use an ESP8266. Does the library automatically use the default SPI pins for any other boards?

In my code I have tried changing the CS pin from 10 to 15 for the ESP8266. All I get is "Initialization failed"! I figure, I need to somehow change the other SPI pins like MOSI, MISO and SCK. Is there a way to do this? I'm an absolute noob so sorry in advance if I oversaw some kind of easy fix.

#include <SdFat.h>
SdFat sd;
SdFile file;
void setup() {
 Serial.begin(9600);
 if (!sd.begin(10, SD_SCK_MHZ(50))) {
 Serial.println("Initialization failed!");
 return;
 }
 if (!file.open("data.csv", O_RDWR | O_CREAT | O_AT_END)) {
 Serial.println("Error opening file!");
 return;
 }
 file.println("Sensor1,Sensor2,Sensor3");
}
void loop() {
 float sensorReading1 = 1;
 float sensorReading2 = 1;
 float sensorReading3 = 1;
 file.print(sensorReading1);
 file.print(",");
 file.print(sensorReading2);
 file.print(",");
 file.println(sensorReading3);
 file.sync();
 delay(1000);
}
ocrdu
1,7953 gold badges12 silver badges24 bronze badges
asked Feb 16, 2024 at 18:11

1 Answer 1

0

So I just tried again and somehow I happened to replace the SD_SCK_MHZ(50), that worked on my arduino Uno, with SPI_HALF_SPEED. Now the same code as above works perfectly fine on my esp8266.

answered Feb 17, 2024 at 11:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.