Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions variants/xiao_s3_wio/XiaoS3WIOBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,47 @@
#include <Arduino.h>
#include <helpers/ESP32Board.h>

/*
* 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() { }

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
}

};