micropython-mcp23017 icon indicating copy to clipboard operation
micropython-mcp23017 copied to clipboard

Will this work for MCP23008

Open ilium007 opened this issue 4 years ago • 8 comments
trafficstars

Unfortunately doesn't seem to work for MCP23008. Was able to create the mcp object but can't configure a pin for input or output.

ilium007 avatar Feb 28 '21 07:02 ilium007

>>> mcp = mcp23017.MCP23017(i2c, 0x20)
>>> i2c
I2C(1, scl=B6, sda=B7, freq=420000)
>>> mcp
<MCP23017 object at 2000bcf0>
>>> mcp.pin(1, mode=1, pullup=True)
False
>>>

ilium007 avatar Mar 01 '21 09:03 ilium007

MCP23008 is a single 8-bit port variant of the MCP23017. While one would expect it to behave similar, if not the same, there's a bunch of code in the library expects to two ports.

I don't have any MCP23008 chips/modules to test with, but I could fork this and rip out all of the 2nd port code if you're able to test it and confirm it all works. Sorry I missed this issue earlier. It's been a while. Are you still interested in the MCP23008?

mcauser avatar Jul 29 '22 02:07 mcauser

@mcauser I recently started a project with both a MCP23008 and a MCP23017. I was looking for a library for the MCP23008 but there's not much out there. I'd be very interested in helping you test this if you made a port for the MCP23008.

plmetz avatar Dec 05 '22 21:12 plmetz

Hi @plmetz , See https://github.com/mcauser/micropython-mcp23008 It's a fork of the current library with all of the PortB code removed.

I haven't tested it on any hardware yet, or written up any documentation. It should work. If you're able to do some testing, that would be awesome! Refer to the readme of this library for examples how to use it, with only the first 8 bits/pins available.

import mcp23008
mcp = mcp23008.MCP23008(i2c, 0x20)

List interface

mcp[0].value()
...
mcp[7].value()

Method interface

mcp.pin(0)
...
mcp.pin(7)

Property interface

mcp.mode = 0xfe
mcp.gpio = 0x01

mcauser avatar Dec 05 '22 22:12 mcauser

Thanks for pulling that library together. It works wonderfully, as far as I can tell. I am a hobbyist just getting started with electronics and python, so by no means an expert, but I did some testing, and on the MCP23008, I was able to:

  • confirm proper input and output functioning of the pins
  • access pins through the list interface and the method interface
  • set and read properties
  • set and use an interrupt

If there is any other specific testing that you think would be warranted I'd be happy to try.

What is your plan with the MCP23008 library? Leave it as a standalone or would you integrate it into this library? Or a "MCP230x" library?

plmetz avatar Dec 07 '22 02:12 plmetz

Hey, there's not a huge difference between them and the MCP23017 was well tested, so it should be good to go. I'll add documentation and examples soon. Could use some examples/tutorials for using things like rotary encoders.

There's a lot of overlap between the two libraries, so a common MCP230x may make sense down the track. The libraries are already quite large, so it would have to be done in a way that doesn't negatively impact each other.

I'll leave MCP23008 as is for now and add some readmes/docs to make it more complete. Then add a common ancestor to the backlog.

mcauser avatar Dec 07 '22 02:12 mcauser

I'm also able to submit some PRs for the documentation. As I work on my project with it I should also be able to get an example together. It's a busy time of year so might not be right away but I'd love to help.

plmetz avatar Dec 08 '22 11:12 plmetz

I wrote an example for the MCP23008

https://github.com/mcauser/micropython-mcp23008/issues/1

cpu012 avatar Oct 04 '23 23:10 cpu012