Idea to Build: An M5Stack CoreInk Room Monitor That Keeps Its Readings on E-Ink and Streams Them to Your Phone - Compoden

Idea to Build: An M5Stack CoreInk Room Monitor That Keeps Its Readings on E-Ink and Streams Them to Your Phone

I wanted a little box on the shelf that tells me how my room is doing: temperature, humidity, pressure and a gas reading, on a screen that doesn't glow at night. Plus the same numbers live on my phone.

An e-ink screen is perfect for that, because it keeps the last image even with the power gone. The M5Stack CoreInk already has one built in, plus an ESP32 with Wi-Fi, so the whole build is one board and one sensor.

Soldr designed this build, the parts list, the pin plan and the code around parts that can be shipped to you in India. Soldr is Compoden's AI, AI built on a catalog, so everything below is a part you can order here. If anything is missing, incorrect, or doesn't work as expected, let us know so it can be fixed.

What you need

Plus a Grove (HY2.0-4P) to female jumper lead and a USB-C data cable.

Step 1: Wire the BME680

Just four wires. The sensor talks I2C on GPIO32 and GPIO33 and runs on 3.3V.

Wiring diagram: M5Stack CoreInk with a BME680 on GPIO32 (SDA) and GPIO33 (SCL) from the Grove port, 3V3 and GND from the bottom header, showing readings on the e-ink and a live phone dashboard over Wi-Fi

BME680 pin CoreInk
BME680 VCC CoreInk 3V3 (bottom header, pin 6)
BME680 GND CoreInk GND (Grove black wire, or bottom header pin 1)
BME680 SDA GPIO32 (Grove yellow wire)
BME680 SCL GPIO33 (Grove white wire)
Grove red wire (5V) Not connected. Tape it off.
Power CoreInk USB-C port (computer or a 5V USB charger)

A few notes so it works the first time:

  • G32 and G33 live on the Grove port. Soldr's pin plan puts the sensor on GPIO32 and GPIO33. On the CoreInk those two pins only come out on the 4-pin Grove (HY2.0-4P) socket on the bottom: black GND, red 5V, yellow G32, white G33. Jumper wires don't push into a Grove socket, so use a Grove to female jumper lead.
  • Feed the BME680 3.3V, not 5V. The Grove socket's red wire is 5V, and this BME680 module is listed as a 3.3V part. Leave the red wire unconnected and take VCC from the 3V3 pin on the CoreInk's bottom header with a male-to-female jumper.
  • No extra resistors. BME680 breakouts normally carry their own I2C pull-ups, and the sketch tries both addresses (0x76, then 0x77), so either SDO setting works.

Step 2: Upload the Soldr firmware

Soldr generated this sketch for the room monitor. Paste it as room_monitor.ino, fill in your Wi-Fi details, and upload with the board set to M5CoreInk.

// legend: [SOLDR] build · [INIT] init · [TEST] self-test · [DATA] telemetry · [WARN]/[ERROR] fault · [FIX] likely remedy
//
// LOOP STRUCTURE (nothing blocks):
//   every pass      : M5.update(), server.handleClient(), button A check
//   millis() timed  : BME680 read cycle (start a reading every 3 s, collect it when ready)
//                     e-ink redraw (at most once per 60 s, only if values changed, or on button A)
//                     Wi-Fi reconnect attempt every 30 s if the link dropped
//   event driven    : HTTP requests to "/" and "/data"
//
// WIRING - generated from the same pin plan as the Wiring tab (follow the Wiring tab if in doubt):
//   3V3 -> BME680 Sensor Module VCC
//   GND -> BME680 Sensor Module GND
//   GPIO32 -> BME680 Sensor Module SDA
//   GPIO33 -> BME680 Sensor Module SCL
//   USB port -> M5Stack CoreInk ESP32 E-Ink Develo powered from its own USB port (a cable to a computer or a 5 V USB charger)
// Gas note: the BME680 gives raw gas RESISTANCE (kOhm). A calibrated IAQ index needs
// Bosch's BSEC library plus a burn-in period, so this sketch does NOT present an IAQ value.
// Higher resistance = cleaner air; watch the trend rather than the absolute number.

#include <M5Unified.h>
#include <Wire.h>
#include <WiFi.h>
#include <WebServer.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>

#define SOLDR_DEBUG 1

#define WIFI_SSID "YOUR_SSID"
#define WIFI_PASS "YOUR_PASSWORD"

#define I2C_SDA_PIN 32
#define I2C_SCL_PIN 33

const unsigned long SENSOR_INTERVAL_MS  = 3000;
const unsigned long DISPLAY_INTERVAL_MS = 60000;
const unsigned long WIFI_RETRY_MS       = 30000;
const int QUALITY_REFRESH_EVERY         = 10;   // full (flashing) refresh every Nth redraw

Adafruit_BME680 bme(&Wire);
WebServer server(80);

bool sensorOk = false;
bool wifiOk = false;

float tempC = NAN, humidityPct = NAN, pressureHpa = NAN, gasKohm = NAN;
bool haveReading = false;

bool readingPending = false;
unsigned long readingReadyAt = 0;
unsigned long lastSensorStart = 0;
unsigned long lastDisplayDraw = 0;
unsigned long lastWifiTry = 0;
bool forceRedraw = true;
int redrawCount = 0;

long shownTemp10 = -99999, shownHum = -1, shownPress = -1, shownGas = -1;

int initOk = 0, initFail = 0;

const char INDEX_HTML[] PROGMEM = R"HTML(
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Room Monitor · Soldr</title>
<style>
  :root{--bg:#0a090c;--card:#141317;--line:rgba(255,255,255,.08);--ink:#f2f1ee;--mut:#8b8985;--hot:#E8421A}
  *{box-sizing:border-box;margin:0}
  body{background:var(--bg);color:var(--ink);font:14px/1.5 -apple-system,Segoe UI,Roboto,sans-serif;padding:16px;max-width:820px;margin:0 auto}
  header{display:flex;align-items:center;gap:10px;padding-bottom:14px;border-bottom:1px solid var(--line);margin-bottom:16px}
  .mark{height:22px;width:auto}
  h1{font-size:15px;font-weight:600;color:var(--mut);letter-spacing:.01em}
  .dot{width:7px;height:7px;border-radius:50%;background:#34d399;box-shadow:0 0 7px #34d399;margin-left:auto;transition:.3s}
  .dot.stale{background:#6b6a67;box-shadow:none}
  .grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:12px}
  .card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:14px}
  .card .k{font:11px/1 ui-monospace,monospace;letter-spacing:.08em;text-transform:uppercase;color:var(--mut)}
  .card .v{font:600 26px/1.1 ui-monospace,monospace;color:var(--ink);margin-top:8px;font-variant-numeric:tabular-nums}
  .card canvas{width:100%;height:34px;display:block;margin-top:8px}
  footer{margin-top:18px;font:11px/1 ui-monospace,monospace;color:var(--mut);text-align:center}
  .empty{color:var(--mut);grid-column:1/-1;text-align:center;padding:28px 0;font-size:13px}
</style></head><body>
<header>
  <!-- SO;DR — the ; is a molten solder drop (bead + drip), iron-hot orange with a highlight -->
  <svg class="mark" viewBox="0 0 132 74" fill="none" xmlns="http://www.w3.org/2000/svg" aria-label="SO;DR">
    <text x="0" y="52" font-family="ui-monospace,monospace" font-size="52" font-weight="700" fill="#f2f1ee">SO</text>
    <g transform="translate(64,0)">
      <circle cx="15" cy="20" r="8.5" fill="#E8421A"/><circle cx="12" cy="17" r="2.6" fill="#FFB499" opacity=".85"/>
      <path d="M15 40 C9 47 7 54 7 60 a8 8 0 0 0 16 0 c0 -6 -2 -13 -8 -20 Z" fill="#E8421A"/><circle cx="12.5" cy="57" r="2.4" fill="#FFB499" opacity=".8"/>
    </g>
    <text x="94" y="52" font-family="ui-monospace,monospace" font-size="52" font-weight="700" fill="#f2f1ee">DR</text>
  </svg>
  <h1>Room Monitor</h1>
  <span id="live" class="dot stale" title="link status"></span>
</header>
<div id="grid" class="grid"><div class="empty">waiting for the board…</div></div>
<footer>Soldr · live dashboard · updates every second</footer>
<script>
(function(){
  var hist={};                                  // per-key rolling values for the sparkline
  var grid=document.getElementById('grid'), live=document.getElementById('live');
  function spark(cv,vals){
    var c=cv.getContext('2d'),w=cv.width=cv.clientWidth*2,h=cv.height=68,n=vals.length; c.clearRect(0,0,w,h);
    if(n<2)return; var lo=Math.min.apply(0,vals),hi=Math.max.apply(0,vals); if(hi===lo){hi++;lo--;}
    c.strokeStyle='#E8421A';c.lineWidth=3;c.beginPath();
    vals.forEach(function(v,i){var x=i/(n-1)*w,y=h-(v-lo)/(hi-lo)*h;i?c.lineTo(x,y):c.moveTo(x,y);});c.stroke();
  }
  function render(d){
    var keys=Object.keys(d); if(!keys.length){return;}
    grid.querySelector('.empty')&&(grid.innerHTML='');
    keys.forEach(function(k){
      (hist[k]=hist[k]||[]).push(+d[k]); if(hist[k].length>60)hist[k].shift();
      var id='c_'+k.replace(/\W/g,''), card=document.getElementById(id);
      if(!card){card=document.createElement('div');card.className='card';card.id=id;
        card.innerHTML='<div class="k"></div><div class="v"></div><canvas></canvas>';
        card.querySelector('.k').textContent=k; grid.appendChild(card);}
      card.querySelector('.v').textContent=d[k];
      spark(card.querySelector('canvas'),hist[k]);
    });
  }
  function poll(){
    fetch('/data').then(function(r){return r.json();}).then(function(d){live.classList.remove('stale');render(d);})
      .catch(function(){live.classList.add('stale');});
  }
  poll(); setInterval(poll,1000);
})();
</script>
</body></html>
)HTML";

void handleRoot() {
  server.send_P(200, "text/html", INDEX_HTML);
}

void handleData() {
  char buf[200];
  if (haveReading) {
    snprintf(buf, sizeof(buf),
             "{\"Temperature (C)\":%.1f,\"Humidity (%%)\":%.1f,\"Pressure (hPa)\":%.1f,\"Gas resistance (kOhm)\":%.1f}",
             tempC, humidityPct, pressureHpa, gasKohm);
  } else {
    snprintf(buf, sizeof(buf), "{}");
  }
  server.sendHeader("Cache-Control", "no-store");
  server.send(200, "application/json", buf);
}

void drawScreen() {
  M5.Display.setEpdMode((redrawCount % QUALITY_REFRESH_EVERY == 0) ? epd_mode_t::epd_quality
                                                                   : epd_mode_t::epd_fast);
  M5.Display.fillScreen(TFT_WHITE);
  M5.Display.setTextColor(TFT_BLACK, TFT_WHITE);

  M5.Display.setTextSize(2);
  M5.Display.setCursor(8, 6);
  M5.Display.print("Room Monitor");
  M5.Display.drawLine(0, 28, M5.Display.width(), 28, TFT_BLACK);

  if (haveReading) {
    M5.Display.setCursor(8, 42);
    M5.Display.printf("Temp  %.1f C", tempC);
    M5.Display.setCursor(8, 74);
    M5.Display.printf("Hum   %.0f %%", humidityPct);
    M5.Display.setCursor(8, 106);
    M5.Display.printf("Pres  %.0f hPa", pressureHpa);
    M5.Display.setCursor(8, 138);
    M5.Display.printf("Gas   %.0f kOhm", gasKohm);
  } else {
    M5.Display.setCursor(8, 74);
    M5.Display.print(sensorOk ? "Reading..." : "Sensor FAIL");
  }

  M5.Display.setTextSize(1);
  M5.Display.setCursor(8, 176);
  if (wifiOk) {
    M5.Display.printf("http://%s/", WiFi.localIP().toString().c_str());
  } else {
    M5.Display.print("Wi-Fi offline");
  }
  M5.Display.display();
  redrawCount++;
}

void connectWifi(unsigned long timeoutMs) {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  unsigned long start = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - start < timeoutMs) {
    delay(250);
  }
  wifiOk = (WiFi.status() == WL_CONNECTED);
}

void setup() {
  auto cfg = M5.config();
  M5.begin(cfg);
  Serial.begin(115200);
  delay(200);

#if SOLDR_DEBUG
  Serial.println();
  Serial.println("[SOLDR] Room Monitor | board:M5Stack CoreInk (ESP32-PICO-D4) | v1.0");
#endif

  // Display
  if (M5.Display.width() > 0) {
    initOk++;
#if SOLDR_DEBUG
    Serial.println("[INIT] E-ink display: OK");
#endif
    M5.Display.setEpdMode(epd_mode_t::epd_quality);
    M5.Display.fillScreen(TFT_WHITE);
    M5.Display.setTextColor(TFT_BLACK, TFT_WHITE);
    M5.Display.setTextSize(2);
    M5.Display.setCursor(8, 80);
    M5.Display.print("Starting...");
    M5.Display.display();
  } else {
    initFail++;
#if SOLDR_DEBUG
    Serial.println("[INIT] E-ink display: FAIL (width 0)");
    Serial.println("[FIX] E-ink display: power-cycle the CoreInk and re-flash with the CoreInk board selected");
#endif
  }

  // BME680 on Port A I2C
  Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
  sensorOk = bme.begin(0x76);
  if (!sensorOk) sensorOk = bme.begin(0x77);
  if (sensorOk) {
    initOk++;
    bme.setTemperatureOversampling(BME680_OS_8X);
    bme.setHumidityOversampling(BME680_OS_2X);
    bme.setPressureOversampling(BME680_OS_4X);
    bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
    bme.setGasHeater(320, 150);  // 320 C for 150 ms
#if SOLDR_DEBUG
    Serial.println("[INIT] BME680: OK");
#endif
  } else {
    initFail++;
#if SOLDR_DEBUG
    Serial.println("[INIT] BME680: FAIL (no response at 0x76 or 0x77)");
    Serial.println("[FIX] BME680: check SDA->GPIO32, SCL->GPIO33, 3V3 and GND; SDO pin must not float");
#endif
  }

  // Wi-Fi (degraded mode if it fails: e-ink still works)
#if SOLDR_DEBUG
  Serial.print("[INIT] WiFi: connecting to ");
  Serial.println(WIFI_SSID);
#endif
  connectWifi(15000);
  lastWifiTry = millis();
  if (wifiOk) {
    initOk++;
    server.on("/", HTTP_GET, handleRoot);
    server.on("/data", HTTP_GET, handleData);
    server.begin();
#if SOLDR_DEBUG
    Serial.print("[INIT] WiFi: connected, IP ");
    Serial.println(WiFi.localIP());
#endif
  } else {
    initFail++;
#if SOLDR_DEBUG
    Serial.println("[INIT] WiFi: FAIL (not connected)");
    Serial.println("[FIX] WiFi: check WIFI_SSID/WIFI_PASS and that the network is 2.4 GHz");
#endif
  }

  // Server routes are registered even if Wi-Fi came up late
  if (!wifiOk) {
    server.on("/", HTTP_GET, handleRoot);
    server.on("/data", HTTP_GET, handleData);
  }

#if SOLDR_DEBUG
  // BME680 takes its first reading in loop(), so no immediate self-test read here
  Serial.println("[TEST] BME680: first reading reported by loop() as [DATA]");
  Serial.printf("[READY] %d OK / %d FAIL\n", initOk, initFail);
#endif
}

void loop() {
  M5.update();
  server.handleClient();

  // Button A forces a redraw
  if (M5.BtnA.wasPressed()) forceRedraw = true;

  // Sensor cycle: start a reading, collect it once it is ready
  if (sensorOk) {
    if (!readingPending && millis() - lastSensorStart >= SENSOR_INTERVAL_MS) {
      lastSensorStart = millis();
      unsigned long endTime = bme.beginReading();
      if (endTime == 0) {
#if SOLDR_DEBUG
        Serial.println("[ERROR] BME680: beginReading failed");
        Serial.println("[FIX] BME680: check I2C wiring and power");
#endif
      } else {
        readingPending = true;
        readingReadyAt = endTime;
      }
    }
    if (readingPending && (long)(millis() - readingReadyAt) >= 0) {
      readingPending = false;
      if (bme.endReading()) {
        tempC = bme.temperature;
        humidityPct = bme.humidity;
        pressureHpa = bme.pressure / 100.0f;
        gasKohm = bme.gas_resistance / 1000.0f;
        haveReading = true;
#if SOLDR_DEBUG
        Serial.printf("[DATA] temp=%.1f hum=%.1f press=%.1f gas_kohm=%.1f\n",
                      tempC, humidityPct, pressureHpa, gasKohm);
#endif
      } else {
#if SOLDR_DEBUG
        Serial.println("[WARN] BME680: endReading failed");
#endif
      }
    }
  }

  // Wi-Fi reconnect attempt (non-blocking: begin() returns immediately)
  bool nowConnected = (WiFi.status() == WL_CONNECTED);
  if (nowConnected != wifiOk) {
    wifiOk = nowConnected;
    if (wifiOk) {
      server.begin();
      forceRedraw = true;
    }
  }
  if (!wifiOk && millis() - lastWifiTry >= WIFI_RETRY_MS) {
    lastWifiTry = millis();
    WiFi.begin(WIFI_SSID, WIFI_PASS);
  }

  // E-ink redraw: rate-limited, only on change (or forced)
  if (M5.Display.width() > 0 && (forceRedraw || millis() - lastDisplayDraw >= DISPLAY_INTERVAL_MS)) {
    long t10 = haveReading ? lroundf(tempC * 10.0f) : -99999;
    long h = haveReading ? lroundf(humidityPct) : -1;
    long p = haveReading ? lroundf(pressureHpa) : -1;
    long g = haveReading ? lroundf(gasKohm) : -1;
    bool changed = (t10 != shownTemp10 || h != shownHum || p != shownPress || g != shownGas);
    if (forceRedraw || changed) {
      drawScreen();
      shownTemp10 = t10; shownHum = h; shownPress = p; shownGas = g;
      forceRedraw = false;
    }
    lastDisplayDraw = millis();
  }
}

How it works

  • Every 3 seconds the sketch starts a BME680 reading and collects it when it's ready, without blocking. It reads temperature, humidity, pressure, and gas resistance, with the gas heater at 320°C for 150 ms.
  • The gas number is raw resistance in kOhm, not an air quality index. Higher means cleaner air, so watch the trend: it drops when you open a marker or spray a deodorant nearby.
  • The e-ink redraws at most once a minute, and only if a value changed, because e-ink is slow and flashes on a full refresh. Most redraws use the fast mode; every 10th is a full quality refresh to clear ghosting.
  • The CoreInk joins your home Wi-Fi and runs a small web server. The page polls /data every second and draws a sparkline under each number from the last 60 readings.
  • If Wi-Fi drops, it retries every 30 seconds and the e-ink keeps working on its own.

Step 3: Try it

  1. In the Arduino IDE, install the esp32 board package and pick M5CoreInk as the board. Then install M5Unified (it pulls in M5GFX) and Adafruit BME680 (it pulls in Adafruit Unified Sensor and BusIO).
  2. Put your Wi-Fi name and password in WIFI_SSID and WIFI_PASS. It has to be a 2.4 GHz network.
  3. Upload the sketch, then open the Serial Monitor at 115200. You'll see the [SOLDR] banner, [INIT] lines for the e-ink, the BME680 and Wi-Fi with the IP address, then [READY] 3 OK / 0 FAIL.
  4. Type the IP from the bottom of the e-ink into your phone's browser, with the phone on the same Wi-Fi. The four cards fill in within a few seconds.
  5. Breathe on the sensor and watch humidity climb on the phone. To update the e-ink right away instead of waiting a minute, push the side dial up (that's button A).

If something's off

  • BME680: FAIL (no response at 0x76 or 0x77): SDA and SCL are probably swapped. Yellow (G32) goes to SDA and white (G33) to SCL. Also check VCC is on 3V3.
  • WiFi: FAIL: check the name and password, and that it's a 2.4 GHz network, since the ESP32 can't join 5 GHz.

How Soldr designs this from the idea

Want a buzzer when humidity goes above 70%, or a battery icon? Describe the idea at soldr.ai. Soldr designs hardware from the idea: it asks which board you want, picks parts from the Compoden catalog, assigns the pins, gives you the wiring and writes the firmware, then compiles it for your board. For this one the idea was simply a room monitor with an M5Stack CoreInk and a BME680 showing temperature, humidity, pressure and gas on the e-ink, with a live dashboard on my phone.

Leave it on a shelf and glance at it like a clock. The phone page is for when you want to watch the numbers move.

Back to blog

Open this project in the Soldr app → What is Soldr.ai → parts, wiring and code for what this guide builds