morrisonj
New member
I'm having trouble using the interrupt feature on a new v3.0 Sixteen LV Digital Input hat (https://sequentmicrosystems.com/products/16-universal-inputs-card-for-raspberry-pi) with Python 3. Here's my code:
The interrupt triggers when I press the onboard button but not when one of the inputs change state. I have a few 24v powered switches connected to inputs 14,15 and 16 on the hat and they function as expected when I switch them and read the input with "16inpind 1 rd 14" etc... They'll output 0 when off and 1 when on.
If it makes any difference I have a sixteen relay hat (early version 1 perhaps) set to id 0 also connected to the Pi. the sixteen LV digital hat is set to id 1. I originally tried to get this working with a different v1.0 input hat and couldn't so I upgraded to the v3.0 board in case that was the issue.
Can anyone spot anything obvious I'm doing wrong or does anyone have any suggestions? Thanks in advance.
Python:
import RPi.GPIO as GPIO
import time
# Pin setup
GPIO.setmode(GPIO.BCM) # Use BCM pin numbering
pin = 26 # GPIO26 according to docs.
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set pin as input with pull-up resistor
# Callback function to run on pin state change
def gpio_callback(channel):
print(f"GPIO {channel} state changed!")
# Add event detection on the pin
GPIO.add_event_detect(pin, GPIO.BOTH, callback=gpio_callback, bouncetime=200)
try:
print("Waiting for GPIO events...")
while True:
time.sleep(1) # Keep the program running
except KeyboardInterrupt:
print("Exiting...")
finally:
GPIO.cleanup() # Clean up GPIO settings
The interrupt triggers when I press the onboard button but not when one of the inputs change state. I have a few 24v powered switches connected to inputs 14,15 and 16 on the hat and they function as expected when I switch them and read the input with "16inpind 1 rd 14" etc... They'll output 0 when off and 1 when on.
If it makes any difference I have a sixteen relay hat (early version 1 perhaps) set to id 0 also connected to the Pi. the sixteen LV digital hat is set to id 1. I originally tried to get this working with a different v1.0 input hat and couldn't so I upgraded to the v3.0 board in case that was the issue.
Can anyone spot anything obvious I'm doing wrong or does anyone have any suggestions? Thanks in advance.