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

mcp23s17

v1.0.12

Published

modul to easy communicate with the io-expander mcp23s17

Downloads

25

Readme

MPC23S17

Readme-Version 1.0.12

This is a small library to communicate with a MCP23S17 io-expander.

GIT repository

Instructables project

Preview

Fixed

  • fixed the chip.set( pin, value, true ) issue

What's working?

You can easily use this library to communicate with 16 of the MCP23S17 chips. You can read from and write to each of its 16 pins.

You should set the directions of each pin you are using. Connect every not used pin to GND and set as an input.

// 0 => Output  Equivalent to the R/W bit
// 1 => Input
s.directions([0, 0, 0, 0, 0, 0, 0, 0,
	          1, 1, 1, 1, 1, 1, 1, 1]);

You can easily set any pin to hight or low with this code:

// s.set( pin, value );
// this function will immediately publish the values to the chip
s.set( 0, 0 );
s.set( 0, 1 );

// s.set( pin, value, false );
// this will NOT publish to the chip
s.set( 0, 0, false );
// you have to manually publish to the chip
s.write( );

To read one of the pins you can chose between this two functions:

// s.get( pin );
// returns latest input of pin 0 (might be not the real one)
s.get( 0 );

s.read( function( ){
	// returns the actual value of pin 0
	s.get( 0 );
});

Is you want to read more than one pin with its real values, you can use this code:

s.read( function( ){ 
    console.log( "All pins are read!" );
    console.log( s.get( 0 );
    console.log( s.get( 1 );
    console.log( s.get( 2 );
} );

You can also add callback functions to pins to detect changes.

// add a callback function to a single pin
// this is NOT a hardware interrupt. The performance depends on how ofter you vall the read function
// a hardware-implementation will may follow
s1.addInterrupt( 8, function( oldValue, newValue ){
    console.log( "Pin <8> changed from " + oldValue + " to " + newValue );
});

Coming soon

  • Support hardware-interrupts with callback functions

Example

v0.0.5

// load the library
MCPLib = require('mcp23s17');

// create new instance width device and chip_adress
// needed default settings are set (more options will follow)
mcp_1 = new MCPLib.MCP23S17( '/dev/spidev0.0' );

s0 = mcp_1.addSlave( 0b00000000 );
s0.directions([0, 0, 0, 0, 0, 0, 0, 0,
	       1, 1, 1, 1, 1, 1, 1, 1]);

s1 = mcp_1.addSlave( 0b00000001 );
s1.directions([0, 0, 0, 0, 0, 0, 0, 0,
	       1, 1, 1, 1, 1, 1, 1, 1]);

// connect decive
mcp_1.connect();

// add a callback function to a single pin
// this is NOT a hardware interrupt. The performance depends on how ofter you vall the read function
// a hardware-implementation will may follow
s1.addInterrupt( 8, function( oldValue, newValue ){
	console.log( "Pin <8> changed from " + oldValue + " to " + newValue );
});

var pin = 0;
setInterval( function(){

	// the set function without additional parameter sets the pin and update to the chip automatically
	// if you want to set more pins and only need to update after, you can pass an additional
	// false parameter. After you set all pins, call the update function, which sends all changes 
	// to the chip.

	s1.set( pin, 0, false );
	s0.set( pin++, 0, false );
	if( pin > 7 )
		pin = 0;

	s0.set( pin, 1, false );
	s1.set( pin, 1, false );
	s0.write();
	s1.write();

	// this function will read all input pins and check for changes
	// it there was a change, the linked callback function will be called
	s1.read();
}, 250);