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

i2cdriver

v1.2.2

Published

A Node.js library for an i2cdriver device http://i2cdriver.com

Downloads

16

Readme

i2cdriver

An i2c development board that works on Mac, Windows, and Linux? ... and has a graphic display? ... and for under $30? Yes please! Buy one now! tfmini-plus tfmini-plus

This library contains functions for:

  • i2c-bus API
  • i2cdriver device API

Swap in place of the i2c-bus module

// const i2c = require('i2c-bus')
// const bus_id = 1

const i2c = require('i2cdriver/i2c-bus')
const bus_id = '/dev/tty.usbserial-DO01INSW'

const tfminiplus = require('tfmini-plus')

i2c.openPromisified(bus_id)
.then(async (bus) => {
  const tfmp = await tfminiplus.I2C(bus, 0x10)
  const distance = await tfmp.distance()
  console.log('distance:', distance)
})
.catch(console.error);

i2c-bus is a popular module for communicating with i2c devices. This module provides a compatible/interchangable API so you can develop your i2c code on your development computer and deploy it to a device later- with only swapping out the module reference and bus id.

i2cdriver API

The API functions try to match the API provided by i2cdriver as close as possible.

The driver API just issues the special device commands. It does not enforce any specific (valid) command order. You will likely want to use i2c-bus compatible APIs which coordinates the device calls properly.

setspeed(100|400)

Sets the i2c bus speed (in KHz).

Supported values are:

  • 100 = 100KHz
  • 400 = 400KHz

setpullups(mask)

Sets the SDA and CLK pull-up resister values. See the i2cdriver documentation for more information.

Valid values: 0b000000 to 0b111111

scan()

Scans the i2c bus (0x08-0x77) for connected devices.

Returns: An array of address numbers of detected devices.

reset()

Resets the i2c bus.

start(addr, rw)

Starts a read or write session to a device on the bus.

addr - The i2c device address rw - Indicates whether to start a read or write session. Valid values:     • "write", 0, false     • "read", 1, true

read(length)

Issues a read request for length bytes. You should call start(addr, 'read') first. The i2cdriver does not restrict you from sending a read/write request out of sequence- but the result will be unknown (probably not good).

NOTE1: The i2c-bus APIs coordinate these calls properly.

NOTE2: The i2cdriver device is limited to 64 bytes in a single read. This function will read 64 byte chunks at a time- but the device must support an internal read cursor (it remembers where it left off).

Returns:: A Buffer of the bytes read.

write(buff)

Writes the Buffer to the i2c bus. You should call start(addr, 'write') first. The i2cdriver does not restrict you from sending a read/write request out of sequence- but the result will be unknown (probably not good).

buff - A Buffer of the bytes you want to send

Note: The i2c-bus APIs coordinate these calls properly.

stop()

Concludes a read or write session.

regrd(addr, register, length = 1)

A helper function that reads from a register on a device.

addr - The i2c device address register - (byte) The register to read from. length - The number of bytes to read. (e.g.: 2 for a 16 bit value)

NOTE: The i2cdriver device is limited to 64 bytes in a single read. This function will read 64 byte chunks at a time- however, this deviates from how other i2c implementations operate and may cause problems.

Returns:: A Buffer of the bytes read.

regwr(addr, register, value)

A helper function that writes to a register on a device.

addr - The i2c device address register - (byte) The register to write to. value - The byte(s) to write. Vaid values:     • byte (Number)     • [byte1, byte2] (Array of bytes) for 16bit values

status()

Gets the device status. See the i2cdriver documentation for more information.

Returns:: An object with the status properties.

License

MIT