How to use MCP23017 with Raspberry Pi

in #raspberry7 years ago

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

Sort:  

Welcome to Steemit

Thanks, Steemit has a fantastic community.

Congratulations @rpsreal! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post
You got a First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Coin Marketplace

STEEM 0.22
TRX 0.21
JST 0.035
BTC 98577.14
ETH 3328.76
USDT 1.00
SBD 3.09