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;
4753static 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
5169static uint32_t gpsResetPin = 0 ;
5270static 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 ;
0 commit comments