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

rpio-pwm

v1.0.4

Published

DMA based soft PWM for raspberry pi gpio

Downloads

25

Readme

rpio-pwm

High performance soft PWM for raspberry pi. Unlike hardware PWM (which limited to those special 4 hardware PWM ports), rpio-pwm allow you to use any GPIO pins. Unlike other soft PWM solutions (which use lot's CPU cycles to switch on/off based on timers), rpio-pwm use DMA, so literily 0 CPU usage at run time.

Note: This current version (1.0.0) is NOT compatible with privous version (0.2.x). This is a total re-write, the new API is much simpler and also more powerful. The new code is only depend on servoblaster.

Pi4 support: Yes, rpio-pwm >1.0.0 supports Pi4, remember to use channel 7 (on Pi4) in stead of 14 (for pi3/2/zero). I tested, it works out of the box.

install

npm install rpio-pwm --save

Quick Start

Simple

const pwm = require('rpio-pwm');

const chNum = 14; // DMA channel 14
const pinNum = 21; // GPIO 21
const ch = pwm.create_dma_channel(chNum);
const pin = ch.create_pwm(pinNum);
pin.set_width(100); // 100 * 10us=1000us

More control

const pwm = require('rpio-pwm');
// DMA channel 14 for pi2/3/zero, channel 7 for pi4
const chNum = pwm.host_is_model_pi4() ? 7 : 14;
const pinNum = 21; // GPIO 21

pwm.set_log_level(pwm.logLevel.debug); // by default info

const cfg = {
  cycle_time_us: 20000, // default 20000us (20ms)
  step_time_us: 10, // default 10us
  delay_hw: 0, // 0=PWM, 1=PCM, (default 0)
  invert: 0, // invert high/low (default 0=no invert)
};
const ch = pwm.create_dma_channel(chNum, cfg);
const pin = ch.create_pwm(pinNum);
pin.set_width(1000);
setTimeout(function () {
  // it's good idea to cleanup before exit.
  ch.shutdown();
}, 2000);

Notes

channel: rpi have 15 DMA channels available (0-14). But you need to know which one might already in use by other services (I found this thread is helpful https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=86339).

gpio: multiple GPIO pin can be created under 1 channel (max 32 pin per channel, is it enough?).

delay_hw: You may choice to use 0=PWM or 1=PCM as delay hardware source. This can be useful in case if you need 1) setup multiple DMA channel with different step_time_us. 2) one of the hardware is alreay be used by something else.

shutdown: you can shutdown 1 gpio pin by pin.release(), or shutdown the whole DMA channel with ch.shutdown(). Typically you want to register a signal handler and shutdown DMA channal before exit.

Thanks to servoblaster

This rpio-pwm is based on the awesome work of servoblaster (git://github.com/richardghirst/PiBits.git).

license

MIT