MCP23017/8 driver for Digital Inputs
Introduction
The MCP23017/8 driver for Digital Inputs is used to detect the level of a digital signal on a selected channel on an external GPIO extender. The selected channel includes an optional internal pull up resistor.
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.
Pull Up
What is Pull Up
Refer to this section if you are not sure what Pull Up is: Explanation
Possible Configurations
Pull Up Enabled:
The channel pin is pulled up internally (see: https://quantumintegrate.atlassian.net/wiki/spaces/HELP/pages/14811466/How+to+use+the+MCP23017+8+driver+for+Digital+Inputs#Pull-Up-Enabled)
Pull Up Disabled:
The channel pin is floating and not pulled in any direction internally (see: https://quantumintegrate.atlassian.net/wiki/spaces/HELP/pages/14811466/How+to+use+the+MCP23017+8+driver+for+Digital+Inputs#Pull-Up-Disabled )
Wiring
The two version of this drivers have different pinouts which can be found below
MCP23017
MCP23018
For the following wiring samples 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.
Pull Up Enabled
The channel GPA0 is pulled up internally. 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 |
Pull Up Disabled
The channel GPA0 is pulled down externally with a 10000Ω resistor. 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 In” 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 In” Object onto the canvas.
Next, locate the “Switch” Object under the “Interface” tab and drag it onto the canvas.
Finally, connect the “State” port from the Digital In Object to the “State” port on the Switch 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 In” hardware option.
Give your device a name, and click “Add Device”
Next, select the “MCP2301/8 “ under the driver dropdown menu, set the I2C Address, Channel, and Pull Up options.
For this example we select:
I2C: 0x20
Channel: A0
Pull Up: Disabled
You may now save your firmware file and upload it to one of your clients.
Supported Hardware
Buttons
Contact sensors
Anything providing a digital signal
Downloads
Apps
Firmware
Assets