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

node-mcp23017

v0.1.0

Published

Library to use the MCP23017 16bit I/O Expander with the Raspberry Pi

Downloads

81

Readme

node-mcp23017

Node.js library for the I2C I/O Expander MCP23017 on a Raspberry Pi

It currently supports reading, writing and changing the pull-up resistor of the GPIOs.

The module tries to mimic the Arduino-Syntax

##Installation

install via npm. just type the following in the terminal/console

npm install node-mcp23017 --save

Raspberry Pi Setup

In order to use this module with the Raspberry Pi running Raspbian you have to enable to stuff

$ sudo vi /etc/modules

Add these two lines

i2c-bcm2708
i2c-dev
$ sudo vi /etc/modprobe.d/raspi-blacklist.conf

Comment out blacklist i2c-bcm2708

#blacklist i2c-bcm2708

Load kernel module

$ sudo modprobe i2c-bcm2708

Make device writable

sudo chmod o+rw /dev/i2c*

Usage

NOTE

Pins are numbered from 0-15 where 0-7 is register A and 8-15 is register B

var MCP23017 = require('node-mcp23017');

var mcp = new MCP23017({
  address: 0x20,//default: 0x20
  device: 1,    // 1 for '/dev/i2c-1' on model B | 0 for '/dev/i2c-0' on model A
                // 'ls /dev/i2c*' to find which device file / number you should use
  debug: true   //default: false
});

/*
  By default all GPIOs are defined as INPUTS.
  You can set them all the be OUTPUTs by using the pinMode-Methode (see below),
  You can also disable the debug option by simply not passing it to the constructor
  or by setting it to false
*/

//set all GPIOS to be OUTPUTS
for (var i = 0; i < 16; i++) {
  mcp.pinMode(i, mcp.OUTPUT);
  //mcp.pinMode(i, mcp.INPUT); //if you want them to be inputs
  //mcp.pinMode(i, mcp.INPUT_PULLUP); //if you want them to be pullup inputs
}

mcp.digitalWrite(0, mcp.HIGH); //set GPIO A Pin 0 to state HIGH
mcp.digitalWrite(0, mcp.LOW); //set GPIO A Pin 0 to state LOW

/*
  to read an input use the following code-block.
  This reads pin Nr. 0 (GPIO A Pin 0)
  value is either false or true
*/
mcp.digitalRead(0, function (pin, err, value) {
  console.log('Pin 0', value);
});

Example (Blink 16 LEDs)

see examples folder

var MCP23017 = require('node-mcp23017');

var mcp = new MCP23017({
  address: 0x20, //all address pins pulled low
  device: 1, // Model B
  debug: false
});

/*
  This function blinks 16 LED, each hooked up to an port of the MCP23017
*/
var pin = 0;
var max = 16;
var state = false;

var blink = function() {
  if (pin >= max) {
    pin = 0; //reset the pin counter if we reach the end
  }

  if (state) {
    mcp.digitalWrite(pin, mcp.LOW); //turn off the current LED
    pin++; //increase counter
  } else {
    mcp.digitalWrite(pin, mcp.HIGH); //turn on the current LED
    console.log('blinking pin', pin);
  }
  state = !state; //invert the state of this LED
};

//define all gpios as outputs
for (var i = 0; i < 16; i++) {
  mcp.pinMode(i, mcp.OUTPUT);
}

setInterval(blink, 100); //blink all LED's with a delay of 100ms

Acknowledgement

some parts are derived from the module https://github.com/x3itsolutions/mcp23017 by x3itsolutions (Fabian Behnke)