Difference between revisions of "MCP23017"

From Let's Control It
Jump to navigation Jump to search
(Updated command list)
 
(5 intermediate revisions by one other user not shown)
Line 17: Line 17:
 
   SCL GPIO 2
 
   SCL GPIO 2
  
= Software =
+
= ESP Easy =
 
 
== ESP Easy ==
 
  
 
Configuration depends on how you want to use a certain port on this device. Ports are numbered 1 to 16 (if you have a single MCP23017 connected)
 
Configuration depends on how you want to use a certain port on this device. Ports are numbered 1 to 16 (if you have a single MCP23017 connected)
  
=== Input ===
+
== Input ==
 
To have an input port act as an input switch device (just like with the default onboard GPIO pins) you need to edit a ESP Easy task and select the "MCP23017 input" device.
 
To have an input port act as an input switch device (just like with the default onboard GPIO pins) you need to edit a ESP Easy task and select the "MCP23017 input" device.
  
 
  [[File:EasyConfigMCP.png]]
 
  [[File:EasyConfigMCP.png]]
  
You then select the portnumber (numbered from 1 - 16) and additional configuration depending on the controller type. For Domoticz, you enter the IDX that was allocated by Domoticz for this virtual switch.
+
You then select the portnumber and additional configuration depending on the controller type. For Domoticz, you enter the IDX that was allocated by Domoticz for this virtual switch.
  
=== Optional settings ===
+
Portnumbering depends on the I2C address used:
  
[[ EasyFormula | Use of formulas]]
+
{| border="1" style="border-collapse:collapse; border:1px solid silver;text-align:left;width:50%;"
 +
! A0:
 +
! A1:
 +
! A2:
 +
! Address:
 +
! Port range:
 +
|-
 +
| ''0''
 +
| ''0''
 +
| ''0''
 +
| 0x20
 +
| 1 - 16
 +
|-
 +
| ''1''
 +
| ''0''
 +
| ''0''
 +
| 0x21
 +
| 17 - 32
 +
|-
 +
| ''0''
 +
| ''1''
 +
| ''0''
 +
| 0x22
 +
| 33 - 48
 +
|-
 +
| ''1''
 +
| ''1''
 +
| ''0''
 +
| 0x23
 +
| 49 - 64
 +
|-
 +
| ''0''
 +
| ''0''
 +
| ''1''
 +
| 0x24
 +
| 65 - 80
 +
|-
 +
| ''1''
 +
| ''0''
 +
| ''1''
 +
| 0x25
 +
| 81 - 96
 +
|-
 +
| ''0''
 +
| ''1''
 +
| ''1''
 +
| 0x26
 +
| 97 - 112
 +
|-
 +
| ''1''
 +
| ''1''
 +
| ''1''
 +
| 0x27
 +
| 113 - 128
 +
|}
  
[[ EasyValueNames | Use of value names]]
+
= Commands =
  
=== Output ===
 
You can control output pins on this chip with the following http command:
 
  
'''<nowiki>http://<ESP IP address>/control?cmd=mcpgpio,<pin>,0</nowiki>'''
+
{| class="wikitable sortable"
 +
|-
 +
! Command
 +
! Value
 +
! Extra information
 +
|-
  
'''<nowiki>http://<ESP IP address>/control?cmd=mcpgpio,<pin>,1</nowiki>'''
+
| MCPGPIO,<pin>,<value>
 +
| '''1,0'''
 +
| Control MCP23017 output pins (1 or 0)
 +
|-
  
== ESP Connexio ==
+
| MCPPulse,<pin>,<value>,<duration>
Command:
+
| '''1,0'''
''<nowiki>MCPWiredOut <pin nr>,<On/Off></nowiki>''
+
| Pulse control on MCP23017 output pins (duration in mS, MILLIseconds)
 +
|-
  
{| border="1" style="border-collapse:collapse; border:1px solid silver;text-align:left;width:50%;"
+
| MCPLongPulse,<pin>,<value>,<duration>
! Parameter:
+
| '''1,0'''
! Beschrijving:
+
| Pulse control on MCP23017 output pins (duration in S, seconds)
! Bereik:
 
! Opmerking:
 
|-
 
| ''Pin nr''
 
| Output pin
 
| 1 t/m 16
 
|
 
 
|-
 
|-
| ''On/Off''
 
| Aan of Uit
 
| On/Off
 
|
 
 
|}
 
|}
 
=== Sample ===
 
MCPWiredOut 1,On
 

Latest revision as of 17:55, 16 October 2017

Introduction

The number of GPIO pins on the ESP module can be expanded with a IO Expander. We will use the MCP23017 that provides 16 more pins that can be used as input or output. This way it becomes possible to control a 16 channel relay board.

Each individual pin can be used as either input or output.

Hardware

MCP23017DIP28.jpg

The MCP23017 needs to be connected through the I2C interface. This chip is compatible with 3V3 and it can be connected to the ESP without levelshifters..

Connections

 MCP23017 	ESP-01
 GND 	 	GND
 VCC    	VCC
 SDA		GPIO 0
 SCL		GPIO 2

ESP Easy

Configuration depends on how you want to use a certain port on this device. Ports are numbered 1 to 16 (if you have a single MCP23017 connected)

Input

To have an input port act as an input switch device (just like with the default onboard GPIO pins) you need to edit a ESP Easy task and select the "MCP23017 input" device.

EasyConfigMCP.png

You then select the portnumber and additional configuration depending on the controller type. For Domoticz, you enter the IDX that was allocated by Domoticz for this virtual switch.

Portnumbering depends on the I2C address used:

A0: A1: A2: Address: Port range:
0 0 0 0x20 1 - 16
1 0 0 0x21 17 - 32
0 1 0 0x22 33 - 48
1 1 0 0x23 49 - 64
0 0 1 0x24 65 - 80
1 0 1 0x25 81 - 96
0 1 1 0x26 97 - 112
1 1 1 0x27 113 - 128

Commands

Command Value Extra information
MCPGPIO,<pin>,<value> 1,0 Control MCP23017 output pins (1 or 0)
MCPPulse,<pin>,<value>,<duration> 1,0 Pulse control on MCP23017 output pins (duration in mS, MILLIseconds)
MCPLongPulse,<pin>,<value>,<duration> 1,0 Pulse control on MCP23017 output pins (duration in S, seconds)