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

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
@@ -24,6 +24,7 @@ npm install node-red-contrib-periph-io-expander
24
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. |
25
25
  | `periph-pcf8574` | input | Controls and reads an 8-bit PCF8574 I/O expander over I²C. |
26
26
  | `periph-pcf8575` | input | Controls and reads a 16-bit PCF8575 I/O expander over I²C. |
27
+ | `periph-tca9554` | input | Controls and reads an 8-bit TCA9554 I/O expander (I²C / SMBus, TI). Every input has a fixed internal 100 kΩ pull-up (always on). |
27
28
  | `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). |
28
29
 
29
30
  ## Links
@@ -0,0 +1,167 @@
1
+ [
2
+ {
3
+ "id": "tab_tca9554_demo",
4
+ "type": "tab",
5
+ "label": "TCA9554 Demo",
6
+ "info": "Output control and input polling on the TCA9554 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 (the internal 100 kΩ pull-ups hold the inputs high)\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_tca9554_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_tca9554_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-tca9554",
45
+ "z": "tab_tca9554_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_tca9554_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-tca9554",
78
+ "z": "tab_tca9554_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_tca9554_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_tca9554_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_tca9554_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-tca9554",
141
+ "z": "tab_tca9554_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_tca9554_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,77 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-tca9554', {
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 || ('TCA9554 @ 0x' + this.address + ' (bus ' + this.bus + ')');
17
+ },
18
+ paletteLabel: 'TCA9554'
19
+ });
20
+ </script>
21
+
22
+ <script type="text/html" data-template-name="periph-tca9554">
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="TCA9554">
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 … 27 (A2..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-tca9554">
47
+ <p>Controls and reads an 8-bit TCA9554 I/O expander (I²C / SMBus, TI). Every input has a fixed internal 100 kΩ pull-up (always on).</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>–<code>27</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 a single supply VCC (1.65–5.5 V).</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 { Tca9554Full } = require('periph/src/chips/io_expander/tca9554');
6
+
7
+ function Tca9554Node(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 Tca9554Full(node.connection);
13
+ node.chip.ready.catch((e) => node.error('TCA9554 init failed: ' + e.message));
14
+ node.status({ fill: 'green', shape: 'dot', text: 'I2C' });
15
+ } catch (e) {
16
+ node.error('TCA9554 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('TCA9554 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('TCA9554 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-tca9554', Tca9554Node);
68
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-io-expander",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Node-RED nodes for IO expander chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -21,6 +21,7 @@
21
21
  "periph-pca9539": "nodes/pca9539/pca9539.js",
22
22
  "periph-pcf8574": "nodes/pcf8574/pcf8574.js",
23
23
  "periph-pcf8575": "nodes/pcf8575/pcf8575.js",
24
+ "periph-tca9554": "nodes/tca9554/tca9554.js",
24
25
  "periph-tpic6b595": "nodes/tpic6b595/tpic6b595.js"
25
26
  }
26
27
  },