Adafruit LCD + keypad with interrupts

Hi,

I have an Adafruit 16x2 LCD display with keypad connected to the head node of a Raspberry Pi 3 cluster to show the status of the nodes in the cluster, selecting different options from a menu by reading button pushes. Currently reading button pushes involves a busy-wait loop which uses CPU cycles that I’d rather have available for other things. I would like to use interrupts but from the schematic it looks like the INTA and INTB interrupt pins of the MCP23017 are not connected to the Pi. Does anyone know whether using interrupts to read button pushes is possible with this kit?

Thanks, Kevin

Hi Kevin,

You could definitely do that, although it’s going to take some edits to the Adafruit libraries. Have a looksee around the functions they use for checking button states, along with how they manage debounces. Let us know how you get on!

Hi Graham,

In the ‘Adafruit LCD + Keypad’ kit, the I2C sits between the buttons and the GPIO of the Raspberry Pi. The only GPIO pins connected to the kit are +5V, GND, SDA (pin 3) and SCL (pin 5). Looking through the Adafruit libraries it seems that to determine if a button is pressed you need to actively read the contents of a register in the I2C. As the buttons are not directly connected to the GPIO I can’t see how they can be configured to directly generate an interrupt on the Pi when they change state. From my reading of the schematic it doesn’t look like the interrupt pins of the I2C are connected to the Pi so I don’t see how to indirectly cause an interrupt either.

I am very much a hardware amateur though and would like to be wrong. Any help is appreciated.

Thanks, Kevin

Hey Kevin,

In order to do what you want, you’re going to have to get pretty DIY. You could modify the HAT, and then modify the library as Graham mentioned to utilise interrupt functionality. Having said that, polling the I2C bus for incoming data isn’t going to take up that many clock cycles when you look at the clock speed of a Pi. It is possible to create software interrupts for the I2C bus, but that’s getting very low-level and beyond the realm of most makers.

Check out thread callbacks; a separate thread (python script) can run in parallel with your main script and then callback a specific function in the main script whenever it likes.

While the following content is not entirely your situation, they are a great step-by-step of how to’s for Python threads alongside Raspberry Pi peripherals

That’s the short of the long, plenty of reading and experimenting to be had. Let us know how you get on!

1 Like