Expanding Microcontroller Pins with an I/O Expander Part 1 (MCP23S08-E/P)

Info

This article is translated from Japanese to English.

https://404background.com/circuit/mcp23s08/

Introduction

This time, I experimented with an I/O Expander called MCP23S08.

An I/O Expander lets you increase the number of I/O pins on your microcontroller.
You can control the expander’s pins through either SPI or I2C communication. Among them, the MCP23S08 uses SPI and allows you to add eight additional GPIO pins.

There’s also another model called MCP23017, which communicates via I2C and provides 16 GPIO pins.
Since there’s more documentation and examples available online for the MCP23017, it might actually be the more convenient choice for most projects.

▼ The product I bought

https://akizukidenshi.com/catalog/g/gI-10643/

▼I also tried the MCP23017

Expanding Microcontroller Pins with an I/O Expander Part 2 (MCP23017)

Info This article is translated from Japanese to English. Introduction Previously, I used an I/O Expander called MCP23S08, but this time, I tried the MCP23017.…

Building the Circuit

In this setup, the GPIO pins on the MCP23S08 control eight LEDs.
The Arduino uses four pins for SPI communication.
It might not seem like much of an expansion, but the MCP23S08 can handle up to four devices using address settings, which means you can increase the number of available pins even further.

▼ The LEDs I used are similar to this bar graph type:

https://eleshop.jp/shop/g/gB5G366

▼ Circuit diagram

▼ Actual wiring

Writing the Program

The program was written using the Arduino IDE.
When I searched for an MCP23S08 library, I found several available — so first, install one through the Library Manager.

▼ Open “Tools → Manage Libraries” in the Arduino IDE.

▼ There are multiple MCP23S08 libraries, but I used the Adafruit version.

With this library, you can control the MCP23S08’s pins just like standard Arduino pins, using familiar functions like pinMode() and digitalWrite().

One important note:
You must declare pin modes inside the setup() function using pinMode().
Unlike regular Arduino pins — which sometimes work even if you skip that step — the MCP23S08 pins won’t respond unless you set their modes explicitly.

▼ Reference sample programs

▼ Combined sample program

▼ Actual operation

Conclusion

In this example, I didn’t specify any addresses, but by doing so, you could expand the number of available pins even further. I plan to take a closer look at the library to learn more. I actually bought the MCP23S08 simply because it had a Japanese datasheet available — but the terminology was still quite dense and not easy to follow.
After looking into I/O Expanders more deeply, it seems like the MCP23017 really does have more information and is easier to work with.
I might end up not using the MCP23S08 much after all…

Leave a Reply

Your email address will not be published. Required fields are marked *