Skip to content

Commit 1de46ea

Browse files
author
Normunds Gavars
committed
Promicro: add support for INA219 current sensor
1 parent 9f5d7a2 commit 1de46ea

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

variants/promicro/platformio.ini

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ build_flags =
3737
lib_deps = ${Faketec.lib_deps}
3838
adafruit/RTClib @ ^2.1.3
3939
robtillaart/INA3221 @ ^0.4.1
40-
40+
robtillaart/INA219 @ ^0.4.1
41+
4142
[env:Faketec_room_server]
4243
extends = Faketec
4344
build_src_filter = ${Faketec.build_src_filter}
@@ -53,7 +54,8 @@ build_flags = ${Faketec.build_flags}
5354
; -D MESH_DEBUG=1
5455
lib_deps = ${Faketec.lib_deps}
5556
adafruit/RTClib @ ^2.1.3
56-
robtillaart/INA3221 @ ^0.4.1
57+
robtillaart/INA3221 @ ^0.4.1
58+
robtillaart/INA219 @ ^0.4.1
5759

5860
[env:Faketec_terminal_chat]
5961
extends = Faketec
@@ -68,6 +70,7 @@ lib_deps = ${Faketec.lib_deps}
6870
densaugeo/base64 @ ~1.4.0
6971
adafruit/RTClib @ ^2.1.3
7072
robtillaart/INA3221 @ ^0.4.1
73+
robtillaart/INA219 @ ^0.4.1
7174

7275
[env:Faketec_companion_radio_usb]
7376
extends = Faketec
@@ -82,7 +85,8 @@ build_src_filter = ${Faketec.build_src_filter}
8285
lib_deps = ${Faketec.lib_deps}
8386
adafruit/RTClib @ ^2.1.3
8487
densaugeo/base64 @ ~1.4.0
85-
robtillaart/INA3221 @ ^0.4.1
88+
robtillaart/INA3221 @ ^0.4.1
89+
robtillaart/INA219 @ ^0.4.1
8690

8791
[env:Faketec_companion_radio_ble]
8892
extends = Faketec
@@ -104,6 +108,7 @@ lib_deps = ${Faketec.lib_deps}
104108
adafruit/RTClib @ ^2.1.3
105109
densaugeo/base64 @ ~1.4.0
106110
robtillaart/INA3221 @ ^0.4.1
111+
robtillaart/INA219 @ ^0.4.1
107112

108113
[ProMicroLLCC68]
109114
extends = nrf52840_base
@@ -134,6 +139,7 @@ build_flags = ${ProMicroLLCC68.build_flags}
134139
lib_deps = ${ProMicroLLCC68.lib_deps}
135140
adafruit/RTClib @ ^2.1.3
136141
robtillaart/INA3221 @ ^0.4.1
142+
robtillaart/INA219 @ ^0.4.1
137143

138144
[env:ProMicroLLCC68_room_server]
139145
extends = ProMicroLLCC68
@@ -148,6 +154,7 @@ build_flags = ${ProMicroLLCC68.build_flags}
148154
lib_deps = ${ProMicroLLCC68.lib_deps}
149155
adafruit/RTClib @ ^2.1.3
150156
robtillaart/INA3221 @ ^0.4.1
157+
robtillaart/INA219 @ ^0.4.1
151158

152159
[env:ProMicroLLCC68_terminal_chat]
153160
extends = ProMicroLLCC68
@@ -162,6 +169,7 @@ lib_deps = ${ProMicroLLCC68.lib_deps}
162169
densaugeo/base64 @ ~1.4.0
163170
adafruit/RTClib @ ^2.1.3
164171
robtillaart/INA3221 @ ^0.4.1
172+
robtillaart/INA219 @ ^0.4.1
165173

166174
[env:ProMicroLLCC68_companion_radio_usb]
167175
extends = ProMicroLLCC68
@@ -176,6 +184,7 @@ lib_deps = ${ProMicroLLCC68.lib_deps}
176184
adafruit/RTClib @ ^2.1.3
177185
densaugeo/base64 @ ~1.4.0
178186
robtillaart/INA3221 @ ^0.4.1
187+
robtillaart/INA219 @ ^0.4.1
179188

180189
[env:ProMicroLLCC68_companion_radio_ble]
181190
extends = ProMicroLLCC68
@@ -196,3 +205,4 @@ lib_deps = ${ProMicroLLCC68.lib_deps}
196205
adafruit/RTClib @ ^2.1.3
197206
densaugeo/base64 @ ~1.4.0
198207
robtillaart/INA3221 @ ^0.4.1
208+
robtillaart/INA219 @ ^0.4.1

variants/promicro/target.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ mesh::LocalIdentity radio_new_identity() {
7676
}
7777

7878
static INA3221 INA_3221(TELEM_INA3221_ADDRESS, &Wire);
79+
static INA219 INA_219(TELEM_INA219_ADDRESS, &Wire);
7980

8081
bool PromicroSensorManager::begin() {
81-
if (INA_3221.begin() ) {
82+
if (INA_3221.begin()) {
8283
MESH_DEBUG_PRINTLN("Found INA3221 at address: %02X", INA_3221.getAddress());
8384
MESH_DEBUG_PRINTLN("%04X %04X %04X", INA_3221.getDieID(), INA_3221.getManufacturerID(), INA_3221.getConfiguration());
8485

@@ -90,6 +91,15 @@ bool PromicroSensorManager::begin() {
9091
INA3221initialized = false;
9192
MESH_DEBUG_PRINTLN("INA3221 was not found at I2C address %02X", TELEM_INA3221_ADDRESS);
9293
}
94+
if (INA_219.begin()) {
95+
MESH_DEBUG_PRINTLN("Found INA219 at address: %02X", INA_219.getAddress());
96+
INA219_CHANNEL = INA3221initialized ? TELEM_CHANNEL_SELF + 4 : TELEM_CHANNEL_SELF + 1;
97+
INA_219.setMaxCurrentShunt(TELEM_INA219_MAX_CURRENT, TELEM_INA219_SHUNT_VALUE);
98+
INA219initialized = true;
99+
} else {
100+
INA219initialized = false;
101+
MESH_DEBUG_PRINTLN("INA219 was not found at I2C address %02X", TELEM_INA219_ADDRESS);
102+
}
93103
return true;
94104
}
95105

@@ -105,6 +115,11 @@ bool PromicroSensorManager::querySensors(uint8_t requester_permissions, CayenneL
105115
}
106116
}
107117
}
118+
if(INA219initialized) {
119+
telemetry.addVoltage(INA219_CHANNEL, INA_219.getBusVoltage());
120+
telemetry.addCurrent(INA219_CHANNEL, INA_219.getCurrent());
121+
telemetry.addPower(INA219_CHANNEL, INA_219.getPower());
122+
}
108123
}
109124

110125
return true;

variants/promicro/target.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <helpers/AutoDiscoverRTCClock.h>
1010
#include <helpers/SensorManager.h>
1111
#include <INA3221.h>
12+
#include <INA219.h>
1213

1314
#define NUM_SENSOR_SETTINGS 3
1415

@@ -23,20 +24,27 @@ void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
2324
void radio_set_tx_power(uint8_t dbm);
2425
mesh::LocalIdentity radio_new_identity();
2526

26-
#define TELEM_INA3221_ADDRESS 0x42 // INA3221 3 channel current, voltage, power sensor I2C address
27+
#define TELEM_INA3221_ADDRESS 0x42 // INA3221 3 channel current sensor I2C address
28+
#define TELEM_INA219_ADDRESS 0x40 // INA219 single channel current sensor I2C address
29+
2730
#define TELEM_INA3221_SHUNT_VALUE 0.100 // most variants will have a 0.1 ohm shunts
2831
#define TELEM_INA3221_SETTING_CH1 "INA3221-1"
2932
#define TELEM_INA3221_SETTING_CH2 "INA3221-2"
3033
#define TELEM_INA3221_SETTING_CH3 "INA3221-3"
3134

35+
#define TELEM_INA219_SHUNT_VALUE 0.100 // shunt value in ohms (may differ between manufacturers)
36+
#define TELEM_INA219_MAX_CURRENT 5
37+
3238
class PromicroSensorManager: public SensorManager {
3339
bool INA3221initialized = false;
40+
bool INA219initialized = false;
3441

3542
// INA3221 channels in telemetry
3643
int INA3221_CHANNELS[NUM_SENSOR_SETTINGS] = {TELEM_CHANNEL_SELF + 1, TELEM_CHANNEL_SELF + 2, TELEM_CHANNEL_SELF+ 3};
3744
const char * INA3221_CHANNEL_NAMES[NUM_SENSOR_SETTINGS] = { TELEM_INA3221_SETTING_CH1, TELEM_INA3221_SETTING_CH2, TELEM_INA3221_SETTING_CH3};
3845
bool INA3221_CHANNEL_ENABLED[NUM_SENSOR_SETTINGS] = {true, true, true};
3946

47+
int INA219_CHANNEL;
4048
public:
4149
PromicroSensorManager(){};
4250
bool begin() override;

0 commit comments

Comments
 (0)