Enter Your Project for a Chance to Win a Thermal Imaging Camera, Germicidal UV Lamp, and a Shopping Cart with Matching Charity Donation! Back to homepage | Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
I just received my VL53L1X sensor that has a 4 meter range from CQRobot. I bought this particular board implementation because it was the only unit that I could get quickly. It has a larger form factor than the VL53L0X sensors that I've been using and it also has a larger shrouded connector. I would have preferred to have gotten a board with the same implementation as the VL53L0X. One noticeable difference in the sensor itself is that it is in a slightly larger package and has much larger transmit and receive windows.
The VL53L0X is on the left and the VL53L1X is on the right.
I've been playing with the VL53L0X for a while and I expected the VL53L1X to be a "drop in" replacement, i.e. run the same code with maybe an address change and more than 2X the range. I was surprised to discover that the API for the VL53L1X seems to be quite different with multiple ranging modes. I installed a new library and got it to "sort of" work. I'm getting some type of "wrap around" in the measurements and can't seem to read a distance of greater than about 1.5 meters. Guess I need to do what I should what I should have done in the first place and take a detailed look at the spec sheet.
In the meantime I wanted to try out the program on the Flora board so I'm temporarily using the VL53L0X until I can get the VL53L1X figured out.
Here is the VL53L0X mounted on the Adafruit Flora. I've just connected the VIN, GND, SDA, and SCL pins. I am not using the XSHUT (shutdown pin to allow programming another I2C module's address) or GPIO1 (used as an interrupt to the microcontroller). I am going to use the onboard Neopixel LED to provide visual social distance range feedback.
Neopixel indication:
- Green - safe, measured distance is out of range (greater than approx 4 meters)
- Yellow - caution, measured distance is approaching 2 meters
- Red - warning, measured distance is less than 2 meters
Because I am using the shorter range sensor initially I had to adjust the values for shorter range but the algorithm is the same.
Flora_vl53l0x.ino
#include "Adafruit_VL53L0X.h" #include <Adafruit_NeoPixel.h> #define PIN 8 Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800); Adafruit_VL53L0X lox = Adafruit_VL53L0X(); void setup() { strip.begin(); strip.setBrightness(50); strip.show(); // Initialize all pixels to 'off' Serial.begin(115200); // wait until serial port opens for native USB devices // while (! Serial) { // delay(1); // } Serial.println("Adafruit VL53L0X test"); if (!lox.begin()) { Serial.println(F("Failed to boot VL53L0X")); while(1); } // power Serial.println(F("VL53L0X API Simple Ranging example\n\n")); } void loop() { VL53L0X_RangingMeasurementData_t measure; Serial.print("Reading a measurement... "); lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout! if (measure.RangeStatus != 4) { // phase failures have incorrect data Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter); if (measure.RangeMilliMeter <= 1000) { colorWipe(strip.Color(255, 0, 0), 500); // Red } else { colorWipe(strip.Color(255, 255, 0), 500); // Yellow } } else { Serial.println(" out of range "); colorWipe(strip.Color(0, 255, 0), 500); // Green } delay(100); } // Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } }
Here is a short video demonstrating it working.
I also plan to add an audible alert to complement the Red visual warning. First I need to figure out the VL53L1X. Then I'll need to add a battery and switch and print a case. The Adafruit Flora has a battery connector but it does not have an integrated charger. It has a battery input range of 3.5V to 16V. I haven't decide yet whether to use a LiPo battery or 3 series AAA batteries.
Top Comments