@@ -4,11 +4,15 @@ This library provides a complete driver to control the MCP23009E I/O expander on
44
55## Features
66
7- - ✅ ** Full GPIO control** : Configure pins as input/output, read/write levels
8- - ✅ ** Pull-up resistors** : Built-in pull-up support
9- - ✅ ** Interrupt support** : Hardware interrupts with callback system
10- - ✅ ** Pin-compatible API** : ` MCP23009Pin ` class compatible with ` machine.Pin `
11- - ✅ ** Register access** : Low-level register access for advanced usage
7+ - ** Full GPIO control** : Configure pins as input/output, read/write levels
8+ - ** Pull-up resistors** : Built-in pull-up support
9+ - ** Interrupt support** : Hardware interrupts with callback system
10+ - ** Pin-compatible API** : ` MCP23009Pin ` class compatible with ` machine.Pin `
11+ - ** Register access** : Low-level register access for advanced usage
12+
13+ ## I²C Address
14+
15+ The base I²C address is \` 0x20\` (A0=A1=A2=LOW). On the STeaMi board, the address is \` 0x20\` .
1216
1317## Quick Start
1418
@@ -85,62 +89,50 @@ def callback(pin):
8589btn.irq(handler = callback, trigger = MCP23009Pin.IRQ_FALLING | MCP23009Pin.IRQ_RISING )
8690```
8791
88- ## Examples
89-
90- The library includes several examples:
91-
92- - ` buttons.py ` - Simple button reading with polling
93- - ` test_basic.py ` - Basic driver functionality tests
94- - ` test_interrupts.py ` - Interrupt system demonstration
95- - ` test_pin.py ` - MCP23009Pin class usage examples
96- - ` test_pin_irq.py ` - Pin-compatible interrupt examples
97-
98- Run examples with [ mpremote] ( https://docs.micropython.org/en/latest/reference/mpremote.html ) :
99-
100- ``` sh
101- mpremote mount . run examples/buttons.py
102- mpremote mount . run examples/test_pin.py
103- ```
104-
10592## API Reference
10693
10794### MCP23009E Class
10895
10996#### Constructor
97+
11098``` python
11199MCP23009E(i2c, address, reset_pin, interrupt_pin = None )
112100```
113101
114102#### Main Methods
115- - ` setup(gpx, direction, pullup, polarity) ` - Configure a GPIO
116- - ` set_level(gpx, level) ` - Set output level
117- - ` get_level(gpx) ` - Read input level
118- - ` interrupt_on_change(gpx, callback) ` - Register change callback
119- - ` interrupt_on_falling(gpx, callback) ` - Register falling edge callback
120- - ` interrupt_on_raising(gpx, callback) ` - Register rising edge callback
121- - ` disable_interrupt(gpx) ` - Disable interrupts on a GPIO
103+
104+ * ` setup(gpx, direction, pullup, polarity) ` - Configure a GPIO
105+ * ` set_level(gpx, level) ` - Set output level
106+ * ` get_level(gpx) ` - Read input level
107+ * ` interrupt_on_change(gpx, callback) ` - Register change callback
108+ * ` interrupt_on_falling(gpx, callback) ` - Register falling edge callback
109+ * ` interrupt_on_raising(gpx, callback) ` - Register rising edge callback
110+ * ` disable_interrupt(gpx) ` - Disable interrupts on a GPIO
122111
123112### MCP23009Pin Class
124113
125114#### Constructor
115+
126116``` python
127117MCP23009Pin(mcp, pin_number, mode = - 1 , pull = - 1 , value = None )
128118```
129119
130120#### Methods (machine.Pin compatible)
131- - ` init(mode, pull, value) ` - (Re)configure the pin
132- - ` value(x=None) ` - Get or set pin value
133- - ` on() ` - Set pin high
134- - ` off() ` - Set pin low
135- - ` toggle() ` - Toggle pin state
136- - ` irq(handler, trigger) ` - Configure interrupt
137- - ` mode(mode=None) ` - Get or set mode
138- - ` pull(pull=None) ` - Get or set pull configuration
121+
122+ * ` init(mode, pull, value) ` - (Re)configure the pin
123+ * ` value(x=None) ` - Get or set pin value
124+ * ` on() ` - Set pin high
125+ * ` off() ` - Set pin low
126+ * ` toggle() ` - Toggle pin state
127+ * ` irq(handler, trigger) ` - Configure interrupt
128+ * ` mode(mode=None) ` - Get or set mode
129+ * ` pull(pull=None) ` - Get or set pull configuration
139130
140131#### Constants
141- - ` MCP23009Pin.IN ` / ` MCP23009Pin.OUT ` - Pin modes
142- - ` MCP23009Pin.PULL_UP ` - Pull-up configuration
143- - ` MCP23009Pin.IRQ_FALLING ` / ` MCP23009Pin.IRQ_RISING ` - Interrupt triggers
132+
133+ * ` MCP23009Pin.IN ` / ` MCP23009Pin.OUT ` - Pin modes
134+ * ` MCP23009Pin.PULL_UP ` - Pull-up configuration
135+ * ` MCP23009Pin.IRQ_FALLING ` / ` MCP23009Pin.IRQ_RISING ` - Interrupt triggers
144136
145137### MCP23009ActiveLowPin Class
146138
@@ -153,8 +145,9 @@ The MCP23009E can sink more current (25mA) than it can source (~1mA). For LEDs a
153145```
154146
155147With ` MCP23009ActiveLowPin ` , the logic is automatically inverted:
156- - ` led.on() ` → GPIO LOW → LED lights up
157- - ` led.off() ` → GPIO HIGH → LED turns off
148+
149+ * ` led.on() ` → GPIO LOW → LED lights up
150+ * ` led.off() ` → GPIO HIGH → LED turns off
158151
159152#### Example
160153
@@ -170,4 +163,52 @@ led.off() # LED turns off (GPIO goes HIGH)
170163led.toggle() # Toggle LED state
171164```
172165
173- The API is identical to ` MCP23009Pin ` - just use ` MCP23009ActiveLowPin ` instead!
166+ The API is identical to ` MCP23009Pin ` - just use ` MCP23009ActiveLowPin ` instead.
167+
168+ ## Power Management
169+
170+ The driver provides simple hardware power management helpers through the reset pin:
171+
172+ ### Power off
173+
174+ ``` python
175+ mcp.power_off()
176+ ```
177+
178+ Holds the reset pin low.
179+
180+ ### Power on
181+
182+ ``` python
183+ mcp.power_on()
184+ ```
185+
186+ Releases the reset pin.
187+
188+ ### Reset
189+
190+ ``` python
191+ mcp.reset()
192+ ```
193+ Toggles the reset pin to perform a hardware reset.
194+
195+ ## Examples
196+
197+ The library includes several examples:
198+
199+ * ` buttons.py ` - Simple button reading with polling
200+ * ` i2c_scan.py ` - Scan I2C buses for connected devices
201+ * ` test_basic.py ` - Basic driver functionality tests
202+ * ` test_interrupts.py ` - Interrupt system demonstration
203+ * ` test_led_simple.py ` - Basic active-low LED control example
204+ * ` test_output_active_low.py ` - Active-low output tests with inverted logic
205+ * ` test_output.py ` - GPIO output tests using low-level and Pin APIs
206+ * ` test_pin.py ` - MCP23009Pin class usage examples
207+ * ` test_pin_irq.py ` - Pin-compatible interrupt examples
208+
209+
210+ ### How to run
211+
212+ ``` python
213+ mpremote mount lib/ mcp23009e run lib/ mcp23009e/ examples/ test_basic.py
214+ ```
0 commit comments