Port expander MCP23017
The MCP23017 is a 16-bit port expander with 32 channels of 12-bit analog-to-digital converters and two generic 8-bit inputs / outputs. Unlike most other port expanders, the MCP23017 has an internal oscillator. The MCP23017 operates at 2 MHz, but can support frequencies up to 1 MHz; It can be cascaded and comes in an 18-pin PDIP package, so you can use it in breadboards and through-hole soldering perfboards. This makes it easy to connect it to other parts of the circuit.
The MCP23017 uses an I2C interface and has two i2c pins, SCL and SDA, used to communicate with the device. The external interrupt pins INT0 and INT1 can be used to signal events such as doorbell buttons or alarm systems. Additionally, the MCP23017 offers 16 general purpose input / output (GPIO) ports. Each port pin can be programmed through three registers.
Each of the 16 ports can be programmed as an input or output and wired for open drain or push-pull operation. In addition to the small size, this means that you can connect an external device (such as a sensor) and have it communicate with other devices on the same I2C bus. At first glance it may seem little, but when you consider that there are hundreds of I2C devices available today that use this protocol, you begin to understand how versatile it is!
The chip runs on 3.3 volts, but has some internal voltage converters, so it can also be used on 5 volts. However, it’s not just for hardware engineers; the data sheet clarifies that this chip is intended for anyone who wants to exploit its features in their projects or prototypes.
Applications of MCP23017
The MCP23017 is a quick and easy way to add more I / O pins to the Arduino, especially in applications where you want to monitor or control multiple devices at the same time. For example, you can use it to add buttons and LEDs to projects or to connect multiple sensors at the same time. It is also ideal for adding other serial communication ports, which can be useful if you want to send data from one device to another. The MCP23017 can even control 8 servomotors!
The I2C interface allows you to connect multiple devices to the microcontroller and read / write on each of them with just two wires. This means that if you are using an ATtiny85 (or similar), you can create 7 digital inputs or 5 3-pin PWM outputs! The analog inputs can be used with existing libraries, allowing you to collect sensor data without any modification.
To use a device, you set the registers in the first bytes of memory that control the behavior of the device (determine if its ports are input or output and if there are internal pull-ups), then set these registers. Each port pin can be programmed as an input or output through three registers. The first register checks whether the pin is configured as an input or an output, while two other sets of bits define more detailed options, such as bidirectional operation and open drain mode.
It is quite easy to configure the microcontroller to do this every time the device starts up, making its use much easier than having to manually locate and set all these pins each time.
Conclusion
In summary, the MCP23017 is a wonderful little device that can be of great help in your projects. It is easy to use and provides 16 general purpose I / O ports. The only real advantage is that it uses the I2C protocol instead of the SPI one, which means that you will need two pins for communication instead of one pin, which makes it interfaceable with other microcontrollers such as Arduino or Raspberry Pi.