fivdi / pigpio

Fast GPIO, PWM, servo control, state change notification and interrupt handling with Node.js on the Raspberry Pi
MIT License
943 stars 89 forks source link

Not working with lastest Raspberry pi OS 64bits (Bookworm) #154

Open lavoiekeven opened 5 months ago

lavoiekeven commented 5 months ago

I had a projet with this library and It was working well last year. Now I'm setuping a new raspberry pi with Raspberry OS Lite 64 bits and I got this error:

Error: pigpio error -123 in gpioSetISRFunc at Gpio.enableInterrupt (/home/cdl/gateopener2/server/node_modules/pigpio/pigpio.js:264:12) at new Gpio (/home/cdl/gateopener2/server/node_modules/pigpio/pigpio.js:173:12)

It happen here:

this._gpio = new Gpio(gpioPin, { mode: Gpio.INPUT, pullUpDown: Gpio.PUD_DOWN, edge: Gpio.EITHER_EDGE });

I tried many pin all the same result.

I also start my app sudo.

Any ideas of what can be my problem?

lavoiekeven commented 4 months ago

Ok by removing "edge: Gpio.EITHER_EDGE" it is working.

optikalefx commented 4 months ago

@lavoiekeven could you share any sample code you're using? I'm trying to get a simple button working and I had the same error as you. The error goes away when making the change you suggested, but the button doesn't seem to do anything.

I'm doing this

const Gpio = require('pigpio').Gpio;

const button = new Gpio(4, {
  mode: Gpio.INPUT,
  pullUpDown: Gpio.PUD_DOWN,
});

button.on('interrupt', (level) => {
  console.log('level', level);
});

Button is plugged into GPIO4 and GND

The log never happens

lavoiekeven commented 4 months ago

Hi, interrupt is not working ether.

So I used alert instead

exemple in TS

` import { Device } from "./Device"; const Gpio = require('pigpio').Gpio;

type AlertCallback = (level: 0 | 1) => void;

export class ContactSensor extends Device {
    private _gpioPin: any;
    private _gpio: any;
    private _alertCallback: AlertCallback;
    /**
     * 
     * @param {*} name 
     * @param {*} gpiopin 
     */
    constructor(name: string, gpioPin: number, callback: AlertCallback | null) {
        super(name, "sensor", false)
        this._gpioPin = gpioPin;
        this._gpio = new Gpio(gpioPin, { mode: Gpio.INPUT, pullUpDown: Gpio.PUD_DOWN });
        this._alertCallback = callback

        this._gpio.on('alert', (level) => {
            console.log(this.name + ' triggered');

            if (this._alertCallback)
                this._alertCallback(level);

            console.log(this.name + ' level changed ' + level);
        });

        this._gpio.enableAlert();
    }

    get gpioPin(): number {
        return this._gpioPin;
    }

    getLevel(): 0 | 1 {
        return this._gpio.digitalRead();
    }
}

`

grevelle commented 3 months ago

Is this project being maintained at this point?

lavoiekeven commented 3 months ago

I guess not, but once i used alert rather than interrupt, the library work well in my case on. Personaly, I didn't find other library that worked that well for what I wanted to do.

grevelle commented 3 months ago

I am a huge fan of this library - it's the most powerful for hardware pwm IMHO. I use it extensively. The march bookworm update put me in a boot loop and I need to figure out the problem. I use alerts in my code already so glad to hear that's not the problem.

UPDATE: The boot loop problem I refer to above is due to a change in how the RPI deals with config.txt. This line worked in the December 2023 pi OS release, but would not boot in the March 2024 release. After some research I learned that this code, which puts the i2c and SPI pins into alt0 mode, is not necessary as it is handled separately by the OS config for those functions.

# Select Alt0 for GPIO pins
gpio=0-3,8-11=a0
grevelle commented 3 weeks ago

I am having the same issue w/ interrupt vs. alert. I can get alerts to work but not interrupts.