npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-vl53l0x

v3.2.0

Published

A Node.js library in Typescript for a vl53l0x device

Downloads

29

Readme

vl53l0x

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!

vl53l0x

Install

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:

npm install ts-vl53l0x

Use

Normal single sensor

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()

Multiple sensors

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

Interface

new VL53L0X(address?: [[pin: number, address: number]] | number = 0x29, bus = 1)

address

For multiple sensors, please use XSHUT and define the pin within the array:

const arrayOfSensors = [
  [
    17, //pin
    0x30, // address to command
  ],
]

vl53l0x.init(opts?: OPTS): Promise

OPTS

  signalRateLimit?: number
  vcselPulsePeriod?: {
    pre: 12 | 14 | 16 | 18
    final: 12 | 14 | 16 | 18
  }
  measurementTimingBudget?: number
  distanceOffset?: number
  regAddressRead?: number

vl53l0x.api: API

API

  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>
  }

References

https://www.st.com/resource/en/datasheet/vl53l0x.pdf

License

MIT