node-red-contrib-periph-io-expander 1.4.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 +5 -0
- package/examples/pca6408a/demo.json +167 -0
- package/examples/pca6416a/demo.json +167 -0
- package/examples/pca9536/demo.json +161 -0
- package/examples/pca9539/demo.json +167 -0
- package/examples/tca9554/demo.json +167 -0
- package/nodes/pca6408a/pca6408a.html +77 -0
- package/nodes/pca6408a/pca6408a.js +68 -0
- package/nodes/pca6416a/pca6416a.html +78 -0
- package/nodes/pca6416a/pca6416a.js +72 -0
- package/nodes/pca9536/pca9536.html +65 -0
- package/nodes/pca9536/pca9536.js +62 -0
- package/nodes/pca9539/pca9539.html +78 -0
- package/nodes/pca9539/pca9539.js +72 -0
- package/nodes/tca9554/tca9554.html +77 -0
- package/nodes/tca9554/tca9554.js +68 -0
- package/package.json +6 -1
|
@@ -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"> (/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
|
+
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"> (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
|
+
};
|
|
@@ -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"> (/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
|
+
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"> (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.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Node-RED nodes for IO expander chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -15,8 +15,13 @@
|
|
|
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",
|
|
24
|
+
"periph-tca9554": "nodes/tca9554/tca9554.js",
|
|
20
25
|
"periph-tpic6b595": "nodes/tpic6b595/tpic6b595.js"
|
|
21
26
|
}
|
|
22
27
|
},
|