MCP23017-E/SS 16路IO扩展模块 IIC扩展板
简介
MCP23017能将16位并行I/O数据和IIC串行数据相互转换;设备IIC通信频率可达1.7MHz;IIC总线上可连接8个器件共128个I/O;两个中断输出引脚,可配置为高/低/开漏有效中断输出;带有外部输入复位引脚,低有效。
MCP23017模块
模块A2、A1、A0接到GND都为0,默认为0100000x,GPIOA、GPIOB默认为输入模式。
Arduino UNO与MCP23017接线
AArduino UNO | MCP23017 |
---|---|
5V | VCC |
GND | GND |
SCL | SCL |
SDA | SDA |
MCP23017的PA0、PA1、PA2接三色LED的R、G、B引脚
测试程序
打开Arduino IDE的库管理器搜索MCP23017例程库并安装,打开toggle例程
#include <Wire.h>
#include "Adafruit_MCP23017.h"
// Basic pin reading and pullup test for the MCP23017 I/O expander
// public domain!
// Connect pin #12 of the expander to Analog 5 (i2c clock)
// Connect pin #13 of the expander to Analog 4 (i2c data)
// Connect pins #15, 16 and 17 of the expander to ground (address selection)
// Connect pin #9 of the expander to 5V (power)
// Connect pin #10 of the expander to ground (common ground)
// Connect pin #18 through a ~10kohm resistor to 5V (reset pin, active low)
// Output #0 is on pin 21 so connect an LED or whatever from that to ground
Adafruit_MCP23017 mcp;
void setup() {
mcp.begin(); // use default address 0
mcp.pinMode(0, OUTPUT);
mcp.pinMode(1, OUTPUT);
mcp.pinMode(2, OUTPUT);
}
// flip the pin #0 up and down
void loop() {
delay(100);
mcp.digitalWrite(0, HIGH);
delay(100);
mcp.digitalWrite(0, LOW);
delay(100);
mcp.digitalWrite(1, HIGH);
delay(100);
mcp.digitalWrite(1, LOW);
delay(100);
mcp.digitalWrite(2, HIGH);
delay(100);
mcp.digitalWrite(2, LOW);
}
总结
在MCU的IO引脚不够用时,选择MCP23017扩展更多的IO引脚与更多的设备实现连接交换数据。