mcp230xx
CircuitPython module for the MCP23017, MCP23008 I2C and MCP23S17, MCP23S08 SPI I/O extenders.
Author(s): Red_M
- class adafruit_mcp230xx.mcp23xxx.MCP23XXX(bus_device: I2C | SPI, address: int, chip_select: digitalio.DigitalInOut | None = None, baudrate: int = 100000)
Base class for MCP23xxx devices.
mcp230xx
CircuitPython module for the MCP23017 and MCP23008 I2C I/O extenders.
Author(s): Tony DiCola, Red_M (2021)
- class adafruit_mcp230xx.mcp230xx.MCP230XX(bus_device: I2C | SPI, address: int, chip_select: digitalio.DigitalInOut | None = None, baudrate: int = 100000)
Base class for MCP230xx devices.
mcp23008
CircuitPython module for the MCP23008 I2C I/O extenders.
Author(s): Tony DiCola
Implementation Notes
Hardware:
- class adafruit_mcp230xx.mcp23008.MCP23008(i2c: I2C, address: int = micropython.const, reset: bool = True)
Supports MCP23008 instance on specified I2C bus and optionally at the specified I2C address.
- get_pin(pin: int) DigitalInOut
Convenience function to create an instance of the DigitalInOut class pointing at the specified pin of this MCP23008 device.
- property gpio: int
The raw GPIO output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
mcp23016
CircuitPython module for the MCP23016 I2C I/O extenders.
Author(s): Diego Elio Pettenò (based on MCP23017.py)
Notes
While the datasheet refers to the two 8-bit ports as port 0 and 1, for API compatibility with more recent expanders, these are exposed as ports A and B.
- class adafruit_mcp230xx.mcp23016.MCP23016(i2c: I2C, address: int = micropython.const, reset: bool = True)
Supports MCP23016 instance on specified I2C bus and optionally at the specified I2C address.
- get_pin(pin: int) DigitalInOut
Convenience function to create an instance of the DigitalInOut class pointing at the specified pin of this MCP23016 device.
- property gpio: int
The raw GPIO output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
- property gpioa: int
The raw GPIO 0 output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
- property gpiob: int
The raw GPIO 1 output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
- property iodir: int
The raw IODIR direction register. Each bit represents direction of a pin, either 1 for an input or 0 for an output mode.
mcp23017
CircuitPython module for the MCP23017 I2C I/O extenders.
Author(s): Tony DiCola
Implementation Notes
Hardware:
- class adafruit_mcp230xx.mcp23017.MCP23017(i2c: I2C, address: int = micropython.const, reset: bool = True)
Supports MCP23017 instance on specified I2C bus and optionally at the specified I2C address.
- property default_value: int
The raw DEFVAL interrupt control register. The default comparison value is configured in the DEFVAL register. If enabled (via GPINTEN and INTCON) to compare against the DEFVAL register, an opposite value on the associated pin will cause an interrupt to occur.
- get_pin(pin: int) DigitalInOut
Convenience function to create an instance of the DigitalInOut class pointing at the specified pin of this MCP23017 device.
- property gpio: int
The raw GPIO output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
- property gpioa: int
The raw GPIO A output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
- property gpiob: int
The raw GPIO B output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
- property gppu: int
The raw GPPU pull-up register. Each bit represents if a pull-up is enabled on the specified pin (1 = pull-up enabled, 0 = pull-up disabled). Note pull-down resistors are NOT supported!
- property gppua: int
The raw GPPU A pull-up register. Each bit represents if a pull-up is enabled on the specified pin (1 = pull-up enabled, 0 = pull-up disabled). Note pull-down resistors are NOT supported!
- property gppub: int
The raw GPPU B pull-up register. Each bit represents if a pull-up is enabled on the specified pin (1 = pull-up enabled, 0 = pull-up disabled). Note pull-down resistors are NOT supported!
- property int_cap: List[int]
Returns a list with the pin values at time of interrupt port A —-> pins 0-7 port B —-> pins 8-15
- property int_flag: List[int]
Returns a list with the pin numbers that caused an interrupt port A —-> pins 0-7 port B —-> pins 8-15
- property int_flaga: List[int]
Returns a list of pin numbers that caused an interrupt in port A pins: 0-7
- property int_flagb: List[int]
Returns a list of pin numbers that caused an interrupt in port B pins: 8-15
- property interrupt_configuration: int
The raw INTCON interrupt control register. The INTCON register controls how the associated pin value is compared for the interrupt-on-change feature. If a bit is set, the corresponding I/O pin is compared against the associated bit in the DEFVAL register. If a bit value is clear, the corresponding I/O pin is compared against the previous value.
- property interrupt_enable: int
The raw GPINTEN interrupt control register. The GPINTEN register controls the interrupt-on-change feature for each pin. If a bit is set, the corresponding pin is enabled for interrupt-on-change. The DEFVAL and INTCON registers must also be configured if any pins are enabled for interrupt-on-change.
- property io_control: int
The raw IOCON configuration register. Bit 1 controls interrupt polarity (1 = active-high, 0 = active-low). Bit 2 is whether irq pin is open drain (1 = open drain, 0 = push-pull). Bit 3 is unused. Bit 4 is whether SDA slew rate is enabled (1 = yes). Bit 5 is if I2C address pointer auto-increments (1 = no). Bit 6 is whether interrupt pins are internally connected (1 = yes). Bit 7 is whether registers are all in one bank (1 = no), this is silently ignored if set to
1
.
- property iodir: int
The raw IODIR direction register. Each bit represents direction of a pin, either 1 for an input or 0 for an output mode.
- property iodira: int
The raw IODIR A direction register. Each bit represents direction of a pin, either 1 for an input or 0 for an output mode.
- property iodirb: int
The raw IODIR B direction register. Each bit represents direction of a pin, either 1 for an input or 0 for an output mode.
- property ipol: int
The raw IPOL output register. Each bit represents the polarity value of the associated pin (0 = normal, 1 = inverted), assuming that pin has been configured as an input previously.
mcp23sxx
CircuitPython module for the MCP23S17 SPI I/O extenders.
Author(s): Romy Bompart (2020), Red_M (2021)
- class adafruit_mcp230xx.mcp23sxx.MCP23SXX(spi: SPI, address: int, chip_select: digitalio.DigitalInOut, baudrate: int = 100000)
Base class for MCP23Sxx devices.
MCP23S08
CircuitPython module for the MCP23S08 I2C I/O extenders.
Author(s): Tony DiCola, Romy Bompart (2020), Red_M (2021)
- class adafruit_mcp230xx.mcp23s08.MCP23S08(spi: SPI, chip_select: digitalio.DigitalInOut, address: int = micropython.const, reset: bool = True, baudrate: int = 100000)
Supports MCP23S08 instance on specified I2C bus and optionally at the specified I2C address.
- get_pin(pin: int) DigitalInOut
Convenience function to create an instance of the DigitalInOut class pointing at the specified pin of this MCP23S08 device.
- property gpio: int
The raw GPIO output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
MCP23S17
CircuitPython module for the MCP23S17 SPI I/O extenders.
Author(s): Tony DiCola, Romy Bompart (2020), Red_M (2021)
- class adafruit_mcp230xx.mcp23s17.MCP23S17(spi: SPI, chip_select: digitalio.DigitalInOut, address: int = micropython.const, reset: bool = True, baudrate: int = 100000)
Supports MCP23S17 instance on specified SPI bus and optionally at the specified SPI address.
- property default_value: int
The raw DEFVAL interrupt control register. The default comparison value is configured in the DEFVAL register. If enabled (via GPINTEN and INTCON) to compare against the DEFVAL register, an opposite value on the associated pin will cause an interrupt to occur.
- get_pin(pin: int) DigitalInOut
Convenience function to create an instance of the DigitalInOut class pointing at the specified pin of this MCP23S17 device.
- property gpio: int
The raw GPIO output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
- property gpioa: int
The raw GPIO A output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
- property gpiob: int
The raw GPIO B output register. Each bit represents the output value of the associated pin (0 = low, 1 = high), assuming that pin has been configured as an output previously.
- property gppu: int
The raw GPPU pull-up register. Each bit represents if a pull-up is enabled on the specified pin (1 = pull-up enabled, 0 = pull-up disabled). Note pull-down resistors are NOT supported!
- property gppua: int
The raw GPPU A pull-up register. Each bit represents if a pull-up is enabled on the specified pin (1 = pull-up enabled, 0 = pull-up disabled). Note pull-down resistors are NOT supported!
- property gppub: int
The raw GPPU B pull-up register. Each bit represents if a pull-up is enabled on the specified pin (1 = pull-up enabled, 0 = pull-up disabled). Note pull-down resistors are NOT supported!
- property int_flag: List[int]
Returns a list with the pin numbers that caused an interrupt port A —-> pins 0-7 port B —-> pins 8-15
- property int_flaga: List[int]
Returns a list of pin numbers that caused an interrupt in port A pins: 0-7
- property int_flagb: List[int]
Returns a list of pin numbers that caused an interrupt in port B pins: 8-15
- property interrupt_configuration: int
The raw INTCON interrupt control register. The INTCON register controls how the associated pin value is compared for the interrupt-on-change feature. If a bit is set, the corresponding I/O pin is compared against the associated bit in the DEFVAL register. If a bit value is clear, the corresponding I/O pin is compared against the previous value.
- property interrupt_enable: int
The raw GPINTEN interrupt control register. The GPINTEN register controls the interrupt-on-change feature for each pin. If a bit is set, the corresponding pin is enabled for interrupt-on-change. The DEFVAL and INTCON registers must also be configured if any pins are enabled for interrupt-on-change.
- property io_control: int
The raw IOCON configuration register. Bit 1 controls interrupt polarity (1 = active-high, 0 = active-low). Bit 2 is whether irq pin is open drain (1 = open drain, 0 = push-pull). Bit 3 is unused. Bit 4 is whether SDA slew rate is enabled (1 = yes). Bit 5 is if SPI address pointer auto-increments (1 = no). Bit 6 is whether interrupt pins are internally connected (1 = yes). Bit 7 is whether registers are all in one bank (1 = no), this is silently ignored if set to
1
.
- property iodir: int
The raw IODIR direction register. Each bit represents direction of a pin, either 1 for an input or 0 for an output mode.
- property iodira: int
The raw IODIR A direction register. Each bit represents direction of a pin, either 1 for an input or 0 for an output mode.
- property iodirb: int
The raw IODIR B direction register. Each bit represents direction of a pin, either 1 for an input or 0 for an output mode.
- property ipol: int
The raw IPOL output register. Each bit represents the polarity value of the associated pin (0 = normal, 1 = inverted), assuming that pin has been configured as an input previously.
digital_inout
Digital input/output of the MCP230xx.
Author(s): Tony DiCola
- class adafruit_mcp230xx.digital_inout.DigitalInOut(pin_number: int, mcp230xx: MCP23XXX)
Digital input/output of the MCP230xx. The interface is exactly the same as the digitalio.DigitalInOut class, however:
MCP230xx family does not support pull-down resistors;
MCP23016 does not support pull-up resistors.
Exceptions will be thrown when attempting to set unsupported pull configurations.
- property direction: bool
The direction of the pin, either True for an input or False for an output.
- property invert_polarity: bool
The polarity of the pin, either True for an Inverted or False for an normal.
- property pull: digitalio.Pull | None
Enable or disable internal pull-up resistors for this pin. A value of digitalio.Pull.UP will enable a pull-up resistor, and None will disable it. Pull-down resistors are NOT supported!
- switch_to_input(pull: digitalio.Pull = None, invert_polarity: bool = False, **kwargs) None
Switch the pin state to a digital input with the provided starting pull-up resistor state (optional, no pull-up by default) and input polarity. Note that pull-down resistors are NOT supported!