0

Example for ML-R LIDAR 4m VL53L1X, analog output (mrm-lid-an2)

Prerequisites

If not already done so already, install Arduino software and make basic connections, as described in page for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32).

Task

We will read analog output of the sensor in order to determine distance to an object.

Connections

Additionally to the basic hardware connection, as depicted in home page for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32), we will connect the sensor, ML-R LIDAR 4m VL53L1X, analog output (mrm-lid-an2). The image here shows just this board and the lidar, not the other parts of the basic connection (power supply and battery), which are also necessary.

Connect 0 and 3.3 V voltage inputs of ML-R LIDAR 4m VL53L1X, analog output (mrm-lid-an2) to appropriate voltage Dupont pins. Connect sensor's "ANA" pin to ESP32 GPIO pin 36.

Program

Here is the simplest code.

const float f = 4000 / 3300.0;

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println(analogRead(36) * f);
}
First, about constant f. Maximum number of millimeters measurable is 4000. As ESP32 uses 12-bit ADC, the values are in range 0 - 4095 (212). However, analog signal from the sensor doesn't reach maximum voltage, 3.3 V. Maximum value is about 3300. You can check and change it, if You get a little different result. When we read the analog value from the sensor, we have to divide it by 3300 in order to get percentage of the maximum value (if the input is 330, and maximum is 3300, 330 / 3300 yields 0.1, 10%). If we multiply this percentage with the maximum possible value, 4000, we get the distance (10% of 4000 mm is 400 mm). Hence, we shall multiply the analog value with f. We'll do so soon.

setup() starts serial interface with PC so that Serial.print will work. In loop() we finally multiply ADC value with f and display the result.

We could use any other of the 16 analog pins, as long as no other device uses them, but read the next paragraph.

Limitations

Some pins are not available or are limited in usage. It is also important to note the ADC anomaly for ESP32 and select the right firmware as the sensor's output value should not start from 0. If it starts, ESP32 will report 0 mm for the first about up to 70 mm. Check this list.

Alternative connection

Dupont žicama spojite LIDAR na mikrokontroler. U primjeru se koristi pločica ML-R I2C 3V3 5V Distribution Pins (mrm-distrib-a).

Skinite https://www.github.com/PribaNosati/MRMS Arduino kod.

Ukoliko želite napraviti složeniji FischerTechnik sistem, pogledajte ovaj spoj .