iTranslated by AI

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

Building an E-Paper Temperature, Humidity, and CO2 Monitor

に公開
2025/12/25

What I Built

I built an electronic paper (e-paper) display that shows the current date, time, room temperature, humidity, and CO2 levels. It updates once per minute and synchronizes with ntp.nict.jp via Wi-Fi once an hour to keep the time accurate. It also logs sensor data to the cloud.

epaper-env-monitor-clock
The pegboard-mount case is custom-made. The sensor is sticking out of the top.

dashboard

Motivation

While decluttering, I found an old temperature and humidity meter. I put batteries in it to get it working, but it felt broken—the temperature readings were oddly high and the humidity levels were very low. Coincidentally, I came across an e-paper display of a perfect size, so I decided to build my own.

Materials

Wiring

wiring

Both the SCD41 and MAX17048 use I2C, so I could have wired them to the same pins, but through the debugging process, they ended up separated and I kept it that way. The CHRG pin of the 4054A is too small to be visible in the photo.

Development Environment

  • macOS 26.1
  • Cursor 2 (Composer 1, Gemini 3 Pro, Opus 4.5)
  • arduino-cli

Agentic Coding in Arduino Development

All source code for this project was generated by Cursor. Early on, I used Composer 1, switched to Gemini 3 Pro, and used Opus 4.5 toward the end. I barely wrote any code manually. I reviewed it to some extent, but there is plenty of code I haven't even looked at. Even the Python scripts to generate bitmap fonts were fully generated. Arduino is basically open C/C++, and since there is a decent amount of knowledge available on it, this level of project wasn't an issue at all.

ChatGPT 5.1 Pro

Before making an implementation plan, I asked ChatGPT about the specifications and behavior of the SCD41 and MAX17048 to confirm details. It can even read CrowPanel schematic files (XML), which was extremely helpful as it suggested how to connect things or identified issues in the circuit.

arduino-cli

arduino-cli is a command-line tool for the Arduino IDE. It allows you to manage Arduino projects from the command line without using the Arduino IDE.
Thanks to the CLI version, I was able to leave everything from compilation to firmware uploading to Cursor. By defining appropriate commands in AGENTS.md, I could have it automatically compile and upload every time the code was updated.

While it is possible to let Cursor open and read the serial monitor, I decided to open it manually in a separate terminal and copy-paste only what was necessary, as dumping all logs consumes too much context.

Next time I build something, I might want to create an MCP server that manages compilation, uploading, and launching the serial monitor seamlessly. (It's a bit annoying when I forget the serial monitor is open and get an error when trying to upload.)

E-Paper Control

Since a tutorial is provided, displaying text and images is straightforward. I had to copy the control library from the sample code.

Partial Updates

I often see e-paper displays flash black and white across the entire screen during updates, but doing that every minute would be extremely distracting. I looked for a solution and found one. However, the control logic is a bit finicky; if you don't follow the procedure exactly, the screen gradually degrades (I had to guess the implementation by observing the behavior, but it works, so I'm assuming it's correct).

https://github.com/Saqoosha/EPDEnvClock/blob/8fe0835e3e4266fcec535888d637e50a6c73409f/EPDEnvClock/display_manager.cpp#L388-L402

Prepare pure white data with EPD_Display and then prepare for the update with EPD_PartUpdate.

After drawing what is needed and calling EPD_PartUpdate again, only the pixels that changed are updated. It doesn't perform a black-and-white flash refresh, making it look closer to a regular display, although a slight ghosting remains (the top image shows this state).

Font Rendering

Whether it's text or images, everything must ultimately be converted into 1-bit binary data per pixel. Naturally, you cannot use standard TrueType/OpenType fonts as they are, so they must be pre-converted into bitmap fonts.

3

I generated a Python script that renders only the necessary characters as bitmap images and outputs them as C header files, which were then integrated into the final program.

https://github.com/Saqoosha/EPDEnvClock/blob/8fe0835e3e4266fcec535888d637e50a6c73409f/EPDEnvClock/bitmaps/Number_M_bitmap.h

Proportional Fonts

In the initial design, I drew them as monospaced fonts because rendering was a hassle, but the character spacing looked strange, so I extracted metrics from the original font files to render them as proportional fonts. This is too tedious to do with manual coding, but being able to leave it to Cursor and wait a few minutes is truly a blessing. It is best to delegate tasks that are "annoying but necessary" to AI.

https://github.com/Saqoosha/EPDEnvClock/blob/8fe0835e3e4266fcec535888d637e50a6c73409f/EPDEnvClock/bitmaps/Kerning_table.h#L83-L148

Sensor Reading

The SCD41 temperature, humidity, and CO2 sensor reads data via I2C. The manufacturer, Sensirion, provides a library, so using that makes it easy (Cursor handled this, so I don't know the details).

Power Management

One of the reasons I chose e-paper was that I wanted to mount it on a wall. E-paper consumes power only when updating the content, so it can run for a long time on battery, but the control ESP32 must also be kept in Deep Sleep to avoid wasting power.

I set the Deep Sleep duration by measuring the time from wake-up until the processing finishes and subtracting that from the next intended wake-up time, ensuring the process runs every minute (the process usually finishes in about 8 seconds, so it sleeps for 52 seconds).

Since all memory is reset during Deep Sleep, I save the frame buffer for the screen to an SD card and reload it upon waking to restore the previous state.

Reading sensor data from the SCD41 requires a 5-second wait, which I managed by using Light Sleep during that time to save power.

The SCD41 sensor itself has various power-saving features, and I initially used its Power-down mode. However, I found that it was counterproductive for once-a-minute readings, so I switched to Single-shot mode to keep the sensor in an idle state.

(However, I haven't tested how many days the battery lasts from a full charge, so I don't know how effective this actually is.)

Battery Monitoring

The first method I implemented was the so-called voltage divider approach, inputting it to a GPIO and reading via ADC. It gives a rough trend, but the accuracy was poor. When I consulted ChatGPT, it suggested, "There's a thing called a fuel gauge IC." Using an Adafruit MAX17048 board made reading the voltage and remaining percentage quite accurate and easy.

There is one point to be careful about: the battery must be connected via the connector or the BAT terminal (not VIN). If not, the MAX17048 won't power up and the device won't be found on I2C (it is actually written on the Adafruit website).

Battery Charging Function

Although it is not mentioned on the CrowPanel page at all, this device has a built-in 4054A IC for LiPo charging. When a battery is connected and USB-C is plugged in, it charges.

Furthermore, this IC has a CHRG pin, and you can tell if it's charging by reading it. However, it's not actually connected to anything, so I had to pull it from the tiny pin to a GPIO with guts (I did it. Refer to the wiring photo).

Screen Design

I had been using Photoshop for a long time, but since Affinity has been a hot topic, I tried it out. However, partly because I'm too used to Photoshop, it was difficult to use... For this level of design work, there are no functional issues, but it was just hard to use.

affinity

So, I decided to do only the rough layout and adjust the rest on the implementation side.

Cloud Dashboard

dashboard

I thought if I'm taking sensor data, I'd want to log it and see it in graphs, so I looked for services of that kind, but none of them were great or they cost money. I decided to make it myself since it's just this much. I told Cursor (Opus 4.5) "something like this," and it produced almost exactly this on the first try, with only minor adjustments needed afterward.

I am accumulating data in Cloudflare D1. The front end is built with Astro and deployed on Pages. I am using Cloudflare Zero Trust to restrict access via a GitHub account. Zero Trust makes it relatively easy to set up flexible access restrictions, so it is great for protecting Cloudflare apps. You can also perform authentication using access tokens, so the ESP32 side sends sensor data using that token.

All Source Code

What I Learned

  • You can definitely do Vibe Coding even with Arduino projects
  • E-paper control is quite finicky
  • Fuel gauge ICs are convenient
  • ChatGPT can read circuit diagrams
  • Zero Trust is convenient

Discussion