node-red-contrib-periph-io-expander 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,6 +18,10 @@ npm install node-red-contrib-periph-io-expander
18
18
  |------|------|-------------|
19
19
  | `periph-mcp23008` | input | Controls and reads an 8-bit MCP23008 (I²C) or MCP23S08 (SPI) I/O expander. Both chips share one register map and one node. |
20
20
  | `periph-mcp23017` | input | Controls and reads a 16-bit MCP23017 I/O expander over I²C. |
21
+ | `periph-pca6408a` | input | Controls and reads an 8-bit PCA6408A I/O expander (I²C / SMBus, NXP). The chip has no internal pull-ups: inputs need external pull-up resistors. |
22
+ | `periph-pca6416a` | input | Controls and reads a 16-bit PCA6416A I/O expander (I²C / SMBus, NXP). The chip has no internal pull-ups: inputs need external pull-up resistors. |
23
+ | `periph-pca9536` | input | Controls and reads a 4-bit PCA9536 I/O expander (I²C / SMBus, TI). The chip has the fixed address 0x41 , no interrupt pin, and a weak (about 100 kΩ) pull-up that is always on each pin, so an open input reads 1. |
24
+ | `periph-pca9539` | input | Controls and reads a 16-bit PCA9539 I/O expander (I²C / SMBus, NXP). The chip has no internal pull-ups: inputs need external pull-up resistors. |
21
25
  | `periph-pcf8574` | input | Controls and reads an 8-bit PCF8574 I/O expander over I²C. |
22
26
  | `periph-pcf8575` | input | Controls and reads a 16-bit PCF8575 I/O expander over I²C. |
23
27
  | `periph-tpic6b595` | input | Drives a Texas Instruments TPIC6B595 8-bit power SIPO shift register (or multiple cascaded devices) through a SiPo (serial-in/parallel-out) connection. SER IN / SRCK may be either an SPI bus (hardware mode) or two plain GPIO lines (software / bit-bang mode); RCK is always a plain GPIO. Optional SRCLR and G lines add shift-register-clear and global output enable (PWM-style dimming). |
@@ -0,0 +1,167 @@
1
+ [
2
+ {
3
+ "id": "tab_pca6408a_demo",
4
+ "type": "tab",
5
+ "label": "PCA6408A Demo",
6
+ "info": "Output control and input polling on the PCA6408A 8-bit I²C / SMBus IO expander.\n\nHardware:\n- P0–P3: four LEDs (anode through 220 Ω, cathode to GND; active-high)\n- P4–P7: push buttons to GND (external pull-ups required: the chip has none)\n\nHow it works:\n1. An Inject node every 200 ms feeds a Function node that writes a rotating one-hot pattern to the LEDs (P0→P3), one pin at a time.\n2. A second Inject node reads the full 8-bit port every second; a Function node formats the hex value for a Debug node.\n3. A third Inject node reads P4 (a button input); a Debug node shows the 0/1 level.\n\nWith the INT line wired (set the INT GPIO line in the node's config panel) the node also emits { port: 0, changed, value } whenever a button on P4–P7 changes.\n\nTo observe: watch the LEDs chase and press the buttons; the port value changes in the debug sidebar."
7
+ },
8
+ {
9
+ "id": "inj_rotate",
10
+ "type": "inject",
11
+ "z": "tab_pca6408a_demo",
12
+ "name": "Rotate 200ms",
13
+ "repeat": "0.2",
14
+ "payload": "",
15
+ "payloadType": "date",
16
+ "topic": "",
17
+ "once": false,
18
+ "x": 120,
19
+ "y": 60,
20
+ "wires": [
21
+ [
22
+ "fn_rotate"
23
+ ]
24
+ ]
25
+ },
26
+ {
27
+ "id": "fn_rotate",
28
+ "type": "function",
29
+ "z": "tab_pca6408a_demo",
30
+ "name": "One-hot pattern",
31
+ "func": "const i = Math.floor(Date.now() / 200) % 4;\nconst prev = (i + 3) % 4;\nreturn [[{ payload: { pin: prev, value: 0 } }, { payload: { pin: i, value: 1 } }]];",
32
+ "outputs": 1,
33
+ "noerr": 0,
34
+ "x": 330,
35
+ "y": 60,
36
+ "wires": [
37
+ [
38
+ "mcp_write"
39
+ ]
40
+ ]
41
+ },
42
+ {
43
+ "id": "mcp_write",
44
+ "type": "periph-pca6408a",
45
+ "z": "tab_pca6408a_demo",
46
+ "name": "Write LEDs",
47
+ "bus": "1",
48
+ "address": "20",
49
+ "gpioChip": "0",
50
+ "intPin": "",
51
+ "x": 560,
52
+ "y": 60,
53
+ "wires": [
54
+ []
55
+ ]
56
+ },
57
+ {
58
+ "id": "inj_port",
59
+ "type": "inject",
60
+ "z": "tab_pca6408a_demo",
61
+ "name": "Read port 1s",
62
+ "repeat": "1",
63
+ "payload": "{\"port\":0}",
64
+ "payloadType": "json",
65
+ "topic": "",
66
+ "once": false,
67
+ "x": 120,
68
+ "y": 160,
69
+ "wires": [
70
+ [
71
+ "mcp_port"
72
+ ]
73
+ ]
74
+ },
75
+ {
76
+ "id": "mcp_port",
77
+ "type": "periph-pca6408a",
78
+ "z": "tab_pca6408a_demo",
79
+ "name": "Read port",
80
+ "bus": "1",
81
+ "address": "20",
82
+ "gpioChip": "0",
83
+ "intPin": "",
84
+ "x": 330,
85
+ "y": 160,
86
+ "wires": [
87
+ [
88
+ "fn_hex"
89
+ ]
90
+ ]
91
+ },
92
+ {
93
+ "id": "fn_hex",
94
+ "type": "function",
95
+ "z": "tab_pca6408a_demo",
96
+ "name": "Format hex",
97
+ "func": "msg.payload = 'PIO=0x' + msg.payload.value.toString(16).padStart(2, '0');\nreturn msg;",
98
+ "outputs": 1,
99
+ "noerr": 0,
100
+ "x": 540,
101
+ "y": 160,
102
+ "wires": [
103
+ [
104
+ "dbg_port"
105
+ ]
106
+ ]
107
+ },
108
+ {
109
+ "id": "dbg_port",
110
+ "type": "debug",
111
+ "z": "tab_pca6408a_demo",
112
+ "name": "Port value",
113
+ "active": true,
114
+ "tosidebar": true,
115
+ "complete": "payload",
116
+ "x": 740,
117
+ "y": 160,
118
+ "wires": []
119
+ },
120
+ {
121
+ "id": "inj_btn",
122
+ "type": "inject",
123
+ "z": "tab_pca6408a_demo",
124
+ "name": "Read P4 500ms",
125
+ "repeat": "0.5",
126
+ "payload": "{\"pin\":4}",
127
+ "payloadType": "json",
128
+ "topic": "",
129
+ "once": false,
130
+ "x": 120,
131
+ "y": 260,
132
+ "wires": [
133
+ [
134
+ "mcp_btn"
135
+ ]
136
+ ]
137
+ },
138
+ {
139
+ "id": "mcp_btn",
140
+ "type": "periph-pca6408a",
141
+ "z": "tab_pca6408a_demo",
142
+ "name": "Read P4",
143
+ "bus": "1",
144
+ "address": "20",
145
+ "gpioChip": "0",
146
+ "intPin": "",
147
+ "x": 330,
148
+ "y": 260,
149
+ "wires": [
150
+ [
151
+ "dbg_btn"
152
+ ]
153
+ ]
154
+ },
155
+ {
156
+ "id": "dbg_btn",
157
+ "type": "debug",
158
+ "z": "tab_pca6408a_demo",
159
+ "name": "P4 level",
160
+ "active": true,
161
+ "tosidebar": true,
162
+ "complete": "payload",
163
+ "x": 540,
164
+ "y": 260,
165
+ "wires": []
166
+ }
167
+ ]
@@ -0,0 +1,167 @@
1
+ [
2
+ {
3
+ "id": "tab_pca6416a_demo",
4
+ "type": "tab",
5
+ "label": "PCA6416A Demo",
6
+ "info": "Output control and input polling on the PCA6416A 16-bit I²C / SMBus IO expander.\n\nHardware:\n- P0_0–P0_7 (port 0): eight LEDs (anode through 220 Ω, cathode to GND; active-high)\n- P1_0–P1_7 (port 1): push buttons to GND (external pull-ups required: the chip has none)\n\nHow it works:\n1. An Inject node every 200 ms feeds a Function node that writes a rotating one-hot pattern to the LEDs (P0_0→P0_7), one pin at a time.\n2. A second Inject node reads all 16 pins every second; a Function node formats the 16-bit hex value for a Debug node.\n3. A third Inject node reads pin 8 (P1_0, a button input); a Debug node shows the 0/1 level.\n\nWith the INT line wired (set the INT GPIO line in the node's config panel) the node also emits { changed, value } whenever a button on port 1 changes.\n\nTo observe: watch the LEDs chase and press the buttons; the pin values change in the debug sidebar."
7
+ },
8
+ {
9
+ "id": "inj_rotate",
10
+ "type": "inject",
11
+ "z": "tab_pca6416a_demo",
12
+ "name": "Rotate 200ms",
13
+ "repeat": "0.2",
14
+ "payload": "",
15
+ "payloadType": "date",
16
+ "topic": "",
17
+ "once": false,
18
+ "x": 120,
19
+ "y": 60,
20
+ "wires": [
21
+ [
22
+ "fn_rotate"
23
+ ]
24
+ ]
25
+ },
26
+ {
27
+ "id": "fn_rotate",
28
+ "type": "function",
29
+ "z": "tab_pca6416a_demo",
30
+ "name": "One-hot pattern",
31
+ "func": "const i = Math.floor(Date.now() / 200) % 8;\nconst prev = (i + 7) % 8;\nreturn [[{ payload: { pin: prev, value: 0 } }, { payload: { pin: i, value: 1 } }]];",
32
+ "outputs": 1,
33
+ "noerr": 0,
34
+ "x": 330,
35
+ "y": 60,
36
+ "wires": [
37
+ [
38
+ "mcp_write"
39
+ ]
40
+ ]
41
+ },
42
+ {
43
+ "id": "mcp_write",
44
+ "type": "periph-pca6416a",
45
+ "z": "tab_pca6416a_demo",
46
+ "name": "Write LEDs",
47
+ "bus": "1",
48
+ "address": "20",
49
+ "gpioChip": "0",
50
+ "intPin": "",
51
+ "x": 560,
52
+ "y": 60,
53
+ "wires": [
54
+ []
55
+ ]
56
+ },
57
+ {
58
+ "id": "inj_port",
59
+ "type": "inject",
60
+ "z": "tab_pca6416a_demo",
61
+ "name": "Read all 1s",
62
+ "repeat": "1",
63
+ "payload": "{}",
64
+ "payloadType": "json",
65
+ "topic": "",
66
+ "once": false,
67
+ "x": 120,
68
+ "y": 160,
69
+ "wires": [
70
+ [
71
+ "mcp_port"
72
+ ]
73
+ ]
74
+ },
75
+ {
76
+ "id": "mcp_port",
77
+ "type": "periph-pca6416a",
78
+ "z": "tab_pca6416a_demo",
79
+ "name": "Read all pins",
80
+ "bus": "1",
81
+ "address": "20",
82
+ "gpioChip": "0",
83
+ "intPin": "",
84
+ "x": 330,
85
+ "y": 160,
86
+ "wires": [
87
+ [
88
+ "fn_hex"
89
+ ]
90
+ ]
91
+ },
92
+ {
93
+ "id": "fn_hex",
94
+ "type": "function",
95
+ "z": "tab_pca6416a_demo",
96
+ "name": "Format hex",
97
+ "func": "msg.payload = 'PIO=0x' + msg.payload.value.toString(16).padStart(4, '0');\nreturn msg;",
98
+ "outputs": 1,
99
+ "noerr": 0,
100
+ "x": 540,
101
+ "y": 160,
102
+ "wires": [
103
+ [
104
+ "dbg_port"
105
+ ]
106
+ ]
107
+ },
108
+ {
109
+ "id": "dbg_port",
110
+ "type": "debug",
111
+ "z": "tab_pca6416a_demo",
112
+ "name": "All pins",
113
+ "active": true,
114
+ "tosidebar": true,
115
+ "complete": "payload",
116
+ "x": 740,
117
+ "y": 160,
118
+ "wires": []
119
+ },
120
+ {
121
+ "id": "inj_btn",
122
+ "type": "inject",
123
+ "z": "tab_pca6416a_demo",
124
+ "name": "Read P1_0 500ms",
125
+ "repeat": "0.5",
126
+ "payload": "{\"pin\":8}",
127
+ "payloadType": "json",
128
+ "topic": "",
129
+ "once": false,
130
+ "x": 120,
131
+ "y": 260,
132
+ "wires": [
133
+ [
134
+ "mcp_btn"
135
+ ]
136
+ ]
137
+ },
138
+ {
139
+ "id": "mcp_btn",
140
+ "type": "periph-pca6416a",
141
+ "z": "tab_pca6416a_demo",
142
+ "name": "Read P1_0",
143
+ "bus": "1",
144
+ "address": "20",
145
+ "gpioChip": "0",
146
+ "intPin": "",
147
+ "x": 330,
148
+ "y": 260,
149
+ "wires": [
150
+ [
151
+ "dbg_btn"
152
+ ]
153
+ ]
154
+ },
155
+ {
156
+ "id": "dbg_btn",
157
+ "type": "debug",
158
+ "z": "tab_pca6416a_demo",
159
+ "name": "P1_0 level",
160
+ "active": true,
161
+ "tosidebar": true,
162
+ "complete": "payload",
163
+ "x": 540,
164
+ "y": 260,
165
+ "wires": []
166
+ }
167
+ ]
@@ -0,0 +1,161 @@
1
+ [
2
+ {
3
+ "id": "tab_pca9536_demo",
4
+ "type": "tab",
5
+ "label": "PCA9536 Demo",
6
+ "info": "Output control, input reading and change polling on the PCA9536 4-bit I²C / SMBus IO expander.\n\nHardware:\n- P0–P1: two LEDs (anode through 220 Ω, cathode to GND; active-high)\n- P2–P3: push buttons to GND (the chip's built-in weak pull-up holds an open input high; no external resistor needed)\n\nHow it works:\n1. An Inject node every 200 ms feeds a Function node that writes a rotating one-hot pattern to the LEDs (P0→P1), one pin at a time.\n2. A second Inject node reads the 4-bit port every second; a Function node formats the hex value for a Debug node.\n3. A third Inject node reads P2 (a button input); a Debug node shows the 0/1 level.\n\nThe chip has no INT pin. Set a poll interval (ms) in the node's config panel and the node also emits { port: 0, changed, value } whenever a button on P2–P3 changes.\n\nTo observe: watch the LEDs chase and press the buttons; the port value changes in the debug sidebar."
7
+ },
8
+ {
9
+ "id": "inj_rotate",
10
+ "type": "inject",
11
+ "z": "tab_pca9536_demo",
12
+ "name": "Rotate 200ms",
13
+ "repeat": "0.2",
14
+ "payload": "",
15
+ "payloadType": "date",
16
+ "topic": "",
17
+ "once": false,
18
+ "x": 120,
19
+ "y": 60,
20
+ "wires": [
21
+ [
22
+ "fn_rotate"
23
+ ]
24
+ ]
25
+ },
26
+ {
27
+ "id": "fn_rotate",
28
+ "type": "function",
29
+ "z": "tab_pca9536_demo",
30
+ "name": "One-hot pattern",
31
+ "func": "const i = Math.floor(Date.now() / 200) % 2;\nconst prev = (i + 1) % 2;\nreturn [[{ payload: { pin: prev, value: 0 } }, { payload: { pin: i, value: 1 } }]];",
32
+ "outputs": 1,
33
+ "noerr": 0,
34
+ "x": 330,
35
+ "y": 60,
36
+ "wires": [
37
+ [
38
+ "mcp_write"
39
+ ]
40
+ ]
41
+ },
42
+ {
43
+ "id": "mcp_write",
44
+ "type": "periph-pca9536",
45
+ "z": "tab_pca9536_demo",
46
+ "name": "Write LEDs",
47
+ "bus": "1",
48
+ "x": 560,
49
+ "y": 60,
50
+ "wires": [
51
+ []
52
+ ],
53
+ "pollInterval": ""
54
+ },
55
+ {
56
+ "id": "inj_port",
57
+ "type": "inject",
58
+ "z": "tab_pca9536_demo",
59
+ "name": "Read port 1s",
60
+ "repeat": "1",
61
+ "payload": "{\"port\":0}",
62
+ "payloadType": "json",
63
+ "topic": "",
64
+ "once": false,
65
+ "x": 120,
66
+ "y": 160,
67
+ "wires": [
68
+ [
69
+ "mcp_port"
70
+ ]
71
+ ]
72
+ },
73
+ {
74
+ "id": "mcp_port",
75
+ "type": "periph-pca9536",
76
+ "z": "tab_pca9536_demo",
77
+ "name": "Read port",
78
+ "bus": "1",
79
+ "x": 330,
80
+ "y": 160,
81
+ "wires": [
82
+ [
83
+ "fn_hex"
84
+ ]
85
+ ],
86
+ "pollInterval": ""
87
+ },
88
+ {
89
+ "id": "fn_hex",
90
+ "type": "function",
91
+ "z": "tab_pca9536_demo",
92
+ "name": "Format hex",
93
+ "func": "msg.payload = 'PIO=0x' + msg.payload.value.toString(16);\nreturn msg;",
94
+ "outputs": 1,
95
+ "noerr": 0,
96
+ "x": 540,
97
+ "y": 160,
98
+ "wires": [
99
+ [
100
+ "dbg_port"
101
+ ]
102
+ ]
103
+ },
104
+ {
105
+ "id": "dbg_port",
106
+ "type": "debug",
107
+ "z": "tab_pca9536_demo",
108
+ "name": "Port value",
109
+ "active": true,
110
+ "tosidebar": true,
111
+ "complete": "payload",
112
+ "x": 740,
113
+ "y": 160,
114
+ "wires": []
115
+ },
116
+ {
117
+ "id": "inj_btn",
118
+ "type": "inject",
119
+ "z": "tab_pca9536_demo",
120
+ "name": "Read P2 500ms",
121
+ "repeat": "0.5",
122
+ "payload": "{\"pin\":2}",
123
+ "payloadType": "json",
124
+ "topic": "",
125
+ "once": false,
126
+ "x": 120,
127
+ "y": 260,
128
+ "wires": [
129
+ [
130
+ "mcp_btn"
131
+ ]
132
+ ]
133
+ },
134
+ {
135
+ "id": "mcp_btn",
136
+ "type": "periph-pca9536",
137
+ "z": "tab_pca9536_demo",
138
+ "name": "Read P2",
139
+ "bus": "1",
140
+ "x": 330,
141
+ "y": 260,
142
+ "wires": [
143
+ [
144
+ "dbg_btn"
145
+ ]
146
+ ],
147
+ "pollInterval": ""
148
+ },
149
+ {
150
+ "id": "dbg_btn",
151
+ "type": "debug",
152
+ "z": "tab_pca9536_demo",
153
+ "name": "P2 level",
154
+ "active": true,
155
+ "tosidebar": true,
156
+ "complete": "payload",
157
+ "x": 540,
158
+ "y": 260,
159
+ "wires": []
160
+ }
161
+ ]
@@ -0,0 +1,167 @@
1
+ [
2
+ {
3
+ "id": "tab_pca9539_demo",
4
+ "type": "tab",
5
+ "label": "PCA9539 Demo",
6
+ "info": "Output control and input polling on the PCA9539 16-bit I²C / SMBus IO expander.\n\nHardware:\n- P00–P07 (port 0): eight LEDs (anode through 220 Ω, cathode to GND; active-high)\n- P10–P17 (port 1): push buttons to GND (external pull-ups required: the chip has none)\n\nHow it works:\n1. An Inject node every 200 ms feeds a Function node that writes a rotating one-hot pattern to the LEDs (P00→P07), one pin at a time.\n2. A second Inject node reads all 16 pins every second; a Function node formats the 16-bit hex value for a Debug node.\n3. A third Inject node reads pin 8 (P10, a button input); a Debug node shows the 0/1 level.\n\nWith the INT line wired (set the INT GPIO line in the node's config panel) the node also emits { changed, value } whenever a button on port 1 changes.\n\nTo observe: watch the LEDs chase and press the buttons; the pin values change in the debug sidebar."
7
+ },
8
+ {
9
+ "id": "inj_rotate",
10
+ "type": "inject",
11
+ "z": "tab_pca9539_demo",
12
+ "name": "Rotate 200ms",
13
+ "repeat": "0.2",
14
+ "payload": "",
15
+ "payloadType": "date",
16
+ "topic": "",
17
+ "once": false,
18
+ "x": 120,
19
+ "y": 60,
20
+ "wires": [
21
+ [
22
+ "fn_rotate"
23
+ ]
24
+ ]
25
+ },
26
+ {
27
+ "id": "fn_rotate",
28
+ "type": "function",
29
+ "z": "tab_pca9539_demo",
30
+ "name": "One-hot pattern",
31
+ "func": "const i = Math.floor(Date.now() / 200) % 8;\nconst prev = (i + 7) % 8;\nreturn [[{ payload: { pin: prev, value: 0 } }, { payload: { pin: i, value: 1 } }]];",
32
+ "outputs": 1,
33
+ "noerr": 0,
34
+ "x": 330,
35
+ "y": 60,
36
+ "wires": [
37
+ [
38
+ "mcp_write"
39
+ ]
40
+ ]
41
+ },
42
+ {
43
+ "id": "mcp_write",
44
+ "type": "periph-pca9539",
45
+ "z": "tab_pca9539_demo",
46
+ "name": "Write LEDs",
47
+ "bus": "1",
48
+ "address": "74",
49
+ "gpioChip": "0",
50
+ "intPin": "",
51
+ "x": 560,
52
+ "y": 60,
53
+ "wires": [
54
+ []
55
+ ]
56
+ },
57
+ {
58
+ "id": "inj_port",
59
+ "type": "inject",
60
+ "z": "tab_pca9539_demo",
61
+ "name": "Read all 1s",
62
+ "repeat": "1",
63
+ "payload": "{}",
64
+ "payloadType": "json",
65
+ "topic": "",
66
+ "once": false,
67
+ "x": 120,
68
+ "y": 160,
69
+ "wires": [
70
+ [
71
+ "mcp_port"
72
+ ]
73
+ ]
74
+ },
75
+ {
76
+ "id": "mcp_port",
77
+ "type": "periph-pca9539",
78
+ "z": "tab_pca9539_demo",
79
+ "name": "Read all pins",
80
+ "bus": "1",
81
+ "address": "74",
82
+ "gpioChip": "0",
83
+ "intPin": "",
84
+ "x": 330,
85
+ "y": 160,
86
+ "wires": [
87
+ [
88
+ "fn_hex"
89
+ ]
90
+ ]
91
+ },
92
+ {
93
+ "id": "fn_hex",
94
+ "type": "function",
95
+ "z": "tab_pca9539_demo",
96
+ "name": "Format hex",
97
+ "func": "msg.payload = 'PIO=0x' + msg.payload.value.toString(16).padStart(4, '0');\nreturn msg;",
98
+ "outputs": 1,
99
+ "noerr": 0,
100
+ "x": 540,
101
+ "y": 160,
102
+ "wires": [
103
+ [
104
+ "dbg_port"
105
+ ]
106
+ ]
107
+ },
108
+ {
109
+ "id": "dbg_port",
110
+ "type": "debug",
111
+ "z": "tab_pca9539_demo",
112
+ "name": "All pins",
113
+ "active": true,
114
+ "tosidebar": true,
115
+ "complete": "payload",
116
+ "x": 740,
117
+ "y": 160,
118
+ "wires": []
119
+ },
120
+ {
121
+ "id": "inj_btn",
122
+ "type": "inject",
123
+ "z": "tab_pca9539_demo",
124
+ "name": "Read P10 500ms",
125
+ "repeat": "0.5",
126
+ "payload": "{\"pin\":8}",
127
+ "payloadType": "json",
128
+ "topic": "",
129
+ "once": false,
130
+ "x": 120,
131
+ "y": 260,
132
+ "wires": [
133
+ [
134
+ "mcp_btn"
135
+ ]
136
+ ]
137
+ },
138
+ {
139
+ "id": "mcp_btn",
140
+ "type": "periph-pca9539",
141
+ "z": "tab_pca9539_demo",
142
+ "name": "Read P10",
143
+ "bus": "1",
144
+ "address": "74",
145
+ "gpioChip": "0",
146
+ "intPin": "",
147
+ "x": 330,
148
+ "y": 260,
149
+ "wires": [
150
+ [
151
+ "dbg_btn"
152
+ ]
153
+ ]
154
+ },
155
+ {
156
+ "id": "dbg_btn",
157
+ "type": "debug",
158
+ "z": "tab_pca9539_demo",
159
+ "name": "P10 level",
160
+ "active": true,
161
+ "tosidebar": true,
162
+ "complete": "payload",
163
+ "x": 540,
164
+ "y": 260,
165
+ "wires": []
166
+ }
167
+ ]
@@ -0,0 +1,77 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-pca6408a', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '20' },
9
+ gpioChip: { value: '0' },
10
+ intPin: { value: '' }
11
+ },
12
+ inputs: 1,
13
+ outputs: 1,
14
+ icon: 'font-awesome/fa-microchip',
15
+ label: function() {
16
+ return this.name || ('PCA6408A @ 0x' + this.address + ' (bus ' + this.bus + ')');
17
+ },
18
+ paletteLabel: 'PCA6408A'
19
+ });
20
+ </script>
21
+
22
+ <script type="text/html" data-template-name="periph-pca6408a">
23
+ <div class="form-row">
24
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
25
+ <input type="text" id="node-input-name" placeholder="PCA6408A">
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
29
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(/dev/i2c-N)
30
+ </div>
31
+ <div class="form-row">
32
+ <label for="node-input-address">Address (hex)</label>
33
+ <input type="text" id="node-input-address" placeholder="20" style="width:80px">
34
+ &nbsp;20 (ADDR = VSS) or 21 (ADDR = VDD(P))
35
+ </div>
36
+ <div class="form-row">
37
+ <label for="node-input-gpioChip">GPIO chip</label>
38
+ <input type="number" id="node-input-gpioChip" min="0" style="width:80px"> &nbsp;(for the optional INT line)
39
+ </div>
40
+ <div class="form-row">
41
+ <label for="node-input-intPin">INT GPIO line</label>
42
+ <input type="number" id="node-input-intPin" min="0" style="width:80px" placeholder="none">
43
+ </div>
44
+ </script>
45
+
46
+ <script type="text/html" data-help-name="periph-pca6408a">
47
+ <p>Controls and reads an 8-bit PCA6408A I/O expander (I²C / SMBus, NXP). The chip has no internal pull-ups: inputs need external pull-up resistors.</p>
48
+
49
+ <h3>Inputs</h3>
50
+ <dl class="message-properties">
51
+ <dt>payload <span class="property-type">object</span></dt>
52
+ <dd>
53
+ <code>{ pin: N, value: 0|1 }</code> — set output pin N (0–7); the pin is switched to output first.<br>
54
+ <code>{ pin: N }</code> — read pin N; reply sent on output.<br>
55
+ <code>{ port: 0 }</code> — read all 8 pins; reply sent on output.
56
+ </dd>
57
+ </dl>
58
+
59
+ <h3>Outputs</h3>
60
+ <dl class="message-properties">
61
+ <dt>payload.pin <span class="property-type">number</span></dt>
62
+ <dd>Pin index (0–7), present when reading a single pin.</dd>
63
+ <dt>payload.value <span class="property-type">number</span></dt>
64
+ <dd>Logic level (0 or 1) when reading a pin; 8-bit bitmask when reading the port.</dd>
65
+ <dt>payload.port <span class="property-type">number</span></dt>
66
+ <dd>Always 0 (the chip has a single port), present when reading the full port or on an interrupt message.</dd>
67
+ <dt>payload.changed <span class="property-type">number</span></dt>
68
+ <dd>Only when an INT GPIO line is configured: mask of the input pins whose level changed since the last INPUT read (sent together with <code>port</code> and <code>value</code>).</dd>
69
+ </dl>
70
+
71
+ <h3>Configuration</h3>
72
+ <p>I²C bus number (Linux <code>/dev/i2c-N</code>) and 7-bit address in hex (<code>20</code> or <code>21</code>).
73
+ The optional <b>INT GPIO line</b> (with GPIO chip number) emits a message whenever an input changes; the line is sampled every 5 ms.</p>
74
+
75
+ <h3>Notes</h3>
76
+ <p>All eight pins (P0–P7) are bidirectional. Pins start as inputs; writing a value switches the pin to output. The chip has two supply rails: VDD(I²C-bus) for the bus and VDD(P) for the port.</p>
77
+ </script>
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { Pca6408aFull } = require('periph/src/chips/io_expander/pca6408a');
6
+
7
+ function Pca6408aNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ node.connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
12
+ node.chip = new Pca6408aFull(node.connection);
13
+ node.chip.ready.catch((e) => node.error('PCA6408A init failed: ' + e.message));
14
+ node.status({ fill: 'green', shape: 'dot', text: 'I2C' });
15
+ } catch (e) {
16
+ node.error('PCA6408A init failed: ' + e.message);
17
+ }
18
+
19
+ // Optional INT line (otherwise nothing is emitted unless polled): emit { port, changed, value }.
20
+ if (node.chip && config.intPin !== '' && config.intPin !== undefined) {
21
+ (async () => {
22
+ try {
23
+ const { Default } = require('opengpio');
24
+ const { PollingInputPin } = require('periph/src/connection/input_pin');
25
+ const line = Default.input({ chip: parseInt(config.gpioChip || 0, 10), line: parseInt(config.intPin, 10) });
26
+ const intPin = new PollingInputPin(() => (line.value ? 1 : 0), 5);
27
+ await node.chip.ready;
28
+ await node.chip.onInterrupt(async (changed) => {
29
+ const value = await node.chip.readPort();
30
+ node.send({ payload: { port: 0, changed, value } });
31
+ }, { intPin });
32
+ } catch (e) {
33
+ node.error('PCA6408A INT setup failed: ' + e.message);
34
+ }
35
+ })();
36
+ }
37
+
38
+ node.on('input', async function(msg, send, done) {
39
+ if (!node.chip) { done(new Error('PCA6408A not initialised')); return; }
40
+ try {
41
+ const p = msg.payload;
42
+ if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
43
+ const pin = node.chip.pin(p.pin);
44
+ if ((node.chip._direction >> p.pin) & 1) await pin.setDirection('out');
45
+ await pin.write(p.value ? 1 : 0);
46
+ done();
47
+ } else if (p && typeof p.pin === 'number') {
48
+ msg.payload = { pin: p.pin, value: ((await node.chip.readPort()) >> p.pin) & 1 };
49
+ send(msg);
50
+ done();
51
+ } else if (p && typeof p.port === 'number') {
52
+ msg.payload = { port: p.port, value: await node.chip.readPort() };
53
+ send(msg);
54
+ done();
55
+ } else {
56
+ done(new Error('msg.payload must be { pin, value }, { pin }, or { port }'));
57
+ }
58
+ } catch (e) { done(e); }
59
+ });
60
+
61
+ node.on('close', async function() {
62
+ if (node.chip) await node.chip.offInterrupt();
63
+ if (node.connection) await node.connection.close();
64
+ });
65
+ }
66
+
67
+ RED.nodes.registerType('periph-pca6408a', Pca6408aNode);
68
+ };
@@ -0,0 +1,78 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-pca6416a', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '20' },
9
+ gpioChip: { value: '0' },
10
+ intPin: { value: '' }
11
+ },
12
+ inputs: 1,
13
+ outputs: 1,
14
+ icon: 'font-awesome/fa-microchip',
15
+ label: function() {
16
+ return this.name || ('PCA6416A @ 0x' + this.address + ' (bus ' + this.bus + ')');
17
+ },
18
+ paletteLabel: 'PCA6416A'
19
+ });
20
+ </script>
21
+
22
+ <script type="text/html" data-template-name="periph-pca6416a">
23
+ <div class="form-row">
24
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
25
+ <input type="text" id="node-input-name" placeholder="PCA6416A">
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
29
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(/dev/i2c-N)
30
+ </div>
31
+ <div class="form-row">
32
+ <label for="node-input-address">Address (hex)</label>
33
+ <input type="text" id="node-input-address" placeholder="20" style="width:80px">
34
+ &nbsp;20 (ADDR = VSS) or 21 (ADDR = VDD(P))
35
+ </div>
36
+ <div class="form-row">
37
+ <label for="node-input-gpioChip">GPIO chip</label>
38
+ <input type="number" id="node-input-gpioChip" min="0" style="width:80px"> &nbsp;(for the optional INT line)
39
+ </div>
40
+ <div class="form-row">
41
+ <label for="node-input-intPin">INT GPIO line</label>
42
+ <input type="number" id="node-input-intPin" min="0" style="width:80px" placeholder="none">
43
+ </div>
44
+ </script>
45
+
46
+ <script type="text/html" data-help-name="periph-pca6416a">
47
+ <p>Controls and reads a 16-bit PCA6416A I/O expander (I²C / SMBus, NXP). The chip has no internal pull-ups: inputs need external pull-up resistors.</p>
48
+
49
+ <h3>Inputs</h3>
50
+ <dl class="message-properties">
51
+ <dt>payload <span class="property-type">object</span></dt>
52
+ <dd>
53
+ <code>{ pin: N, value: 0|1 }</code> — set output pin N (0–15); the pin is switched to output first.<br>
54
+ <code>{ pin: N }</code> — read pin N; reply sent on output.<br>
55
+ <code>{ port: N }</code> — read the 8 pins of port N (0 or 1); reply sent on output.<br>
56
+ <code>{}</code> (no <code>pin</code> / <code>port</code>) — read all 16 pins; reply sent on output.
57
+ </dd>
58
+ </dl>
59
+
60
+ <h3>Outputs</h3>
61
+ <dl class="message-properties">
62
+ <dt>payload.pin <span class="property-type">number</span></dt>
63
+ <dd>Pin index (0–15), present when reading a single pin (0–7 = P0_0–P0_7, 8–15 = P1_0–P1_7).</dd>
64
+ <dt>payload.value <span class="property-type">number</span></dt>
65
+ <dd>Logic level (0 or 1) when reading a pin; 8-bit bitmask when reading a port; 16-bit value when reading all pins.</dd>
66
+ <dt>payload.port <span class="property-type">number</span></dt>
67
+ <dd>Port number (0 or 1), present when reading a port.</dd>
68
+ <dt>payload.changed <span class="property-type">number</span></dt>
69
+ <dd>Only when an INT GPIO line is configured: 16-bit mask of the input pins whose level changed since the last INPUT read (sent together with the 16-bit <code>value</code>).</dd>
70
+ </dl>
71
+
72
+ <h3>Configuration</h3>
73
+ <p>I²C bus number (Linux <code>/dev/i2c-N</code>) and 7-bit address in hex (<code>20</code> or <code>21</code>).
74
+ The optional <b>INT GPIO line</b> (with GPIO chip number) emits a message whenever an input changes; the line is sampled every 5 ms.</p>
75
+
76
+ <h3>Notes</h3>
77
+ <p>All sixteen pins (P0_0–P0_7, P1_0–P1_7) are bidirectional. Pins start as inputs; writing a value switches the pin to output. The chip has two supply rails: VDD(I²C-bus) for the bus and VDD(P) for the port.</p>
78
+ </script>
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { Pca6416aFull } = require('periph/src/chips/io_expander/pca6416a');
6
+
7
+ function Pca6416aNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ node.connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
12
+ node.chip = new Pca6416aFull(node.connection);
13
+ node.chip.ready.catch((e) => node.error('PCA6416A init failed: ' + e.message));
14
+ node.status({ fill: 'green', shape: 'dot', text: 'I2C' });
15
+ } catch (e) {
16
+ node.error('PCA6416A init failed: ' + e.message);
17
+ }
18
+
19
+ // Optional INT line (otherwise nothing is emitted unless polled): emit { changed, value } (16-bit masks).
20
+ if (node.chip && config.intPin !== '' && config.intPin !== undefined) {
21
+ (async () => {
22
+ try {
23
+ const { Default } = require('opengpio');
24
+ const { PollingInputPin } = require('periph/src/connection/input_pin');
25
+ const line = Default.input({ chip: parseInt(config.gpioChip || 0, 10), line: parseInt(config.intPin, 10) });
26
+ const intPin = new PollingInputPin(() => (line.value ? 1 : 0), 5);
27
+ await node.chip.ready;
28
+ await node.chip.onInterrupt(async (changed) => {
29
+ const value = await node.chip.readAll();
30
+ node.send({ payload: { changed, value } });
31
+ }, { intPin });
32
+ } catch (e) {
33
+ node.error('PCA6416A INT setup failed: ' + e.message);
34
+ }
35
+ })();
36
+ }
37
+
38
+ node.on('input', async function(msg, send, done) {
39
+ if (!node.chip) { done(new Error('PCA6416A not initialised')); return; }
40
+ try {
41
+ const p = msg.payload;
42
+ if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
43
+ const pin = node.chip.pin(p.pin);
44
+ if ((node.chip._direction >> p.pin) & 1) await pin.setDirection('out');
45
+ await pin.write(p.value ? 1 : 0);
46
+ done();
47
+ } else if (p && typeof p.pin === 'number') {
48
+ msg.payload = { pin: p.pin, value: ((await node.chip.readAll()) >> p.pin) & 1 };
49
+ send(msg);
50
+ done();
51
+ } else if (p && typeof p.port === 'number') {
52
+ msg.payload = { port: p.port, value: await node.chip.readPort(p.port) };
53
+ send(msg);
54
+ done();
55
+ } else if (p && typeof p === 'object') {
56
+ msg.payload = { value: await node.chip.readAll() };
57
+ send(msg);
58
+ done();
59
+ } else {
60
+ done(new Error('msg.payload must be { pin, value }, { pin }, { port }, or {} (read all pins)'));
61
+ }
62
+ } catch (e) { done(e); }
63
+ });
64
+
65
+ node.on('close', async function() {
66
+ if (node.chip) await node.chip.offInterrupt();
67
+ if (node.connection) await node.connection.close();
68
+ });
69
+ }
70
+
71
+ RED.nodes.registerType('periph-pca6416a', Pca6416aNode);
72
+ };
@@ -0,0 +1,65 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-pca9536', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ pollInterval: { value: '' }
9
+ },
10
+ inputs: 1,
11
+ outputs: 1,
12
+ icon: 'font-awesome/fa-microchip',
13
+ label: function() {
14
+ return this.name || ('PCA9536 (bus ' + this.bus + ')');
15
+ },
16
+ paletteLabel: 'PCA9536'
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="periph-pca9536">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
+ <input type="text" id="node-input-name" placeholder="PCA9536">
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
27
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(/dev/i2c-N)
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-pollInterval">Poll interval</label>
31
+ <input type="number" id="node-input-pollInterval" min="0" style="width:80px" placeholder="off"> &nbsp;ms (the chip has no INT pin; address is fixed at 0x41)
32
+ </div>
33
+ </script>
34
+
35
+ <script type="text/html" data-help-name="periph-pca9536">
36
+ <p>Controls and reads a 4-bit PCA9536 I/O expander (I²C / SMBus, TI). The chip has the fixed address <code>0x41</code>, no interrupt pin, and a weak (about 100 kΩ) pull-up that is always on each pin, so an open input reads 1.</p>
37
+
38
+ <h3>Inputs</h3>
39
+ <dl class="message-properties">
40
+ <dt>payload <span class="property-type">object</span></dt>
41
+ <dd>
42
+ <code>{ pin: N, value: 0|1 }</code> — set output pin N (0–3); the pin is switched to output first.<br>
43
+ <code>{ pin: N }</code> — read pin N; reply sent on output.<br>
44
+ <code>{ port: 0 }</code> — read the 4-bit port; reply sent on output.
45
+ </dd>
46
+ </dl>
47
+
48
+ <h3>Outputs</h3>
49
+ <dl class="message-properties">
50
+ <dt>payload.pin <span class="property-type">number</span></dt>
51
+ <dd>Pin index (0–3), present when reading a single pin.</dd>
52
+ <dt>payload.value <span class="property-type">number</span></dt>
53
+ <dd>Logic level (0 or 1) when reading a pin; 4-bit bitmask when reading the port.</dd>
54
+ <dt>payload.port <span class="property-type">number</span></dt>
55
+ <dd>Always 0 (the chip has a single port), present when reading the full port or on a change message.</dd>
56
+ <dt>payload.changed <span class="property-type">number</span></dt>
57
+ <dd>Only when a poll interval is configured: mask of the input pins whose level changed since the last poll (sent together with <code>port</code> and <code>value</code>).</dd>
58
+ </dl>
59
+
60
+ <h3>Configuration</h3>
61
+ <p>I²C bus number (Linux <code>/dev/i2c-N</code>). The optional <b>poll interval</b> (ms) emits a message whenever an input changes.</p>
62
+
63
+ <h3>Notes</h3>
64
+ <p>All four pins (P0–P3) are bidirectional. Pins start as inputs; writing a value switches the pin to output.</p>
65
+ </script>
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { Pca9536Full } = require('periph/src/chips/io_expander/pca9536');
6
+
7
+ function Pca9536Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ node.connection = new I2CConnection(parseInt(config.bus), 0x41);
12
+ node.chip = new Pca9536Full(node.connection);
13
+ node.chip.ready.catch((e) => node.error('PCA9536 init failed: ' + e.message));
14
+ node.status({ fill: 'green', shape: 'dot', text: 'I2C' });
15
+ } catch (e) {
16
+ node.error('PCA9536 init failed: ' + e.message);
17
+ }
18
+
19
+ // Optional change polling (the chip has no interrupt pin): emit { port, changed, value }.
20
+ const interval = parseFloat(config.pollInterval);
21
+ if (node.chip && interval > 0) {
22
+ node.chip.ready.then(() => {
23
+ node.chip.watchChanges(async (changed) => {
24
+ const value = await node.chip.readPort();
25
+ node.send({ payload: { port: 0, changed, value } });
26
+ }, interval / 1000);
27
+ }).catch((e) => node.error('PCA9536 polling setup failed: ' + e.message));
28
+ }
29
+
30
+ node.on('input', async function(msg, send, done) {
31
+ if (!node.chip) { done(new Error('PCA9536 not initialised')); return; }
32
+ try {
33
+ const p = msg.payload;
34
+ if (p && typeof p.pin === 'number' && (p.pin < 0 || p.pin > 3)) {
35
+ done(new Error('pin must be 0-3'));
36
+ } else if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
37
+ const pin = node.chip.pin(p.pin);
38
+ if ((node.chip._direction >> p.pin) & 1) await pin.setDirection('out');
39
+ await pin.write(p.value ? 1 : 0);
40
+ done();
41
+ } else if (p && typeof p.pin === 'number') {
42
+ msg.payload = { pin: p.pin, value: ((await node.chip.readPort()) >> p.pin) & 1 };
43
+ send(msg);
44
+ done();
45
+ } else if (p && typeof p.port === 'number') {
46
+ msg.payload = { port: p.port, value: await node.chip.readPort() };
47
+ send(msg);
48
+ done();
49
+ } else {
50
+ done(new Error('msg.payload must be { pin, value }, { pin }, or { port }'));
51
+ }
52
+ } catch (e) { done(e); }
53
+ });
54
+
55
+ node.on('close', async function() {
56
+ if (node.chip) node.chip.unwatchChanges();
57
+ if (node.connection) await node.connection.close();
58
+ });
59
+ }
60
+
61
+ RED.nodes.registerType('periph-pca9536', Pca9536Node);
62
+ };
@@ -0,0 +1,78 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-pca9539', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '74' },
9
+ gpioChip: { value: '0' },
10
+ intPin: { value: '' }
11
+ },
12
+ inputs: 1,
13
+ outputs: 1,
14
+ icon: 'font-awesome/fa-microchip',
15
+ label: function() {
16
+ return this.name || ('PCA9539 @ 0x' + this.address + ' (bus ' + this.bus + ')');
17
+ },
18
+ paletteLabel: 'PCA9539'
19
+ });
20
+ </script>
21
+
22
+ <script type="text/html" data-template-name="periph-pca9539">
23
+ <div class="form-row">
24
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
25
+ <input type="text" id="node-input-name" placeholder="PCA9539">
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
29
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(/dev/i2c-N)
30
+ </div>
31
+ <div class="form-row">
32
+ <label for="node-input-address">Address (hex)</label>
33
+ <input type="text" id="node-input-address" placeholder="74" style="width:80px">
34
+ &nbsp;74–77 (A1, A0)
35
+ </div>
36
+ <div class="form-row">
37
+ <label for="node-input-gpioChip">GPIO chip</label>
38
+ <input type="number" id="node-input-gpioChip" min="0" style="width:80px"> &nbsp;(for the optional INT line)
39
+ </div>
40
+ <div class="form-row">
41
+ <label for="node-input-intPin">INT GPIO line</label>
42
+ <input type="number" id="node-input-intPin" min="0" style="width:80px" placeholder="none">
43
+ </div>
44
+ </script>
45
+
46
+ <script type="text/html" data-help-name="periph-pca9539">
47
+ <p>Controls and reads a 16-bit PCA9539 I/O expander (I²C / SMBus, NXP). The chip has no internal pull-ups: inputs need external pull-up resistors.</p>
48
+
49
+ <h3>Inputs</h3>
50
+ <dl class="message-properties">
51
+ <dt>payload <span class="property-type">object</span></dt>
52
+ <dd>
53
+ <code>{ pin: N, value: 0|1 }</code> — set output pin N (0–15); the pin is switched to output first.<br>
54
+ <code>{ pin: N }</code> — read pin N; reply sent on output.<br>
55
+ <code>{ port: N }</code> — read the 8 pins of port N (0 or 1); reply sent on output.<br>
56
+ <code>{}</code> (no <code>pin</code> / <code>port</code>) — read all 16 pins; reply sent on output.
57
+ </dd>
58
+ </dl>
59
+
60
+ <h3>Outputs</h3>
61
+ <dl class="message-properties">
62
+ <dt>payload.pin <span class="property-type">number</span></dt>
63
+ <dd>Pin index (0–15), present when reading a single pin (0–7 = P00–P07, 8–15 = P10–P17).</dd>
64
+ <dt>payload.value <span class="property-type">number</span></dt>
65
+ <dd>Logic level (0 or 1) when reading a pin; 8-bit bitmask when reading a port; 16-bit value when reading all pins.</dd>
66
+ <dt>payload.port <span class="property-type">number</span></dt>
67
+ <dd>Port number (0 or 1), present when reading a port.</dd>
68
+ <dt>payload.changed <span class="property-type">number</span></dt>
69
+ <dd>Only when an INT GPIO line is configured: 16-bit mask of the input pins whose level changed since the last INPUT read (sent together with the 16-bit <code>value</code>).</dd>
70
+ </dl>
71
+
72
+ <h3>Configuration</h3>
73
+ <p>I²C bus number (Linux <code>/dev/i2c-N</code>) and 7-bit address in hex (<code>74</code>–<code>77</code>).
74
+ The optional <b>INT GPIO line</b> (with GPIO chip number) emits a message whenever an input changes; the line is sampled every 5 ms.</p>
75
+
76
+ <h3>Notes</h3>
77
+ <p>All sixteen pins (P00–P07, P10–P17) are bidirectional. Pins start as inputs; writing a value switches the pin to output. The chip has no internal pull-ups; use external resistors on inputs.</p>
78
+ </script>
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { Pca9539Full } = require('periph/src/chips/io_expander/pca9539');
6
+
7
+ function Pca9539Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ node.connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
12
+ node.chip = new Pca9539Full(node.connection);
13
+ node.chip.ready.catch((e) => node.error('PCA9539 init failed: ' + e.message));
14
+ node.status({ fill: 'green', shape: 'dot', text: 'I2C' });
15
+ } catch (e) {
16
+ node.error('PCA9539 init failed: ' + e.message);
17
+ }
18
+
19
+ // Optional INT line (otherwise nothing is emitted unless polled): emit { changed, value } (16-bit masks).
20
+ if (node.chip && config.intPin !== '' && config.intPin !== undefined) {
21
+ (async () => {
22
+ try {
23
+ const { Default } = require('opengpio');
24
+ const { PollingInputPin } = require('periph/src/connection/input_pin');
25
+ const line = Default.input({ chip: parseInt(config.gpioChip || 0, 10), line: parseInt(config.intPin, 10) });
26
+ const intPin = new PollingInputPin(() => (line.value ? 1 : 0), 5);
27
+ await node.chip.ready;
28
+ await node.chip.onInterrupt(async (changed) => {
29
+ const value = await node.chip.readAll();
30
+ node.send({ payload: { changed, value } });
31
+ }, { intPin });
32
+ } catch (e) {
33
+ node.error('PCA9539 INT setup failed: ' + e.message);
34
+ }
35
+ })();
36
+ }
37
+
38
+ node.on('input', async function(msg, send, done) {
39
+ if (!node.chip) { done(new Error('PCA9539 not initialised')); return; }
40
+ try {
41
+ const p = msg.payload;
42
+ if (p && typeof p.pin === 'number' && typeof p.value === 'number') {
43
+ const pin = node.chip.pin(p.pin);
44
+ if ((node.chip._direction >> p.pin) & 1) await pin.setDirection('out');
45
+ await pin.write(p.value ? 1 : 0);
46
+ done();
47
+ } else if (p && typeof p.pin === 'number') {
48
+ msg.payload = { pin: p.pin, value: ((await node.chip.readAll()) >> p.pin) & 1 };
49
+ send(msg);
50
+ done();
51
+ } else if (p && typeof p.port === 'number') {
52
+ msg.payload = { port: p.port, value: await node.chip.readPort(p.port) };
53
+ send(msg);
54
+ done();
55
+ } else if (p && typeof p === 'object') {
56
+ msg.payload = { value: await node.chip.readAll() };
57
+ send(msg);
58
+ done();
59
+ } else {
60
+ done(new Error('msg.payload must be { pin, value }, { pin }, { port }, or {} (read all pins)'));
61
+ }
62
+ } catch (e) { done(e); }
63
+ });
64
+
65
+ node.on('close', async function() {
66
+ if (node.chip) await node.chip.offInterrupt();
67
+ if (node.connection) await node.connection.close();
68
+ });
69
+ }
70
+
71
+ RED.nodes.registerType('periph-pca9539', Pca9539Node);
72
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-io-expander",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Node-RED nodes for IO expander chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -15,6 +15,10 @@
15
15
  "mcp23008": "nodes/mcp23008/mcp23008.js",
16
16
  "periph-mcp23008": "nodes/mcp23008/mcp23008.js",
17
17
  "periph-mcp23017": "nodes/mcp23017/mcp23017.js",
18
+ "periph-pca6408a": "nodes/pca6408a/pca6408a.js",
19
+ "periph-pca9536": "nodes/pca9536/pca9536.js",
20
+ "periph-pca6416a": "nodes/pca6416a/pca6416a.js",
21
+ "periph-pca9539": "nodes/pca9539/pca9539.js",
18
22
  "periph-pcf8574": "nodes/pcf8574/pcf8574.js",
19
23
  "periph-pcf8575": "nodes/pcf8575/pcf8575.js",
20
24
  "periph-tpic6b595": "nodes/tpic6b595/tpic6b595.js"