A Node.js library for a vl53l0x proximity sensor.
NOTE: This package addresses the issue of adding multiple vl53l0x on one device. Please read below how to.
NOTE:
I honestly have very little knowledge of GPIO and hardware programming. This is a fork from https://github.com/williamkapke/vl53l0x
I did this to try and understand a bit more how to develop nodejs -> sensors apis. and to typescript the hell out of it!
From: https://www.npmjs.com/package/i2c-bus#installation
The way in which I2C is configured varies from board to board. Sometimes no
configuration is required, but sometimes it is:
- Configuring I2C on the Raspberry Pi
- Configuring Software I2C on the Raspberry Pi
- Consider software I2C when there are issues communicating with a device on a Raspberry Pi
npm install ts-vl53l0x
import VL53L0X from 'ts-vl53l0x'
const vl53l0x = new VL53L0X()
const init = async () => {
await vl53l0x.init()
while (true) {
console.log(await vl53l0x.api.measure())
// output: { '0': 8191 }
}
}
init()
import VL53L0X from 'ts-vl53l0x'
const arrayOfSensors = [
[17, 0x30],
[22, 0x31],
]
const vl53l0x = new VL53L0X(arrayOfSensors)
const init = async () => {
await vl53l0x.init()
while (true) {
console.log(await vl53l0x.api.measure())
// output: { '17': 8191, '22': 8191 }
console.log(await vl53l0x.api.measure(17))
// output: { '17': 8191 }
console.log(await vl53l0x.api.measure(22))
// output: { '22': 8191 }
}
}
init()
You should be able to allocate individual calibrations:
import VL53L0X from 'ts-vl53l0x'
const arrayOfSensors = [
[17, 0x30],
[22, 0x31],
]
const vl53l0x = new VL53L0X(arrayOfSensors)
const init = async () => {
await vl53l0x.init()
// The next options without a specific pin will do it all, or you can use the opts on init.
// await vl53l0x.init({...}) read bellow of rthe options available
await vl53l0x.api.setSignalRateLimit(0.1)
await vl53l0x.api.setVcselPulsePeriod('pre', 18)
await vl53l0x.api.setVcselPulsePeriod('final', 14)
//... or
await vl53l0x.api.setSignalRateLimit(0.1, 17)
await vl53l0x.api.setVcselPulsePeriod('pre', 18, 22)
await vl53l0x.api.setVcselPulsePeriod('final', 14, 22)
while (true) {
// If you add a pin that does not exists it will error.
console.log(await vl53l0x.api.measure())
// output: { '17': 8191, '22': 8191 }
console.log(await vl53l0x.api.measure(17))
// output: { '17': 8191 }
console.log(await vl53l0x.api.measure(22))
// output: { '22': 8191 }
}
}
init()
note If by any chance you change back to single sensor, you will have to restart your device. WIP to go back to the default address
address
For multiple sensors, please use XSHUT
and define the pin within the array:
const arrayOfSensors = [
[
17, //pin
0x30, // address to command
],
]
signalRateLimit?: number
vcselPulsePeriod?: {
pre: 12 | 14 | 16 | 18
final: 12 | 14 | 16 | 18
}
measurementTimingBudget?: number
distanceOffset?: number
regAddressRead?: number
measure: (pin?: number | string) => Promise<number> | Promise<{[pin: number]: number}>
resetPinsAddresses: () => Promise<void>
config: {
bus: number
options: OPTS
}
addresses: {
[key: number]: { addr: number; gpio?: Gpio; timingBudget: any }
}
scanAddressesBeingUsed: () => Promise<{ scan: number[]; hex: string[] }>
setSignalRateLimit(limit_Mcps: number, pin?: string | number): Promise<void | { [key: string]: BytesWritten } | BytesWritten>
getSignalRateLimit(pin?: string | number): Promise<number | { [key: string]: number }>
getMeasurementTimingBudget(pin?: string | number): Promise<number | { [key: string]: number }>
setMeasurementTimingBudget(budget_us: number, pin: string | number): Promise<void>
setVcselPulsePeriod: (type: 'pre' | 'final', period_pclks: 8 | 10 | 12 | 14 | 16 | 18, pin?: number) => Promise<void>
getVcselPulsePeriod(type: number, pin?: string | number): Promise<number | { [key: string]: number }>
performSingleRefCalibration(vhv_init_byte: number, pin?: string | number): Promise<void>
io: {
write(data: Buffer, addr: number): Promise<BytesWritten>
writeReg(register: REG, value: number, addr: number, isReg16: boolean): Promise<BytesWritten>
writeMulti(register: REG, array: Buffer, addr: number): Promise<BytesWritten>
readReg(register: REG, addr: number, isReg16: boolean): Promise<number>
readMulti(register: REG, addr: number, length?: number): Promise<Buffer>
}
https://www.st.com/resource/en/datasheet/vl53l0x.pdf
MIT