iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🙌

How to: Create an E-paper Name Badge with M5PaperS3

に公開

Hi everyone! As a maker, you've probably thought at least once about making a dream e-paper name tag, right? This time, I'm going to show you how to create that coveted e-paper name tag.

In this article, I'll introduce how to make an e-paper name tag using the M5PaperS3. But if you're thinking, "I don't care about the details, I just want to make a name tag easily!", please try out the software I created called M5PEasyTag!.

Write from your browser here 👇
https://app.nanana.uno/

Source code here 👇
https://github.com/nananauno/M5PEasyTag

Finished image
https://x.com/nananauno/status/1893615196943622638

Goals & Learning Points

What we want to do is create a name tag by displaying your favorite images on the M5PaperS3's Electronic Paper Display (EPD). We'll load and display images from both a microSD card and LittleFS.

The three key learning points this time are:

  • Overview and usage of LittleFS
  • Overview and usage of SD cards
  • Displaying images on EPD

Target Audience

  • People who want to try making a dream name tag with e-paper
  • People who want to know how to use the M5PaperS3
  • People who want to know how to load and display images

What is M5PaperS3?

M5PaperS3 is a microcontroller module from M5Stack equipped with an EPD and an ESP32-S3. Since it's e-paper, you might think you need code that's different from other M5Stack Core series devices. However, if you use M5Unified, you can draw on the screen and detect touches just like with the Core series! There are a few settings specific to e-paper, which I'll explain later.

https://ssci.to/10112

Electronic Paper Displays (EPD) use a different technology than typical LCD or OLED screens and have the following characteristics:

  • Low power consumption
  • Slow drawing speed
  • Clear even under sunlight

Low power consumption
This might be the biggest feature of EPD. Since EPD only consumes power when refreshing the screen, the biggest strength is that it consumes almost no power once the screen is updated! Because it only uses power when "updating (drawing)" the screen, you can make a name tag that lasts for days or even weeks on a single charge once displayed.

Slow drawing speed
EPD can take anywhere from several hundred milliseconds to a few seconds to update the display. This is unavoidable due to the way it works, but it's not much of an issue for applications where the screen rarely changes, such as e-books or the name tag we're making this time. Conversely, it's not suited for video playback or animation, so use it in the right place for the right purpose.

Clear even under sunlight
LCDs are invisible without backlight, but EPD can display clearly using natural light even without a backlight. This makes it very attractive because it's as easy to read as paper, even in bright outdoor locations.

Various Ways to Load Images

To display a name tag image on the EPD, you first need to save the name tag image somewhere. Here, I'll explain how to load from the flash memory built into the M5PaperS3 and how to load from a microSD card.

LittleFS

LittleFS is a file system for holding, reading, and writing arbitrary data on flash memory. The M5PaperS3 is equipped with 16MB of flash memory, and the contents of this flash memory can be partitioned just like a PC. By default, when nothing is specified, the following settings are used.

https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default_16MB.csv

I'll briefly summarize the purpose of each partition below. The area for saving images with LittleFS is the section called spiffs. As an aside, ota is a mechanism for updating firmware over Wi-Fi. It uses two app areas, downloads the firmware to the unused area, and switches the active area once the download is confirmed successful. If it fails, it boots from the existing area, allowing for safe firmware updates over Wi-Fi.

Name Use
nvs Non-volatile storage for settings (Wi-Fi settings, etc.). Supports encryption.
ota Saves information related to OTA (Over-The-Air updates), like which app area is current.
ota_0 First application area
ota_1 Second application area
spiffs Area where users can save files
coredump Saves dump data in case of an abnormal termination (for debugging)

Flash memory partitions can be selected from the board settings in the Arduino IDE, or via board_build.partitions in platformio.ini for PlatformIO.

While you can change partitions freely, there are recommended settings and size requirements. So please choose from the partitions provided by Espressif, or read their official documentation carefully if you decide to customize them.

https://docs.espressif.com/projects/arduino-esp32/en/latest/tutorials/partition_table.html

How to upload data to the LittleFS area?
To upload data to the LittleFS area using PlatformIO, create a folder named data at the same level as src and save the files you want to upload there. Then, select "Upload Filesystem Image" from the PlatformIO menu. It sometimes fails, so please try a few times if it does.

How to load an image from the LittleFS area?
Loading and displaying an image from the LittleFS area is very easy! The following code loads a file named card.png from the LittleFS area and displays it on the screen.

#include <LittleFS.h>
#include <M5Unified.h>
#include <epdiy.h>

void setup() {
  // Initialize M5Unified
  M5.begin();

  // Initialize LittleFS
  if (!LittleFS.begin()) {
    M5.Display.println("LittleFS init .. NG");
    esp_restart();
  }
  M5.Display.drawPngFile(LittleFS, "/card.png");
}

void loop() {
}

microSD

The M5PaperS3 is equipped with a microSD card slot, so you can also save images to a microSD card and load them for display. Here, I'll explain how to load images from a microSD card and display them on the screen.

The microSD card is connected to the ESP32-S3 via a signal method called SPI (Serial Peripheral Interface). SPI uses four signals: MOSI, MISO, SCLK, and CS. You can easily obtain the pin number for each using M5Unified.

#include <SD.h>
#include <M5Unified.h>
#include <epdiy.h>

void setup() {
  // Initialize M5Unified
  M5.begin();

  // Get SPI pins
  auto mosi = M5.getPin(m5::pin_name_t::sd_spi_mosi);
  auto miso = M5.getPin(m5::pin_name_t::sd_spi_miso);
  auto sclk = M5.getPin(m5::pin_name_t::sd_spi_sclk);
  auto cs = M5.getPin(m5::pin_name_t::sd_spi_cs);

  // Initialize SD card
  SPI.begin(sclk, miso, mosi);
  if (!SD.begin(cs, SPI, 4000000)) {
    M5.Display.println("SD card init .. NG");
    esp_restart();
  }

  M5.Display.drawPngFile(SD, "/card.png");
}

Just like with LittleFS, you can load images from a microSD card simply by using drawPngFile and specifying SD as the first argument. It's very easy!

What about JPEG images?
Please use M5.Display.drawJpgFile.

Image Display on EPD

I explained how to load and display images from LittleFS and microSD cards, but to recap, we saw how easily it can be done using M5.Display.drawPngFile(stream_name, path). This is the same for the M5Stack Core2 and others, but the EPD used in the M5PaperS3 has some specific settings. Here, I'll explain the settings used only for EPD.

EPD-Specific Settings (EPDmode)

EPDs have a slower drawing speed compared to LCDs. When drawing with M5Unified, you can adjust the settings depending on the content—whether you want to "draw quickly even if quality drops" or "draw beautifully even if it's slow."

In M5Unified, you can switch drawing modes using M5.Display.setEpdMode(). Each mode has characteristics suited for different purposes, so try using them effectively.

I'll introduce the EPD modes available in M5Unified and their uses. Switching modes is simple; just call setEpdMode where you want to switch, like this:

M5.Display.setEpdMode(epd_mode_t::epd_fast);

Types and Comparison of epd_mode_t

Mode Name Characteristics
epd_quality Best quality. Slowest drawing speed.
epd_text ↑
epd_fast ↓
epd_fastest Fastest drawing speed. Lowest quality.

Let's Build It

Have you understood how to save and load images from flash memory or microSD cards and how to display them on the EPD? Once you can do those things, you're almost done! Now, let's combine the code to finish it as a complete project.

We'll build it with the following logic:

  • If card.png exists on the microSD card, load and display it.
  • If it doesn't exist, load card.png from LittleFS and display it.
  • If neither exists, display "No image" on the screen.

Environment

The build environment for this project is as follows. There's an issue with the EPDiy library required for the M5PaperS3, so be careful with the environment setup. If you can't build it, read this section carefully.

  • M5PaperS3
  • PlatformIO
  • M5Unified 0.22 or later
  • epdiy @ 2.0.0+sha.cbdaaa7

Platformio.ini

https://github.com/nananauno/M5PEasyTag/blob/main/platformio.ini

Replace the epdiy specification in the platformio.ini above as follows:

epdiy=https://github.com/vroland/epdiy.git#cbdaaa7

Sample Code

You can write the code yourself based on what has been explained so far, but I've also provided a sample code below just in case.

#include <LittleFS.h>
#include <SD.h>
#include <M5Unified.h>
#include <epdiy.h>

void setup() {
  // put your setup code here, to run once:
  M5.begin();
  
  // Get SPI pins
  auto mosi = M5.getPin(m5::pin_name_t::sd_spi_mosi);
  auto miso = M5.getPin(m5::pin_name_t::sd_spi_miso);
  auto sclk = M5.getPin(m5::pin_name_t::sd_spi_sclk);
  auto cs = M5.getPin(m5::pin_name_t::sd_spi_cs);

  // Initialize SD card
  SPI.begin(sclk, miso, mosi);
  if (!SD.begin(cs, SPI, 4000000)) {
    //SD card init .. NG
  }

  // Initialize LittleFS
  if (!LittleFS.begin()) {
    //LittleFS init .. NG
  }

  M5.Display.setEpdMode(epd_mode_t::epd_quality);
  bool success = M5.Display.drawPngFile(SD, "/card.png");
  if (!success) {
    success = M5.Display.drawPngFile(LittleFS, "/card.png");
  }
  if (!success) {
    M5.Display.println("No image");
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}

Let's Run It

The resolution of the M5PaperS3 EPD is 540 pixels wide and 960 pixels high, so create card.png at this size and place it in the root of the microSD card and the data folder for LittleFS. The image can be either grayscale or color. If you create it in color, it will be automatically converted to grayscale when drawn.

Once the image is ready, build the sample code and flash it to the M5PaperS3. To flash the M5PaperS3, long-press the reset button until the red LED flashes to boot in bootloader mode, then write the firmware in that state.

Try starting the M5PaperS3 first without writing anything to the LittleFS area and without a microSD card inserted. You should see "No image" displayed very small in the upper left. After that, try inserting a microSD card or uploading files to the LittleFS area to see how the display changes.

Summary

Were you able to create your own e-paper name tag using the M5PaperS3? In this article, I introduced how to make a coveted e-paper name tag using the M5PaperS3! I mainly explained how to load and display images from LittleFS and microSD cards, as well as settings specific to EPD. Even though it's e-paper, it wasn't used that differently from other M5Stack series, was it?

Since you can update the e-paper name tag just by swapping images, it's easy to change the image according to your mood. It will definitely stand out at events or exhibitions, and it would be even more interesting if you changed the display with touch!

Finally, let me introduce the software I made once more, which lets you easily create an e-paper name tag with M5Paper/S3. This can be easily flashed via a browser or M5Burner, so even without a development environment, you can very easily turn your M5Paper/S3 into an e-paper name tag, so please give it a try.

Write from your browser here 👇
https://app.nanana.uno/

I hope you all try making your own e-paper name tag! Well then, see you later!

References

https://qiita.com/mitsuharu_e/items/63e9f278bd48933f372a

Discussion