feb. 2022 | Matthieu Savary

NodeJS package to retrieve rotary encoder data from GPIO on Raspberry Pi

Event-based NodeJS package that relies on the onoff lib to get rotary encoder data from GPIO pins on Raspberry Pi.

 

On Github

Changelog

Latest changes pushed on feb. 2022

✔︎ Initial commit

How-to

Based off https://github.com/nstansby/rpi-rotary-encoder-python & https://github.com/pichfl/onoff-rotary: event-based NodeJS lib that relies on https://github.com/fivdi/onoff to get rotary encoder (such as https://thepihut.com/products/rotary-encoder-extras) data from GPIO pins on Raspberry Pi.

Installation

npm i nodary-encoder --save

Usage

const nodaryEncoder = require('nodary-encoder');
const myEncoder = nodaryEncoder(17, 18); // Using GPIO17 & GPIO18

myEncoder.on('rotation', (direction, value) => {
  if (direction == 'R') {
    console.log('Encoder rotated right');
  } else {
    console.log('Encoder rotated left');
  }

  console.log('Value is', value);
});

What it should look like

Well, more or less anyway. Enjoy!

open source Raspberry Pi Raspbian RasPi Linux Tinkering rotary encoder NodeJS

Contact