1

How do I declare a Python callback handler method on a MCP23008 input pin? This Adafruit tutorial, which uses CircuitPython shows how to read input from the extended GPIO pin on the MCP23008, but does not appear to have a callback/interrupt handler interface:

import board
import busio
import digitalio

from adafruit_mcp230xx.mcp23008 import MCP23008

i2c = busio.I2C(board.SCL, board.SDA) mcp = MCP23008(i2c) pin1 = mcp.get_pin(1) pin1.direction = digitalio.Direction.INPUT print(f"Value = {}", pin1.value)

I want to treat the GPIO pins on the MCP23008 just as I would treat GPIO pins on the Raspberry Pi, and bind a callback handler when the input changes, as in this example that uses RPi.GPIO:

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD) GPIO.setup(1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

def my_callback(channel): print('callback was called! This is what I want to do!')

GPIO.add_event_detect(7, GPIO.RISING, callback=my_callback, bouncetime=300)

(source)

I am currently using these versions, but I am open to other libraries.

adafruit-circuitpython-busdevice 5.1.1      
adafruit-circuitpython-mcp230xx  2.5.1 
JJ Zabkar
  • 111
  • 3

0 Answers0