Skip to content

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

Merged
merged 1 commit into from
Aug 3, 2020

Conversation

Flameeyes
Copy link
Contributor

@Flameeyes Flameeyes commented Jun 28, 2020

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.

@Flameeyes
Copy link
Contributor Author

This is "intended" on top of #28, in which case this is just a single commit :)

@dhalbert dhalbert requested a review from a team June 28, 2020 17:37
@caternuson
Copy link
Contributor

Is this PR essentially the same as #28 with the addition of the new MCP23016 code?

@Flameeyes
Copy link
Contributor Author

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.

@caternuson
Copy link
Contributor

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.

@Flameeyes
Copy link
Contributor Author

Opened #30.

@Flameeyes Flameeyes mentioned this pull request Jun 28, 2020
@Flameeyes Flameeyes changed the title Pull request for mcp23016 Add support for the old, deprecated MCP23016 expander, too. Jul 2, 2020
@Flameeyes Flameeyes force-pushed the mcp23016 branch 2 times, most recently from e7b2350 to f0b57af Compare July 21, 2020 13:18
@Flameeyes
Copy link
Contributor Author

Now that #28 is merged, this pull request has the single change (MCP23016 support).

@tannewt
Copy link
Member

tannewt commented Jul 21, 2020

@caternuson Mind reviewing this?

@FoamyGuy
Copy link
Contributor

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.

Copy link
Contributor

@caternuson caternuson left a 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.

@caternuson
Copy link
Contributor

@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.
Copy link
Contributor

@FoamyGuy FoamyGuy left a 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

mcp23016

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

@Flameeyes
Copy link
Contributor Author

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…

@caternuson
Copy link
Contributor

Nah, let's just merge this. Thanks for testing @FoamyGuy

@caternuson caternuson merged commit c05ae62 into adafruit:master Aug 3, 2020
@caternuson
Copy link
Contributor

@FoamyGuy wanna make a release?

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Aug 3, 2020

Yep, will do.

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants