-
Notifications
You must be signed in to change notification settings - Fork 36
Add support for the old, deprecated MCP23016 expander, too. #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is "intended" on top of #28, in which case this is just a single commit :) |
Is this PR essentially the same as #28 with the addition of the new MCP23016 code? |
Yep. I split the two because I think the other one is uncontroversial, and this one I'm not sure. In the sense that I don't know if supporting MCP23016 (which is no longer recommended, but slightly cheaper) fits into the library's roadmap. |
I'd suggest pausing on this PR and opening an issue for "Adding support for MCP23016". A discussion could then be had there about adding MCP23016 support. |
Opened #30. |
e7b2350
to
f0b57af
Compare
Now that #28 is merged, this pull request has the single change (MCP23016 support). |
@caternuson Mind reviewing this? |
The details of the code / implementation are a bit above my head still, so I don't think I have much to offer in that area. But I did grab a few of these ICs with a recent DigiKey order with the intention of testing the functionality of this PR with them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor cosmetic change.
@FoamyGuy If you can test, that would be great :) |
The main difference with the '17 is that it lacks advanced interrupt control features, and pull-up configuration. This includes changes to DigitalInOut to raise ValueError when trying to set pull-up configuration as well as pull-down, on the MCP23016 only. Note that for compatibility with the already existing '17 module, and for an eventual '18 module, the ports are called A and B, rather than 0 and 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to get this working. The library changes seem to be working correctly as far as I can tell.
Thank you for adding support for this version of the IC!
I tested all 16 IO pins on output in sets of 4 at a time. And I tested input using external pull up resistor on 1 of the IO pins
I tested with this code:
import time
import board
import busio
import digitalio
from adafruit_mcp230xx.mcp23016 import MCP23016
# Initialize the I2C bus:
i2c = busio.I2C(board.SCL, board.SDA)
mcp = MCP23016(i2c)
pin_nums = [12,13,14,15]
pins = []
pin8 = mcp.get_pin(8)
pin8.direction = digitalio.Direction.INPUT
for pin in pin_nums:
pins.append(mcp.get_pin(pin))
for pin in pins:
# Setup pin0 as an output that's at a high logic level.
pin.switch_to_output(value=True)
# Now loop blinking the pin 0 output and reading the state of pin 1 input.
while True:
for i, pin in enumerate(pins):
pin.value = i % 2 == 0
time.sleep(0.5)
for i, pin in enumerate(pins):
pin.value = i % 2 != 0
time.sleep(0.5)
# Read pin 1 and print its state.
print("Pin 8 is at a high level: {0}".format(pin8.value))
It would probably good eventually to add this variant to the example script. And possibly document the required wiring setup to get it working
Can this be merged as is for now, or should I try adding more documentation first? I mean technically the MCP23018 is still missing too, but I don't have one of those at hand… |
Nah, let's just merge this. Thanks for testing @FoamyGuy |
@FoamyGuy wanna make a release? |
Yep, will do. |
Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx to 2.4.0 from 2.3.3: > Merge pull request adafruit/Adafruit_CircuitPython_MCP230xx#29 from Flameeyes/mcp23016
The main difference with the '17 is that it lacks advanced interrupt
control features, and pull-up configuration.
This includes changes to DigitalInOut to raise ValueError when trying to
set pull-up configuration as well as pull-down, on the MCP23016 only.
Note that for compatibility with the already existing '17 module, and for
an eventual '18 module, the ports are called A and B, rather than 0 and 1.