node-red-contrib-periph-tof 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 +1 -0
- package/examples/vl6180x/demo.json +129 -0
- package/nodes/vl6180x/vl6180x.html +75 -0
- package/nodes/vl6180x/vl6180x.js +59 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ npm install node-red-contrib-periph-tof
|
|
|
18
18
|
|------|------|-------------|
|
|
19
19
|
| `periph-vl53l0x` | input | Measures distance with a VL53L0X time-of-flight laser-ranging sensor over I²C (up to ~2 m), and optionally reports distance-threshold events. |
|
|
20
20
|
| `periph-vl53l1x` | input | Measures distance with a VL53L1X long-distance time-of-flight laser-ranging sensor over I²C (up to 4 m), and optionally reports distance-threshold events. |
|
|
21
|
+
| `periph-vl6180x` | input | Measures distance (0–100 mm) and ambient light with a VL6180X proximity and ambient-light sensor over I²C. |
|
|
21
22
|
|
|
22
23
|
## Links
|
|
23
24
|
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-vl6180x-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "VL6180X Proximity Light Demo",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "An Inject node fires every 500 ms into a periph-vl6180x node (I²C bus 1, address 0x29, ALS gain 1, 100 ms integration). The node performs one single-shot range measurement and one single-shot ambient-light measurement per message and outputs msg.payload = { range_mm, range_error, valid, lux }. A Switch node routes on msg.payload.range_mm < 50 with msg.payload.valid true: a hand within 50 mm goes to a Debug node labelled \"hand detected\" and to a gauge-style Function node that reports the proximity in percent (100 at 0 mm, 0 at 50 mm); everything else goes to a Debug node labelled \"idle\" that shows the lux reading, so the sensor works as a proximity-activated light meter."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "inj-vl6180x",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"name": "Measure (500 ms)",
|
|
13
|
+
"topic": "",
|
|
14
|
+
"payload": "",
|
|
15
|
+
"payloadType": "date",
|
|
16
|
+
"repeat": "0.5",
|
|
17
|
+
"crontab": "",
|
|
18
|
+
"once": true,
|
|
19
|
+
"onceDelay": 1,
|
|
20
|
+
"z": "tab-vl6180x-demo",
|
|
21
|
+
"x": 150,
|
|
22
|
+
"y": 100,
|
|
23
|
+
"wires": [
|
|
24
|
+
[
|
|
25
|
+
"vl6180x-node"
|
|
26
|
+
]
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "vl6180x-node",
|
|
31
|
+
"type": "periph-vl6180x",
|
|
32
|
+
"name": "Proximity VL6180X",
|
|
33
|
+
"bus": "1",
|
|
34
|
+
"address": "0x29",
|
|
35
|
+
"gain": "6",
|
|
36
|
+
"integrationMs": "100",
|
|
37
|
+
"z": "tab-vl6180x-demo",
|
|
38
|
+
"x": 360,
|
|
39
|
+
"y": 100,
|
|
40
|
+
"wires": [
|
|
41
|
+
[
|
|
42
|
+
"sw-near"
|
|
43
|
+
]
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"id": "sw-near",
|
|
48
|
+
"type": "switch",
|
|
49
|
+
"name": "range < 50 mm?",
|
|
50
|
+
"property": "payload.range_mm",
|
|
51
|
+
"propertyType": "msg",
|
|
52
|
+
"rules": [
|
|
53
|
+
{
|
|
54
|
+
"t": "lt",
|
|
55
|
+
"v": "50",
|
|
56
|
+
"vt": "num"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"t": "else"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"checkall": "false",
|
|
63
|
+
"repeat": false,
|
|
64
|
+
"outputs": 2,
|
|
65
|
+
"z": "tab-vl6180x-demo",
|
|
66
|
+
"x": 570,
|
|
67
|
+
"y": 100,
|
|
68
|
+
"wires": [
|
|
69
|
+
[
|
|
70
|
+
"fn-percent"
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
"dbg-idle"
|
|
74
|
+
]
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "fn-percent",
|
|
79
|
+
"type": "function",
|
|
80
|
+
"name": "proximity %",
|
|
81
|
+
"func": "if (!msg.payload.valid) { return null; }\nmsg.payload = Math.round(100 * (50 - msg.payload.range_mm) / 50);\nreturn msg;",
|
|
82
|
+
"outputs": 1,
|
|
83
|
+
"timeout": 0,
|
|
84
|
+
"noerr": 0,
|
|
85
|
+
"initialize": "",
|
|
86
|
+
"finalize": "",
|
|
87
|
+
"libs": [],
|
|
88
|
+
"z": "tab-vl6180x-demo",
|
|
89
|
+
"x": 780,
|
|
90
|
+
"y": 60,
|
|
91
|
+
"wires": [
|
|
92
|
+
[
|
|
93
|
+
"dbg-hand"
|
|
94
|
+
]
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"id": "dbg-hand",
|
|
99
|
+
"type": "debug",
|
|
100
|
+
"name": "hand detected",
|
|
101
|
+
"active": true,
|
|
102
|
+
"tosidebar": true,
|
|
103
|
+
"console": false,
|
|
104
|
+
"tostatus": true,
|
|
105
|
+
"complete": "payload",
|
|
106
|
+
"targetType": "msg",
|
|
107
|
+
"statusVal": "payload",
|
|
108
|
+
"statusType": "auto",
|
|
109
|
+
"z": "tab-vl6180x-demo",
|
|
110
|
+
"x": 990,
|
|
111
|
+
"y": 60,
|
|
112
|
+
"wires": []
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"id": "dbg-idle",
|
|
116
|
+
"type": "debug",
|
|
117
|
+
"name": "idle",
|
|
118
|
+
"active": true,
|
|
119
|
+
"tosidebar": true,
|
|
120
|
+
"console": false,
|
|
121
|
+
"tostatus": false,
|
|
122
|
+
"complete": "payload",
|
|
123
|
+
"targetType": "msg",
|
|
124
|
+
"z": "tab-vl6180x-demo",
|
|
125
|
+
"x": 770,
|
|
126
|
+
"y": 140,
|
|
127
|
+
"wires": []
|
|
128
|
+
}
|
|
129
|
+
]
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-vl6180x', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x29' },
|
|
9
|
+
gain: { value: '6' },
|
|
10
|
+
integrationMs: { value: '100', validate: RED.validators.number() }
|
|
11
|
+
},
|
|
12
|
+
inputs: 1,
|
|
13
|
+
outputs: 1,
|
|
14
|
+
icon: 'font-awesome/fa-arrows-h',
|
|
15
|
+
label: function() { return this.name || 'VL6180X'; },
|
|
16
|
+
paletteLabel: 'VL6180X'
|
|
17
|
+
});
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script type="text/html" data-template-name="periph-vl6180x">
|
|
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="VL6180X">
|
|
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"> (Linux /dev/i2c-N)
|
|
28
|
+
</div>
|
|
29
|
+
<div class="form-row">
|
|
30
|
+
<label for="node-input-address"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
31
|
+
<input type="text" id="node-input-address" style="width:80px"> (default 0x29)
|
|
32
|
+
</div>
|
|
33
|
+
<div class="form-row">
|
|
34
|
+
<label for="node-input-gain"><i class="fa fa-adjust"></i> ALS gain</label>
|
|
35
|
+
<select id="node-input-gain" style="width:240px">
|
|
36
|
+
<option value="6">1 (code 6, up to about 20 klux)</option>
|
|
37
|
+
<option value="5">1.25 (code 5)</option>
|
|
38
|
+
<option value="4">1.67 (code 4)</option>
|
|
39
|
+
<option value="3">2.5 (code 3)</option>
|
|
40
|
+
<option value="2">5 (code 2)</option>
|
|
41
|
+
<option value="1">10 (code 1)</option>
|
|
42
|
+
<option value="0">20 (code 0)</option>
|
|
43
|
+
<option value="7">40 (code 7, dim light)</option>
|
|
44
|
+
</select>
|
|
45
|
+
</div>
|
|
46
|
+
<div class="form-row">
|
|
47
|
+
<label for="node-input-integrationMs"><i class="fa fa-clock-o"></i> Integration ms</label>
|
|
48
|
+
<input type="text" id="node-input-integrationMs" style="width:80px"> (1–512 ms; 50–100 ms reduces flicker error)
|
|
49
|
+
</div>
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<script type="text/html" data-help-name="periph-vl6180x">
|
|
53
|
+
<p>Measures distance (0–100 mm) and ambient light with a VL6180X proximity and ambient-light sensor over I²C.</p>
|
|
54
|
+
|
|
55
|
+
<h3>Inputs</h3>
|
|
56
|
+
<dl class="message-properties">
|
|
57
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
58
|
+
<dd>Any incoming message triggers one single-shot range measurement followed by one single-shot ambient-light measurement.</dd>
|
|
59
|
+
</dl>
|
|
60
|
+
|
|
61
|
+
<h3>Outputs</h3>
|
|
62
|
+
<dl class="message-properties">
|
|
63
|
+
<dt>payload.range_mm <span class="property-type">number</span></dt>
|
|
64
|
+
<dd>Distance in mm (0–255; reliable up to about 100 mm). Only meaningful when <code>valid</code> is true.</dd>
|
|
65
|
+
<dt>payload.range_error <span class="property-type">number</span></dt>
|
|
66
|
+
<dd>Range error code, 0 = no error (1–15 are the datasheet error codes).</dd>
|
|
67
|
+
<dt>payload.valid <span class="property-type">boolean</span></dt>
|
|
68
|
+
<dd>True when the range error code is 0.</dd>
|
|
69
|
+
<dt>payload.lux <span class="property-type">number</span></dt>
|
|
70
|
+
<dd>Ambient light in lux (0.32 lux/count at gain 1 and 100 ms, without cover glass).</dd>
|
|
71
|
+
</dl>
|
|
72
|
+
|
|
73
|
+
<h3>Configuration</h3>
|
|
74
|
+
<p>Set the I²C bus number and the address (0x29 by default; the address can only be changed from code and reverts at power-up). The ALS gain and integration time apply to the lux value: pick a low gain in bright light and a high gain in dim light; a longer integration time improves resolution but slows each message by that time. Cover glass in front of the sensor reduces both range and light signals; calibrate offset, crosstalk and lux resolution in the final assembly.</p>
|
|
75
|
+
</script>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { VL6180XFull } = require('periph/src/chips/tof/vl6180x');
|
|
6
|
+
|
|
7
|
+
function VL6180XNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
const gainCode = parseInt(config.gain, 10);
|
|
11
|
+
const integrationMs = parseInt(config.integrationMs, 10) || 100;
|
|
12
|
+
|
|
13
|
+
// Every driver call goes through one queue so input messages never interleave their I²C sequences.
|
|
14
|
+
let queue = Promise.resolve();
|
|
15
|
+
const serial = (fn) => {
|
|
16
|
+
const run = queue.then(fn);
|
|
17
|
+
queue = run.catch(() => {});
|
|
18
|
+
return run;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const address = parseInt(config.address, 16) || VL6180XFull.I2C_ADDRESS;
|
|
23
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), address, null, null, 2);
|
|
24
|
+
node.driver = new VL6180XFull(connection);
|
|
25
|
+
node.connection = connection;
|
|
26
|
+
|
|
27
|
+
serial(async () => {
|
|
28
|
+
await node.driver.init();
|
|
29
|
+
await node.driver.setAlsGain(isNaN(gainCode) ? 6 : gainCode);
|
|
30
|
+
await node.driver.setAlsIntegrationTime(integrationMs);
|
|
31
|
+
node.status({ fill: 'green', shape: 'dot', text: 'ready' });
|
|
32
|
+
}).catch((e) => {
|
|
33
|
+
node.status({ fill: 'red', shape: 'ring', text: 'init failed' });
|
|
34
|
+
node.error('VL6180X init failed: ' + e.message);
|
|
35
|
+
});
|
|
36
|
+
} catch (e) {
|
|
37
|
+
node.error('VL6180X init failed: ' + e.message);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
node.on('input', function(msg, send, done) {
|
|
41
|
+
if (!node.driver) { done(); return; }
|
|
42
|
+
serial(async () => {
|
|
43
|
+
const { mm, error } = await node.driver.readRangeStatus();
|
|
44
|
+
const lux = await node.driver.readLux();
|
|
45
|
+
msg.payload = { range_mm: mm, range_error: error, valid: error === 0, lux };
|
|
46
|
+
send(msg);
|
|
47
|
+
}).then(() => done(), (e) => done(e));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
node.on('close', function(removed, done) {
|
|
51
|
+
serial(async () => {
|
|
52
|
+
if (node.connection) await node.connection.close();
|
|
53
|
+
}).catch(() => {
|
|
54
|
+
// bus may already be gone; nothing more to do on close
|
|
55
|
+
}).finally(() => done());
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
RED.nodes.registerType('periph-vl6180x', VL6180XNode);
|
|
59
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-tof",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Node-RED nodes for time-of-flight sensor chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"node-red": {
|
|
14
14
|
"nodes": {
|
|
15
15
|
"vl53l0x": "nodes/vl53l0x/vl53l0x.js",
|
|
16
|
-
"vl53l1x": "nodes/vl53l1x/vl53l1x.js"
|
|
16
|
+
"vl53l1x": "nodes/vl53l1x/vl53l1x.js",
|
|
17
|
+
"vl6180x": "nodes/vl6180x/vl6180x.js"
|
|
17
18
|
}
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|