Lapidus
Lapidus

Reputation: 925

Simple Raspberry PI 5 GPIO button reading does not work (NodeJS)

I'm trying to read a simple momentary push button on a Raspberry Pi 5 using NodeJS.

const button = new Gpio(538, 'in', 'both');
button.watch((error, value) => {
    console.log(error);
    console.log(value);
});

process.on('SIGINT', _ => {
    button.unexport();
});

The script runs without errors but whenever I connect pin 26 and GND nothing happens. What's going wrong?

enter image description here

Upvotes: 0

Views: 35

Answers (1)

Lapidus
Lapidus

Reputation: 925

Finally succeeded using the node-libgpiod package

import pkg from 'node-libgpiod';
const { Chip, Line } = pkg;

global.chip = new Chip(4);
global.line = new Line(chip, 2);

line.requestInputMode();

const cycle = () => {
    const value = line.getValue();
    console.log(value);
};

setInterval(cycle, 50);

Upvotes: 0

Related Questions