Hi There,
So You , Do’nt need to make it so complex , it is a pretty straight forward ask, and done often,. search the posts and you will find more.
You want to use an E-paper instead of the OLED,
You’re not doing Graphics or crazy Icons, SO Keep is Simple. e-paper draws almost no power and none when off Use the Xiao to control its Vcc and wire the Sleep mode correctly and it should work a reasonable amount of time on 3 NON_rechargable batteries.
Here is a good starting point for this configuration, I have some experience with it.
#include <Wire.h>
#include <SPI.h>
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <TMAG5273.h> // Ensure you have the TI TMAG5273 library installed
// Define pins for XIAO ESP32-C6 SPI E-Paper Display
// Adjust these depending on your specific e-paper wiring breakout
const int EPD_CS = D3;
const int EPD_DC = D2;
const int EPD_RST = D1;
const int EPD_BUSY = D0;
// Initialize E-Paper (e.g., 2.9 inch monochrome display variant)
GxEPD2_BW<GxEPD2_290_T9, GxEPD2_290_T9::HEIGHT> display(GxEPD2_290_T9(/*CS*/ EPD_CS, /*DC*/ EPD_DC, /*RST*/ EPD_RST, /*BUSY*/ EPD_BUSY));
TMAG5273 tmagSensor;
// Sleep interval configuration (e.g., wake every 60 seconds)
#define uS_TO_S_FACTOR 1000000ULL
#define TIME_TO_SLEEP 60
void setup() {
Serial.begin(115200);
delay(1000);
// Initialize I2C for TMAG5273
Wire.begin();
// Initialize TMAG5273 sensor
if (!tmagSensor.begin(Wire, TMAG5273_I2C_ADDRESS_DEFAULT)) {
Serial.println("Could not find a valid TMAG5273 sensor, check wiring!");
while (1) { delay(10); }
}
// Configure TMAG5273 for automatic temperature and 3-axis conversion
tmagSensor.setAxis(TMAG5273_X_ENABLE | TMAG5273_Y_ENABLE | TMAG5273_Z_ENABLE);
tmagSensor.setMeasurementMode(TMAG5273_STANDBY_MODE);
// Initialize E-Paper Display SPI
display.init(115200, true, 2, false); // init parameters for typical SPI setup
display.setRotation(1);
// Read Sensor Data
float xVal = tmagSensor.getXData();
float yVal = tmagSensor.getYData();
float zVal = tmagSensor.getZData();
// Update E-Paper Screen
drawDisplayData(xVal, yVal, zVal);
// Put E-Paper into sleep/power-off state to draw zero quiescent power
display.hibernate();
// Configure Deep Sleep Timer
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Entering ESP32-C6 deep sleep...");
Serial.flush();
esp_deep_sleep_start();
}
void loop() {
// Not used in deep sleep architecture
}
void drawDisplayData(float x, float y, float z) {
display.setFullWindow();
display.firstPage();
do {
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeSansBold9pt7b);
display.setCursor(10, 25);
display.print("SENSOR: TMAG5273");
display.setCursor(10, 50);
display.print("X: "); display.print(x, 1); display.print(" mT");
display.setCursor(10, 75);
display.print("Y: "); display.print(y, 1); display.print(" mT");
display.setCursor(10, 100);
display.print("Z: "); display.print(z, 1); display.print(" mT");
display.setCursor(10, 125);
display.print("STATUS: OK");
} while (display.nextPage());
}
- Install the
GxEPD2 and TMAG5273 libraries via the Arduino IDE Library Manager.
- Double-check your SPI pin mapping if you use a standard Waveshare or Seeed e-paper breakout module to match
D0-D3 on the XIAO ESP32-C6.
HTH
GL
PJ 
This one, connects your XIAO ESP32-C6 to your local Wi-Fi network and publishes the TMAG5273 magnetic sensor readings to a simple built-in web server page. When it wakes up, it connects, hosts a local webpage for a few seconds so you can view it (or fetch it via an automation script), updates the e-paper screen, and goes right back to deep sleep.
#include <Wire.h>
#include <SPI.h>
#include <WiFi.h>
#include <WebServer.h>
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <TMAG5273.h>
// Wi-Fi Credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
WebServer server(80);
// Define pins for XIAO ESP32-C6 SPI E-Paper Display
const int EPD_CS = D3;
const int EPD_DC = D2;
const int EPD_RST = D1;
const int EPD_BUSY = D0;
GxEPD2_BW<GxEPD2_290_T9, GxEPD2_290_T9::HEIGHT> display(GxEPD2_290_T9(EPD_CS, EPD_DC, EPD_RST, EPD_BUSY));
TMAG5273 tmagSensor;
// Global variables to hold latest readings for the web server
float currentX = 0, currentY = 0, currentZ = 0;
#define uS_TO_S_FACTOR 1000000ULL
#define TIME_TO_SLEEP 60
void handleRoot() {
String html = "<html lang='en'><head><meta http-equiv='refresh' content='10'/></head><body>";
html += "<h2>TMAG5273 Sensor Status</h2>";
html += "<p><strong>X-Axis:</strong> " + String(currentX, 1) + " mT</p>";
html += "<p><strong>Y-Axis:</strong> " + String(currentY, 1) + " mT</p>";
html += "<p><strong>Z-Axis:</strong> " + String(currentZ, 1) + " mT</p>";
html += "<p>Status: OK</p>";
html += "</body></html>";
server.send(200, "text/html", html);
}
void setup() {
Serial.begin(115200);
delay(1000);
// Initialize I2C and Sensor
Wire.begin();
if (!tmagSensor.begin(Wire, TMAG5273_I2C_ADDRESS_DEFAULT)) {
Serial.println("Could not find a valid TMAG5273 sensor!");
} else {
tmagSensor.setAxis(TMAG5273_X_ENABLE | TMAG5273_Y_ENABLE | TMAG5273_Z_ENABLE);
tmagSensor.setMeasurementMode(TMAG5273_STANDBY_MODE);
currentX = tmagSensor.getXData();
currentY = tmagSensor.getYData();
currentZ = tmagSensor.getZData();
}
// Initialize E-Paper Display
display.init(115200, true, 2, false);
display.setRotation(1);
drawDisplayData(currentX, currentY, currentZ);
display.hibernate();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to Wi-Fi");
unsigned long startAttemptTime = millis();
// Wait up to 10 seconds for connection
while (WiFi.status() != WL_CONNECTED && millis() - startAttemptTime < 10000) {
delay(500);
Serial.print(".");
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("\nConnected! IP Address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.begin();
// Keep server active for 15 seconds to allow requests before sleeping
unsigned long serverStartTime = millis();
while (millis() - serverStartTime < 15000) {
server.handleClient();
}
} else {
Serial.println("\nWi-Fi connection failed. Skipping web server.");
}
// Enter Deep Sleep
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Entering ESP32-C6 deep sleep...");
Serial.flush();
esp_deep_sleep_start();
}
void loop() {
// Not used in deep sleep architecture
}
void drawDisplayData(float x, float y, float z) {
display.setFullWindow();
display.firstPage();
do {
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeSansBold9pt7b);
display.setCursor(10, 25);
display.print("SENSOR: TMAG5273");
display.setCursor(10, 50);
display.print("X: "); display.print(x, 1); display.print(" mT");
display.setCursor(10, 75);
display.print("Y: "); display.print(y, 1); display.print(" mT");
display.setCursor(10, 100);
display.print("Z: "); display.print(z, 1); display.print(" mT");
display.setCursor(10, 125);
display.print("STATUS: OK");
} while (display.nextPage());
}
Generates , This Web page..

- Estimated Battery Life: Roughly 3 to 5 months (approx. 90 to 150 days) on a standard set of 3x AA alkaline batteries, assuming a 60-second wake/sleep cycle.
Why this duration?
-
Deep Sleep Power: The XIAO ESP32-C6 in deep sleep with the RTC running draws just a few microamps ($\approx 10\mu A$ to $15\mu A$).
-
Active Wi-Fi / Sensor Bursts: When waking up every minute, the ESP32-C6 connects to Wi-Fi, reads the I2C sensor, updates the SPI e-paper display, and runs the local web server for 15 seconds. This active window draws roughly 80mA to 120mA.
-
Display Quiescent Draw: E-paper displays draw zero power while maintaining the image during deep sleep, which massively extends life compared to an OLED or LCD.
-
Battery Capacity: Three standard AA alkaline batteries in series provide about 4.5V (stepped down cleanly to 3.3V via your buck converter) with roughly 2500mAh to 3000mAh of total capacity.
If you lengthen the sleep timer from 60 seconds to 5 or 15 minutes, you can easily stretch the battery life past a year.