Code packages that connects an Arduino board to different devices, including break out boards, sensors, displays, communication and storage devices, are available from different libraries. The Arduino app has a library manager that you reach from the menu:
Breakout boards with the VL6180X lidar+ambinent light sensors are offered both by adafruit, sparkfun and Pololu. Sparkfun is easier to work with if you use their Qwiic connect system for I2C devices. You can then use the Qwiic Cable - Breadboard Jumper (4-pin) for connecting the spectrometer to the board. If you use Adafruit or Pololu you have to solder the breakout board.
Wiring
The wiring is the same regardless if you use the Adafruit, Sparkfun or Pololu breakout boards.
Just connect power (5v) and ground, and then the SCL and SDA ports. All connections are item to item (5v -> 5v, gnd -> gnd, SCL -> SCL, SDA -> SDA).
/* This minimal example shows how to get single-shot range
measurements from the VL6180X.
The range readings are in units of mm. */
#include <Wire.h>
#include <VL6180X.h>
VL6180X sensor;
void setup()
{
Serial.begin(9600);
Wire.begin();
sensor.init();
sensor.configureDefault();
sensor.setTimeout(500);
}
void loop()
{
Serial.print(sensor.readRangeSingleMillimeters());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}
Continuous
/* This example demonstrates how to use interleaved mode to
take continuous range and ambient light measurements. The
datasheet recommends using interleaved mode instead of
running "range and ALS continuous modes simultaneously (i.e.
asynchronously)".
In order to attain a faster update rate (10 Hz), the max
convergence time for ranging and integration time for
ambient light measurement are reduced from the normally
recommended defaults. See section 2.4.4 ("Continuous mode
limits") and Table 6 ("Interleaved mode limits (10 Hz
operation)") in the VL6180X datasheet for more details.
Raw ambient light readings can be converted to units of lux
using the equation in datasheet section 2.13.4 ("ALS count
to lux conversion").
Example: A VL6180X gives an ambient light reading of 613
with the default gain of 1 and an integration period of
50 ms as configured in this sketch (reduced from 100 ms as
set by configureDefault()). With the factory calibrated
resolution of 0.32 lux/count, the light level is therefore
(0.32 * 613 * 100) / (1 * 50) or 392 lux.
The range readings are in units of mm. */
#include <Wire.h>
#include <VL6180X.h>
VL6180X sensor;
void setup()
{
Serial.begin(9600);
Wire.begin();
sensor.init();
sensor.configureDefault();
// Reduce range max convergence time and ALS integration
// time to 30 ms and 50 ms, respectively, to allow 10 Hz
// operation (as suggested by Table 6 ("Interleaved mode
// limits (10 Hz operation)") in the datasheet).
sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 30);
sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 50);
sensor.setTimeout(500);
// stop continuous mode if already active
sensor.stopContinuous();
// in case stopContinuous() triggered a single-shot
// measurement, wait for it to complete
delay(300);
// start interleaved continuous mode with period of 100 ms
sensor.startInterleavedContinuous(100);
}
void loop()
{
Serial.print("Ambient: ");
Serial.print(sensor.readAmbientContinuous());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.print("\tRange: ");
Serial.print(sensor.readRangeContinuousMillimeters());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}