Skip to content

Commit 6dc9920

Browse files
authored
Merge pull request #287 from ngavars/dev
Promicro: add INA219 current sensor support
2 parents f38532b + 1de46ea commit 6dc9920

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

variants/promicro/platformio.ini

Lines changed: 20 additions & 1 deletion
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,6 +54,8 @@ build_flags = ${Faketec.build_flags}
5354
; -D MESH_DEBUG=1
5455
lib_deps = ${Faketec.lib_deps}
5556
adafruit/RTClib @ ^2.1.3
57+
robtillaart/INA3221 @ ^0.4.1
58+
robtillaart/INA219 @ ^0.4.1
5659

5760
[env:Faketec_terminal_chat]
5861
extends = Faketec
@@ -66,6 +69,8 @@ build_src_filter = ${Faketec.build_src_filter}
6669
lib_deps = ${Faketec.lib_deps}
6770
densaugeo/base64 @ ~1.4.0
6871
adafruit/RTClib @ ^2.1.3
72+
robtillaart/INA3221 @ ^0.4.1
73+
robtillaart/INA219 @ ^0.4.1
6974

7075
[env:Faketec_companion_radio_usb]
7176
extends = Faketec
@@ -80,6 +85,8 @@ build_src_filter = ${Faketec.build_src_filter}
8085
lib_deps = ${Faketec.lib_deps}
8186
adafruit/RTClib @ ^2.1.3
8287
densaugeo/base64 @ ~1.4.0
88+
robtillaart/INA3221 @ ^0.4.1
89+
robtillaart/INA219 @ ^0.4.1
8390

8491
[env:Faketec_companion_radio_ble]
8592
extends = Faketec
@@ -100,6 +107,8 @@ build_src_filter = ${Faketec.build_src_filter}
100107
lib_deps = ${Faketec.lib_deps}
101108
adafruit/RTClib @ ^2.1.3
102109
densaugeo/base64 @ ~1.4.0
110+
robtillaart/INA3221 @ ^0.4.1
111+
robtillaart/INA219 @ ^0.4.1
103112

104113
[ProMicroLLCC68]
105114
extends = nrf52840_base
@@ -129,6 +138,8 @@ build_flags = ${ProMicroLLCC68.build_flags}
129138
; -D MESH_DEBUG=1
130139
lib_deps = ${ProMicroLLCC68.lib_deps}
131140
adafruit/RTClib @ ^2.1.3
141+
robtillaart/INA3221 @ ^0.4.1
142+
robtillaart/INA219 @ ^0.4.1
132143

133144
[env:ProMicroLLCC68_room_server]
134145
extends = ProMicroLLCC68
@@ -142,6 +153,8 @@ build_flags = ${ProMicroLLCC68.build_flags}
142153
; -D MESH_DEBUG=1
143154
lib_deps = ${ProMicroLLCC68.lib_deps}
144155
adafruit/RTClib @ ^2.1.3
156+
robtillaart/INA3221 @ ^0.4.1
157+
robtillaart/INA219 @ ^0.4.1
145158

146159
[env:ProMicroLLCC68_terminal_chat]
147160
extends = ProMicroLLCC68
@@ -155,6 +168,8 @@ build_src_filter = ${ProMicroLLCC68.build_src_filter}
155168
lib_deps = ${ProMicroLLCC68.lib_deps}
156169
densaugeo/base64 @ ~1.4.0
157170
adafruit/RTClib @ ^2.1.3
171+
robtillaart/INA3221 @ ^0.4.1
172+
robtillaart/INA219 @ ^0.4.1
158173

159174
[env:ProMicroLLCC68_companion_radio_usb]
160175
extends = ProMicroLLCC68
@@ -168,6 +183,8 @@ build_src_filter = ${ProMicroLLCC68.build_src_filter}
168183
lib_deps = ${ProMicroLLCC68.lib_deps}
169184
adafruit/RTClib @ ^2.1.3
170185
densaugeo/base64 @ ~1.4.0
186+
robtillaart/INA3221 @ ^0.4.1
187+
robtillaart/INA219 @ ^0.4.1
171188

172189
[env:ProMicroLLCC68_companion_radio_ble]
173190
extends = ProMicroLLCC68
@@ -187,3 +204,5 @@ build_src_filter = ${ProMicroLLCC68.build_src_filter}
187204
lib_deps = ${ProMicroLLCC68.lib_deps}
188205
adafruit/RTClib @ ^2.1.3
189206
densaugeo/base64 @ ~1.4.0
207+
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)