Closed uxhamby closed 2 years ago
I added some docs about the different interfaces here: https://github.com/mcauser/micropython-mcp23017/tree/master/examples/interfaces
There's 3 interfaces, list, method and property, each with their strengths.
The list interface gives you a list of 16 virtual pin objects, which are each just an abstraction layer to represent a single pin. When you want to configure multiple pins, you have to call the config methods on each virtual pin.
The method interface is similar to the list interface, only there is only 1 pin central method used to control the IOs, and you need to tell it which specific pin you wish to control. Configuring multiple pins means calling the method multiple times. Someone coming from Arduino would probably be most comfortable with this pattern.
The property interface is more advanced and lets you fiddle with the bits of each port register directly. There are 11x 16-bit registers you can read and write to. You can reconfigure multiple pins in a single call.
I'm going to add more examples and if you have any suggestions or specific examples you'd like to see, let me know.
The pin method for configuring a single pin inside one of the two 8bit ports.
mcp.pin(0, mode=1)
The first argument is the pin number. eg. 0 is the first pin in the port A. 15 would be the last pin in port B.
The rest of the optional and when provided set features on the port for this pin.
The config method is for setting features for the entire chip.
mcp.config(interrupt_polarity=0, interrupt_mirror=1)
Similar to pin(), all arguments are optional. Any provided will configure the device.
Great library - thanks very much.
I can't figure out how to configure an output pin as open-drain? Can you provide an example?
Thanks in advance.
Hi @kwijibo007 On the MCP23017 only the INT pins can be configured as OD.
mcp.config(interrupt_open_drain=1)
If you want the GPIOs to be configurable as OD, checkout the MCP23018: https://www.microchip.com/wwwproducts/en/MCP23018 http://ww1.microchip.com/downloads/en/devicedoc/22103a.pdf
Cheers @mcauser, I'll take a look. Does your library work with the MCP23018?
Appreciate your help.
Looks like they have the same registers, so should be mostly compatible. https://piers.rocks/i2c/mcp23016/mcp23017/gpio/2018/09/11/differences-between-mcp23017-and-mcp23018.html
Thanks, if I give it a crack I'll report back.
I am finding the documentation text on this a bit esoteric, especially as concerning the 'virtual ports'. Are any more examples available for study? Thanks and best regards.