2020-09-12 16:47:58 +02:00
|
|
|
#include <Arduino.h>
|
2023-03-22 20:02:23 +01:00
|
|
|
#include "driver/pcnt.h"
|
|
|
|
#include <VL53L0X.h>
|
2020-09-12 16:47:58 +02:00
|
|
|
|
2022-04-02 22:10:31 +02:00
|
|
|
|
|
|
|
#define OUTPUT_SENSOR 14
|
|
|
|
#define SENSOR_PLANT 17
|
2020-10-09 20:45:47 +02:00
|
|
|
|
2023-03-22 20:02:23 +01:00
|
|
|
VL53L0X tankSensor;
|
2020-10-09 19:29:28 +02:00
|
|
|
|
2021-12-05 02:36:03 +01:00
|
|
|
void setup()
|
2021-12-04 17:04:18 +01:00
|
|
|
{
|
2021-05-19 20:54:11 +02:00
|
|
|
Serial.begin(115200);
|
2020-10-09 19:29:28 +02:00
|
|
|
pinMode(OUTPUT_SENSOR, OUTPUT);
|
2023-03-22 20:02:23 +01:00
|
|
|
tankSensor.setTimeout(500);
|
2021-04-07 20:27:42 +02:00
|
|
|
|
2021-07-21 21:23:58 +02:00
|
|
|
digitalWrite(OUTPUT_SENSOR, HIGH);
|
2022-04-02 22:10:31 +02:00
|
|
|
Serial.println("Nodemcu ESP32 Start done");
|
2023-03-22 20:02:23 +01:00
|
|
|
|
|
|
|
tankSensor.setTimeout(500);
|
|
|
|
long start = millis();
|
|
|
|
bool distanceReady = false;
|
|
|
|
while (start + 500 > millis())
|
|
|
|
{
|
|
|
|
if (tankSensor.init())
|
|
|
|
{
|
|
|
|
distanceReady = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delay(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (distanceReady)
|
|
|
|
{
|
|
|
|
Serial.println("Sensor init done");
|
|
|
|
tankSensor.setSignalRateLimit(0.1);
|
|
|
|
// increase laser pulse periods (defaults are 14 and 10 PCLKs)
|
|
|
|
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
|
|
|
|
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
|
|
|
|
tankSensor.setMeasurementTimingBudget(200000);
|
|
|
|
} else {
|
|
|
|
Serial.println("Sensor init failed");
|
|
|
|
}
|
2021-01-30 23:28:15 +01:00
|
|
|
}
|
2020-10-09 19:29:28 +02:00
|
|
|
|
2021-02-04 23:52:54 +01:00
|
|
|
void loop() {
|
2021-07-21 21:23:58 +02:00
|
|
|
|
2023-03-22 20:02:23 +01:00
|
|
|
delay(500);
|
2021-07-21 21:23:58 +02:00
|
|
|
|
2023-03-22 20:02:23 +01:00
|
|
|
|
|
|
|
if (!tankSensor.timeoutOccurred())
|
|
|
|
{
|
|
|
|
uint16_t distance = tankSensor.readRangeSingleMillimeters();
|
|
|
|
}
|
2022-06-25 17:28:01 +02:00
|
|
|
}
|