RPS Electronics avatar

How to use MCP23017 with Raspberry Pi

rpsreal

Published: 12 Nov 2017 › Updated: 12 Nov 2017How to use MCP23017 with Raspberry Pi

How to use MCP23017 with Raspberry Pi

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

Leave How to use MCP23017 with Raspberry Pi to:

Written by

Raspberry Pi - Microcontrolers - Electronics - and more

Read more #raspberry posts


Best Posts From RPS Electronics

We have not curated any of rpsreal's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From RPS Electronics