# Adafruit MCP23017 I2C GPIO Expander

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/122/978/medium800/adafruit_products_5346-09.jpg?1690378501)

We’ve gotten a lot of requests for a MCP23017 breakout and we’ve always sorta been like “[ehh why not just use the DIP chip?](https://www.adafruit.com/product/732)” but with STEMMA QT we could see the use case for a plug and play version that comes with all the passives on board. This **Adafruit MCP23017 I2C GPIO Expander Breakout** has 16 GPIO with matching ground pad.

We particularly like the '17 as an expander for it's simple no-nonsense capability. It runs happily from 3V or 5V logic and power. Each GPIO can be an output driving up to 25mA, so LEDs are no problem. Or, each can be an input, with optional pullup. There are two IRQ pins that are configurable for what inputs to keep track of so no I2C bus polling is required. With 3 address pins, you can have up to 8 on a single bus for a total of 8 x 16 = 128 GPIO all on one I2C bus!

![](https://cdn-learn.adafruit.com/assets/assets/000/122/979/medium800/adafruit_products_5346-07.jpg?1690378521)

We've got solid [Arduino](https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library) and [CircuitPython libraries](https://learn.adafruit.com/using-mcp23008-mcp23017-with-circuitpython) with examples, all ready for this chip. But even if you are using some other platform, the MCP23017 is so classic, you'll likely be able to find example code.

Comes with two sticks of header so you can use it in a breadboard, with some soldering. You can also free-wire buttons by connecting one side to the GPIO (set as input with pullup) and the other side to a ground pad.

![](https://cdn-learn.adafruit.com/assets/assets/000/122/980/medium800/adafruit_products_5346-08.jpg?1690378539)

To get you going fast, we spun up a custom-made PCB in the[&nbsp; **STEMMA QT** &nbsp;form factor](https://www.adafruit.com/?q=stemma%20qt%20sensor "STEMMA QT form factor"), making it easy to interface with. The&nbsp;[STEMMA QT connectors](https://learn.adafruit.com/introducing-adafruit-stemma-qt/what-is-stemma-qt)&nbsp;on either side are compatible with the&nbsp;[SparkFun Qwiic](https://www.sparkfun.com/qwiic)&nbsp;I2C connectors. This allows you to make solderless connections between your development board and the MCP23017 or to chain it with a wide range of other sensors and accessories using a&nbsp;[**compatible cable**](https://www.adafruit.com/?q=stemma%20qt%20cable).

[**QT Cable is not included** , but we have a variety in the shop](https://www.adafruit.com/?q=stemma+qt+cable&sort=BestMatch).&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/122/981/medium800/adafruit_products_5346-06.jpg?1690378565)

# Adafruit MCP23017 I2C GPIO Expander

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/109/778/medium800/adafruit_products_front.png?1647531928)

![](https://cdn-learn.adafruit.com/assets/assets/000/109/779/medium800/adafruit_products_back.png?1647531959)

The default I2C address for this board is **0x20**.

## Power Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/109/780/medium800/adafruit_products_powerPins.png?1647532425)

This breakout works with both 3V and 5V power and logic, so it can be easily used with most microcontrollers from an Arduino to a Feather or something else.

- **VIN** - This is the power pin. To power the board, give it the same power as the logic level of your microcontroller - i.e. for a 5V micro like Arduino, use 5V, or for a 3V micro like a Feather, use 3V.
- **GND** - This is common ground for power and logic.
- **GND pads** - The ground pads (highlighted in white on the board's silk) are available as discrete ground connections for the GPIO.

## I2C Logic Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/109/781/medium800/adafruit_products_stemma.png?1647532844)

- **SCL** - I2C clock pin, connect to your microcontroller's I2C clock line. This pin is level shifted so you can use 3-5V logic, and there's a **10K pullup** on this pin.
- **SDA** - I2C data pin, connect to your microcontroller's I2C data line. This pin is level shifted so you can use 3-5V logic, and there's a **10K pullup** on this pin.
- [**STEMMA QT**](https://learn.adafruit.com/introducing-adafruit-stemma-qt) **-** These connectors allow you to connect to development boards with **STEMMA QT** connectors, or to other things, with [various associated accessories](https://www.adafruit.com/category/619).

## GPIO Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/109/782/medium800/adafruit_products_inOut.png?1647533245)

Pins **A0** - **A7** and **B0** - **B7** are bidirectional digital input and digital output pins, for a total of 16 inputs or outputs. When a pin is an output, it can drive up to 25 mA. When a pin is an input, it can have an optional pull-up. The A pins are PORTA and the B pins are PORTB.

Despite the naming convention, the A prefix _ **does not** _ stand for analog input/output.

Warning: 

## MCP23017
![](https://cdn-learn.adafruit.com/assets/assets/000/109/783/medium800/adafruit_products_23017.png?1647534426)

The **MCP23017** , the square chip located in the left-center on the front of the board, provides general purpose parallel I/O expansion over I2C.

## Interrupt Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/109/784/medium800/adafruit_products_interupt.png?1647534557)

- **IA** **(INTA)** - configurable for what inputs to keep track of on PORTA. It can be configured as active-high, active-low or open-drain.
- **IB** **(INTB)** -&nbsp;configurable for what inputs to keep track of on PORTB. It can be configured as active-high, active-low or open-drain.

## Address Pins
![](https://cdn-learn.adafruit.com/assets/assets/000/109/785/medium800/adafruit_products_addressFront.png?1647534865)

![](https://cdn-learn.adafruit.com/assets/assets/000/109/786/medium800/adafruit_products_addressBack.png?1647535143)

On the back of the board are **three address jumpers** , labeled **+1** , **+2** , and **+4,** above the **I2C Addr** label on the board silk. These jumpers allow you to chain up to 8 of these boards on the same pair of I2C clock and data pins. To do so, you solder the jumpers "closed" by connecting the two pads.

On the front of the board are three address pins, labeled **D0** , **D1** and **D2**. Just like the jumpers, these pins allow you to change the I2C address to connect multiple boards by connecting them to **VIN**.

The default I2C address is **0x20**. The other address options can be calculated by “adding” the **D0/D1/D2** &nbsp;to the base of **0x20**.

**D0** sets the lowest bit with a value of **1** , **D1** sets the next bit with a value of **2** and **D2** sets the next bit with a value of **4.** The final address is **0x20 + D2 + D1 + D0** which would be **0x27**.

 So for example if **D2** is soldered closed and **D0** is soldered closed, the address is **0x20 + 4 + 1 = 0x25**.

 If only **D0** is soldered closed, the address is **0x20 + 1 = 0x21**

 If only **D1** is soldered closed, the address is **0x20 + 2 = 0x22**

 If only **D2** is soldered closed, the address is **0x20 + 4 = 0x24**

The table below shows all possible addresses, and whether the pin(s) should be high (closed) or low (open).

![](https://cdn-learn.adafruit.com/assets/assets/000/109/791/medium800/adafruit_products_i2ctable.png?1647536363)

## RST Pin
![](https://cdn-learn.adafruit.com/assets/assets/000/109/788/medium800/adafruit_products_rst.png?1647535676)

- **RST** - This is the reset pin. Connect this pin to ground to reset the board.

## Power LED and Jumper
![](https://cdn-learn.adafruit.com/assets/assets/000/109/789/medium800/adafruit_products_led.png?1647535817)

![](https://cdn-learn.adafruit.com/assets/assets/000/109/790/medium800/adafruit_products_ledJumper.png?1647535853)

- **Power LED -** In the upper left corner, above the STEMMA connector, on the front of the board, is the power LED, labeled **on**.&nbsp;
- **LED jumper** - On the back of the board is a jumper for the power LED. If you wish to disable the power LED, simply cut the trace on this jumper.

# Adafruit MCP23017 I2C GPIO Expander

## Python & CircuitPython

It's easy to use the **Adafruit**  **MCP23017** with Python or CircuitPython with the [Adafruit CircuitPython MCP23017](https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx) module. This module allows you to easily write Python code that adds up to 16 inputs or outputs over I2C.

You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python [thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

## CircuitPython Microcontroller Wiring

First wire up a MCP23017 to your board exactly as shown below. Here's an example of wiring a Feather M4, a button and an LED to the expander using a solderless breadboard:

 **MCP23017**

- **Board 3V** to **expander VIN (red wire)**
- **Board GND** to **expander GND (black wire)**
- **Board SCL** to **expander SCL (yellow wire)**
- **Board SDA** to **expander SDA (blue wire)**

**LED**

- **LED +** to **470Ω resistor**
- **LED -** to **Board GND (black wire)**
- **470Ω resistor** to **expander A0 (pink wire)**

**Button**

- **Button leg** to **expander A1 (green wire)**
- **Opposite button leg** to **Board GND (black wire)**

![adafruit_products_featherNoStemma_bbExtra.png](https://cdn-learn.adafruit.com/assets/assets/000/109/839/medium640/adafruit_products_featherNoStemma_bbExtra.png?1647626462)

## Python Computer Wiring

Since there's _dozens_ of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, [please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Here's the Raspberry Pi, a button and an LED wired to the expander using a solderless breadboard:

 **MCP23017**

- **Pi 3V** to **expander VIN (red wire)**
- **Pi GND** to **expander GND (black wire)**
- **Pi SCL** to **expander SCL (yellow wire)**
- **Pi SDA** to **expander SDA (blue wire)**

**LED**

- **LED +** to **470Ω resistor**
- **LED -** to **Pi GND (black wire)**
- **470Ω resistor** to **expander A0 (pink wire)**

**Button**

- **Button leg** to **expander A1 (green wire)**
- **Opposite button leg** to **Pi GND (black wire)**

![adafruit_products_piNoStemma_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/109/838/medium640/adafruit_products_piNoStemma_bb.png?1647626435)

## Python Installation of MCP230xx Library

You'll need to install the **Adafruit\_Blinka** library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3.&nbsp;[Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following command:

- `pip3 install adafruit-circuitpython-mcp230xx`

If your default Python is version 3, you may need to run `pip` instead. Make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

## CircuitPython Usage

To use with CircuitPython, you need to first install the MCP230xx library, and its dependencies, into the **lib** folder on your **CIRCUITPY** drive. Then you need to update **code.py** with the example script.

Thankfully, we can do this in one go. In the example below, click the **Download Project Bundle** button below to download the necessary libraries and the **code.py** file in a zip file. Extract the contents of the zip file, and copy the **entire**  **lib**  **folder** and the **code.py** file to your **CIRCUITPY** drive.

Your **CIRCUITPY/lib** folder should contain the following folders:

- **adafruit\_bus\_device/**
- **adafruit\_mcp230xx/**

![cp](https://adafruit.github.io/Adafruit_CircuitPython_Bundle/mcp230xx_mcp230xx_simpletest.py.png)

Before running the code, comment out the `adafruit_mcp230xx.mcp23008` library&nbsp;and uncomment the `adafruit_mcp230xx.mcp23017` library to import the correct library for the MCP23017.

```python
# from adafruit_mcp230xx.mcp23008 import MCP23008

from adafruit_mcp230xx.mcp23017 import MCP23017
```

Then, comment out the `mcp` instance using the `MCP23008` class, and uncomment the `mcp` instance using the `MCP23017` class.

```python
# Create an instance of either the MCP23008 or MCP23017 class depending on
# which chip you're using:
# mcp = MCP23008(i2c)  # MCP23008
mcp = MCP23017(i2c)  # MCP23017
```

## Python Usage

Once you have the library `pip3` installed on your computer, copy or download the following example to your computer, and run the following, replacing **code.py** with whatever you named the file:

`python3 code.py`

## Example Code
https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx/blob/main/examples/mcp230xx_simpletest.py

 **If running CircuitPython:** Once everything is saved to the **CIRCUITPY** drive, [connect to the serial console](https://learn.adafruit.com/welcome-to-circuitpython/kattni-connecting-to-the-serial-console) to see the data printed out!

**If running Python:** The console output will appear wherever you are running Python.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/814/medium800/adafruit_products_repl.png?1647615742)

You will see the connected LED begin to blink on and off.

When you press the button, its status will be printed to the REPL.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/815/medium800thumb/adafruit_products_featherNoStemma.jpg?1647616744)

That's all there is to using the MCP23017 with CircuitPython!

# Adafruit MCP23017 I2C GPIO Expander

## Python Docs

# Adafruit MCP23017 I2C GPIO Expander

## Arduino

Using the MCP23017 with Arduino involves wiring up the expander to your Arduino-compatible microcontroller, installing the [Adafruit MCP23017](https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library) library and running the provided example code.

## Wiring

Wire as shown for a **5V** board like an Uno. If you are using a **3V** board, like an Adafruit Feather, wire the board's 3V pin to the MCP23017 VIN.

Here is an Adafruit Metro, a button and an LED wired up to the MCP23017 using a solderless breadboard:

 **MCP23017**

- **Board 5V** to **expander VIN (red wire)**
- **Board GND** to **expander GND (black wire)**
- **Board SCL** to **expander SCL (yellow wire)**
- **Board SDA** to **expander SDA (blue wire)**

**LED**

- **LED +** to **470Ω resistor**
- **LED -** to **Board GND (black wire)**
- **470Ω resistor** to **expander A0 (pink wire)**

**Button**

- **Button leg** to **expander A1 (green wire)**
- **Opposite button leg** to **Board GND (black wire)**

![adafruit_products_metroNoStemma_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/109/845/medium640/adafruit_products_metroNoStemma_bb.png?1647628331)

## Library Installation

You can install the **MCP23017** library for Arduino using the Library Manager in the Arduino IDE.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/806/medium800/adafruit_products_Arduino_Open_Library_Manager.png?1647549858)

Click the&nbsp; **Manage Libraries ...** menu item, search for **MCP23017** ,&nbsp;and select the **Adafruit MCP23017**  **Arduino Library** library:

![](https://cdn-learn.adafruit.com/assets/assets/000/109/807/medium800/adafruit_products_arduinoLib.png?1647549946)

If asked about dependencies, click "Install all".

![](https://cdn-learn.adafruit.com/assets/assets/000/109/812/medium800/adafruit_products_arduinoDependencies.png?1647615660)

If the "Dependencies" window does not come up, then you already have the dependencies installed.&nbsp;

Warning: 

## Load Example

Open up **File**  **-\> Examples -\> Adafruit MCP23017 Arduino Library -\> mcp23xxx\_combo**. Before uploading the code, comment out the `mcp` instance using the `Adafruit_MCP23X08` class, and uncomment the `mcp` instance using the `Adafruit_MCP23X17` class.

```cpp
// uncomment appropriate line
// Adafruit_MCP23X08 mcp;
Adafruit_MCP23X17 mcp;
```

https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/blob/master/examples/mcp23xxx_combo/mcp23xxx_combo.ino

Upload the sketch to your board and open up the Serial Monitor ( **Tools -\> Serial Monitor** ) at 9600 baud. You should see the text "`Looping...`" in the Serial Monitor.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/813/medium800/adafruit_products_arduinoSerial.png?1647615680)

When you press the button, the LED will light up.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/844/medium800thumb/adafruit_products_arduinoNoStemma.jpg?1647627568)

That's all there is to using the MCP23017 STEMMA breakout with Arduino!

# Adafruit MCP23017 I2C GPIO Expander

## Arduino Docs

# Adafruit MCP23017 I2C GPIO Expander

## Downloads

## Files

- [MCP23017 Datasheet](https://cdn-shop.adafruit.com/datasheets/mcp23017.pdf)
- [EagleCAD PCB Files on GitHub](https://github.com/adafruit/Adafruit-MCP23017-PCB)
- [Fritzing object in the Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20MCP23017%20STEMMA%20QT.fzpz)

## Schematic and Fab Print for MCP23017
![](https://cdn-learn.adafruit.com/assets/assets/000/109/792/medium800/adafruit_products_mcp23017schem.png?1647544296)

![](https://cdn-learn.adafruit.com/assets/assets/000/109/797/medium800/adafruit_products_mcp23017Board.png?1647545639)


## Primary Products

### Adafruit MCP23017 I2C GPIO Expander Breakout

[Adafruit MCP23017 I2C GPIO Expander Breakout](https://www.adafruit.com/product/5346)
We’ve gotten a lot of requests for a MCP23017 breakout and we’ve always sorta been like “[ehh why not just use the DIP chip?](https://www.adafruit.com/product/732)” but with STEMMA QT we could see the use case for a plug and play version that comes with all...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5346)
[Related Guides to the Product](https://learn.adafruit.com/products/5346/guides)

## Featured Products

### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long](https://www.adafruit.com/product/4401)
This 4-wire cable is a little over 200mm / 7.8" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4401)
[Related Guides to the Product](https://learn.adafruit.com/products/4401/guides)
### STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable

[STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable](https://www.adafruit.com/product/4209)
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium Dupont male headers on the other. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4209)
[Related Guides to the Product](https://learn.adafruit.com/products/4209/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable with Premium Female Sockets

[STEMMA QT / Qwiic JST SH 4-pin Cable with Premium Female Sockets](https://www.adafruit.com/product/4397)
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium female headers on the other. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and...

In Stock
[Buy Now](https://www.adafruit.com/product/4397)
[Related Guides to the Product](https://learn.adafruit.com/products/4397/guides)
### JST SH 4-pin Cable with Alligator Clips - STEMMA QT / Qwiic

[JST SH 4-pin Cable with Alligator Clips - STEMMA QT / Qwiic](https://www.adafruit.com/product/4398)
This cable will make it super easy to use our plug-and-play STEMMA QT boards with boards like Circuit Playground. On one end you get a Qwiic / STEMMA QT connector (technically known as a JST SH 4-pin plug)&nbsp; into 4 individual wires with grippy alligator clips. We're carrying these to...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4398)
[Related Guides to the Product](https://learn.adafruit.com/products/4398/guides)

## Related Guides

- [Ambient Sound Machine](https://learn.adafruit.com/ambient-machine.md)
- [Cooperative Multitasking in CircuitPython with asyncio](https://learn.adafruit.com/cooperative-multitasking-in-circuitpython-with-asyncio.md)
- [CircuitPython Hardware: ILI9341 TFT & FeatherWing](https://learn.adafruit.com/micropython-hardware-ili9341-tft-and-featherwing.md)
- [Microsoft Azure Cost Monitor](https://learn.adafruit.com/azure-cost-monitor.md)
- [Adafruit NeoSlider](https://learn.adafruit.com/adafruit-neoslider.md)
- [LED Glasses Custom Animated Graphics with Sprites](https://learn.adafruit.com/led-glasses-custom-animated-graphics-with-sprites.md)
- [Adafruit TCA8418 Keypad Matrix and GPIO Expander Breakout](https://learn.adafruit.com/adafruit-tca8418-keypad-matrix-and-gpio-expander-breakout.md)
- [Adafruit VS1053 MP3/AAC/Ogg/MIDI/WAV Codec Breakout Tutorial](https://learn.adafruit.com/adafruit-vs1053-mp3-aac-ogg-midi-wav-play-and-record-codec-tutorial.md)
- [Measuring Parts from Product Photos in FreeCAD](https://learn.adafruit.com/measuring-parts-from-product-photos-in-freecad.md)
- [MagTag Dishwasher Status](https://learn.adafruit.com/magtag-dishwasher-status.md)
- [RGB Matrix Portal Room CO2 Monitor](https://learn.adafruit.com/matrix-portal-room-co2-monitor.md)
- [Adafruit Qwiik/STEMMA QT 5 Port Hub](https://learn.adafruit.com/qwiik-stemma-qt-5-port-hub.md)
- [Adafruit PyPortal - IoT for CircuitPython](https://learn.adafruit.com/adafruit-pyportal.md)
- [Custom Scrolling Quote Board Matrix Display](https://learn.adafruit.com/aio-quote-board-matrix-display.md)
- [Using VCNL4010 Proximity Sensor](https://learn.adafruit.com/using-vcnl4010-proximity-sensor.md)
