A Node.js library for a vl53l1x TOF distance sensor
const VL53L1X = require('vl53l1x')
//Development i2c board: https://www.npmjs.com/package/i2cdriver
// const driver = 'i2cdriver/i2c-bus'
// const busNumber = '/dev/tty.usbserial-DO01INSW'
//Builtin i2c bus: //https://www.npmjs.com/package/i2c-bus
const driver = 'i2c-bus'
const busNumber = 1
VL53L1X(busNumber, 0x29, {driver:driver}).then(async (device) => {
device.on('data', (data) =>
console.log(data)
)
await device.start()
process.on('exit', async (code) => {
await device.stop()
})
})
All functions return a Promise.
busNumber
: The bus number to use
address
: The i2c address of the device. (Default 0x29
)
options
:
driver
: The Node.js module that communicates with the i2c bus. (Default: 'i2c-bus')
Any module that matches the 'i2c-bus' interface can be used.config
: AnArray
of bytes to initialize the device. (Default: VL51L1X_DEFAULT_CONFIGURATION)
mode
: 'short'
or 'long'
Gets the current timing settings.
returns: An object with { dwell: int, sleep: int }
Sets the timing settings.
dwell
: Time in milliseconds the device will spend collecting signals
mode
: Time in milliseconds the device will wait between measurements
Sets the Region Of Interest.
width
: Number of SPADs to use horizontally. (min 4, max 16)
height
: Number of SPADs to use vertically. (min 4, max 16)
Sets the calibration offset.
distance
: The offset distance in millimeters. Max resolution is .25 mm
.
Use calibrate_offset() to determine the offset.
Sets the crosstalk compensation.
cps
: The compensation value in cps (counts per second).
Use calibrate_xtalk() to determine the value.
Starts polling for data. Results are emitted to the data
event.
Stops polling for data.
Performs a single measurement and returns the result. Results are also emitted to the data
event.
returns: An object with the measurement data.
Performs offset calibration. When complete, returns the value that was written to the device. You should pass this value to vl53l1x.offset(distance) on device start.
Performs crosstalk calibration. When complete, returns the value that was written to the device. You should pass this value to vl53l1x.xtalk(cps) on device start.
Receives measurement data. Use vl53l1x.start() to start polling.
Example data:
{
status: 0,
ambient: 8,
numSPADs: 4,
sigPerSPAD: 19944,
distance: 115
}
MIT