MCP23017: Difference between revisions

From RevSpace
Jump to navigation Jump to search
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
  |Omschrijving= Guide: Connecting MCP23017 to ESP8266
  |Omschrijving= Guide: Connecting MCP23017 to ESP8266
  |Status=Completed
  |Status=Completed
  |Contact=sttc
  |Contact=Sttc
}}
}}


Line 24: Line 24:


* ESP8266:   
* ESP8266:   
LiLon NodeMCU V3  4MB flash ESP8266 12E
LoLin NodeMCU V3  4MB flash ESP8266 12E
More info on ESP8266:
More info on ESP8266:
https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
Line 32: Line 32:
Setting up ESP8266 for I2C pins is not necessary in this code. SCL and SDA pins as below:
Setting up ESP8266 for I2C pins is not necessary in this code. SCL and SDA pins as below:
   
   
Connecting pins between MCP23017 and ESP8266
{| class="wikitable"
{| class="wikitable"
|-
|-
! Pin on MCP23017 !! ESP8266
! MCP23017 <-- !! --> ESP8266
|-
|-
| GND || GND
| GND || GND
Line 147: Line 148:
   
   
== Remarks ==  
== 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)
*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)
 
<br>
== Links ==
*ESP8266 configuration on Arduino IDE:
<br>
 
[[File:ESP conf.png|100px|left|thumb|esp8266]]
<br>

Latest revision as of 19:59, 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:

LoLin 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:

Connecting pins between MCP23017 and ESP8266

MCP23017 <-- --> ESP8266
GND GND
VCC 3V
SCL D1 (GPIO5)
SDA D2 (GPIO4)

Code

Required libraries:

  • Wire
  • Adafruit_MCP23017
// 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)


  • ESP8266 configuration on Arduino IDE:


esp8266