From e8a564b1cf1d1c91c7aba7f6ba39dc16c9d4b9ae Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Wed, 17 Jun 2026 12:33:49 +0200 Subject: [PATCH 1/2] feat(xiao_s3_wio): add battery read with voltage divider --- variants/xiao_s3_wio/XiaoS3WIOBoard.h | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/variants/xiao_s3_wio/XiaoS3WIOBoard.h b/variants/xiao_s3_wio/XiaoS3WIOBoard.h index 7ae06a359b..98283c2c91 100644 --- a/variants/xiao_s3_wio/XiaoS3WIOBoard.h +++ b/variants/xiao_s3_wio/XiaoS3WIOBoard.h @@ -3,6 +3,25 @@ #include #include +/* + * This board has no built-in way to read battery voltage. + * Nevertheless it's very easy to make it work, you only require two 1% resistors. + * If your using the WIO SX1262 Addon for xaio, make sure you dont connect D1! + * + * BAT+ -----+ + * | + * VSYS --+ -/\/\/\/\- --+ + * 200k | + * +-- D1 + * | + * GND --+ -/\/\/\/\- --+ + * | 100k + * BAT- -----+ + */ +#define PIN_VBAT_READ 2 // D1 +#define BATTERY_SAMPLES 8 +#define ADC_MULTIPLIER (3.0f * 3.3f * 1000) + class XiaoS3WIOBoard : public ESP32Board { public: XiaoS3WIOBoard() { } @@ -10,4 +29,21 @@ class XiaoS3WIOBoard : public ESP32Board { const char* getManufacturerName() const override { return "Xiao S3 WIO"; } + + uint16_t getBattMilliVolts() override { +#if defined(PIN_VBAT_READ) && defined(ADC_MULTIPLIER) + analogReadResolution(12); + + uint32_t raw = 0; + for (int i = 0; i < BATTERY_SAMPLES; i++) { + raw += analogRead(PIN_VBAT_READ); + } + raw = raw / BATTERY_SAMPLES; + + return (ADC_MULTIPLIER * raw) / 4096; +#else + return 0; +#endif + } + }; From a0c1e655da49cb9875d21baca255066e69da6032 Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Tue, 8 Sep 2026 16:53:50 +0200 Subject: [PATCH 2/2] chore(xiao_s3_wio): calibrate ADC_MULTIPLIER --- variants/xiao_s3_wio/XiaoS3WIOBoard.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variants/xiao_s3_wio/XiaoS3WIOBoard.h b/variants/xiao_s3_wio/XiaoS3WIOBoard.h index 98283c2c91..74093b208f 100644 --- a/variants/xiao_s3_wio/XiaoS3WIOBoard.h +++ b/variants/xiao_s3_wio/XiaoS3WIOBoard.h @@ -15,12 +15,12 @@ * +-- D1 * | * GND --+ -/\/\/\/\- --+ - * | 100k + * | 200k * BAT- -----+ */ #define PIN_VBAT_READ 2 // D1 #define BATTERY_SAMPLES 8 -#define ADC_MULTIPLIER (3.0f * 3.3f * 1000) +#define ADC_MULTIPLIER (7.46f * 1000) class XiaoS3WIOBoard : public ESP32Board { public: