# Adafruit AW9523 GPIO Expander and LED Driver

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/099/328/medium800/adafruit_products_AW9523_top.jpg?1612904620)

Expand your project possibilities, with the **Adafruit AW9523 GPIO Expander and LED Driver Breakout** - a cute and powerful I2C expander with a lot of tricks up it's sleeve.

GPIO expanders work like this: you have a board with some number of GPIO but not enough for your project - maybe you need more buttons or LEDs. [You _could_ upgrade to a board with massive number of GPIO like the Grand Central](https://www.adafruit.com/?q=grand+central&sort=BestMatch), or you could pop on one of these boards. Connect it over I2C and then you can send/receive I2C commands to control the GPIO pins to write and read them. It's going to be slower than direct GPIO access, but maybe that doesn't matter if it takes a millisecond instead of a microsecond. You only need the two I2C pins, and you can even share the I2C port with other sensors and devices. Heck, you can even add more expanders for massive I/O control!

![](https://cdn-learn.adafruit.com/assets/assets/000/099/329/medium800/adafruit_products_AW9523_top_header.jpg?1612904628)

The AW9523 is a twist on the common I2C expander:

- First up, its very affordable - who doesn't love that?
- It has 16 I/O pins, that'll double most boards' pin count
- Four I2C address options, so you can connect 4 expanders to one bus
- Each pin can be an input or an output
- IRQ output can alert you when input pins change value
- This chip _does not_ support internal pull-ups or pull-downs, you will need to add an external resistor if you need one
- However, it _does_ have 8-bit linear constant-current LED dimming support so you can connect LEDs without resistors and have great looking dimming without PWM
- The first 8 pins can be configured as open drain (as a group)

![](https://cdn-learn.adafruit.com/assets/assets/000/099/330/medium800/adafruit_products_AW9523_top_angle.jpg?1612904641)

The lack of internally-configurable pull's is a bit of a bummer, but we think the expander more than makes up for it with the constant-current LED drive. If you're using an expander to add lots of controllable LEDs, this board will make it very easy. Since its constant-current, you _don't_ need resistors in line with each LED (although it won't hurt if you do): simply connect the LED anode to one of the many VIN pads, then connect the cathode to the GPIO pin.

Of course, you can control any buttons or other I/O with the pins - we just think this board is particularly suited to LED driving. There's also an interrupt output, you can enable the pin-change IRQ for any pins so you can be notified when its time to read the I/O states.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/331/medium800/adafruit_products_AW9523_back.jpg?1612904649)

One oddity about this chip is the default I2C address determines the initial boot-state of the pins. Our libraries immediately soft-reset and configure all the pins to inputs and push-pull so you can expect the same behavior no matter what the I2C address is. However, we recommend you check the datasheet Table 1 to make sure this doesn't affect your hardware.

[We've written both Arduino](https://github.com/adafruit/Adafruit_AW9523) and [CircuitPython/Python libraries](https://github.com/adafruit/Adafruit_CircuitPython_AW9523) for the AW9523, so you can get started whether you have an Arduino-compatible UNO or a Raspberry Pi 4 - or anything in between.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/332/medium800/adafruit_products_AW9523_STEMMA_side.jpg?1612904656)

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

# Adafruit AW9523 GPIO Expander and LED Driver

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/099/333/medium800/adafruit_products_AW9523_pinouts.jpg?1612904714)

## Power Pins:

- **VIN -** This is the power pin. To power the expander breakout board, give it the same power as the logic level of your microcontroller - e.g. for a 5V micro like Arduino, use 5V
- **GND** - common ground for power and logic

## I2C Logic pins:

- **SCL** -_&nbsp;_I2C clock pin, connect to your microcontroller I2C clock line.   
- **SDA** - I2C data pin, connect to your microcontroller I2C data line.   
- [**STEMMA QT**](https://learn.adafruit.com/introducing-adafruit-stemma-qt) **&nbsp;-** These connectors allow you to connectors to dev boards with&nbsp; **STEMMA QT** connectors or to other things with&nbsp;[various associated accessories](https://www.adafruit.com/?q=JST%20SH%204)

## GPIO Pins

- **0 - 15** - GPIO expander pins for LED drive (current-source dimming) or GPIO mode. Can be used as input or output. Supports 8-bit linear constant-current LED dimming support so you can connect LEDs without resistors. Note that this chip does not support internal pull-up or pull-downs, so you will need to add an external resistor if you need one.

## Other Pins

- **INT** - Interrupt output pin, can alert you when input value changes.
- **RST** - Hardware reset pin, set low to perform a hardware reset. Has 10kΩ pull-up resistor.
- **A0 and A1 jumpers** - These can be used to change the default I2C address from 0x58 to 0x59 (A0 shorted), 0x5A (A1 shorted) or 0x5B (both shorted!)

# Adafruit AW9523 GPIO Expander and LED Driver

## Arduino

## Wiring

Connecting the AW9523 breakout to your Feather or Arduino is easy:

- If you are running a Feather (3.3V), connect&nbsp; **Feather**  **3V** to **board**  **VIN**
- If you are running a 5V Arduino (Uno, etc.), connect **Arduino**  **5V** to&nbsp; **board**  **VIN**
- Connect **Feather or Arduino**  **GND** to **board**  **GND**
- Connect **Feather or Arduino**  **SCL** to **board SCL**
- Connect **Feather or Arduino**  **SDA** to **board SDA**

![adafruit_products_AW9523_Arduino_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/099/359/medium640/adafruit_products_AW9523_Arduino_bb.png?1612987809)

The final results should resemble the illustration above, showing an Adafruit Metro development board.

## Installation

You can install the **Adafruit AW9523 Library** for Arduino using the Library Manager in the Arduino IDE:

![](https://cdn-learn.adafruit.com/assets/assets/000/099/336/medium800/adafruit_products_Arduino_Library_Manager.png?1612906678)

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

![](https://cdn-learn.adafruit.com/assets/assets/000/099/337/medium800/adafruit_products_AW9523_Arduino_lib_install.png?1612906768)

Then follow the same process for the **Adafruit BusIO** library.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/338/medium800/adafruit_products_Arduino_BusIO_Lib_Install.png?1612906789)

# Load Example

There are three different examples for the Adafruit AW9523 in Arduino.

### Blink

This example, unsurprisingly, blinks a single GPIO output pin. It's a good demo for setting a pin to be an output and changing the state

In this example, connect an LED + resistor to the expander pin labeled **0**

Connect the anode (positive) leg of the LED to the 0 pad, then the cathode (negative) leg of the LED to a ~ 1K ohm resistor and the other end of the resistor to ground.

![adafruit_products_oneled.png](https://cdn-learn.adafruit.com/assets/assets/000/099/360/medium640/adafruit_products_oneled.png?1612988086)

https://github.com/adafruit/Adafruit_AW9523/blob/master/examples/blink_demo/blink_demo.ino

The LED connected to pin 0 will blink every 100 milliseconds!

### Button Input and LED Output

This example shows how you can create an input on the expander. Note that this expander does not support internal pull resistors

Keep the LED wired up on pin 0, with a resistor to ground, this is the output

Connect a tactile switch with one side connected to pin 1 of the expander. Add a ~10K pull-up resistor on the expander pin 1 to Vin. Connect the other side of the button to ground. This makes it so the button pin is HIGH by default, and when you press the button, the pin goes LOW

![](https://cdn-learn.adafruit.com/assets/assets/000/099/363/medium800/adafruit_products_AW9523_Arduino_LED_button_bb.png?1612990426)

Open up **File -\> Examples -\> Adafruit AW9523**  **-\> ledbutton\_demo** and upload to your Arduino wired up to the breakout.

https://github.com/adafruit/Adafruit_AW9523/blob/master/examples/ledbutton_demo/ledbutton_demo.ino

This line in the main loop does all the work:

`aw.digitalWrite(LedPin, aw.digitalRead(ButtonPin));`

We read the button pin, and whatever the logic value is, sets that to the LED output. So when the button is _not_ pressed, the LED is on (HIGH). When the button _is_ pressed, the LED is off (LOW)

You can also see we enable the interrupt pin to listen to the button, you can use the INT pin to then monitor for 'changes' without performing an I2C read of the expander

### Constant current LED fade demo

This example shows how to set up a pin to use it as a constant-current driver for an LED. This is great for flicker-free LED driving, and consistent brightness no matter what the voltage is

In this example, connect an LED to the expander pin labeled **0**

Connect the **cathode (negative)** leg of the LED to the 0 pad, then the **anode (positive)** to power

Note that you do not need a resistor with the LED because we are limited the current internally. However, there's no harm if the LED has a resistor.

![adafruit_products_constcurr.png](https://cdn-learn.adafruit.com/assets/assets/000/099/362/medium640/adafruit_products_constcurr.png?1612988671)

Warning: 

https://github.com/adafruit/Adafruit_AW9523/blob/master/examples/constcurrent_demo/constcurrent_demo.ino

Open up **File -\> Examples -\> Adafruit AW9523**  **-\> constcurrent\_demo** and upload to your Arduino wired up to the breakout.

The `aw.analogWrite(LedPin, x++);` line will cause the LED on pin 0 to fade up from 0 (no current) to 255 (max current) Then once at maximum 255, the x variable will wrap around and start again from 0 so you'll see it 'pulse'

# Adafruit AW9523 GPIO Expander and LED Driver

## Arduino Docs

# Adafruit AW9523 GPIO Expander and LED Driver

## Python & CircuitPython

It's easy to use the Adafruit AW9523 GPIO Expander and LED Driver Breakout with CircuitPython and the [Adafruit CircuitPython AW9523](https://github.com/adafruit/Adafruit_CircuitPython_AW9523) module.&nbsp; This module allows you to easily write Python code that reads temperature and humidity data from the sensor.

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

## CircuitPython Microcontroller Wiring

First wire up an AW9523 to your board exactly as follows. Here is an example of the AW9523 wired to a Feather using I2C:

- **Board 3V** &nbsp;to&nbsp;**breakout VIN (red wire)**
- **Board GND** &nbsp;to&nbsp;**breakout GND (black wire)**
- **Board SCL** &nbsp;to&nbsp;**breakout SCL (yellow wire)**
- **Board SDA** &nbsp;to&nbsp;**breakout SDA (blue wire)**

![adafruit_products_AW9523_Feather_I2C_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/099/364/medium640/adafruit_products_AW9523_Feather_I2C_bb.jpg?1612994190)

## Python Computer Wiring

Since there's&nbsp;_dozens_&nbsp;of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms,&nbsp;[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 wired with I2C:

- **Pi 3V** &nbsp;to **breakout VIN (red wire)**
- **Pi GND** &nbsp;to **breakout GND (black wire)**
- **Pi SCL** &nbsp;to&nbsp;**breakout SCL (yellow wire)**
- **Pi SDA** &nbsp;to&nbsp;**breakout SDA (blue wire)**

![adafruit_products_AW9523_RasPi_I2C_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/099/365/medium640/adafruit_products_AW9523_RasPi_I2C_bb.jpg?1612994404)

## CircuitPython Installation of AW9523 Library

You'll need to install the [Adafruit CircuitPython AW9523](https://github.com/adafruit/Adafruit_CircuitPython_AW9523) library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://circuitpython.org/libraries).&nbsp; Our CircuitPython starter guide has [a great page on how to install libraries from the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

Copy the following file from the bundle to the **lib** folder on your **CIRCUITPY** drive:

- **adafruit\_aw9523.mpy**

Also copy the following folder (not its individual contents, but the _whole folder itself_) into **lib** :

- **adafruit\_register**

Before continuing make sure your board's **lib** folder or root filesystem has both the&nbsp; **adafruit\_aw9523.mpy** file and **adafruit\_register** folder copied over.

## Python Installation of AW9523 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-aw9523`

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

## CircuitPython & Python Usage

To demonstrate the usage of this breakout, you have two examples to choose from: I/O using a button and an LED, and constant current fade.

### Button and LED

This example shows how you can create an output and an input on the expander. Note that this expander does not support internal pull resistors.

Connect an LED to pin 0, with a resistor to ground, this is the output.

Connect a tactile switch with one side connected to pin 1 of the expander. Add a ~10K pull-up resistor on the expander pin 1 to Vin. Connect the other side of the button to ground. This makes it so the button pin is HIGH by default, and when you press the button, the pin goes LOW.

- **LED+** to **breakout GPIO 0**
- **LED-** to **1K resistor**
- **1K resistor** to **breadboard ground rail**
- **One leg** of **button to breadboard ground rail**
- **Other leg of button** to **breakout GPIO 1 + 10K pull-up resistor**
- **10K pull-up resistor** to **breadboard VIN rail**

![adafruit_products_AW9523_Feather_I2C_LED_button_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/099/368/medium640/adafruit_products_AW9523_Feather_I2C_LED_button_bb.jpg?1612994860)

Save the following as **code.py** on your **CIRCUITPY** drive.

https://github.com/adafruit/Adafruit_CircuitPython_AW9523/blob/main/examples/aw9523_simpletest.py

Now, press the button. The LED lights up! The LED mirrors the button, so when the button is pressed, the LED lights up.

### Constant Current Fade

This example shows how to set up all the pins to use them as a constant-current driver for LEDs. This is great for flicker-free LED driving, and consistent brightness no matter what the voltage is.

In this example, connect LEDs to each expander pin.

Connect the **cathode (negative)** leg of the LED to the numbered GPIO pad, then the **anode (positive)** to power

Note that you do not need resistors with the LEDs because we are limiting the current internally. However, there's no harm if the LED has a resistor.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/369/medium800/adafruit_products_AW9523_Feather_I2C_cont_current_LEDs_bb.jpg?1612996382)

Warning: 

Save the following as **code.py** on your **CIRCUITPY** drive.

https://github.com/adafruit/Adafruit_CircuitPython_AW9523/blob/main/examples/aw9523_constant_current_leds.py

All of the LEDs light up in a pattern.

The `aw.set_constant_current(pin, (pin * 16 + n) % 256)` plus `n = (n + 1) % ``256` will cause the LEDs on each pin to fade up from 0 (no current) to 255 (max current), then fade back down. The fade on each pin is offset by 16 counts so they don't all pulse together.

That's all there is to using the AW9523 with CircuitPython and Python!

# Adafruit AW9523 GPIO Expander and LED Driver

## Python Docs

# Adafruit AW9523 GPIO Expander and LED Driver

## Downloads

## Files:

- [AW9523 Datasheet](https://cdn-shop.adafruit.com/product-files/4886/AW9523%20English%20Datasheet.pdf)
- [Fritzing object in the Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20AW9523.fzpz)
- [EagleCAD PCB files on GitHub](https://github.com/adafruit/Adafruit-AW9523-PCB)

# Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/099/334/medium800/adafruit_products_AW9523_sch.png?1612906135)

# Fab Print
![](https://cdn-learn.adafruit.com/assets/assets/000/099/335/medium800/adafruit_products_AW9523_fab_print.png?1612906145)


## Primary Products

### Adafruit AW9523 GPIO Expander and LED Driver Breakout

[Adafruit AW9523 GPIO Expander and LED Driver Breakout](https://www.adafruit.com/product/4886)
Expand your project possibilities, with the **Adafruit AW9523 GPIO Expander and LED Driver Breakout** - a cute and powerful I2C expander with a lot of tricks up its sleeve.

GPIO expanders work like this: you have a board with some number of GPIO but not enough for your...

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

## Related Guides

- [16-Step Drum Sequencer](https://learn.adafruit.com/16-step-drum-sequencer.md)
- [Adafruit nOOds Überguide](https://learn.adafruit.com/noods-uberguide.md)
- [Raspberry Pi Pico and LED Arcade Button MIDI Controller](https://learn.adafruit.com/raspberry-pi-pico-led-arcade-button-midi-controller-fighter.md)
- [LED Noodle Holiday Tree](https://learn.adafruit.com/led-noodle-tree.md)
- [LED Masquerade Masks with n00ds](https://learn.adafruit.com/led-masquerade-masks-with-n00ds.md)
- [LEGO Set Lighting](https://learn.adafruit.com/lego-set-lighting.md)
- [Adafruit E-Ink Bonnet for Raspberry Pi](https://learn.adafruit.com/adafruit-e-ink-bonnet-for-raspberry-pi.md)
- [Adafruit Circuit Playground Bluefruit](https://learn.adafruit.com/adafruit-circuit-playground-bluefruit.md)
- [Adafruit FONA 800 Shield](https://learn.adafruit.com/adafruit-fona-800-shield.md)
- [Adafruit OLED FeatherWing](https://learn.adafruit.com/adafruit-oled-featherwing.md)
- [Adafruit ItsyBitsy ESP32](https://learn.adafruit.com/adafruit-itsybitsy-esp32.md)
- [Adafruit INA260 Current + Voltage + Power Sensor Breakout](https://learn.adafruit.com/adafruit-ina260-current-voltage-power-sensor-breakout.md)
- [Adafruit DRV2605L Haptic Controller Breakout](https://learn.adafruit.com/adafruit-drv2605-haptic-controller-breakout.md)
- [Adafruit 1.3" Color TFT Bonnet for Raspberry Pi](https://learn.adafruit.com/adafruit-1-3-color-tft-bonnet-for-raspberry-pi.md)
- [Wireless LED Maracas](https://learn.adafruit.com/wireless-led-maracas.md)
