@@ -10,6 +10,14 @@ This library provides a complete driver to control the MCP23009E I/O expander on
1010- ✅ ** Pin-compatible API** : ` MCP23009Pin ` class compatible with ` machine.Pin `
1111- ✅ ** Register access** : Low-level register access for advanced usage
1212
13+ ## I²C Address
14+
15+ The default I²C address is:
16+
17+ - ` 0x20 `
18+
19+ The STeaMi board uses this default address. : contentReference [ oaicite:3] { index =3 }
20+
1321## Quick Start
1422
1523### Basic Usage with MCP23009E class
@@ -85,62 +93,50 @@ def callback(pin):
8593btn.irq(handler = callback, trigger = MCP23009Pin.IRQ_FALLING | MCP23009Pin.IRQ_RISING )
8694```
8795
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-
10596## API Reference
10697
10798### MCP23009E Class
10899
109100#### Constructor
101+
110102``` python
111103MCP23009E(i2c, address, reset_pin, interrupt_pin = None )
112104```
113105
114106#### 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
107+
108+ * ` setup(gpx, direction, pullup, polarity) ` - Configure a GPIO
109+ * ` set_level(gpx, level) ` - Set output level
110+ * ` get_level(gpx) ` - Read input level
111+ * ` interrupt_on_change(gpx, callback) ` - Register change callback
112+ * ` interrupt_on_falling(gpx, callback) ` - Register falling edge callback
113+ * ` interrupt_on_raising(gpx, callback) ` - Register rising edge callback
114+ * ` disable_interrupt(gpx) ` - Disable interrupts on a GPIO
122115
123116### MCP23009Pin Class
124117
125118#### Constructor
119+
126120``` python
127121MCP23009Pin(mcp, pin_number, mode = - 1 , pull = - 1 , value = None )
128122```
129123
130124#### 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
125+
126+ * ` init(mode, pull, value) ` - (Re)configure the pin
127+ * ` value(x=None) ` - Get or set pin value
128+ * ` on() ` - Set pin high
129+ * ` off() ` - Set pin low
130+ * ` toggle() ` - Toggle pin state
131+ * ` irq(handler, trigger) ` - Configure interrupt
132+ * ` mode(mode=None) ` - Get or set mode
133+ * ` pull(pull=None) ` - Get or set pull configuration
139134
140135#### Constants
141- - ` MCP23009Pin.IN ` / ` MCP23009Pin.OUT ` - Pin modes
142- - ` MCP23009Pin.PULL_UP ` - Pull-up configuration
143- - ` MCP23009Pin.IRQ_FALLING ` / ` MCP23009Pin.IRQ_RISING ` - Interrupt triggers
136+
137+ * ` MCP23009Pin.IN ` / ` MCP23009Pin.OUT ` - Pin modes
138+ * ` MCP23009Pin.PULL_UP ` - Pull-up configuration
139+ * ` MCP23009Pin.IRQ_FALLING ` / ` MCP23009Pin.IRQ_RISING ` - Interrupt triggers
144140
145141### MCP23009ActiveLowPin Class
146142
@@ -153,8 +149,9 @@ The MCP23009E can sink more current (25mA) than it can source (~1mA). For LEDs a
153149```
154150
155151With ` MCP23009ActiveLowPin ` , the logic is automatically inverted:
156- - ` led.on() ` → GPIO LOW → LED lights up
157- - ` led.off() ` → GPIO HIGH → LED turns off
152+
153+ * ` led.on() ` → GPIO LOW → LED lights up
154+ * ` led.off() ` → GPIO HIGH → LED turns off
158155
159156#### Example
160157
@@ -170,4 +167,42 @@ led.off() # LED turns off (GPIO goes HIGH)
170167led.toggle() # Toggle LED state
171168```
172169
173- The API is identical to ` MCP23009Pin ` - just use ` MCP23009ActiveLowPin ` instead!
170+ The API is identical to ` MCP23009Pin ` - just use ` MCP23009ActiveLowPin ` instead.
171+
172+ ## Power Management
173+
174+ The driver provides simple hardware power management helpers through the reset pin:
175+
176+ ### Power off
177+
178+ ``` python
179+ mcp.power_off()
180+ ```
181+
182+ Holds the reset pin low.
183+
184+ ### Power on
185+
186+ ``` python
187+ mcp.power_on()
188+ ```
189+
190+ Releases the reset pin.
191+
192+ ### Reset
193+
194+ ``` python
195+ mcp.reset()
196+ ```
197+
198+ Toggles the reset pin to perform a hardware reset.
199+
200+ ## Examples
201+
202+ The library includes several examples:
203+
204+ * ` buttons.py ` - Simple button reading with polling
205+ * ` test_basic.py ` - Basic driver functionality tests
206+ * ` test_interrupts.py ` - Interrupt system demonstration
207+ * ` test_pin.py ` - MCP23009Pin class usage examples
208+ * ` test_pin_irq.py ` - Pin-compatible interrupt examples
0 commit comments