How to use MCP23017 with Raspberry Pi

Words
136
Reading
1 min
Listen
Play
9y

The MCP23017 I2C port expander have a total of 16 ports. You can use a Python library to control the MCP23017 GPIO.
To do this:

  1. Install libraries: sudo apt-get install -y python-smbus i2c-tools;

  2. Download this file;

  3. Do the wiring as the figure below;

Now let's make a small program to control the MCP23017. Using the library is very easy, all you have to do is follow the examples below:

from MCP23017_I2C import *                      # import library in the same folder
GPIO.setup( 0, 'OUT', 'A')                      # to configure GPA0 like output
GPIO.output(0, 1, 'A')                          # to write in GPA0 1 (high)
switch = GPIO.input(7, 'B')                     # to save the state of GPB7 in 'switch'

So it's like programming in arduino, very easy.
You can use this Example to control a circuit equal to the figure above

Based on the work of http://www.raspberrypi-spy.co.uk
GitHub Code

How to use MCP23017 with Raspberry Pi | Ecency