node-red-contrib-periph-adc-dac 1.5.1 → 1.5.3
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 +49 -27
- package/examples/ad5243/demo.json +11 -5
- package/examples/ad5248/demo.json +1 -1
- package/examples/ad5251/demo.json +11 -5
- package/examples/ad5252/demo.json +11 -5
- package/examples/ad7705/demo.json +1 -1
- package/examples/ad7706/demo.json +1 -1
- package/examples/ads1013/demo.json +1 -76
- package/examples/ads1014/demo.json +1 -77
- package/examples/ads1113/demo.json +10 -4
- package/examples/ads1114/demo.json +10 -4
- package/examples/ads1115/demo.json +11 -5
- package/examples/ads7828/demo.json +12 -6
- package/examples/cat5171/demo.json +10 -4
- package/examples/cs43l22/demo.json +13 -7
- package/examples/ds1881/demo.json +12 -6
- package/examples/ds3502/demo.json +11 -5
- package/examples/es8311/demo.json +1 -1
- package/examples/hx710a/demo.json +38 -10
- package/examples/hx710b/demo.json +56 -15
- package/examples/hx711/demo.json +32 -9
- package/examples/hy3131/demo.json +1 -1
- package/examples/mcp3422/demo.json +12 -6
- package/examples/mcp4725/demo.json +1 -1
- package/examples/mcp4728/demo.json +5 -5
- package/examples/mcp4xxx/demo.json +1 -1
- package/examples/pcf8591/demo.json +30 -8
- package/nodes/ad5243/ad5243.html +46 -20
- package/nodes/ad5243/ad5243.js +28 -22
- package/nodes/ad5248/ad5248.html +3 -3
- package/nodes/ad5248/ad5248.js +1 -1
- package/nodes/ad5251/ad5251.html +45 -19
- package/nodes/ad5251/ad5251.js +29 -23
- package/nodes/ad5252/ad5252.html +45 -19
- package/nodes/ad5252/ad5252.js +29 -23
- package/nodes/ad7705/ad7705.html +3 -3
- package/nodes/ad7705/ad7705.js +1 -1
- package/nodes/ad7706/ad7706.html +3 -3
- package/nodes/ad7706/ad7706.js +1 -1
- package/nodes/ads1013/ads1013.html +44 -18
- package/nodes/ads1013/ads1013.js +22 -16
- package/nodes/ads1014/ads1014.html +46 -20
- package/nodes/ads1014/ads1014.js +22 -16
- package/nodes/ads1113/ads1113.html +44 -18
- package/nodes/ads1113/ads1113.js +17 -8
- package/nodes/ads1114/ads1114.html +46 -20
- package/nodes/ads1114/ads1114.js +17 -8
- package/nodes/ads1115/ads1115.html +48 -22
- package/nodes/ads1115/ads1115.js +17 -8
- package/nodes/ads7828/ads7828.html +47 -21
- package/nodes/ads7828/ads7828.js +23 -17
- package/nodes/cat5171/cat5171.html +46 -20
- package/nodes/cat5171/cat5171.js +28 -22
- package/nodes/cs43l22/cs43l22.html +48 -22
- package/nodes/cs43l22/cs43l22.js +29 -22
- package/nodes/ds1881/ds1881.html +48 -22
- package/nodes/ds1881/ds1881.js +34 -27
- package/nodes/ds3502/ds3502.html +46 -20
- package/nodes/ds3502/ds3502.js +25 -19
- package/nodes/es8311/es8311.html +3 -3
- package/nodes/es8311/es8311.js +1 -1
- package/nodes/hx710a/hx710a.html +48 -22
- package/nodes/hx710a/hx710a.js +18 -13
- package/nodes/hx710b/hx710b.html +48 -22
- package/nodes/hx710b/hx710b.js +18 -13
- package/nodes/hx711/hx711.html +48 -22
- package/nodes/hx711/hx711.js +17 -12
- package/nodes/hy3131/hy3131.html +3 -3
- package/nodes/hy3131/hy3131.js +1 -1
- package/nodes/mcp3422/mcp3422.html +46 -20
- package/nodes/mcp3422/mcp3422.js +28 -22
- package/nodes/mcp4725/mcp4725.html +3 -3
- package/nodes/mcp4725/mcp4725.js +1 -1
- package/nodes/mcp4728/mcp4728.html +3 -3
- package/nodes/mcp4728/mcp4728.js +1 -1
- package/nodes/mcp4xxx/mcp4xxx.html +3 -3
- package/nodes/mcp4xxx/mcp4xxx.js +1 -1
- package/nodes/pcf8591/pcf8591.html +37 -11
- package/nodes/pcf8591/pcf8591.js +16 -7
- package/package.json +31 -3
- package/index.js +0 -11
package/nodes/hx710a/hx710a.js
CHANGED
|
@@ -5,10 +5,9 @@ module.exports = function(RED) {
|
|
|
5
5
|
const { HX711Connection } = require('periph/src/connection/hx711');
|
|
6
6
|
const { HX710AFull } = require('periph/src/chips/adc_dac/hx710a');
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
function HX710ADeviceNode(config) {
|
|
9
9
|
RED.nodes.createNode(this, config);
|
|
10
10
|
const node = this;
|
|
11
|
-
|
|
12
11
|
try {
|
|
13
12
|
const chip = parseInt(config.gpioChip || 0);
|
|
14
13
|
const dout = Default.input({ chip, line: parseInt(config.doutPin) });
|
|
@@ -24,20 +23,31 @@ module.exports = function(RED) {
|
|
|
24
23
|
node.error('HX710A init failed: ' + e.message);
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
node.on('close', function() {
|
|
27
|
+
if (node.connection) node.connection.close();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
RED.nodes.registerType('hx710a-device', HX710ADeviceNode);
|
|
31
|
+
|
|
32
|
+
function HX710AReadNode(config) {
|
|
33
|
+
RED.nodes.createNode(this, config);
|
|
34
|
+
const node = this;
|
|
35
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
36
|
+
|
|
27
37
|
node.on('input', function(msg, send, done) {
|
|
28
|
-
if (!
|
|
38
|
+
if (!deviceNode.driver) { done(); return; }
|
|
29
39
|
try {
|
|
30
40
|
if (msg.payload === 'tare') {
|
|
31
|
-
|
|
41
|
+
deviceNode.driver.tare(10);
|
|
32
42
|
done();
|
|
33
43
|
} else if (msg.payload === 'temperature') {
|
|
34
|
-
const raw_temperature =
|
|
44
|
+
const raw_temperature = deviceNode.driver.readTemperatureRaw();
|
|
35
45
|
msg.payload = { raw_temperature };
|
|
36
46
|
send(msg);
|
|
37
47
|
done();
|
|
38
48
|
} else {
|
|
39
|
-
const raw =
|
|
40
|
-
const weight = (raw -
|
|
49
|
+
const raw = deviceNode.driver.readRaw();
|
|
50
|
+
const weight = (raw - deviceNode.driver.getOffset()) / deviceNode.driver.getScale();
|
|
41
51
|
msg.payload = { raw, weight };
|
|
42
52
|
send(msg);
|
|
43
53
|
done();
|
|
@@ -46,11 +56,6 @@ module.exports = function(RED) {
|
|
|
46
56
|
done(e);
|
|
47
57
|
}
|
|
48
58
|
});
|
|
49
|
-
|
|
50
|
-
node.on('close', function() {
|
|
51
|
-
if (node.connection) node.connection.close();
|
|
52
|
-
});
|
|
53
59
|
}
|
|
54
|
-
|
|
55
|
-
RED.nodes.registerType('periph-hx710a', HX710ANode);
|
|
60
|
+
RED.nodes.registerType('hx710a', HX710AReadNode);
|
|
56
61
|
};
|
package/nodes/hx710b/hx710b.html
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
4
|
-
color: '#C084FC',
|
|
3
|
+
RED.nodes.registerType('hx710b-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
gpioChip: { value: '0', required: true, validate: RED.validators.number() },
|
|
@@ -11,49 +11,75 @@
|
|
|
11
11
|
scaleFactor: { value: '1.0' },
|
|
12
12
|
tareOffset: { value: '0' }
|
|
13
13
|
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
label: function() { return this.name || 'HX710B'; },
|
|
18
|
-
paletteLabel: 'HX710B'
|
|
14
|
+
label: function() {
|
|
15
|
+
return this.name || 'HX710B';
|
|
16
|
+
}
|
|
19
17
|
});
|
|
20
18
|
</script>
|
|
21
19
|
|
|
22
|
-
<script type="text/html" data-template-name="
|
|
20
|
+
<script type="text/html" data-template-name="hx710b-device">
|
|
23
21
|
<div class="form-row">
|
|
24
|
-
<label for="node-input-gpioChip"><i class="fa fa-microchip"></i> GPIO chip</label>
|
|
25
|
-
<input type="number" id="node-input-gpioChip" min="0" style="width:80px"> gpiochip index (e.g. 0 for /dev/gpiochip0)
|
|
22
|
+
<label for="node-config-input-gpioChip"><i class="fa fa-microchip"></i> GPIO chip</label>
|
|
23
|
+
<input type="number" id="node-config-input-gpioChip" min="0" style="width:80px"> gpiochip index (e.g. 0 for /dev/gpiochip0)
|
|
26
24
|
</div>
|
|
27
25
|
<div class="form-row">
|
|
28
|
-
<label for="node-input-doutPin"><i class="fa fa-microchip"></i> DOUT line</label>
|
|
29
|
-
<input type="number" id="node-input-doutPin" min="0" style="width:80px"> gpiod line offset (BCM on Raspberry Pi)
|
|
26
|
+
<label for="node-config-input-doutPin"><i class="fa fa-microchip"></i> DOUT line</label>
|
|
27
|
+
<input type="number" id="node-config-input-doutPin" min="0" style="width:80px"> gpiod line offset (BCM on Raspberry Pi)
|
|
30
28
|
</div>
|
|
31
29
|
<div class="form-row">
|
|
32
|
-
<label for="node-input-pdSckPin"><i class="fa fa-microchip"></i> PD_SCK line</label>
|
|
33
|
-
<input type="number" id="node-input-pdSckPin" min="0" style="width:80px"> gpiod line offset (BCM on Raspberry Pi)
|
|
30
|
+
<label for="node-config-input-pdSckPin"><i class="fa fa-microchip"></i> PD_SCK line</label>
|
|
31
|
+
<input type="number" id="node-config-input-pdSckPin" min="0" style="width:80px"> gpiod line offset (BCM on Raspberry Pi)
|
|
34
32
|
</div>
|
|
35
33
|
<div class="form-row">
|
|
36
|
-
<label for="node-input-rate"><i class="fa fa-tachometer-alt"></i> Rate</label>
|
|
37
|
-
<select id="node-input-rate" style="width:200px">
|
|
34
|
+
<label for="node-config-input-rate"><i class="fa fa-tachometer-alt"></i> Rate</label>
|
|
35
|
+
<select id="node-config-input-rate" style="width:200px">
|
|
38
36
|
<option value="10">10 SPS (default)</option>
|
|
39
37
|
<option value="40">40 SPS</option>
|
|
40
38
|
</select>
|
|
41
39
|
</div>
|
|
42
40
|
<div class="form-row">
|
|
43
|
-
<label for="node-input-scaleFactor"><i class="fa fa-balance-scale"></i> Scale factor</label>
|
|
44
|
-
<input type="text" id="node-input-scaleFactor" style="width:120px"> counts per unit weight
|
|
41
|
+
<label for="node-config-input-scaleFactor"><i class="fa fa-balance-scale"></i> Scale factor</label>
|
|
42
|
+
<input type="text" id="node-config-input-scaleFactor" style="width:120px"> counts per unit weight
|
|
45
43
|
</div>
|
|
46
44
|
<div class="form-row">
|
|
47
|
-
<label for="node-input-tareOffset"><i class="fa fa-crosshairs"></i> Tare offset</label>
|
|
48
|
-
<input type="text" id="node-input-tareOffset" style="width:120px"> or send <code>msg.payload = "tare"</code>
|
|
45
|
+
<label for="node-config-input-tareOffset"><i class="fa fa-crosshairs"></i> Tare offset</label>
|
|
46
|
+
<input type="text" id="node-config-input-tareOffset" style="width:120px"> or send <code>msg.payload = "tare"</code>
|
|
49
47
|
</div>
|
|
48
|
+
<div class="form-row">
|
|
49
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
50
|
+
<input type="text" id="node-config-input-name" placeholder="HX710B">
|
|
51
|
+
</div>
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<!-- Read node -->
|
|
55
|
+
<script type="text/javascript">
|
|
56
|
+
RED.nodes.registerType('hx710b', {
|
|
57
|
+
category: 'Peripheral',
|
|
58
|
+
color: '#C084FC',
|
|
59
|
+
defaults: {
|
|
60
|
+
name: { value: '' },
|
|
61
|
+
device: { value: '', type: 'hx710b-device', required: true }
|
|
62
|
+
},
|
|
63
|
+
inputs: 1,
|
|
64
|
+
outputs: 1,
|
|
65
|
+
icon: 'font-awesome/fa-weight-hanging',
|
|
66
|
+
label: function() { return this.name || 'HX710B'; },
|
|
67
|
+
paletteLabel: 'HX710B'
|
|
68
|
+
});
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<script type="text/html" data-template-name="hx710b">
|
|
50
72
|
<div class="form-row">
|
|
51
73
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
52
74
|
<input type="text" id="node-input-name" placeholder="HX710B">
|
|
53
75
|
</div>
|
|
76
|
+
<div class="form-row">
|
|
77
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
78
|
+
<input type="text" id="node-input-device">
|
|
79
|
+
</div>
|
|
54
80
|
</script>
|
|
55
81
|
|
|
56
|
-
<script type="text/html" data-help-name="
|
|
82
|
+
<script type="text/html" data-help-name="hx710b">
|
|
57
83
|
<p>Reads weight from an HX710B 24-bit ADC connected to a load cell via two GPIO pins.
|
|
58
84
|
Also exposes the chip's DVDD-AVDD supply-voltage-difference channel as a raw ADC code
|
|
59
85
|
for battery-monitoring applications.</p>
|
package/nodes/hx710b/hx710b.js
CHANGED
|
@@ -5,10 +5,9 @@ module.exports = function(RED) {
|
|
|
5
5
|
const { HX711Connection } = require('periph/src/connection/hx711');
|
|
6
6
|
const { HX710BFull } = require('periph/src/chips/adc_dac/hx710b');
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
function HX710BDeviceNode(config) {
|
|
9
9
|
RED.nodes.createNode(this, config);
|
|
10
10
|
const node = this;
|
|
11
|
-
|
|
12
11
|
try {
|
|
13
12
|
const chip = parseInt(config.gpioChip || 0);
|
|
14
13
|
const dout = Default.input({ chip, line: parseInt(config.doutPin) });
|
|
@@ -24,20 +23,31 @@ module.exports = function(RED) {
|
|
|
24
23
|
node.error('HX710B init failed: ' + e.message);
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
node.on('close', function() {
|
|
27
|
+
if (node.connection) node.connection.close();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
RED.nodes.registerType('hx710b-device', HX710BDeviceNode);
|
|
31
|
+
|
|
32
|
+
function HX710BReadNode(config) {
|
|
33
|
+
RED.nodes.createNode(this, config);
|
|
34
|
+
const node = this;
|
|
35
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
36
|
+
|
|
27
37
|
node.on('input', function(msg, send, done) {
|
|
28
|
-
if (!
|
|
38
|
+
if (!deviceNode.driver) { done(); return; }
|
|
29
39
|
try {
|
|
30
40
|
if (msg.payload === 'tare') {
|
|
31
|
-
|
|
41
|
+
deviceNode.driver.tare(10);
|
|
32
42
|
done();
|
|
33
43
|
} else if (msg.payload === 'supply_diff') {
|
|
34
|
-
const raw_supply_diff =
|
|
44
|
+
const raw_supply_diff = deviceNode.driver.readSupplyDiffRaw();
|
|
35
45
|
msg.payload = { raw_supply_diff };
|
|
36
46
|
send(msg);
|
|
37
47
|
done();
|
|
38
48
|
} else {
|
|
39
|
-
const raw =
|
|
40
|
-
const weight = (raw -
|
|
49
|
+
const raw = deviceNode.driver.readRaw();
|
|
50
|
+
const weight = (raw - deviceNode.driver.getOffset()) / deviceNode.driver.getScale();
|
|
41
51
|
msg.payload = { raw, weight };
|
|
42
52
|
send(msg);
|
|
43
53
|
done();
|
|
@@ -46,11 +56,6 @@ module.exports = function(RED) {
|
|
|
46
56
|
done(e);
|
|
47
57
|
}
|
|
48
58
|
});
|
|
49
|
-
|
|
50
|
-
node.on('close', function() {
|
|
51
|
-
if (node.connection) node.connection.close();
|
|
52
|
-
});
|
|
53
59
|
}
|
|
54
|
-
|
|
55
|
-
RED.nodes.registerType('periph-hx710b', HX710BNode);
|
|
60
|
+
RED.nodes.registerType('hx710b', HX710BReadNode);
|
|
56
61
|
};
|
package/nodes/hx711/hx711.html
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
4
|
-
color: '#C084FC',
|
|
3
|
+
RED.nodes.registerType('hx711-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
gpioChip: { value: '0', required: true, validate: RED.validators.number() },
|
|
@@ -11,50 +11,76 @@
|
|
|
11
11
|
scaleFactor: { value: '1.0' },
|
|
12
12
|
tareOffset: { value: '0' }
|
|
13
13
|
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
label: function() { return this.name || 'HX711'; },
|
|
18
|
-
paletteLabel: 'HX711'
|
|
14
|
+
label: function() {
|
|
15
|
+
return this.name || 'HX711';
|
|
16
|
+
}
|
|
19
17
|
});
|
|
20
18
|
</script>
|
|
21
19
|
|
|
22
|
-
<script type="text/html" data-template-name="
|
|
20
|
+
<script type="text/html" data-template-name="hx711-device">
|
|
23
21
|
<div class="form-row">
|
|
24
|
-
<label for="node-input-gpioChip"><i class="fa fa-microchip"></i> GPIO chip</label>
|
|
25
|
-
<input type="number" id="node-input-gpioChip" min="0" style="width:80px"> gpiochip index (e.g. 0 for /dev/gpiochip0)
|
|
22
|
+
<label for="node-config-input-gpioChip"><i class="fa fa-microchip"></i> GPIO chip</label>
|
|
23
|
+
<input type="number" id="node-config-input-gpioChip" min="0" style="width:80px"> gpiochip index (e.g. 0 for /dev/gpiochip0)
|
|
26
24
|
</div>
|
|
27
25
|
<div class="form-row">
|
|
28
|
-
<label for="node-input-doutPin"><i class="fa fa-microchip"></i> DOUT line</label>
|
|
29
|
-
<input type="number" id="node-input-doutPin" min="0" style="width:80px"> gpiod line offset (BCM on Raspberry Pi)
|
|
26
|
+
<label for="node-config-input-doutPin"><i class="fa fa-microchip"></i> DOUT line</label>
|
|
27
|
+
<input type="number" id="node-config-input-doutPin" min="0" style="width:80px"> gpiod line offset (BCM on Raspberry Pi)
|
|
30
28
|
</div>
|
|
31
29
|
<div class="form-row">
|
|
32
|
-
<label for="node-input-pdSckPin"><i class="fa fa-microchip"></i> PD_SCK line</label>
|
|
33
|
-
<input type="number" id="node-input-pdSckPin" min="0" style="width:80px"> gpiod line offset (BCM on Raspberry Pi)
|
|
30
|
+
<label for="node-config-input-pdSckPin"><i class="fa fa-microchip"></i> PD_SCK line</label>
|
|
31
|
+
<input type="number" id="node-config-input-pdSckPin" min="0" style="width:80px"> gpiod line offset (BCM on Raspberry Pi)
|
|
34
32
|
</div>
|
|
35
33
|
<div class="form-row">
|
|
36
|
-
<label for="node-input-gain"><i class="fa fa-sliders-h"></i> Gain</label>
|
|
37
|
-
<select id="node-input-gain" style="width:200px">
|
|
34
|
+
<label for="node-config-input-gain"><i class="fa fa-sliders-h"></i> Gain</label>
|
|
35
|
+
<select id="node-config-input-gain" style="width:200px">
|
|
38
36
|
<option value="128">128 — Channel A (default)</option>
|
|
39
37
|
<option value="64">64 — Channel A</option>
|
|
40
38
|
<option value="32">32 — Channel B</option>
|
|
41
39
|
</select>
|
|
42
40
|
</div>
|
|
43
41
|
<div class="form-row">
|
|
44
|
-
<label for="node-input-scaleFactor"><i class="fa fa-balance-scale"></i> Scale factor</label>
|
|
45
|
-
<input type="text" id="node-input-scaleFactor" style="width:120px"> counts per unit weight
|
|
42
|
+
<label for="node-config-input-scaleFactor"><i class="fa fa-balance-scale"></i> Scale factor</label>
|
|
43
|
+
<input type="text" id="node-config-input-scaleFactor" style="width:120px"> counts per unit weight
|
|
46
44
|
</div>
|
|
47
45
|
<div class="form-row">
|
|
48
|
-
<label for="node-input-tareOffset"><i class="fa fa-crosshairs"></i> Tare offset</label>
|
|
49
|
-
<input type="text" id="node-input-tareOffset" style="width:120px"> or send <code>msg.payload = "tare"</code>
|
|
46
|
+
<label for="node-config-input-tareOffset"><i class="fa fa-crosshairs"></i> Tare offset</label>
|
|
47
|
+
<input type="text" id="node-config-input-tareOffset" style="width:120px"> or send <code>msg.payload = "tare"</code>
|
|
50
48
|
</div>
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
51
|
+
<input type="text" id="node-config-input-name" placeholder="HX711">
|
|
52
|
+
</div>
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<!-- Read node -->
|
|
56
|
+
<script type="text/javascript">
|
|
57
|
+
RED.nodes.registerType('hx711', {
|
|
58
|
+
category: 'Peripheral',
|
|
59
|
+
color: '#C084FC',
|
|
60
|
+
defaults: {
|
|
61
|
+
name: { value: '' },
|
|
62
|
+
device: { value: '', type: 'hx711-device', required: true }
|
|
63
|
+
},
|
|
64
|
+
inputs: 1,
|
|
65
|
+
outputs: 1,
|
|
66
|
+
icon: 'font-awesome/fa-weight-hanging',
|
|
67
|
+
label: function() { return this.name || 'HX711'; },
|
|
68
|
+
paletteLabel: 'HX711'
|
|
69
|
+
});
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<script type="text/html" data-template-name="hx711">
|
|
51
73
|
<div class="form-row">
|
|
52
74
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
53
75
|
<input type="text" id="node-input-name" placeholder="HX711">
|
|
54
76
|
</div>
|
|
77
|
+
<div class="form-row">
|
|
78
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
79
|
+
<input type="text" id="node-input-device">
|
|
80
|
+
</div>
|
|
55
81
|
</script>
|
|
56
82
|
|
|
57
|
-
<script type="text/html" data-help-name="
|
|
83
|
+
<script type="text/html" data-help-name="hx711">
|
|
58
84
|
<p>Reads weight from an HX711 24-bit ADC connected to a load cell via two GPIO pins.</p>
|
|
59
85
|
<p>Any input message triggers a raw ADC read. Sending <code>msg.payload = "tare"</code> captures
|
|
60
86
|
the current reading as the zero offset instead of producing output.</p>
|
package/nodes/hx711/hx711.js
CHANGED
|
@@ -5,10 +5,9 @@ module.exports = function(RED) {
|
|
|
5
5
|
const { HX711Connection } = require('periph/src/connection/hx711');
|
|
6
6
|
const { HX711Full } = require('periph/src/chips/adc_dac/hx711');
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
function HX711DeviceNode(config) {
|
|
9
9
|
RED.nodes.createNode(this, config);
|
|
10
10
|
const node = this;
|
|
11
|
-
|
|
12
11
|
try {
|
|
13
12
|
const chip = parseInt(config.gpioChip || 0);
|
|
14
13
|
const dout = Default.input({ chip, line: parseInt(config.doutPin) });
|
|
@@ -24,15 +23,26 @@ module.exports = function(RED) {
|
|
|
24
23
|
node.error('HX711 init failed: ' + e.message);
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
node.on('close', function() {
|
|
27
|
+
if (node.connection) node.connection.close();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
RED.nodes.registerType('hx711-device', HX711DeviceNode);
|
|
31
|
+
|
|
32
|
+
function HX711ReadNode(config) {
|
|
33
|
+
RED.nodes.createNode(this, config);
|
|
34
|
+
const node = this;
|
|
35
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
36
|
+
|
|
27
37
|
node.on('input', function(msg, send, done) {
|
|
28
|
-
if (!
|
|
38
|
+
if (!deviceNode.driver) { done(); return; }
|
|
29
39
|
try {
|
|
30
40
|
if (msg.payload === 'tare') {
|
|
31
|
-
|
|
41
|
+
deviceNode.driver.tare(10);
|
|
32
42
|
done();
|
|
33
43
|
} else {
|
|
34
|
-
const raw =
|
|
35
|
-
const weight = (raw -
|
|
44
|
+
const raw = deviceNode.driver.readRaw();
|
|
45
|
+
const weight = (raw - deviceNode.driver.getOffset()) / deviceNode.driver.getScale();
|
|
36
46
|
msg.payload = { raw, weight };
|
|
37
47
|
send(msg);
|
|
38
48
|
done();
|
|
@@ -41,11 +51,6 @@ module.exports = function(RED) {
|
|
|
41
51
|
done(e);
|
|
42
52
|
}
|
|
43
53
|
});
|
|
44
|
-
|
|
45
|
-
node.on('close', function() {
|
|
46
|
-
if (node.connection) node.connection.close();
|
|
47
|
-
});
|
|
48
54
|
}
|
|
49
|
-
|
|
50
|
-
RED.nodes.registerType('periph-hx711', HX711Node);
|
|
55
|
+
RED.nodes.registerType('hx711', HX711ReadNode);
|
|
51
56
|
};
|
package/nodes/hy3131/hy3131.html
CHANGED
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
</script>
|
|
66
66
|
|
|
67
67
|
<script type="text/javascript">
|
|
68
|
-
RED.nodes.registerType('
|
|
68
|
+
RED.nodes.registerType('hy3131', {
|
|
69
69
|
category: 'Peripheral',
|
|
70
70
|
color: '#C084FC',
|
|
71
71
|
defaults: {
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
});
|
|
81
81
|
</script>
|
|
82
82
|
|
|
83
|
-
<script type="text/html" data-template-name="
|
|
83
|
+
<script type="text/html" data-template-name="hy3131">
|
|
84
84
|
<div class="form-row">
|
|
85
85
|
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
86
86
|
<input type="text" id="node-input-device">
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
</div>
|
|
92
92
|
</script>
|
|
93
93
|
|
|
94
|
-
<script type="text/html" data-help-name="
|
|
94
|
+
<script type="text/html" data-help-name="hy3131">
|
|
95
95
|
<p>Reads the AD1 differential input (PB2 vs AGND) of an HY3131 DMM analog front end over SPI. Data-ready is polled via the INTF register, so only CK/DI/DO/CS are needed.</p>
|
|
96
96
|
|
|
97
97
|
<h3>Inputs</h3>
|
package/nodes/hy3131/hy3131.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
4
|
-
color: '#C084FC',
|
|
3
|
+
RED.nodes.registerType('mcp3422-device', {
|
|
4
|
+
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
7
|
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
@@ -9,26 +9,24 @@
|
|
|
9
9
|
resolution: { value: '16' },
|
|
10
10
|
gain: { value: '1' }
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
label: function() { return this.name || 'MCP3422'; },
|
|
16
|
-
paletteLabel: 'MCP3422'
|
|
12
|
+
label: function() {
|
|
13
|
+
return this.name || ('MCP3422 @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
14
|
+
}
|
|
17
15
|
});
|
|
18
16
|
</script>
|
|
19
17
|
|
|
20
|
-
<script type="text/html" data-template-name="
|
|
18
|
+
<script type="text/html" data-template-name="mcp3422-device">
|
|
21
19
|
<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="MCP3422">
|
|
20
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
21
|
+
<input type="text" id="node-config-input-name" placeholder="MCP3422">
|
|
24
22
|
</div>
|
|
25
23
|
<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)
|
|
24
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
25
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
28
26
|
</div>
|
|
29
27
|
<div class="form-row">
|
|
30
|
-
<label for="node-input-address"><i class="fa fa-at"></i> I²C address</label>
|
|
31
|
-
<select id="node-input-address" style="width:200px">
|
|
28
|
+
<label for="node-config-input-address"><i class="fa fa-at"></i> I²C address</label>
|
|
29
|
+
<select id="node-config-input-address" style="width:200px">
|
|
32
30
|
<option value="0x68">0x68 (order code A0)</option><option value="0x69">0x69 (A1)</option>
|
|
33
31
|
<option value="0x6A">0x6A (A2)</option><option value="0x6B">0x6B (A3)</option>
|
|
34
32
|
<option value="0x6C">0x6C (A4)</option><option value="0x6D">0x6D (A5)</option>
|
|
@@ -36,22 +34,50 @@
|
|
|
36
34
|
</select>
|
|
37
35
|
</div>
|
|
38
36
|
<div class="form-row">
|
|
39
|
-
<label for="node-input-resolution"><i class="fa fa-sliders"></i> Resolution</label>
|
|
40
|
-
<select id="node-input-resolution" style="width:200px">
|
|
37
|
+
<label for="node-config-input-resolution"><i class="fa fa-sliders"></i> Resolution</label>
|
|
38
|
+
<select id="node-config-input-resolution" style="width:200px">
|
|
41
39
|
<option value="12">12 bit / 240 SPS</option><option value="14">14 bit / 60 SPS</option>
|
|
42
40
|
<option value="16">16 bit / 15 SPS</option><option value="18">18 bit / 3.75 SPS</option>
|
|
43
41
|
</select>
|
|
44
42
|
</div>
|
|
45
43
|
<div class="form-row">
|
|
46
|
-
<label for="node-input-gain"><i class="fa fa-expand"></i> Gain</label>
|
|
47
|
-
<select id="node-input-gain" style="width:120px">
|
|
44
|
+
<label for="node-config-input-gain"><i class="fa fa-expand"></i> Gain</label>
|
|
45
|
+
<select id="node-config-input-gain" style="width:120px">
|
|
48
46
|
<option value="1">x1</option><option value="2">x2</option>
|
|
49
47
|
<option value="4">x4</option><option value="8">x8</option>
|
|
50
48
|
</select>
|
|
51
49
|
</div>
|
|
52
50
|
</script>
|
|
53
51
|
|
|
54
|
-
|
|
52
|
+
<!-- Read node -->
|
|
53
|
+
<script type="text/javascript">
|
|
54
|
+
RED.nodes.registerType('mcp3422', {
|
|
55
|
+
category: 'Peripheral',
|
|
56
|
+
color: '#C084FC',
|
|
57
|
+
defaults: {
|
|
58
|
+
name: { value: '' },
|
|
59
|
+
device: { value: '', type: 'mcp3422-device', required: true }
|
|
60
|
+
},
|
|
61
|
+
inputs: 1,
|
|
62
|
+
outputs: 1,
|
|
63
|
+
icon: 'font-awesome/fa-area-chart',
|
|
64
|
+
label: function() { return this.name || 'MCP3422'; },
|
|
65
|
+
paletteLabel: 'MCP3422'
|
|
66
|
+
});
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<script type="text/html" data-template-name="mcp3422">
|
|
70
|
+
<div class="form-row">
|
|
71
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
72
|
+
<input type="text" id="node-input-name" placeholder="MCP3422">
|
|
73
|
+
</div>
|
|
74
|
+
<div class="form-row">
|
|
75
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
76
|
+
<input type="text" id="node-input-device">
|
|
77
|
+
</div>
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<script type="text/html" data-help-name="mcp3422">
|
|
55
81
|
<p>Reads the two differential inputs of a MCP3422 18-bit delta-sigma ADC (I²C) with a one-shot conversion per channel. Full scale is ±2.048 V / gain; the LSB is 2·2.048 V / 2<sup>bits</sup> / gain.</p>
|
|
56
82
|
|
|
57
83
|
<h3>Inputs</h3>
|
package/nodes/mcp3422/mcp3422.js
CHANGED
|
@@ -4,10 +4,9 @@ module.exports = function(RED) {
|
|
|
4
4
|
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { MCP3422Full } = require('periph/src/chips/adc_dac/mcp3422');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function MCP3422DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
|
-
|
|
11
10
|
try {
|
|
12
11
|
const address = parseInt(config.address || '0x68', 16);
|
|
13
12
|
node.connection = new I2CConnection(parseInt(config.bus, 10), address);
|
|
@@ -23,22 +22,39 @@ module.exports = function(RED) {
|
|
|
23
22
|
node.error('MCP3422 init failed: ' + e.message);
|
|
24
23
|
}
|
|
25
24
|
|
|
25
|
+
node.on('close', async function(removed, done) {
|
|
26
|
+
try {
|
|
27
|
+
if (node.connection) await node.connection.close();
|
|
28
|
+
} catch (e) {
|
|
29
|
+
// bus may already be gone; nothing more to do on close
|
|
30
|
+
} finally {
|
|
31
|
+
done();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
RED.nodes.registerType('mcp3422-device', MCP3422DeviceNode);
|
|
36
|
+
|
|
37
|
+
function MCP3422ReadNode(config) {
|
|
38
|
+
RED.nodes.createNode(this, config);
|
|
39
|
+
const node = this;
|
|
40
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
41
|
+
|
|
26
42
|
node.on('input', async function(msg, send, done) {
|
|
27
|
-
if (!
|
|
43
|
+
if (!deviceNode.driver) { done(new Error('MCP3422 not initialised')); return; }
|
|
28
44
|
try {
|
|
29
|
-
await
|
|
45
|
+
await deviceNode.ready;
|
|
30
46
|
// msg.gain / msg.resolution apply before the conversion and persist.
|
|
31
|
-
if (msg.resolution !== undefined) await
|
|
32
|
-
if (msg.gain !== undefined) await
|
|
33
|
-
const lsb =
|
|
34
|
-
const gain =
|
|
47
|
+
if (msg.resolution !== undefined) await deviceNode.driver.setResolution(Number(msg.resolution));
|
|
48
|
+
if (msg.gain !== undefined) await deviceNode.driver.setGain(Number(msg.gain));
|
|
49
|
+
const lsb = deviceNode.driver.lsb();
|
|
50
|
+
const gain = deviceNode.driver.getGain();
|
|
35
51
|
if (msg.channel !== undefined) {
|
|
36
52
|
const channel = Number(msg.channel) < 1 ? 0 : 1;
|
|
37
|
-
const raw = await
|
|
53
|
+
const raw = await deviceNode.driver.readRaw(channel);
|
|
38
54
|
msg.payload = { channel, raw, voltage: raw * lsb / gain };
|
|
39
55
|
} else {
|
|
40
|
-
const raw0 = await
|
|
41
|
-
const raw1 = await
|
|
56
|
+
const raw0 = await deviceNode.driver.readRaw(0);
|
|
57
|
+
const raw1 = await deviceNode.driver.readRaw(1);
|
|
42
58
|
msg.payload = { channels: [raw0 * lsb / gain, raw1 * lsb / gain], raw: [raw0, raw1] };
|
|
43
59
|
}
|
|
44
60
|
send(msg);
|
|
@@ -47,16 +63,6 @@ module.exports = function(RED) {
|
|
|
47
63
|
done(e);
|
|
48
64
|
}
|
|
49
65
|
});
|
|
50
|
-
|
|
51
|
-
node.on('close', async function(removed, done) {
|
|
52
|
-
try {
|
|
53
|
-
if (node.connection) await node.connection.close();
|
|
54
|
-
} catch (e) {
|
|
55
|
-
// bus may already be gone; nothing more to do on close
|
|
56
|
-
} finally {
|
|
57
|
-
done();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
66
|
}
|
|
61
|
-
RED.nodes.registerType('
|
|
67
|
+
RED.nodes.registerType('mcp3422', MCP3422ReadNode);
|
|
62
68
|
};
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
</script>
|
|
29
29
|
|
|
30
30
|
<script type="text/javascript">
|
|
31
|
-
RED.nodes.registerType('
|
|
31
|
+
RED.nodes.registerType('mcp4725', {
|
|
32
32
|
category: 'Peripheral',
|
|
33
33
|
color: '#C084FC',
|
|
34
34
|
defaults: {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
});
|
|
45
45
|
</script>
|
|
46
46
|
|
|
47
|
-
<script type="text/html" data-template-name="
|
|
47
|
+
<script type="text/html" data-template-name="mcp4725">
|
|
48
48
|
<div class="form-row">
|
|
49
49
|
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
50
50
|
<input type="text" id="node-input-device">
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
</div>
|
|
63
63
|
</script>
|
|
64
64
|
|
|
65
|
-
<script type="text/html" data-help-name="
|
|
65
|
+
<script type="text/html" data-help-name="mcp4725">
|
|
66
66
|
<p>Sets the output voltage of an MCP4725 12-bit DAC over I²C.</p>
|
|
67
67
|
<p>Any input message triggers a DAC write. The device is configured via a <b>mcp4725-device</b> config node.</p>
|
|
68
68
|
|
package/nodes/mcp4725/mcp4725.js
CHANGED