Skip to content

Commit 93802fe

Browse files
committed
Add VL53L0X time-of-flight distance sensor to Heltec V3 Sensor
1 parent 9f2a77c commit 93802fe

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ static Adafruit_INA219 INA219(TELEM_INA219_ADDRESS);
5959
static Adafruit_MLX90614 MLX90614;
6060
#endif
6161

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+
6268
#if ENV_INCLUDE_GPS && RAK_BOARD
6369
static uint32_t gpsResetPin = 0;
6470
static bool i2cGPSFlag = false;
@@ -169,6 +175,16 @@ bool EnvironmentSensorManager::begin() {
169175
}
170176
#endif
171177

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+
172188
return true;
173189
}
174190

@@ -256,6 +272,18 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
256272
}
257273
#endif
258274

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+
259287
}
260288

261289
return true;

src/helpers/sensors/EnvironmentSensorManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class EnvironmentSensorManager : public SensorManager {
1616
bool SHTC3_initialized = false;
1717
bool LPS22HB_initialized = false;
1818
bool MLX90614_initialized = false;
19+
bool VL53L0X_initialized = false;
1920

2021
bool gps_detected = false;
2122
bool gps_active = false;

variants/heltec_v3/platformio.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ build_flags =
158158
-D ENV_PIN_SDA=33
159159
-D ENV_PIN_SCL=34
160160
-D ENV_INCLUDE_MLX90614=1
161+
-D ENV_INCLUDE_VL53L0X=1
161162
-D DISPLAY_CLASS=SSD1306Display
162163
; -D MESH_PACKET_LOGGING=1
163164
; -D MESH_DEBUG=1
@@ -168,6 +169,7 @@ lib_deps =
168169
${Heltec_lora32_v3.lib_deps}
169170
${esp32_ota.lib_deps}
170171
adafruit/Adafruit MLX90614 Library @ ^2.1.5
172+
adafruit/Adafruit_VL53L0X @ ^1.2.4
171173

172174
[env:Heltec_WSL3_repeater]
173175
extends = Heltec_lora32_v3

0 commit comments

Comments
 (0)