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 🙏

© 2026 – Pkg Stats / Ryan Hefner

analog-reader

v1.0.3

Published

An event based analog input reader for your GPIO.

Downloads

19

Readme

Analog Reader

An event based analog input reader with sampling for less jittery values. Currently only tested using a Raspberry Pi 2 along with an MCP3008. Might work with other SPI setups as well. Heavily based on Ladyada's python code.

Installing

npm i --save analog-reader

Usage

For instructions on wiring the MCP3008 to a Raspberry Pi, see here.

After that, configure the pins to be used and initialize the reader

const AnalogReader = require('analog-reader');
const CLOCKPIN = 18;
const MOSIPIN = 24;
const MISOPIN = 23;
const CSPIN = 25;

var reader = new AnalogReader(CLOCKPIN,MOSIPIN,MISOPIN,CSPIN);

After initializing you can change some properties, such as the readDelay, sampleSize and watch/unwatch inputs.

// Sets how often (milliseconds) should we poll for data, defaults to 2 ms.
// I'm not sure how to get how low can you go, as it will depend on the setup.
reader.readDelay = 2;

// Setting a higher sample size will take longer. It's a tradeoff between accuracy and speed. Defaults to 50.

reader.sampleSize = 50;

Watching / unwatching

// Watch input 0, 1 and 2
reader.watch(0);
reader.watch(1);
reader.watch(2);

// Stop watching input 1
reader.unwatch(1);

Set up a listener

reader.on('value', function(evt){
	console.log(evt);
	/*
	{
		value: 14, // Sampled value
		buffer: [...], // Values sampled for this reading
		num: 0 // ADC Number
	}
	*/
})

// Starts reading!
reader.start()

Finally, to stop reading, try

// Stops reading! Can be resumed later!
reader.stop()

To manually destroy the reader, use the following. This will unexport and free up the used pins. It should be automatically called when stopping your program (SIGINT) as well.

Once done you can't start listening again with the same reader.

reader.close()

Development

Use npm install and then run npm start to compile from coffeescript.

Tests

TODO proper testing.

npm run test currently runs a webpack-dev-server with a mocked up read method to test the sampling behaviour.