I wanted to create some kind of radar with VL53L1X Sensor from pololu. I attach that sensor to Analog Servo S-0307 so I can rotate it.
I used arduino NANO 33 IOT, Library VL53L1X from Pololu and Servo library.
I have tested first the code without the servo and I can see in the serial monitor my Range. Likewise I also test the servo rotation without the Range sensor and it rotate. But then when I combine both, the I didn't see any Range in my Serial Monitor, nor the servo Rotate.
Could anyone please help me? where did I do wrong or some other suggestion? or may be some link where I could see the code of similar project ?
Thank You
#include "Wire.h"
#include "VL53L1X.h"
#include "Servo.h"
Servo myservo;
VL53L1X sensor;
int pos = 93; // Horizontal Position
void setup()
{
myservo.attach(2);
myservo.write(pos);
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000); // use 400 kHz I2C
sensor.setTimeout(500);
if (!sensor.init())
{
Serial.println("Failed to detect and initialize sensor!");
while (1);
}
sensor.setDistanceMode(VL53L1X::Long);
sensor.setMeasurementTimingBudget(50000);
sensor.startContinuous(50);
}
void loop()
{
static bool dir = false;
myservo.write(pos);
sensor.read();
// Rotate to +45 and back to -45 from Horizontal Pos 93
if (dir) {
pos++;
if (pos >= 138) {
dir = !dir;
}
} else {
pos--;
if (pos <= 48) {
dir = !dir;
}
}
Serial.print("\tPos");
Serial.print(pos);
Serial.print("\tRange: ");
Serial.print(sensor.ranging_data.range_mm);
Serial.println();
delay(15);
}[code/]