Hi,
i was wondering if it is possible to set an i/o port pin to generate a software interrupt. i am new on the Pi and have done this on the arduino, any pointers would be much appreciated.
Hi,
i was wondering if it is possible to set an i/o port pin to generate a software interrupt. i am new on the Pi and have done this on the arduino, any pointers would be much appreciated.
I got this Python example from Copilot:
import RPi.GPIO as GPIO
import time
# Pin configuration
BUTTON_GPIO = 16
# Callback function for the interrupt
def button_callback(channel):
print("Button pressed!")
# Setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Add interrupt detection
GPIO.add_event_detect(BUTTON_GPIO, GPIO.FALLING, callback=button_callback, bouncetime=200)
try:
# Keep the program running
while True:
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
This code sets up GPIO 16 to detect a FALLING edge (button press) and calls the button_callback function when the event occurs.