MCP23017: Difference between revisions

From RevSpace
Jump to navigation Jump to search
(Created page with " {{Project |Name=MCP23017 |Picture=Mcp23017.jpg |Omschrijving= Guide: Connecting MCP23017 to ESP8266 |Status=Completed |Contact=sttc }} == Status == Status as of 2020...")
 
Line 15: Line 15:


== Introduction ==
== Introduction ==
MCP23017 is a GPIO expander runs on I2C.
MCP23017 is a GPIO expander that runs on I2C.
This page forms wiring and communication guide for MCP23017 on ESP8266.
This page forms wiring and communication guide for MCP23017 on ESP8266.



Revision as of 17:11, 15 February 2020


Project MCP23017
Mcp23017.jpg
Guide: Connecting MCP23017 to ESP8266
Status Completed
Contact sttc
Last Update 2020-02-15


Status

Status as of 2020/1/13:

  • Completed


Introduction

MCP23017 is a GPIO expander that runs on I2C. This page forms wiring and communication guide for MCP23017 on ESP8266.

Used components:

  • MCP23017

MCP23017 I2C Interface 16bit I/O Extension Module Pin Board IIC to GIPO Converter https://www.aliexpress.com/item/32883688022.html?spm=a2g0s.9042311.0.0.5d3e4c4d6bMkco

  • ESP8266:

LiLon NodeMCU V3 4MB flash ESP8266 12E More info on ESP8266: https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/

Wiring

Setting up ESP8266 for I2C pins is not necessary in this code. SCL and SDA pins as below:

Pin on MCP23017 ESP8266
GND GND
VCC 3V
SCL D1 (GPIO5)
SDA D2 (GPIO4)

Code

// MCP23017 Example: Slow key press reaction.
//
// Toggle LEDs and detect keypress.
//
// Example code showing slow reaction of 'button' 
// LED to keypress. Leading into why interrupts
// are useful (See next example).
//
// Copyright : John Main
// Free for non commercial use.

#include <Wire.h>
#include <Adafruit_MCP23017.h>

#define MCP_LED1 7
#define MCP_INPUTPIN 8
#define MCP_LEDTOG1 11 

Adafruit_MCP23017 mcp;
  
void setup() {  
  mcp.begin();      // Default device address 0

  mcp.pinMode(MCP_LEDTOG1, OUTPUT);  // LED for blinking
  
  mcp.pinMode(MCP_LED1, OUTPUT);     // LED output for button
  
  mcp.digitalWrite(MCP_LED1, HIGH);  // default > LED turn on

  mcp.pinMode(MCP_INPUTPIN,INPUT);   // Button i/p to GND
  mcp.pullUp(MCP_INPUTPIN,HIGH);     // Puled high to ~100k
}
 
void loop() {

  // blinking led
  delay(300);
  mcp.digitalWrite(MCP_LEDTOG1, HIGH); 
  delay(300);
  mcp.digitalWrite(MCP_LEDTOG1, LOW); 
  
  
  
  // Transfer input pin state to LED1
  if (mcp.digitalRead(MCP_INPUTPIN)) {
     mcp.digitalWrite(MCP_LED1,HIGH);
  } else {
     mcp.digitalWrite(MCP_LED1,LOW);
  }
  
}

MCP21017 GPIO

Number in IDE =
mcp.pinMode(Number in IDE, OUTPUT);


MCP21017 Number in IDE
PA0 0
PA1 1
PA2 2
PA3 3
PA4 4
PA5 5
PA6 6
PA7 7
PB0 8
PB1 9
PB2 10
PB3 11
PB4 12
PB5 13
PB6 14
PB7 15

Remarks

Pins of VCC,GND,SCL,SDA,RT,ITA,ITB line do not fit to the board together with GPIO pins (PA7, PA6...) > (Do not solder VCC... line pins)

Links