pi4j and MCP23017 - reading and writing device registers

39 views
Skip to first unread message

dwa...@millersoftwaresolutions.com

unread,
Dec 24, 2017, 5:48:43 PM12/24/17
to Pi4J
I have connected an Adafruit 16x2 plate that uses the MCP23017 expander to control a 16x2 LCD display and read 5 pushbuttons.  All appears to be working fine.  After reading the specs for the MCP23017 expander, and reviewing the design documents for the Adafruit plate, I was trying to find a way to read the expander's Interrupt registers (there are two of them) to determine if a button press had generated an interrupt.

I had tried to use the listener feature of the MCP23017 provider, but doing so resulted in a lot of read and write exceptions due to multi-threaded aspect of my project's software.  Instead of using the listener, I thought that I would just read the state of the two interrupt registers to see if any pin had triggered an interrupt.  But have not seen any examples of how to do that.

The MCP23017 provider "MCP23017GpioProvider.java" has some internal use of some of the registers, but does not expose any public methods for reading or writing to registers.  Some things that would appear to require such register read/write capability:

  - set up device such that the two interrupt pins are mirrored,
  - configure the device to compare input pin state changes to a predefined state, or...
  - configure the device to compare input pin state changes to previous state
  - read the two interrupt registers to check for interrupts (reading also part of clearing interrupts).

I was about to embark on making/submitting a change the the provider class, but thought I would first check to see if this would violate rules for encapsulation or other OO paradigms.

Or... is there another way to check the internal registers?
Reply all
Reply to author
Forward
0 new messages