Skip to content

Commit a2e3e66

Browse files
authored
Merge pull request #534 from mikenz/heltec-v3-sensor
Allow the SDA and SCL pins for Environment sensors to be configured independently of the OLED I2C
2 parents 64cc4cf + 93802fe commit a2e3e66

File tree

3 files changed

+94
-7
lines changed

3 files changed

+94
-7
lines changed

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#include "EnvironmentSensorManager.h"
22

3+
#if ENV_PIN_SDA && ENV_PIN_SCL
4+
#define TELEM_WIRE &Wire1 // Use Wire1 as the I2C bus for Environment Sensors
5+
#else
6+
#define TELEM_WIRE &Wire // Use default I2C bus for Environment Sensors
7+
#endif
8+
39
#if ENV_INCLUDE_AHTX0
410
#define TELEM_AHTX_ADDRESS 0x38 // AHT10, AHT20 temperature and humidity sensor I2C address
511
#include <Adafruit_AHTX0.h>
@@ -47,6 +53,18 @@ static Adafruit_INA3221 INA3221;
4753
static Adafruit_INA219 INA219(TELEM_INA219_ADDRESS);
4854
#endif
4955

56+
#if ENV_INCLUDE_MLX90614
57+
#define TELEM_MLX90614_ADDRESS 0x5A // MLX90614 IR temperature sensor I2C address
58+
#include <Adafruit_MLX90614.h>
59+
static Adafruit_MLX90614 MLX90614;
60+
#endif
61+
62+
#if ENV_INCLUDE_VL53L0X
63+
#define TELEM_VL53L0X_ADDRESS 0x29 // VL53L0X time-of-flight distance sensor I2C address
64+
#include <Adafruit_VL53L0X.h>
65+
static Adafruit_VL53L0X VL53L0X;
66+
#endif
67+
5068
#if ENV_INCLUDE_GPS && RAK_BOARD
5169
static uint32_t gpsResetPin = 0;
5270
static bool i2cGPSFlag = false;
@@ -65,8 +83,13 @@ bool EnvironmentSensorManager::begin() {
6583
#endif
6684
#endif
6785

86+
#if ENV_PIN_SDA && ENV_PIN_SCL
87+
Wire1.begin(ENV_PIN_SDA, ENV_PIN_SCL, 100000);
88+
MESH_DEBUG_PRINTLN("Second I2C initialized on pins SDA: %d SCL: %d", ENV_PIN_SDA, ENV_PIN_SCL);
89+
#endif
90+
6891
#if ENV_INCLUDE_AHTX0
69-
if (AHTX0.begin(&Wire, 0, TELEM_AHTX_ADDRESS)) {
92+
if (AHTX0.begin(TELEM_WIRE, 0, TELEM_AHTX_ADDRESS)) {
7093
MESH_DEBUG_PRINTLN("Found AHT10/AHT20 at address: %02X", TELEM_AHTX_ADDRESS);
7194
AHTX0_initialized = true;
7295
} else {
@@ -76,7 +99,7 @@ bool EnvironmentSensorManager::begin() {
7699
#endif
77100

78101
#if ENV_INCLUDE_BME280
79-
if (BME280.begin(TELEM_BME280_ADDRESS, &Wire)) {
102+
if (BME280.begin(TELEM_BME280_ADDRESS, TELEM_WIRE)) {
80103
MESH_DEBUG_PRINTLN("Found BME280 at address: %02X", TELEM_BME280_ADDRESS);
81104
MESH_DEBUG_PRINTLN("BME sensor ID: %02X", BME280.sensorID());
82105
BME280_initialized = true;
@@ -118,7 +141,7 @@ bool EnvironmentSensorManager::begin() {
118141
#endif
119142

120143
#if ENV_INCLUDE_INA3221
121-
if (INA3221.begin(TELEM_INA3221_ADDRESS, &Wire)) {
144+
if (INA3221.begin(TELEM_INA3221_ADDRESS, TELEM_WIRE)) {
122145
MESH_DEBUG_PRINTLN("Found INA3221 at address: %02X", TELEM_INA3221_ADDRESS);
123146
MESH_DEBUG_PRINTLN("%04X %04X", INA3221.getDieID(), INA3221.getManufacturerID());
124147

@@ -133,7 +156,7 @@ bool EnvironmentSensorManager::begin() {
133156
#endif
134157

135158
#if ENV_INCLUDE_INA219
136-
if (INA219.begin(&Wire)) {
159+
if (INA219.begin(TELEM_WIRE)) {
137160
MESH_DEBUG_PRINTLN("Found INA219 at address: %02X", TELEM_INA219_ADDRESS);
138161
INA219_initialized = true;
139162
} else {
@@ -142,6 +165,26 @@ bool EnvironmentSensorManager::begin() {
142165
}
143166
#endif
144167

168+
#if ENV_INCLUDE_MLX90614
169+
if (MLX90614.begin(TELEM_MLX90614_ADDRESS, TELEM_WIRE)) {
170+
MESH_DEBUG_PRINTLN("Found MLX90614 at address: %02X", TELEM_MLX90614_ADDRESS);
171+
MLX90614_initialized = true;
172+
} else {
173+
MLX90614_initialized = false;
174+
MESH_DEBUG_PRINTLN("MLX90614 was not found at I2C address %02X", TELEM_MLX90614_ADDRESS);
175+
}
176+
#endif
177+
178+
#if ENV_INCLUDE_VL53L0X
179+
if (VL53L0X.begin(TELEM_VL53L0X_ADDRESS, false, TELEM_WIRE)) {
180+
MESH_DEBUG_PRINTLN("Found VL53L0X at address: %02X", TELEM_VL53L0X_ADDRESS);
181+
VL53L0X_initialized = true;
182+
} else {
183+
VL53L0X_initialized = false;
184+
MESH_DEBUG_PRINTLN("VL53L0X was not found at I2C address %02X", TELEM_VL53L0X_ADDRESS);
185+
}
186+
#endif
187+
145188
return true;
146189
}
147190

@@ -222,6 +265,25 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
222265
}
223266
#endif
224267

268+
#if ENV_INCLUDE_MLX90614
269+
if (MLX90614_initialized) {
270+
telemetry.addTemperature(TELEM_CHANNEL_SELF, MLX90614.readObjectTempC());
271+
telemetry.addTemperature(TELEM_CHANNEL_SELF + 1, MLX90614.readAmbientTempC());
272+
}
273+
#endif
274+
275+
#if ENV_INCLUDE_VL53L0X
276+
if (VL53L0X_initialized) {
277+
VL53L0X_RangingMeasurementData_t measure;
278+
VL53L0X.rangingTest(&measure, false); // pass in 'true' to get debug data
279+
if (measure.RangeStatus != 4) { // phase failures
280+
telemetry.addDistance(TELEM_CHANNEL_SELF, measure.RangeMilliMeter / 1000.0f); // convert mm to m
281+
} else {
282+
telemetry.addDistance(TELEM_CHANNEL_SELF, 0.0f); // no valid measurement
283+
}
284+
}
285+
#endif
286+
225287
}
226288

227289
return true;
@@ -327,14 +389,14 @@ void EnvironmentSensorManager::rakGPSInit(){
327389
}
328390
else if(gpsIsAwake(WB_IO4)){
329391
// MESH_DEBUG_PRINTLN("RAK base board is RAK19003/9");
330-
// MESH_DEBUG_PRINTLN("GPS is installed on Socket C");
392+
// MESH_DEBUG_PRINTLN("GPS is installed on Socket C");
331393
}
332394
else if(gpsIsAwake(WB_IO5)){
333395
// MESH_DEBUG_PRINTLN("RAK base board is RAK19001/11");
334396
// MESH_DEBUG_PRINTLN("GPS is installed on Socket F");
335397
}
336398
else{
337-
MESH_DEBUG_PRINTLN("No GPS found");
399+
MESH_DEBUG_PRINTLN("No GPS found");
338400
gps_active = false;
339401
gps_detected = false;
340402
return;

src/helpers/sensors/EnvironmentSensorManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class EnvironmentSensorManager : public SensorManager {
1515
bool INA219_initialized = false;
1616
bool SHTC3_initialized = false;
1717
bool LPS22HB_initialized = false;
18+
bool MLX90614_initialized = false;
19+
bool VL53L0X_initialized = false;
1820

1921
bool gps_detected = false;
2022
bool gps_active = false;

variants/heltec_v3/platformio.ini

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,30 @@ lib_deps =
147147
${Heltec_lora32_v3.lib_deps}
148148
densaugeo/base64 @ ~1.4.0
149149

150+
[env:Heltec_v3_sensor]
151+
extends = Heltec_lora32_v3
152+
build_flags =
153+
${Heltec_lora32_v3.build_flags}
154+
-D ADVERT_NAME='"Heltec v3 Sensor"'
155+
-D ADVERT_LAT=0.0
156+
-D ADVERT_LON=0.0
157+
-D ADMIN_PASSWORD='"password"'
158+
-D ENV_PIN_SDA=33
159+
-D ENV_PIN_SCL=34
160+
-D ENV_INCLUDE_MLX90614=1
161+
-D ENV_INCLUDE_VL53L0X=1
162+
-D DISPLAY_CLASS=SSD1306Display
163+
; -D MESH_PACKET_LOGGING=1
164+
; -D MESH_DEBUG=1
165+
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
166+
+<helpers/ui/SSD1306Display.cpp>
167+
+<../examples/simple_sensor>
168+
lib_deps =
169+
${Heltec_lora32_v3.lib_deps}
170+
${esp32_ota.lib_deps}
171+
adafruit/Adafruit MLX90614 Library @ ^2.1.5
172+
adafruit/Adafruit_VL53L0X @ ^1.2.4
173+
150174
[env:Heltec_WSL3_repeater]
151175
extends = Heltec_lora32_v3
152176
build_flags =
@@ -214,4 +238,3 @@ build_src_filter = ${Heltec_lora32_v3.build_src_filter}
214238
lib_deps =
215239
${Heltec_lora32_v3.lib_deps}
216240
${esp32_ota.lib_deps}
217-

0 commit comments

Comments
 (0)