MCP23017/8 driver for Digital Outputs
Introduction
The MCP23017/8 driver for Digital Outputs is used to set the digital level of a selected channel on an external GPIO extender. The selected channel includes an optional initial value.
Driver Parameters
The GPIO driver for Digital Inputs has three parameters that have to be configured:
I2C Address
This is the address the device is being referenced by on the I2C bus. The two chips have a different way of being addressed:
MCP23017
The MCP23017 has 3 address pins (A0, A1, A2). To select the correct address, please view the following table:
More information about addressing can be found in the datasheet
MCP23018
The MCP23018 has only one address pin (ADDR). The address selection here is achieved by feeding a voltage level between voltage and ground to the ADDR pin. To select the correct address, please view the following table:
Address | Ideal level | Permitted range | R1 | R2 | Actual level |
---|---|---|---|---|---|
0x20 | 1/16 = 0.625 | 0 – 0.0875 | 4K7 | Open circuit | 0 |
0x21 | 3/16 = 0.1875 | 0.1625 – 0.2125 | 1K | 4K7 in parallel with 56K | 0.1726 – 0.2031 |
0x22 | 5/16 = 0.3125 | 0.2875 – 0.3375 | 1K5 | 3K3 | 0.2914 – 0.3344 |
0x23 | 7/16 = 0.4375 | 0.4125 – 0.4625 | 2K2 in parallel with 47K | 2K7 | 0.4132 – 0.4625 |
0x24 | 9/16 = 0.5625 | 0.5375 – 0.5875 | 2K7 | 2K2 in parallel with 47K | 0.5375 – 0.5868 |
0x25 | 11/16 = 0.6875 | 0.6625 – 0.7125 | 3K3 | 1K5 | 0.6656 – 0.7086 |
0x26 | 13/16 = 0.8125 | 0.7875 – 0.8375 | 4K7 in parallel with 56K | 1K | 0.7968 – 0.8274 |
0x27 | 5/16 = 0.9375 | 0.9125 – 1 | Open circuit | 4K7 | 1 |
The resistors are from the E12 series with a tolerance of 5% max
More information about addressing can be found in the datasheet
Channel
The channel is the port/pin combination on the chip. Just select from the dropdown list what channel your project connects to.
Mode
This is the initial output mode of the channel
Possible Configurations
High: The channel has a logic level of 1 at initialization
Low: The channel has a logic level of 0 at initialization
Wiring
The two version of this drivers have different pinouts which can be found below
MCP23017
MCP23018
For the following wiring sample we concentrate on the MCP23017. The change to the MCP23018 can be made by adjusting the addressing and relocating all pins used in a sample and wiring them up to the appropriate location on the MCP23018.
Example
The channel GPA0 is connected to the LED directly. The chip is connected to address 0x20 of the I2C bus because all address lines are pulled low.
Breadboard
Schematic
Used Pins
Used Pins | Description |
---|---|
3V3 | The voltage level for the assembly |
GND | The ground potential for the assembly |
SDA | The I2C data line |
SCL | The I2C clock line |
How to write an App
Navigate to the App Builder and create a new application. You can find the “Digital Out” code object under the “Hardware” Tab in the object drop down menu on the left, or you can also use the search bar.
Drag the “Digital Out” Object onto the canvas.
Next, locate the “Button” Object under the Interface tab and drag it onto the canvas.
Finally, connect the “State” port from the Digital Out Object to the “State” port on the Button Object and save your application.
How to create a firmware
Navigate to the Firmware Builder and create a new firmware file.
Click the “+ Add Hardware” button which will open a modal window. Scroll down in the list to find the “Generic” section and select the “Digital Out” hardware option.
Give your device a name, and click “Add Device”
Next, select the “GPIO” driver under the driver dropdown menu, set the I2C address, channel, and the mode.
For this example we select:
I2C Address: 0x20
Channel: A0
Mode: Initially low
You may now save your firmware file and upload it to one of your clients.
Supported Hardware
LEDs
Relays
Most anything that can receive a digital signal
Downloads
Apps
Firmware
Assets