Skip to content

Commit aa3c702

Browse files
author
Normunds Gavars
committed
Read battery voltage on Minewsemi ME25LS01
1 parent 70a9990 commit aa3c702

File tree

5 files changed

+23
-74
lines changed

5 files changed

+23
-74
lines changed

src/helpers/nrf52/MinewsemiME25LS01Board.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ void MinewsemiME25LS01Board::begin() {
88
// for future use, sub-classes SHOULD call this from their begin()
99
startup_reason = BD_STARTUP_NORMAL;
1010
btn_prev_state = HIGH;
11+
12+
pinMode(PIN_VBAT_READ, INPUT);
1113

1214
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
1315

1416
#ifdef BUTTON_PIN
15-
// pinMode(BATTERY_PIN, INPUT);
1617
pinMode(BUTTON_PIN, INPUT);
1718
pinMode(LED_PIN, OUTPUT);
1819
#endif
@@ -31,7 +32,6 @@ void MinewsemiME25LS01Board::begin() {
3132
delay(10); // give sx1262 some time to power up
3233
}
3334

34-
#if 0
3535
static BLEDfu bledfu;
3636

3737
static void connect_callback(uint16_t conn_handle) {
@@ -47,7 +47,7 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
4747
}
4848

4949

50-
bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
50+
bool MinewsemiME25LS01Board::startOTAUpdate(const char* id, char reply[]) {
5151
// Config the peripheral connection with maximum bandwidth
5252
// more SRAM required by SoftDevice
5353
// Note: All config***() function must be called before begin()
@@ -58,7 +58,7 @@ bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
5858
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
5959
Bluefruit.setTxPower(4);
6060
// Set the BLE device name
61-
Bluefruit.setName("T1000E_OTA");
61+
Bluefruit.setName("Minewsemi_OTA");
6262

6363
Bluefruit.Periph.setConnectCallback(connect_callback);
6464
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
@@ -88,5 +88,4 @@ bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
8888

8989
strcpy(reply, "OK - started");
9090
return true;
91-
}
92-
#endif
91+
}

src/helpers/nrf52/MinewsemiME25LS01Board.h

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#define LR11X0_DIO_AS_RF_SWITCH true
1717
#define LR11X0_DIO3_TCXO_VOLTAGE 1.6
1818

19-
// built-ins
20-
//#define PIN_VBAT_READ 5
21-
//#define ADC_MULTIPLIER (3 * 1.73 * 1000)
19+
#define PIN_VBAT_READ BATTERY_PIN
20+
#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
21+
2222

2323
class MinewsemiME25LS01Board : public mesh::MainBoard {
2424
protected:
@@ -28,43 +28,23 @@ class MinewsemiME25LS01Board : public mesh::MainBoard {
2828
public:
2929
void begin();
3030

31+
#define BATTERY_SAMPLES 8
32+
3133
uint16_t getBattMilliVolts() override {
32-
#ifdef BATTERY_PIN
33-
#ifdef PIN_3V3_EN
34-
digitalWrite(PIN_3V3_EN, HIGH);
35-
#endif
36-
analogReference(AR_INTERNAL_3_0);
3734
analogReadResolution(12);
38-
delay(10);
39-
float volts = (analogRead(BATTERY_PIN) * ADC_MULTIPLIER * AREF_VOLTAGE) / 4096;
40-
#ifdef PIN_3V3_EN
41-
digitalWrite(PIN_3V3_EN, LOW);
42-
#endif
43-
44-
analogReference(AR_DEFAULT); // put back to default
45-
analogReadResolution(10);
46-
47-
return volts * 1000;
48-
#else
49-
return 0;
50-
#endif
35+
36+
uint32_t raw = 0;
37+
for (int i = 0; i < BATTERY_SAMPLES; i++) {
38+
raw += analogRead(PIN_VBAT_READ);
39+
}
40+
raw = raw / BATTERY_SAMPLES;
41+
return (ADC_MULTIPLIER * raw);
5142
}
5243

5344
uint8_t getStartupReason() const override { return startup_reason; }
5445

5546
const char* getManufacturerName() const override {
56-
return "m25ls01";
57-
}
58-
59-
int buttonStateChanged() {
60-
#ifdef BUTTON_PIN
61-
uint8_t v = digitalRead(BUTTON_PIN);
62-
if (v != btn_prev_state) {
63-
btn_prev_state = v;
64-
return (v == LOW) ? 1 : -1;
65-
}
66-
#endif
67-
return 0;
47+
return "Minewsemi";
6848
}
6949

7050
void powerOff() override {
@@ -81,10 +61,6 @@ class MinewsemiME25LS01Board : public mesh::MainBoard {
8161
digitalWrite(BUZZER_EN, LOW);
8262
#endif
8363

84-
#ifdef PIN_3V3_EN
85-
digitalWrite(PIN_3V3_EN, LOW);
86-
#endif
87-
8864
#ifdef LED_PIN
8965
digitalWrite(LED_PIN, LOW);
9066
#endif
@@ -108,5 +84,5 @@ class MinewsemiME25LS01Board : public mesh::MainBoard {
10884
NVIC_SystemReset();
10985
}
11086

111-
// bool startOTAUpdate(const char* id, char reply[]) override;
87+
bool startOTAUpdate(const char* id, char reply[]) override;
11288
};

variants/minewsemi_me25ls01/platformio.ini

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ build_flags = ${nrf52_base.build_flags}
88
-I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52
99
lib_ignore =
1010
BluetoothOTA
11-
lvgl
1211
lib5b4
1312
lib_deps =
1413
${nrf52_base.lib_deps}
@@ -67,7 +66,6 @@ build_flags = ${me25ls01.build_flags}
6766
;-D PIN_BUZZER_EN=37
6867
build_src_filter = ${me25ls01.build_src_filter}
6968
+<helpers/nrf52/SerialBLEInterface.cpp>
70-
;+<helpers/ui/buzzer.cpp>
7169
+<../examples/companion_radio/*.cpp>
7270
lib_deps = ${me25ls01.lib_deps}
7371
adafruit/RTClib @ ^2.1.3
@@ -92,9 +90,6 @@ build_flags = ${me25ls01.build_flags}
9290
-D MAX_NEIGHBOURS=8
9391
-D DISPLAY_CLASS=NullDisplayDriver
9492
build_src_filter = ${me25ls01.build_src_filter}
95-
;+<helpers/nrf52/SerialBLEInterface.cpp>
96-
;+<helpers/ui/buzzer.cpp>
97-
;+<../examples/companion_radio/*.cpp>
9893
+<../examples/simple_repeater>
9994
lib_deps = ${me25ls01.lib_deps}
10095
adafruit/RTClib @ ^2.1.3
@@ -121,10 +116,6 @@ build_flags = ${me25ls01.build_flags}
121116
-D MAX_NEIGHBOURS=8
122117
-D DISPLAY_CLASS=NullDisplayDriver
123118
build_src_filter = ${me25ls01.build_src_filter}
124-
;+<helpers/nrf52/SerialBLEInterface.cpp>
125-
;+<helpers/ui/buzzer.cpp>
126-
;+<../examples/companion_radio/*.cpp>
127-
;+<../examples/simple_repeater>
128119
+<../examples/simple_room_server>
129120
lib_deps = ${me25ls01.lib_deps}
130121
adafruit/RTClib @ ^2.1.3
@@ -149,11 +140,6 @@ build_flags = ${me25ls01.build_flags}
149140
-D MAX_NEIGHBOURS=8
150141
-D DISPLAY_CLASS=NullDisplayDriver
151142
build_src_filter = ${me25ls01.build_src_filter}
152-
;+<helpers/nrf52/SerialBLEInterface.cpp>
153-
;+<helpers/ui/buzzer.cpp>
154-
;+<../examples/companion_radio/*.cpp>
155-
;+<../examples/simple_repeater>
156-
;+<../examples/simple_room_server>
157143
+<../examples/simple_secure_chat/main.cpp>
158144
lib_deps = ${me25ls01.lib_deps}
159145
adafruit/RTClib @ ^2.1.3
@@ -173,11 +159,6 @@ build_flags = ${me25ls01.build_flags}
173159
-D DISPLAY_CLASS=NullDisplayDriver
174160
build_src_filter = ${me25ls01.build_src_filter}
175161
+<helpers/nrf52/*.cpp>
176-
;+<helpers/nrf52/SerialBLEInterface.cpp>
177-
;+<helpers/ui/buzzer.cpp>
178-
;+<../examples/companion_radio/*.cpp>
179-
;+<../examples/simple_repeater>
180-
;+<../examples/simple_room_server>
181162
+<../examples/companion_radio>
182163
lib_deps = ${me25ls01.lib_deps}
183164
adafruit/RTClib @ ^2.1.3

variants/minewsemi_me25ls01/variant.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const uint32_t g_ADigitalPinMap[PINS_COUNT + 1] =
3535
28, // P0.28
3636
29, // P0.29,
3737
30, // P0.30
38-
31, // P0.31,
38+
31, // P0.31, BATTERY_PIN
3939
32, // P1.00
4040
33, // P1.01, LORA_DIO_1
4141
34, // P1.02
@@ -60,8 +60,8 @@ void initVariant()
6060
pinMode(BATTERY_PIN, INPUT);
6161
pinMode(PIN_BUTTON1, INPUT);
6262

63-
pinMode(PIN_3V3_EN, OUTPUT);
64-
pinMode(PIN_3V3_ACC_EN, OUTPUT);
63+
// pinMode(PIN_3V3_EN, OUTPUT);
64+
// pinMode(PIN_3V3_ACC_EN, OUTPUT);
6565
pinMode(LED_PIN, OUTPUT);
6666
pinMode(P_LORA_TX_LED, OUTPUT);
6767

variants/minewsemi_me25ls01/variant.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,19 @@
22

33
#include "WVariant.h"
44

5-
////////////////////////////////////////////////////////////////////////////////
65
// Low frequency clock source
7-
86
#define USE_LFXO // 32.768 kHz crystal oscillator
97
#define VARIANT_MCK (64000000ul)
108
// #define USE_LFRC // 32.768 kHz RC oscillator
119

1210
// Power
13-
#define PIN_3V3_EN (32 + 5) // P1.6 Power to Sensors
14-
#define PIN_3V3_ACC_EN -1
15-
16-
#define BATTERY_PIN (-1) // P0.2/AIN0
11+
#define BATTERY_PIN (31)
1712
#define BATTERY_IMMUTABLE
1813
#define ADC_MULTIPLIER (2.0F)
1914

2015
#define ADC_RESOLUTION (14)
2116
#define BATTERY_SENSE_RES (12)
2217

23-
#define AREF_VOLTAGE (3.0)
24-
2518
// Number of pins
2619
#define PINS_COUNT (48)
2720
#define NUM_DIGITAL_PINS (48)

0 commit comments

Comments
 (0)