You can easily wire this breakout to any microcontroller, we'll be using an Arduino. For another kind of microcontroller, just make sure it has I2C, then port the API code. We strongly recommend using an Arduino to start though!
Wiring
There's two versions of this sensor, and the pin orders vary slightly so be sure to read the text on the breakout to match the pins to the wiring diagrams.
- Connect Vin to the power supply, 3-5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V (red wire on STEMMA)
- Connect GND to common power/data ground (black wire on STEMMA)
- Connect the SCL pin to the I2C clock SCL pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3 (yellow wire on STEMMA)
- Connect the SDA pin to the I2C data SDA pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2 (blue wire on STEMMA)
The VL6180X has a default I2C address of 0x29!
Install Adafruit_VL6180X
To begin reading sensor data, you will need to install Adafruit_VL6180X Library from our github repository. It is available from the Arduino library manager so we recommend using that.
From the IDE open up the library manager...
And type in adafruit vl6180 to locate the library. Click Install
We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use
Load Demo
Open up File->Examples->Adafruit_VL6180X->vl6180x and upload to your Arduino wired up to the sensor
Thats it! Now open up the serial terminal window at 115200 speed to begin the test.
Move your hand up and down to read the sensor data, the range readings are in millimeters and the light sensors in Lux. Note that when nothing is detected, it will print out the error which may vary.
Adafruit_VL6180X vl = Adafruit_VL6180X();
Once started, you can initialize the sensor which will also do some simple initializations and settings using begin(). Note that this will return True if the sensor was found and initialized. If not, it will return False.
vl.begin()
vl.readRange()
which will return the range in millimeters. If you get 0 or a value over 200 there's likely an error. Either way, before you trust that reading make sure to ask the sensor if the last reading had an error:
uint8_t status = vl.readRangeStatus()
The status will be 0 on no error, anything else is an error. Here's a simple code chunk that will decode the error!
if ((status >= VL6180X_ERROR_SYSERR_1) && (status <= VL6180X_ERROR_SYSERR_5)) { Serial.println("System error"); } else if (status == VL6180X_ERROR_ECEFAIL) { Serial.println("ECE failure"); } else if (status == VL6180X_ERROR_NOCONVERGE) { Serial.println("No convergence"); } else if (status == VL6180X_ERROR_RANGEIGNORE) { Serial.println("Ignoring range"); } else if (status == VL6180X_ERROR_SNR) { Serial.println("Signal/Noise error"); } else if (status == VL6180X_ERROR_RAWUFLOW) { Serial.println("Raw reading underflow"); } else if (status == VL6180X_ERROR_RAWOFLOW) { Serial.println("Raw reading overflow"); } else if (status == VL6180X_ERROR_RANGEUFLOW) { Serial.println("Range reading underflow"); } else if (status == VL6180X_ERROR_RANGEOFLOW) { Serial.println("Range reading overflow"); }
vl.readLux(GAIN)
which will return a semi-calibrated Lux reading. You can use different Gain settings to get a different range. For better results at low light, use higher gain. For better results at high light, use a lower gain.
Here's the gain's available:
- VL6180X_ALS_GAIN_1 - gain of 1x
- VL6180X_ALS_GAIN_1_25 - gain of 1.25x
- VL6180X_ALS_GAIN_1_67 - gain of 1.67x
- VL6180X_ALS_GAIN_2_5 - gain of 2.5x
- VL6180X_ALS_GAIN_5 - gain of 5x
- VL6180X_ALS_GAIN_10 - gain of 10x
- VL6180X_ALS_GAIN_20 - gain of 20x
- VL6180X_ALS_GAIN_40 - gain of 40x
We suggest starting with a gain of 5x and then adjusting up or down as necessary
Text editor powered by tinymce.