HUM: MCP23017 IO EXPANDER
You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Croduino and the basic code. Everything else is left to your imagination.
With some more complex projects. it is possible that your Croduino does not have enough digital inputs or outputs. Do not despair! We have a solution for you. It is about a breakout module which contains MCP23017 IC and allows you to connect additional sixteen digital inputs/outputs. There are two types of this chip, and we will use a variant with the I2C communication.
Power supply voltage: 1.8V – 5.5V
Maximum current per pin: 25mA
Number of digital inputs/outputs: 16
Maximum communication speed: 1.7MHz
Communication interface: I2C
Dimensions: 35 mm x 24 mm
HOW DOES IT WORK?
Along with the communication hardware, this chip we are using contains two 8bit GPIO (general purpose input output) modules, providing a total of 16 inputs/outputs. For each of them, we can determine whether it is an input or output. If the GPIO pin works as a digital input, then its functionality can simply be described as a voltage comparator. Depending on the IC’s power supply, the controller determines which voltage range is considered low, and which is at a high level. When we use GPIO as an input, we actually want to determine if some physical (analog signal) is above a certain voltage level, and according to that we assign the value “HIGH” or if it is below a certain level, we assign “LOW” value to it. Often, signals we want to determine as “HIGH” or “LOW” are not constant but their voltage can change. That is why this IC uses the so-called Schmitt trigger. This way, a security zone, into which the measured signal can enter without the controller recognizing it as wrong value, is ensured.
If we have determined for some GPIO pin to work as a digital output, we have a simpler situation. Through communication, we get the information on whether to set the pin as “LOW” or “HIGH”. If we have received “LOW”, the output is connected to the ground, and if we have received “HIGH” the output is connected to the power supply. GPIO inputs have a built-in pull-up resistor so we can simply add push buttons and switches without additional hardware onto them. This IC has another interesting feature – hardware interrupt. It can be programmed so that the breakout sets interrupt if it comes to a change on one or the other GPIO module, so, according to that, on the board we have two pins marked with INTA and INTB.
HOW TO CONNECT?
VCC: power supply 1.8V – 5.5V
SDA: serial data I2C
SCL: serial clock
A0 to A7: I/O
B8 to B15: I/O
Connecting to Croduino is simple, and you only need four wires, two of which you need for power supply and the other two for communication (SDA and SCL). We have a solution for you in case you are using a large number of inputs/outputs. On the board you can see three address jumpers, using which we determine the module’s address on the I2C communication. Each jumper determines one address bit and can have values ‘0’ or ‘1’ which means you have eight combinations available, so you can connect eight such modules to one Croduino, which provides a total of 128 new digital inputs/outputs you use the same way as normal digital inputs/outputs on the Croduino.
To properly execute this code, you need to download the library from the following link. In case you do not know how to install a library, read our tutorial. The program code tests the accuracy of the module’s operation, whereby as a digital input we use the push button, and as a digital output, the LED. NOTE: it is necessary to set the module’s address on the I2C communication right. The module’s address can easily be checked by connecting it to Croduino and launching the I2C Scanner which can be found in this link.
//if you want to use more of these modules, you need to declare them here e.g. Adafruit_MCP23017 mcp1, mcp2;
// enter the module's address on the I2C communication
//enabling pull-up resistor since we use the push button
//when we push the button, the digital input will read LOW, and when it is released it will read HIGH due to pull-up resistor
Products used in this tutorial
No products found