MCP23017 Class

The MCP23017 Class provides a programming interface to the MCP23017 I2C port expander chip.

MCP23017 - i2c 16 input/output port expander

PRODUCT ID: 732
Add another 16 pins to your microcontroller using a MCP23017 port expander. The MCP23017 uses two i2c pins (these can be shared with other i2c devices), and in exchange gives you 16...
$2.95
IN STOCK

Constructors

The MCP23017 Class has a single constructor. The constructor takes an optional argument of an I2C address. I2C addresses for the chip are in the range 0x20 to 0x27.

If no argument is provided the constructor configures the class to use the default I2C address of 0x20 for the MCP23017.

The MCP23017 class references the I2CBase class as superclass.  The I2C address in the constructor is passed to the superclass

Download: file
public MCP23017(int addr) public MCP23017(int addr = MCP23017_ADDRESS) :base(addr)

Methods

InitMCP23017Async

This is an asynchronous method whih initializes the I2C interface by calling the I2CBase Class InitI2CAsync method, and sets all MCP23017 GPIO pins to outputs.

Download: file
public async Task InitMCP23017Async()

pinMode

The PinMode method sets the input/output direction of a single GPIO pin. It takes two arguments, the pin number, andthe direction.

Pin number is an integer in the range 0..15, where pins numbered from 0 to 7 are on Port A, and pins numbered from 8 to 15 are on Port B.

The direction argument is of type Direction, which is an enumeration defined within the class. Defined values are "INPUT" and "OUTPUT"

Download: file
public enum Direction { INPUT = 0, OUTPUT = 1 };
public void pinMode(int p, Direction d)

pullup

This method sets the pullup state of a single GPIO pin to logical HIGH or LOW. It takes two arguments, a pin number and a logic value.

Pin number is an integer in the range 0..15, where pins numbered from 0 to 7 are on Port A, and pins numbered from 8 to 15 are on Port B.

The logic value argument is of type Level, which is an enumeration defined within the class. Defined values are "LOW" and "HIGH"

Download: file
public enum Level { LOW = 0, HIGH = 1 };
public void pullUp(int pin, Level d)

digitalWrite

This method sets the state of a single GPIO pin to logical HIGH or LOW. It takes two arguments, a pin number and a logic value.

Pin number is an integer in the range 0..15, where pins numbered from 0 to 7 are on Port A, and pins numbered from 8 to 15 are on Port B.

The logic value argument is of type Level, which is an enumeration defined within the class. Defined values are "LOW" and "HIGH"

Download: file
public enum Level { LOW = 0, HIGH = 1 };
public void digitalWrite(int pin, Level d)

digitalRead

This method gets the state of a single GPIO pin, and returns it as a logical HIGH or LOW. It takes a single arguments, a pin number.

Pin number is an integer in the range 0..15, where pins numbered from 0 to 7 are on Port A, and pins numbered from 8 to 15 are on Port B.

The return value is of type Level, which is an enumeration defined within the class. Defined values are "LOW" and "HIGH"

Download: file
public enum Level { LOW = 0, HIGH = 1 };
public Level digitalRead(int pin)

writeGPIOAB

This writeGPIOAB method writes to all pins simultaneously. It takes a single argument, an unsigned 16-bit integer representing a bitmask of the desired logic state for each pin. The LSB corresponds to Port A, pin 0, and the MSB corresponds to Port B, pin 7.

Download: file
public void writeGPIOAB(UInt16 ba)

readGPIOAB

This readGPIOAB method reads all pins simultaneously. It returns a single value, an unsigned 16-bit integer representing a bitmask of the current logic state for each pin. The LSB corresponds to Port A, pin 0, and the MSB corresponds to Port B, pin 7.

Download: file
public UInt16 readGPIOAB()
This guide was first published on Nov 22, 2016. It was last updated on Nov 22, 2016. This page (MCP23017 Class) was last updated on Dec 04, 2016.