Read battery voltage on Minewsemi ME25LS01

This commit is contained in:
Normunds Gavars
2025-07-04 19:27:11 +03:00
parent 70a9990f45
commit aa3c702ffd
5 changed files with 22 additions and 73 deletions
+5 -6
View File
@@ -8,11 +8,12 @@ void MinewsemiME25LS01Board::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
btn_prev_state = HIGH;
pinMode(PIN_VBAT_READ, INPUT);
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
#ifdef BUTTON_PIN
// pinMode(BATTERY_PIN, INPUT);
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
#endif
@@ -31,7 +32,6 @@ void MinewsemiME25LS01Board::begin() {
delay(10); // give sx1262 some time to power up
}
#if 0
static BLEDfu bledfu;
static void connect_callback(uint16_t conn_handle) {
@@ -47,7 +47,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
}
bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
bool MinewsemiME25LS01Board::startOTAUpdate(const char* id, char reply[]) {
// Config the peripheral connection with maximum bandwidth
// more SRAM required by SoftDevice
// Note: All config***() function must be called before begin()
@@ -58,7 +58,7 @@ bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
Bluefruit.setTxPower(4);
// Set the BLE device name
Bluefruit.setName("T1000E_OTA");
Bluefruit.setName("Minewsemi_OTA");
Bluefruit.Periph.setConnectCallback(connect_callback);
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
@@ -88,5 +88,4 @@ bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
strcpy(reply, "OK - started");
return true;
}
#endif
}
+13 -37
View File
@@ -16,9 +16,9 @@
#define LR11X0_DIO_AS_RF_SWITCH true
#define LR11X0_DIO3_TCXO_VOLTAGE 1.6
// built-ins
//#define PIN_VBAT_READ 5
//#define ADC_MULTIPLIER (3 * 1.73 * 1000)
#define PIN_VBAT_READ BATTERY_PIN
#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
class MinewsemiME25LS01Board : public mesh::MainBoard {
protected:
@@ -28,43 +28,23 @@ protected:
public:
void begin();
#define BATTERY_SAMPLES 8
uint16_t getBattMilliVolts() override {
#ifdef BATTERY_PIN
#ifdef PIN_3V3_EN
digitalWrite(PIN_3V3_EN, HIGH);
#endif
analogReference(AR_INTERNAL_3_0);
analogReadResolution(12);
delay(10);
float volts = (analogRead(BATTERY_PIN) * ADC_MULTIPLIER * AREF_VOLTAGE) / 4096;
#ifdef PIN_3V3_EN
digitalWrite(PIN_3V3_EN, LOW);
#endif
analogReference(AR_DEFAULT); // put back to default
analogReadResolution(10);
return volts * 1000;
#else
return 0;
#endif
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);
}
uint8_t getStartupReason() const override { return startup_reason; }
const char* getManufacturerName() const override {
return "m25ls01";
}
int buttonStateChanged() {
#ifdef BUTTON_PIN
uint8_t v = digitalRead(BUTTON_PIN);
if (v != btn_prev_state) {
btn_prev_state = v;
return (v == LOW) ? 1 : -1;
}
#endif
return 0;
return "Minewsemi";
}
void powerOff() override {
@@ -81,10 +61,6 @@ public:
digitalWrite(BUZZER_EN, LOW);
#endif
#ifdef PIN_3V3_EN
digitalWrite(PIN_3V3_EN, LOW);
#endif
#ifdef LED_PIN
digitalWrite(LED_PIN, LOW);
#endif
@@ -108,5 +84,5 @@ public:
NVIC_SystemReset();
}
// bool startOTAUpdate(const char* id, char reply[]) override;
bool startOTAUpdate(const char* id, char reply[]) override;
};