MCP23017
This example demonstrates the use of MCP23017 IO expanders as if they were just normal IO pins.
- Boards:
- AVR, AVR USB, Nano Every, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Due, Teensy 3.x, ESP8266, ESP32
Connections
Connect an LED (and series resistor) between pin GPA0 of the MCP and ground. Connect a push button between pin GPB0 of the MCP and ground. The internal pull-up resistor will be used.
Tie the three address lines of the MCP to ground.
Behavior
When the push button is pressed, the LED turns on.
Written by PieterP, 2020-11-20
https://github.com/tttapa/Arduino-Helpers
#include <Wire.h>
using WireType = decltype(Wire);
Wire,
0x0,
2,
};
pin_t buttonPin = mcp.pinB(0);
void setup() {
Wire.begin();
Wire.setClock(800000);
mcp.begin();
}
void loop() {
}
constexpr PinStatus_t LOW
constexpr PinStatus_t HIGH
constexpr PinMode_t INPUT_PULLUP
constexpr PinMode_t OUTPUT
Dummy header file for Arduino builder.
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Class for MCP23017 I²C I/O expanders.
pin_t pinA(pin_t p)
Get the identifier of the given pin in register A.
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
PinStatus_t digitalRead(pin_t pin)
An ExtIO version of the Arduino function.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.
A namespace with alternatives to the standard Arduino IO functions that can be used with extended IO ...