Skip to content

Access a MPR121 breakout using Node.js from a Raspberry Pi or BeagleBone Black.

License

Notifications You must be signed in to change notification settings

adafruit/node_mpr121

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MPR121 Library for Node.js

Access a MPR121 breakout using Node.js from a Raspberry Pi or BeagleBone Black.

Installation

This library requires Node.js v6.0.0 or higher.

$ npm install adafruit-mpr121

Detailed Installation for Raspberry Pi

On a Raspberry Pi configure I2C following these instructions. E.g.

sudo apt-get update
sudo apt full-upgrade -y
sudo apt-get install i2c-tools

Make sure you follow these steps to enable autoloading of I2C Kernel module.

Install Node.js if not yet installed, e.g. to install Node v10:

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

Reboot for above changes to take affect:

sudo reboot

You can check Node version like this:

node -v
# v10.11.0

To install adafruit-mpr121 in your own Node app:

mkdir myapp
cd myapp
npm init
npm install adafruit-mpr121 --save

To run node in interactive mode on command line:

node

Example code below should now work.

Example

const MPR121 = require('adafruit-mpr121'),
      mpr121  = new MPR121(0x5A, 1);

// listen for touch events
mpr121.on('touch', (pin) => console.log(`pin ${pin} touched`));

// listen for release events
mpr121.on('release', (pin) => console.log(`pin ${pin} released`));

// listen for changes to the state of a specific pin
mpr121.on(3, (state) => console.log(`pin 3 is ${state ? 'touched' : 'released'}`));

// check the current state of a specific pin synchronously
const state = mpr121.isTouched(2);
console.log(`pin 2 is ${state ? 'touched' : 'released'}`);

License

Copyright (c) 2016 Adafruit Industries. Licensed under the MIT license.

About

Access a MPR121 breakout using Node.js from a Raspberry Pi or BeagleBone Black.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •