# node-mcp23017_with_i2c_updated

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

Latest version **0.0.2** (published 2016-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-mcp23017_with_i2c_updated
pnpm add node-mcp23017_with_i2c_updated
yarn add node-mcp23017_with_i2c_updated
bun add node-mcp23017_with_i2c_updated
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2016-12-12 |
| First published | 2016-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Kai Henzler |
| Maintainers | ci24 |

## Links

- npm: https://www.npmjs.com/package/node-mcp23017_with_i2c_updated
- Repository: https://github.com/kaihenzler/node-mcp23017
- Homepage: https://github.com/kaihenzler/node-mcp23017#readme
- Issues: https://github.com/kaihenzler/node-mcp23017/issues
- npm.io page: https://npm.io/package/node-mcp23017_with_i2c_updated

## Dependencies (1)

- [i2c](https://npm.io/package/i2c.md) 0.2.3

## Recent versions

- 0.0.2 (latest) — 2016-12-12

## README

node-mcp23017_with_i2c_updated
=============

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

It currently only supports reading from and writing to the chip

The module tries to mimic the Arduino-Syntax

##Installation

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

````bash
npm install node-mcp23017_with_i2c_updated --save
```

## Raspberry Pi Setup

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


````bash
$ sudo vi /etc/modules
````

Add these two lines

````bash
i2c-bcm2708
i2c-dev
````

````bash
$ sudo vi /etc/modprobe.d/raspi-blacklist.conf
````

Comment out blacklist i2c-bcm2708

````
#blacklist i2c-bcm2708
````

Load kernel module

````bash
$ sudo modprobe i2c-bcm2708
````

Make device writable

````bash
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

```javascript
var MCP23017 = require('node-mcp23017_with_i2c_updated');

var mcp = new MCP23017({
  address: 0x20, //default: 0x20
  device: '/dev/i2c-1', // '/dev/i2c-1' on model B | '/dev/i2c-0' on model A
  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.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 (err, value) {
  console.log('Pin 0', value);
});

````

## Example (Blink 16 LEDs)
#### see examples folder

```javascript
var MCP23017 = require('node-mcp23017_with_i2c_updated');

var mcp = new MCP23017({
  address: 0x20, //all address pins pulled low
  device: '/dev/i2c-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
````


## TODO

- implement built-in pullup resistors
- implement interrupt handling

## Acknowledgement

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

---
_Source: https://npm.io/package/node-mcp23017_with_i2c_updated · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
