Overview
This is the documentation on node-libgpiod. Here ypu find the minimum needed to make yur SBC rig blink things with ease using node.js.
Quickstart
You need, to get started:
- An SBC running a modern linux
- Node.js installed with devel headers
- Linux libgpiod installed with devel headers
- C++ and Python tooling installed
Installing requirements
Install the dependencies on your system:
bash
sudo dnf install @development-tools g++ \
libgpiod libgpiod-devel libgpiod-utils \
nodejs nodejs-develbash
sudo zypper in -t pattern devel_basis
sudo zypper in libgpiod libgpiod-devel libgpiod-utils
sudo zypper in nodejs-default nodejs-devel-defaultbash
sudo apt install build-essential gpiod libgpiod2 \
libgpiod-dev libnode-dev nodejs npmInstall the npm dependency
Now, in your npm project, install the library:
bash
npm i node-libgpiodThe native part will be compiled during the installation.
Blink a led
Do the hello world:
javascript
// blink.js
import { Chip } from 'node-libgpiod'
const chip = new Chip(0)
const led = chip.getLine(21)
led.requestOutputMode()
let count = 5
const interval = setInterval(() => {
if(count > 0) led.setValue(count-- % 2)
else led.release()
}, 1000)
while(led.used){
// console.log('hardware resources still being used')
}
clearInterval(interval)