Example Node-RED MCP23017

This is a simple working Node-Red example for a Raspberry PI with an GPIO Port extender MCP23017. It is easy possible to control the MCP23017 with Node-RED.

Here a screenshots from the devices. The description on developer page is not really good. We needed 2 days for the right settings. It is really simple.

The overview Example Node-RED MCP23017

Node-Red-MCP23017
Node-Red-MCP23017

 

Here the screenshot from the Raspberry PI mcp23017

Node-Red-MCP23017-02
Node-Red-MCP23017-02

The Status Node (To see which pin is off or on)

Node-Red-MCP23017-03
Node-Red-MCP23017-03

The Pin 7 OFF

Node-Red-MCP23017-04
Node-Red-MCP23017-04

Pin 7 ON

Node-Red-MCP23017-05
Node-Red-MCP23017-05

All ON

Node-Red-MCP23017-06
Node-Red-MCP23017-06

All OFF

Node-Red-MCP23017-07
Node-Red-MCP23017-07

A switch for the Website (Dashboard) for all GPIOs

Node-Red-MCP23017-08
Node-Red-MCP23017-08

The msg.payload is only for debug to see the commands. You don’t need it.

Node-Red-MCP23017-09
Node-Red-MCP23017-09

So now you can extend your program and try some solutions.

Here is the complete code from this Flow to import in your system Node-RED MCP23017.

[
{
"id": "ed2d8f08.a0c38",
"type": "tab",
"label": "Flow 1"
},
{
"id": "ed29ea8a.fe4058",
"type": "mcp23017",
"z": "ed2d8f08.a0c38",
"name": "MCP23017 Node",
"topic": "",
"address": "0x20",
"device": "/dev/i2c-1",
"x": 391,
"y": 264,
"wires": [
[
"7d7f7a50.181eb4"
]
]
},
{
"id": "9051c299.39168",
"type": "inject",
"z": "ed2d8f08.a0c38",
"name": "Get Status",
"topic": "home/sprinklers/status",
"payload": "",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"x": 183,
"y": 116,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "5daeb3b2.2b1e9c",
"type": "inject",
"z": "ed2d8f08.a0c38",
"name": "pin7 ON",
"topic": "devices/sprinklers/7",
"payload": "ON",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"x": 132,
"y": 275,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "f839911c.dd3338",
"type": "inject",
"z": "ed2d8f08.a0c38",
"name": "pin7 OFF",
"topic": "devices/sprinklers/7",
"payload": "OFF",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"x": 138,
"y": 217,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "594acb2c.00199c",
"type": "inject",
"z": "ed2d8f08.a0c38",
"name": "all",
"topic": "home/sprinklers/ALL",
"payload": "ON",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"x": 117,
"y": 342,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "7d7f7a50.181eb4",
"type": "debug",
"z": "ed2d8f08.a0c38",
"name": "",
"active": true,
"console": "false",
"complete": "payload",
"x": 434,
"y": 126,
"wires": []
},
{
"id": "15134f70.7a7aa1",
"type": "inject",
"z": "ed2d8f08.a0c38",
"name": "all",
"topic": "home/sprinklers/ALL",
"payload": "OFF",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"x": 119,
"y": 449,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "4197d82b.22a208",
"type": "ui_switch",
"z": "ed2d8f08.a0c38",
"name": "ALL Switch",
"label": "switch",
"group": "a1871db5.cff14",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"topic": "ALL",
"style": "",
"onvalue": "OFF",
"onvalueType": "str",
"onicon": "",
"oncolor": "",
"offvalue": "ON",
"offvalueType": "str",
"officon": "",
"offcolor": "",
"x": 143,
"y": 554,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "a1871db5.cff14",
"type": "ui_group",
"z": "",
"name": "Default",
"tab": "eb7d3ee9.f2da28",
"disp": true,
"width": "6"
},
{
"id": "eb7d3ee9.f2da28",
"type": "ui_tab",
"z": "",
"name": "Home",
"icon": "dashboard"
}
]

Only the flow

[
{
"id": "ed29ea8a.fe4058",
"type": "mcp23017",
"z": "ed2d8f08.a0c38",
"name": "MCP23017 Node",
"topic": "",
"address": "0x20",
"device": "/dev/i2c-1",
"x": 391,
"y": 264,
"wires": [
[
"7d7f7a50.181eb4"
]
]
},
{
"id": "9051c299.39168",
"type": "inject",
"z": "ed2d8f08.a0c38",
"name": "Get Status",
"topic": "home/sprinklers/status",
"payload": "",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"x": 183,
"y": 116,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "5daeb3b2.2b1e9c",
"type": "inject",
"z": "ed2d8f08.a0c38",
"name": "pin7 ON",
"topic": "devices/sprinklers/7",
"payload": "ON",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"x": 132,
"y": 275,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "f839911c.dd3338",
"type": "inject",
"z": "ed2d8f08.a0c38",
"name": "pin7 OFF",
"topic": "devices/sprinklers/7",
"payload": "OFF",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"x": 138,
"y": 217,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "594acb2c.00199c",
"type": "inject",
"z": "ed2d8f08.a0c38",
"name": "all",
"topic": "home/sprinklers/ALL",
"payload": "ON",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"x": 117,
"y": 342,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "7d7f7a50.181eb4",
"type": "debug",
"z": "ed2d8f08.a0c38",
"name": "",
"active": true,
"console": "false",
"complete": "payload",
"x": 434,
"y": 126,
"wires": []
},
{
"id": "15134f70.7a7aa1",
"type": "inject",
"z": "ed2d8f08.a0c38",
"name": "all",
"topic": "home/sprinklers/ALL",
"payload": "OFF",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"x": 119,
"y": 449,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "4197d82b.22a208",
"type": "ui_switch",
"z": "ed2d8f08.a0c38",
"name": "ALL Switch",
"label": "switch",
"group": "a1871db5.cff14",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"topic": "ALL",
"style": "",
"onvalue": "OFF",
"onvalueType": "str",
"onicon": "",
"oncolor": "",
"offvalue": "ON",
"offvalueType": "str",
"officon": "",
"offcolor": "",
"x": 143,
"y": 554,
"wires": [
[
"ed29ea8a.fe4058"
]
]
},
{
"id": "a1871db5.cff14",
"type": "ui_group",
"z": "",
"name": "Default",
"tab": "eb7d3ee9.f2da28",
"disp": true,
"width": "6"
},
{
"id": "eb7d3ee9.f2da28",
"type": "ui_tab",
"z": "",
"name": "Home",
"icon": "dashboard"
}
]

 

Leave a Reply

Your email address will not be published. Required fields are marked *