m5paper_sd_card_log.ino
Demonstrates interaction with the integrated SD module for IoT data storage.
The M5Paper has an SD slot. The select GPIO is 12. Ensure the SD card is formatted as FAT32. Frequent writing wears out the SD card, hence the 5-second delay.
m5paper_sd_card_log.ino
#include <M5EPD.h>
#include <SD.h>
M5EPD m5epd;
const int chipSelect = 12; // GPIO pour la carte SD sur M5Paper
int counter = 0;
void setup() {
m5epd.begin();
m5epd.updateBuffer();
if (!SD.begin(chipSelect)) {
m5epd.drawCentreString("SD Card Failed", 480, 270, 4);
m5epd.updateDisplay();
while(1);
}
File myFile = SD.open("log.txt", FILE_WRITE);
if (myFile) {
myFile.println("--- New Session ---");
myFile.close();
}
}
void loop() {
File myFile = SD.open("log.txt", FILE_WRITE);
if (myFile) {
myFile.print(millis());
myFile.print(", Tick: ");
myFile.println(counter++);
myFile.close();
}
m5epd.drawCentreString(String(counter), 480, 270, 6);
m5epd.updateDisplay();
delay(5000); // Écrite toutes les 5 secondes
}