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

tfmini-plus

v2.1.0

Published

A Node.js library for the TFMini Plus

Downloads

8

Readme

tfmini-plus

A Node.js library for the TFMini Plus.

This little device can measure long distances and is reasonably priced.

The TFMini Plus supports UART and I2C communication. The factory default is UART and can be changed programmatically.

tfmini-plis (A tfmini plus connected to a Raspberry Pi Zero W)

tfmini-plus (An i2cdriver controlling an ssd1327 display with the measurement)

BYO[protocol]

Since you can communicate using I2C or UART- I've opted to leave the communication protocol libraries out to keep from installing extra cruft that isn't needed.

This means you will need to install the i2c-bus-promise or @serialport/bindings independently.

Interface

All functions return a Promise.

DON'T FORGET TO await (or use .then())!!

I2C(bus, address = 0x10, provider = 'i2c-bus')

Creates an I2C tfminiplus instance.

bus: · (Object) An existing bus instance · (String or Number) The bus number to open address: (Number) The i2c device address (factory default is 0x10) provider: (String) The Node module to use

Returns: a Promise that resolve with the tfminiplus instance.

To use I2C, you will need to install i2c-bus OR i2c-bus-promise

.. OR, for development- Check out an i2cdriver!

npm install tfmini-plus i2c-bus
const tfminiplus = require('tfmini-plus')

tfminiplus.I2C(1, 0x10)
.then(async (tfmp) => {
  const measurements = await tfmp.measure()
  console.log('distance:', measurements.distance)
  console.log('strength:', measurements.strength)
  console.log('temperature:', measurements.temperature)
})
.catch(console.error)

... with i2cdriver:

const tfminiplus = require('tfmini-plus')

tfminiplus.I2C('/dev/tty.usbserial-DO010000', 0x10, 'i2cdriver/i2c-bus')
.then(async (tfmp) => {
  console.log('distance:', await tfmp.distance())
})
.catch(console.error)

UART(path, options)

Creates an UART tfminiplus instance.

path: The device path options: The serialport options

Returns: a Promise that resolve with the tfminiplus instance. To use UART, you will need to install @serialport/bindings

npm install tfmini-plus @serialport/bindings
const tfminiplus = require('tfmini-plus')
tfminiplus.UART('/dev/serial0', { baudRate: 115200 }).then(async (tfmp) => {
  const measurements = await tfmp.measure()
  console.log('distance:', measurements.distance)
  console.log('strength:', measurements.strength)
  console.log('temperature:', measurements.temperature)
})
.catch(console.error)

The tfminiplus instance

version()

Returns the device version number (string)

measure(unit = 'mm')

Gets a measurement from the device.

returns:

{
    distance: number,
    strength: number,
    temperature: number
}

tfminiplus.distance(unit = 'mm')

Does the same thing as measure(), but only returns the distance (number).

tfminiplus.address(addr)

Changes the I2C device address. You must call save() to have the setting persist.

tfminiplus.save()

Saves the current device settings.

tfminiplus.reset()

Resets the device.

tfminiplus.restore()

Restores the factory settings.

tfminiplus.mode(type='i2c')

Sets the mode: i2c or uart

References

https://acroname.com/sites/default/files/assets/sj-pm-tfmini_plus_a04_product_mannual_en.pdf

License

MIT