Merge pull request #1071 from tpp-at-idx/thinknode_m2

Thinknode_M2: better battery reading accuracy and no display on powerup fix
This commit is contained in:
ripplebiz
2025-11-14 15:11:06 +11:00
committed by GitHub
2 changed files with 22 additions and 17 deletions

View File

@@ -3,12 +3,13 @@
void ThinknodeM2Board::begin() {
pinMode(PIN_VEXT_EN, OUTPUT);
digitalWrite(PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE); // force power cycle
delay(20); // allow power rail to discharge
digitalWrite(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE); // turn backlight back on
delay(120); // give display time to bias on cold boot
ESP32Board::begin();
pinMode(PIN_VEXT_EN, OUTPUT); // init display
digitalWrite(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE); // pin needs to be high
delay(10);
digitalWrite(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE); // need to do this twice. do not know why..
pinMode(PIN_STATUS_LED, OUTPUT); // init power led
pinMode(PIN_STATUS_LED, OUTPUT); // init power led
}
void ThinknodeM2Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) {
@@ -19,14 +20,21 @@ void ThinknodeM2Board::begin() {
enterDeepSleep(0);
}
uint16_t ThinknodeM2Board::getBattMilliVolts() {
uint16_t ThinknodeM2Board::getBattMilliVolts() {
analogReadResolution(12);
delay(10);
float volts = (analogRead(PIN_VBAT_READ) * ADC_MULTIPLIER * AREF_VOLTAGE) / 4096;
analogReadResolution(10);
return volts * 1000;
}
analogSetPinAttenuation(PIN_VBAT_READ, ADC_11db);
uint32_t mv = 0;
for (int i = 0; i < 8; ++i) {
mv += analogReadMilliVolts(PIN_VBAT_READ);
delayMicroseconds(200);
}
mv /= 8;
analogReadResolution(10);
return static_cast<uint16_t>(mv * ADC_MULTIPLIER );
}
const char* ThinknodeM2Board::getManufacturerName() const {
return "Elecrow ThinkNode M2";
}
}

View File

@@ -1,8 +1,8 @@
#define I2C_SCL 15
#define I2C_SDA 16
#define PIN_VBAT_READ 17
#define PIN_VBAT_READ 17
#define AREF_VOLTAGE (3.0)
#define ADC_MULTIPLIER (1.548F)
#define ADC_MULTIPLIER (1.509F)
#define PIN_BUZZER 5
#define PIN_VEXT_EN_ACTIVE HIGH
#define PIN_VEXT_EN 46
@@ -10,6 +10,3 @@
#define PIN_LED 6
#define PIN_STATUS_LED 6
#define PIN_PWRBTN 4