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

adafruit-i2c-pwm-driver-async

v1.1.0

Published

node.js i2c control for the Adafruit PWM servo driver

Downloads

4

Readme

Adafruit I2C PWM Driver

About

Node.js driver implementation for a PWM i2c device (PCA9685) present in these products:

This project is a fork from this project that is a fork from this project (original, unmaintained). This bring the following to the original project:

  • maintains promise chains
  • major code cleanup and refactoring to use ES6 syntax
  • improved debugging options
  • unit tests
  • capability to compile on non Unix systems

Try out this project with my PWM Controller App.

Installation

Before installing the driver on a Raspberry Pi you need to enable i2c. Follow these steps to enable it while ignoring the Python related instructions: you do not need to install libi2c-dev and python-smbus (first and last set of instructions).

Install the driver with this command:

npm i adafruit-i2c-pwm-driver-async

The driver requires a i2c binding to run but the binding is kept apart from the project dependencies in order to support compilation on non Unix systems. Install the i2c binding dependency on a Raspberry Pi with this command:

./install-i2c.sh

Reminder: running this command will fail on non Unix systems. If you wish to develop on a non Unix system, use the isMockDriver flag (see documentation).

Usage

const { PwmDriver, sleep } = require('adafruit-i2c-pwm-driver-async');

// Configure driver
const pwm = new PwmDriver({
  address: 0x40,
  device: '/dev/i2c-1',
  debug: true,
  isMockDriver: true // Remove this if running on a Raspberry Pi
});

// Configure min and max servo pulse lengths
const servoMin = 150; // Min pulse length out of 4096
const servoMax = 600; // Max pulse length out of 4096

const loop = () => {
  return sleep(1)
    .then(pwm.setPWM(0, 0, servoMin))
    .then(sleep(1))
    .then(pwm.setPWM(0, 0, servoMax))
    .then(loop);
};

// Initialize driver and loop
pwm.init()
  .then(pwm.setPWMFreq(50))
  .then(sleep(1))
  .then(loop)
  .catch(console.error);

To configure I2c on your Raspberry-pi / Beaglebone please see here

You can find a simple example here

API

PwmDriver({address:Number, device:String, debug:Bool, i2cDebug:Bool, isMockDriver:Bool})

Setting up a new PwmDriver

  • address: Address of the i2c panel (defaults to 0x40)
  • device: Device name (defaults to /dev/i2c-1)
  • debug: Flag used to display high level debug messages (defaults to false)
  • i2cDebug: Flag used to display low level i2c signals (defaults to false)
  • isMockDriver: Whether to use the real i2c binding or not (defaults to false). This is usefull for compiling on non Unix systems that don't support i2c.

pwmDriver.init()

Initialize the PwmDriver. Only required once after PwmDriver constructor is called. Returns a Promise.

pwmDriver.setPWMFreq(frequency:Number)

Set the PWM frequency to the provided value (in hertz). Returns a Promise.

pwmDriver.setPWM(channel:Number, on:Number, off:Number)

Sets a single PWM channel. Returns a Promise.

pwmDriver.setALLPWM(channel:Number, on:Number, off:Number)

Sets all PWM channels. Returns a Promise.

pwmDriver.stop()

Stops PWM signals. Returns a Promise.

License

MIT

Based on the Adafruit's Raspberry-Pi Python Code Library

Here is a growing collection of libraries and example python scripts for controlling a variety of Adafruit electronics with a Raspberry Pi

In progress!

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

Written by Limor Fried, Kevin Townsend and Mikey Sklar for Adafruit Industries. BSD license, all text above must be included in any redistribution

To download, we suggest logging into your Pi with Internet accessibility and typing: git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git