implement vl53l1x tof sensor
This commit is contained in:
parent
5d47246bda
commit
c588c99cd7
|
@ -214,7 +214,8 @@ platform = espressif8266 @ 2.5.0
|
|||
board = d1_mini
|
||||
framework = arduino
|
||||
|
||||
monitor_port = /dev/ttyUSB0
|
||||
#monitor_port = /dev/ttyUSB0
|
||||
monitor_port = COM3
|
||||
monitor_speed = 115200
|
||||
|
||||
build_flags =
|
||||
|
@ -238,8 +239,9 @@ build_flags =
|
|||
-D dataBH1750_senddelaymax=1000*60*2
|
||||
|
||||
-D SENSOR_VL53L1X
|
||||
-D dataBH1750_minchange=10.0
|
||||
-D dataBH1750_senddelaymax=1000*60*2
|
||||
-D dataVL53L1X_minchange=100
|
||||
-D dataVL53L1X_senddelaymax=1000*30
|
||||
-D dataVL53L1X_readdelay=1000
|
||||
|
||||
|
||||
|
||||
|
|
48
src/main.cpp
48
src/main.cpp
|
@ -236,12 +236,12 @@ struct sensordata
|
|||
#include <VL53L1X.h>
|
||||
VL53L1X vl53l1x;
|
||||
bool vl53l1xinit_ok=false;
|
||||
struct sensordata dataVL53L1X_range;
|
||||
struct sensordata dataVL53L1X_peak_signal_count_rate;
|
||||
struct sensordata dataVL53L1X_ambient_count_rate;
|
||||
struct sensordata dataVL53L1X;
|
||||
|
||||
uint16_t value_vl53l1x_range;
|
||||
|
||||
unsigned long lastread_vl53l1x=0;
|
||||
VL53L1X::RangeStatus lastsentvalue_vl53l1x_status;
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_ANEMOMETER
|
||||
|
@ -487,10 +487,16 @@ void setup() {
|
|||
vl53l1xinit_ok=true;
|
||||
vl53l1x.setDistanceMode(VL53L1X::Long);
|
||||
vl53l1x.setMeasurementTimingBudget(50000);
|
||||
vl53l1x.startContinuous(50); //This period should be at least as long as the timing budget.
|
||||
vl53l1x.startContinuous(1000); //This period should be at least as long as the timing budget.
|
||||
}
|
||||
#ifdef dataVL53L1X_range_minchange
|
||||
dataVL53L1X_range.minchange=dataVL53L1X_range_minchange;
|
||||
#ifdef dataVL53L1X_minchange
|
||||
dataVL53L1X.minchange=dataVL53L1X_minchange;
|
||||
#endif
|
||||
#ifdef dataVL53L1X_senddelaymax
|
||||
dataVL53L1X.senddelaymax=dataVL53L1X_senddelaymax;
|
||||
#endif
|
||||
#ifdef dataVL53L1X_readdelay
|
||||
dataVL53L1X.readdelay=dataVL53L1X_readdelay;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -608,7 +614,10 @@ void setup() {
|
|||
#endif
|
||||
|
||||
#ifdef SENSOR_VL53L1X
|
||||
sensorNode.advertise("range");
|
||||
sensorNode.advertise("tofstatus");
|
||||
sensorNode.advertise("tofrange");
|
||||
sensorNode.advertise("tofpeaksignal");
|
||||
sensorNode.advertise("tofambient");
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_ANEMOMETER
|
||||
|
@ -1200,9 +1209,9 @@ void loop_TCS34725_colortemp()
|
|||
|
||||
|
||||
#ifdef SENSOR_VL53L1X
|
||||
void loop_VL53L1X_range()
|
||||
void loop_VL53L1X()
|
||||
{
|
||||
sensordata &d=dataVL53L1X_range;
|
||||
sensordata &d=dataVL53L1X;
|
||||
|
||||
bool _changed=false;
|
||||
if (millis() >= (d.lastreadtime+d.readdelay)) {
|
||||
|
@ -1213,18 +1222,27 @@ void loop_VL53L1X_range()
|
|||
}
|
||||
|
||||
value_vl53l1x_range=vl53l1x.ranging_data.range_mm;
|
||||
|
||||
/* for debugging
|
||||
Serial.print("range: ");
|
||||
Serial.print(vl53l1x.ranging_data.range_mm);
|
||||
Serial.print("\tstatus: ");
|
||||
Serial.print(VL53L1X::rangeStatusToString(vl53l1x.ranging_data.range_status));
|
||||
Serial.print("\tstatus=");
|
||||
Serial.print(vl53l1x.ranging_data.range_status);
|
||||
Serial.print("\tpeak signal: ");
|
||||
Serial.print(vl53l1x.ranging_data.peak_signal_count_rate_MCPS);
|
||||
Serial.print("\tambient: ");
|
||||
Serial.print(vl53l1x.ranging_data.ambient_count_rate_MCPS);
|
||||
Serial.println();
|
||||
*/
|
||||
|
||||
if (abs((int)d.lastsentvalue-value_vl53l1x_range)>=d.minchange){ //int abs
|
||||
_changed=true;
|
||||
}
|
||||
if (lastsentvalue_vl53l1x_status!=vl53l1x.ranging_data.range_status) { //sensor status changed
|
||||
_changed=true;
|
||||
}
|
||||
d.lastreadtime=millis();
|
||||
}
|
||||
|
||||
|
@ -1235,10 +1253,14 @@ void loop_VL53L1X_range()
|
|||
|
||||
Homie.getLogger() << "range vl53l1x " << ": " << value_vl53l1x_range << endl;
|
||||
|
||||
sensorNode.setProperty("range").send(String(value_vl53l1x_range));
|
||||
|
||||
sensorNode.setProperty("tofstatus").send(VL53L1X::rangeStatusToString(vl53l1x.ranging_data.range_status));
|
||||
sensorNode.setProperty("tofrange").send(String(value_vl53l1x_range));
|
||||
sensorNode.setProperty("tofpeaksignal").send(String(vl53l1x.ranging_data.peak_signal_count_rate_MCPS));
|
||||
sensorNode.setProperty("tofambient").send(String(vl53l1x.ranging_data.ambient_count_rate_MCPS));
|
||||
|
||||
d.lastsentvalue=value_vl53l1x_range;
|
||||
lastsentvalue_vl53l1x_status=vl53l1x.ranging_data.range_status;
|
||||
|
||||
d.lastsent=millis();
|
||||
}
|
||||
|
@ -1394,6 +1416,12 @@ void loopHandler() {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_VL53L1X
|
||||
if (vl53l1xinit_ok) {
|
||||
loop_VL53L1X();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_ANEMOMETER
|
||||
loop_anemometer();
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue