🛠 Save Data to MicroSD and Display on e-paper

M5Stack PaperDIY Assembly Kit (ESP32-S3) · debutant · Apprenez à enregistrer des données sur la carte MicroSD et à les afficher sur l'écran e-paper de votre M5Stack PaperDIY.

Objectifs

This tutorial guides you to create a simple logbook. You will learn to write text to a file on the MicroSD card and retrieve it to display on the 4.7-inch e-paper screen. This is a fundamental skill for creating autonomous devices that retain information even when powered off.

Matériel nécessaire

Étapes

  1. Environment Setup: Open Arduino IDE. Ensure the board is selected as "M5Stack-ATOMS3" or "ESP32-S3 Dev Module" depending on your configuration. Enable "USB CDC On Boot".
  1. System Initialization: Include necessary libraries. The code must initialize the M5PM1 power management, the e-paper display, and the SD reader.
#include <M5Unified.h>
#include <SD.h>

#define SD_CS 13 // Check your kit's schematic for the exact CS pin

void setup() {
  M5.begin();
  M5.Power.begin();
  if(!SD.begin(SD_CS)) {
    M5.Display.println("SD Error");
    return;
  }
  M5.Display.setRotation(1);
}
  1. Data Writing: Create a function to save text. We will use a journal.txt file.
void saveData(String text) {
  File file = SD.open("/journal.txt", FILE_APPEND);
  if(file) {
    file.println(text);
    file.close();
  }
}
  1. Reading and Displaying: Read the file content and display it. The ED047TC1 screen is slow; use M5.Display.update() to refresh.
void displayData() {
  M5.Display.clear();
  File file = SD.open("/journal.txt", FILE_READ);
  if(file) {
    while(file.available()) {
      M5.Display.println((char)file.read());
    }
    file.close();
  }
  M5.Display.update();
}
  1. Main Loop: In loop(), call the functions to test. For example, save the current time every 10 seconds and display the journal.
void loop() {
  saveData("Test : " + String(millis()));
  displayData();
  delay(10000);
}

Vérification

Insert the MicroSD card, upload the code, and power the kit. You should see text accumulating on the e-paper screen. Turn the kit off and on again: the data should persist, proving that writing to flash/MicroSD works correctly.

Pour aller plus loin

Explore WiFi 4 connectivity to send this data to a server. You can also use Bluetooth 5.0 LE to transfer the journal to a smartphone, turning your PaperDIY into a portable connected logbook.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials