-
Notifications
You must be signed in to change notification settings - Fork 8
Closed
Description
Experiencing a quite weird effect and hoping you could help - I'm finding only some my pin bindings will work within my node application, but if I then test a Python script on the same pin numbers, I will start receiving those missing pin bindings inside my node app.
Here is the node code - where initially only OMNI and SKIPPREV (pins 8 and 7) will work:
const VOLUP = 'VOLUP'
const VOLDOWN = 'VOLDOWN'
const OMNI = 'OMNI'
const SKIPNEXT = 'SKIPNEXT'
const SKIPPREV = 'SKIPPREV'
const PLAYPAUSE = 'PLAYPAUSE'
const BTNS = {
12: VOLUP,
9: VOLDOWN,
8: OMNI,
11: SKIPNEXT,
10: PLAYPAUSE,
7: SKIPPREV
}
console.log( `[o-dsk] pins ${Object.keys(BTNS).join(',')}`)
const gpio = async e => {
let buttons = new RPiGPIOButtons( {
pins: Object.keys(BTNS),
mode: RPiGPIOButtons.MODE_BCM,
usePullUp: false,
debounce: 10,
pressed: 10,
clicked: 10
} )
buttons.on('pressed', async pin => {
let PIN = BTNS[pin]
console.log('[o-dsk] released', PIN)
})
buttons.on('clicked', async pin => {
let PIN = BTNS[pin]
console.log('[o-dsk] clicked', PIN)
})
buttons.on('released', async pin => {
let PIN = BTNS[pin]
console.log('[o-dsk] pressed', PIN)
})
buttons.init().catch(err => {
console.error('[o-dsk] error initialising buttons:', err.message)
})
}
Then once I run the following Python script the rest of the pins start working:
#!/usr/bin/env python
# sudo apt-get install python-dev python-rpi.gpio
import RPi.GPIO as GPIO
from time import sleep
import signal, os, subprocess, sys
buttons = [26,24,21,19,23,32,7,8,9,10,11,12]
def button_pressed(channel):
print("BUTTON PRESSED")
print(channel)
def unregister_events():
for pin in buttons:
GPIO.remove_event_detect(pin)
if __name__ == '__main__':
signal.signal(signal.SIGINT, unregister_events)
try:
GPIO.setmode(GPIO.BCM)
for pin in buttons:
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(pin, GPIO.RISING, callback=button_pressed, bouncetime=200)
while True:
sleep(10)
except Exception as e:
print("Caught exception:", e)
unregister_events()
Wondering if its to do with leftover states or bindings - I've tried clearing with destroy function and also unregistering pins with echo "11" > /sys/class/gpio/unexport etc, but it's only the Python script which gets it working again.
Metadata
Metadata
Assignees
Labels
No labels