Open nicolasdb opened 2 years ago
https://forum.m5stack.com/topic/4197/stamp-c3-c3u-spi/2
First of all I really really like the Stamp C3(U), I find the plastic cover totally great. But what frustrates me (maybe I'm doing something wrong) is that SPI is not usable. The reason is that for classic full-duplex SPI on a ESP32C3 you need SPI2 (Fast SPI) which leads to the following:
- MOSI = FSPID = GPIO7 --> nicely on the PIN header
- MISO = FSPIQ = GPIO2 --> the status LED on Stamp C3(U), not on the header
- CLK = FSPICLK = GPIO6 --> nicely on the PIN header
- CS = FSPICS0~5 = GPIO10 for CS0 --> nicely on the PIN header and in general chip select is a bit easier I really don't get why GPIO2 was used for the status LED, from what I get there's nothing special about it. So I think / strongly believe / am convinced that SPI peripherals just don't work on the stamp...
Hello @dominik the nice thing about ESP32 and its variants (like the C3) is that different functions (like SPI) can use almost any GPIOs. With the Arduino environment you can define the GPIOs to be used for SPI like this:
#define SCK GPIO_NUM_6
#define MISO GPIO_NUM_4
#define MOSI GPIO_NUM_7
#define CS GPIO_NUM_5
SPI.begin(SCK, MISO, MOSI, -1);
So depending version, it should match like that with my selection of pins : SD card: D5 = CLK = SCK = FSPICLK = GPIO10 D6 = DO = MISO = FSPIQ = GPIO8 D7 = DI = MOSI = FSPID = GPIO7 D8 = CS = FSPICS0~5 = GPIO6
https://github.com/PaulStoffregen/DS1307RTC > doesn't work. https://wiki.seeedstudio.com/Grove-RTC/ > doesn't work https://github.com/adafruit/RTClib > working following this tutorial https://lastminuteengineers.com/ds1307-rtc-arduino-tutorial/ , but:
I needed to add:
void setup() { // Open serial communications and wait for port to open: Serial.begin(115200); SPI.begin(SCK, MISO, MOSI, CS);
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized: if (!SD.begin(CS)) { Serial.println("Card failed, or not present"); // don't do anything more: return; } Serial.println("card initialized."); }
void loop() { // make a string for assembling the data to log: String dataString = "";
// read three sensors and append to the string: //for (int analogPin = 0; analogPin < 3; analogPin++) { // int sensor = analogRead(analogPin); // dataString += String(sensor); // if (analogPin < 2) { // dataString += ","; // } //} // The WeMos D1 Mini only has one analog pin A0. int sensor = analogRead(3); dataString += String(sensor);
// open the file. note that only one file can be open at a time, // so you have to close this one before opening another. File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it: if (dataFile) { dataFile.println(dataString); dataFile.close(); // print to the serial port too: Serial.println(dataString); } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); }
delay(1000); }
Ok, I get that I need to define SPI pins.
#define SCK 10
#define MISO 8
#define MOSI 7
#define CS 6
And launch it in Setup:
SPI.begin(SCK, MISO, MOSI, CS);
and SD.begin(CS);
but then,
I still get "Card failed, or not present" or nothing.
I tried example from several library and tutorial, with a focus on the Setup to just get to initialize the module....
I quit. I will try something else, like writing my log on a internal SPIFFS partition
upload ok but fail to mount partition.
Data logger module - RTC DS1307 + SDcard
Features:
With this Data Log Shield for WiFi D1 Mini board, can saving data to files on any FAT16 or FAT32 formatted MicroSD card. The included RTC (Real Time Clock) can be used to timestamp all your data with the current time, so that you know precisely what happened when! SD card interface works with FAT16 or FAT32 formatted cards. Real time clock (RTC) keeps the time going even when the power disconnected. The coin cell battery backup last date and time. RTC protected from wrong connecting of battery.
Pinout:
RTC: D1 - SCL D2 - SDA
SD card: D5 - CLK D6 - DO D7 - DI D8 - CS
https://github.com/wemos/D1_mini_Examples/blob/master/examples/04.Shields/Micro_SD_Shield/Datalogger/Datalogger.ino