Native nodejs bindings for libgpiod
You need, to get started:
- An SBC running a modern linux
- Node.js (version 12 or newer) installed with devel headers
- Linux libgpiod (version 1.5 or 1.6) installed with devel headers
- C++ and Python tooling installed
Install the dependencies on your system:
sudo dnf install @development-tools g++ \
libgpiod libgpiod-devel libgpiod-utils \
nodejs nodejs-develsudo zypper in -t pattern devel_basis
sudo zypper in libgpiod libgpiod-devel libgpiod-utils
sudo zypper in nodejs-default nodejs-devel-defaultsudo apt install build-essential gpiod libgpiod2 \
libgpiod-dev libnode-dev nodejs npmNow, in your npm project, install the library:
npm i node-libgpiodThe native part will be compiled during the installation.
Do the hello world:
// blink.js
import gpio from 'node-libgpiod'
const chip = new gpio.Chip(0)
const led = chip.getLine(20)
led.requestOutputMode()
let count = 5
const interval = setInterval(() => {
if(count > 0) {
const v = count-- % 2
led.setValue(v)
console.log(`blink ${v}!`)
} else {
led.setValue(0)
led.release()
clearInterval(interval)
}
}, 1000)Check out or complete documentation.