node-red-contrib-periph-adc-dac 1.0.1 → 1.2.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 +12 -2
- package/examples/ad7705/demo.json +108 -0
- package/examples/ad7706/demo.json +125 -0
- package/examples/hx710a/demo.json +128 -0
- package/examples/hx710b/demo.json +162 -0
- package/examples/hx711/demo.json +95 -0
- package/examples/mcp4728/demo.json +188 -0
- package/examples/pcf8591/demo.json +82 -0
- package/nodes/ad7705/ad7705.html +93 -0
- package/nodes/ad7705/ad7705.js +78 -0
- package/nodes/ad7706/ad7706.html +95 -0
- package/nodes/ad7706/ad7706.js +92 -0
- package/nodes/hx710a/hx710a.html +92 -0
- package/nodes/hx710a/hx710a.js +56 -0
- package/nodes/hx710b/hx710b.html +95 -0
- package/nodes/hx710b/hx710b.js +56 -0
- package/nodes/hx711/hx711.html +89 -0
- package/nodes/hx711/hx711.js +51 -0
- package/nodes/mcp4725/mcp4725.html +1 -1
- package/nodes/mcp4725/mcp4725.js +9 -9
- package/nodes/mcp4728/mcp4728.html +108 -0
- package/nodes/mcp4728/mcp4728.js +71 -0
- package/nodes/pcf8591/pcf8591.html +68 -0
- package/nodes/pcf8591/pcf8591.js +37 -0
- package/package.json +12 -2
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-hx710a', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
gpioChip: { value: '0', required: true, validate: RED.validators.number() },
|
|
8
|
+
doutPin: { value: '5', required: true, validate: RED.validators.number() },
|
|
9
|
+
pdSckPin: { value: '6', required: true, validate: RED.validators.number() },
|
|
10
|
+
rate: { value: '10' },
|
|
11
|
+
scaleFactor: { value: '1.0' },
|
|
12
|
+
tareOffset: { value: '0' }
|
|
13
|
+
},
|
|
14
|
+
inputs: 1,
|
|
15
|
+
outputs: 1,
|
|
16
|
+
icon: 'font-awesome/fa-weight-hanging',
|
|
17
|
+
label: function() { return this.name || 'HX710A'; },
|
|
18
|
+
paletteLabel: 'HX710A'
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script type="text/html" data-template-name="periph-hx710a">
|
|
23
|
+
<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)
|
|
26
|
+
</div>
|
|
27
|
+
<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)
|
|
30
|
+
</div>
|
|
31
|
+
<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)
|
|
34
|
+
</div>
|
|
35
|
+
<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">
|
|
38
|
+
<option value="10">10 SPS (default)</option>
|
|
39
|
+
<option value="40">40 SPS</option>
|
|
40
|
+
</select>
|
|
41
|
+
</div>
|
|
42
|
+
<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
|
|
45
|
+
</div>
|
|
46
|
+
<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>
|
|
49
|
+
</div>
|
|
50
|
+
<div class="form-row">
|
|
51
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
52
|
+
<input type="text" id="node-input-name" placeholder="HX710A">
|
|
53
|
+
</div>
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<script type="text/html" data-help-name="periph-hx710a">
|
|
57
|
+
<p>Reads weight from an HX710A 24-bit ADC connected to a load cell via two GPIO pins.
|
|
58
|
+
Also exposes the chip's on-chip temperature sensor as a raw ADC code.</p>
|
|
59
|
+
|
|
60
|
+
<h3>Inputs</h3>
|
|
61
|
+
<dl class="message-properties">
|
|
62
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
63
|
+
<dd>Any message triggers a weight reading. If <code>payload</code> is the string
|
|
64
|
+
<code>"tare"</code>, the node captures the current average (10 readings) as the
|
|
65
|
+
zero offset and produces no output message. If <code>payload</code> is the string
|
|
66
|
+
<code>"temperature"</code>, the node triggers a temperature-channel reading instead.</dd>
|
|
67
|
+
</dl>
|
|
68
|
+
|
|
69
|
+
<h3>Outputs</h3>
|
|
70
|
+
<dl class="message-properties">
|
|
71
|
+
<dt>payload.raw <span class="property-type">number</span></dt>
|
|
72
|
+
<dd>Signed 24-bit differential-input ADC value (-8 388 608 to +8 388 607).</dd>
|
|
73
|
+
<dt>payload.weight <span class="property-type">number</span></dt>
|
|
74
|
+
<dd>Calibrated weight: <code>(raw - tareOffset) / scaleFactor</code>.
|
|
75
|
+
Returns <code>0.0</code> when scale factor is 1.0 and offset is 0.</dd>
|
|
76
|
+
<dt>payload.raw_temperature <span class="property-type">number</span></dt>
|
|
77
|
+
<dd>Only present when triggered by <code>payload = "temperature"</code>. Raw,
|
|
78
|
+
uncalibrated on-chip temperature sensor code (~20.4 LSB/°C, not a °C value).</dd>
|
|
79
|
+
</dl>
|
|
80
|
+
|
|
81
|
+
<h3>Details</h3>
|
|
82
|
+
<p><b>GPIO chip</b> is the gpiochip index (check with <code>gpiodetect</code>); <b>DOUT line</b> and
|
|
83
|
+
<b>PD_SCK line</b> are gpiod line offsets on that chip (check with <code>gpioinfo</code> — matches
|
|
84
|
+
the BCM GPIO number directly on Raspberry Pi's <code>pinctrl-bcm2711</code>).</p>
|
|
85
|
+
<p><b>Rate</b> selects the differential-input output rate: 10 or 40 samples per second.
|
|
86
|
+
The HX710A has a single, fixed-gain (128) differential input — unlike the HX711, there
|
|
87
|
+
is no channel or gain selection.</p>
|
|
88
|
+
<p><b>Scale factor</b> is the number of ADC counts per unit weight. Calibrate by placing a
|
|
89
|
+
known weight on the scale: <code>factor = (readAverage() - tareOffset) / knownWeight</code>.</p>
|
|
90
|
+
<p><b>Tare offset</b> sets the initial zero point. You can also zero the scale at any time
|
|
91
|
+
by injecting a message with <code>payload = "tare"</code>.</p>
|
|
92
|
+
</script>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { Default } = require('opengpio');
|
|
5
|
+
const { HX711Connection } = require('periph/src/connection/hx711');
|
|
6
|
+
const { HX710AFull } = require('periph/src/chips/adc_dac/hx710a');
|
|
7
|
+
|
|
8
|
+
function HX710ANode(config) {
|
|
9
|
+
RED.nodes.createNode(this, config);
|
|
10
|
+
const node = this;
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const chip = parseInt(config.gpioChip || 0);
|
|
14
|
+
const dout = Default.input({ chip, line: parseInt(config.doutPin) });
|
|
15
|
+
const pd_sck = Default.output({ chip, line: parseInt(config.pdSckPin) });
|
|
16
|
+
node.connection = new HX711Connection(dout, pd_sck);
|
|
17
|
+
node.driver = new HX710AFull(node.connection);
|
|
18
|
+
|
|
19
|
+
const rate = parseInt(config.rate || 10);
|
|
20
|
+
if (rate !== 10) node.driver.setRate(rate);
|
|
21
|
+
node.driver._offset = parseInt(config.tareOffset || 0);
|
|
22
|
+
node.driver.setScale(parseFloat(config.scaleFactor || 1.0));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
node.error('HX710A init failed: ' + e.message);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
node.on('input', function(msg, send, done) {
|
|
28
|
+
if (!node.driver) { done(); return; }
|
|
29
|
+
try {
|
|
30
|
+
if (msg.payload === 'tare') {
|
|
31
|
+
node.driver.tare(10);
|
|
32
|
+
done();
|
|
33
|
+
} else if (msg.payload === 'temperature') {
|
|
34
|
+
const raw_temperature = node.driver.readTemperatureRaw();
|
|
35
|
+
msg.payload = { raw_temperature };
|
|
36
|
+
send(msg);
|
|
37
|
+
done();
|
|
38
|
+
} else {
|
|
39
|
+
const raw = node.driver.readRaw();
|
|
40
|
+
const weight = (raw - node.driver.getOffset()) / node.driver.getScale();
|
|
41
|
+
msg.payload = { raw, weight };
|
|
42
|
+
send(msg);
|
|
43
|
+
done();
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
done(e);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
node.on('close', function() {
|
|
51
|
+
if (node.connection) node.connection.close();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
RED.nodes.registerType('periph-hx710a', HX710ANode);
|
|
56
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-hx710b', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
gpioChip: { value: '0', required: true, validate: RED.validators.number() },
|
|
8
|
+
doutPin: { value: '5', required: true, validate: RED.validators.number() },
|
|
9
|
+
pdSckPin: { value: '6', required: true, validate: RED.validators.number() },
|
|
10
|
+
rate: { value: '10' },
|
|
11
|
+
scaleFactor: { value: '1.0' },
|
|
12
|
+
tareOffset: { value: '0' }
|
|
13
|
+
},
|
|
14
|
+
inputs: 1,
|
|
15
|
+
outputs: 1,
|
|
16
|
+
icon: 'font-awesome/fa-weight-hanging',
|
|
17
|
+
label: function() { return this.name || 'HX710B'; },
|
|
18
|
+
paletteLabel: 'HX710B'
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script type="text/html" data-template-name="periph-hx710b">
|
|
23
|
+
<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)
|
|
26
|
+
</div>
|
|
27
|
+
<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)
|
|
30
|
+
</div>
|
|
31
|
+
<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)
|
|
34
|
+
</div>
|
|
35
|
+
<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">
|
|
38
|
+
<option value="10">10 SPS (default)</option>
|
|
39
|
+
<option value="40">40 SPS</option>
|
|
40
|
+
</select>
|
|
41
|
+
</div>
|
|
42
|
+
<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
|
|
45
|
+
</div>
|
|
46
|
+
<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>
|
|
49
|
+
</div>
|
|
50
|
+
<div class="form-row">
|
|
51
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
52
|
+
<input type="text" id="node-input-name" placeholder="HX710B">
|
|
53
|
+
</div>
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<script type="text/html" data-help-name="periph-hx710b">
|
|
57
|
+
<p>Reads weight from an HX710B 24-bit ADC connected to a load cell via two GPIO pins.
|
|
58
|
+
Also exposes the chip's DVDD-AVDD supply-voltage-difference channel as a raw ADC code
|
|
59
|
+
for battery-monitoring applications.</p>
|
|
60
|
+
|
|
61
|
+
<h3>Inputs</h3>
|
|
62
|
+
<dl class="message-properties">
|
|
63
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
64
|
+
<dd>Any message triggers a weight reading. If <code>payload</code> is the string
|
|
65
|
+
<code>"tare"</code>, the node captures the current average (10 readings) as the
|
|
66
|
+
zero offset and produces no output message. If <code>payload</code> is the string
|
|
67
|
+
<code>"supply_diff"</code>, the node triggers a supply-difference-channel reading instead.</dd>
|
|
68
|
+
</dl>
|
|
69
|
+
|
|
70
|
+
<h3>Outputs</h3>
|
|
71
|
+
<dl class="message-properties">
|
|
72
|
+
<dt>payload.raw <span class="property-type">number</span></dt>
|
|
73
|
+
<dd>Signed 24-bit differential-input ADC value (-8 388 608 to +8 388 607).</dd>
|
|
74
|
+
<dt>payload.weight <span class="property-type">number</span></dt>
|
|
75
|
+
<dd>Calibrated weight: <code>(raw - tareOffset) / scaleFactor</code>.
|
|
76
|
+
Returns <code>0.0</code> when scale factor is 1.0 and offset is 0.</dd>
|
|
77
|
+
<dt>payload.raw_supply_diff <span class="property-type">number</span></dt>
|
|
78
|
+
<dd>Only present when triggered by <code>payload = "supply_diff"</code>. Raw,
|
|
79
|
+
uncalibrated DVDD-AVDD supply-difference code — the datasheet gives no absolute
|
|
80
|
+
LSB-to-volts scale factor for this reading; use it for relative drift tracking
|
|
81
|
+
against a known-good baseline, not as an absolute voltage.</dd>
|
|
82
|
+
</dl>
|
|
83
|
+
|
|
84
|
+
<h3>Details</h3>
|
|
85
|
+
<p><b>GPIO chip</b> is the gpiochip index (check with <code>gpiodetect</code>); <b>DOUT line</b> and
|
|
86
|
+
<b>PD_SCK line</b> are gpiod line offsets on that chip (check with <code>gpioinfo</code> — matches
|
|
87
|
+
the BCM GPIO number directly on Raspberry Pi's <code>pinctrl-bcm2711</code>).</p>
|
|
88
|
+
<p><b>Rate</b> selects the differential-input output rate: 10 or 40 samples per second.
|
|
89
|
+
The HX710B has a single, fixed-gain (128) differential input — unlike the HX711, there
|
|
90
|
+
is no channel or gain selection.</p>
|
|
91
|
+
<p><b>Scale factor</b> is the number of ADC counts per unit weight. Calibrate by placing a
|
|
92
|
+
known weight on the scale: <code>factor = (readAverage() - tareOffset) / knownWeight</code>.</p>
|
|
93
|
+
<p><b>Tare offset</b> sets the initial zero point. You can also zero the scale at any time
|
|
94
|
+
by injecting a message with <code>payload = "tare"</code>.</p>
|
|
95
|
+
</script>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { Default } = require('opengpio');
|
|
5
|
+
const { HX711Connection } = require('periph/src/connection/hx711');
|
|
6
|
+
const { HX710BFull } = require('periph/src/chips/adc_dac/hx710b');
|
|
7
|
+
|
|
8
|
+
function HX710BNode(config) {
|
|
9
|
+
RED.nodes.createNode(this, config);
|
|
10
|
+
const node = this;
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const chip = parseInt(config.gpioChip || 0);
|
|
14
|
+
const dout = Default.input({ chip, line: parseInt(config.doutPin) });
|
|
15
|
+
const pd_sck = Default.output({ chip, line: parseInt(config.pdSckPin) });
|
|
16
|
+
node.connection = new HX711Connection(dout, pd_sck);
|
|
17
|
+
node.driver = new HX710BFull(node.connection);
|
|
18
|
+
|
|
19
|
+
const rate = parseInt(config.rate || 10);
|
|
20
|
+
if (rate !== 10) node.driver.setRate(rate);
|
|
21
|
+
node.driver._offset = parseInt(config.tareOffset || 0);
|
|
22
|
+
node.driver.setScale(parseFloat(config.scaleFactor || 1.0));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
node.error('HX710B init failed: ' + e.message);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
node.on('input', function(msg, send, done) {
|
|
28
|
+
if (!node.driver) { done(); return; }
|
|
29
|
+
try {
|
|
30
|
+
if (msg.payload === 'tare') {
|
|
31
|
+
node.driver.tare(10);
|
|
32
|
+
done();
|
|
33
|
+
} else if (msg.payload === 'supply_diff') {
|
|
34
|
+
const raw_supply_diff = node.driver.readSupplyDiffRaw();
|
|
35
|
+
msg.payload = { raw_supply_diff };
|
|
36
|
+
send(msg);
|
|
37
|
+
done();
|
|
38
|
+
} else {
|
|
39
|
+
const raw = node.driver.readRaw();
|
|
40
|
+
const weight = (raw - node.driver.getOffset()) / node.driver.getScale();
|
|
41
|
+
msg.payload = { raw, weight };
|
|
42
|
+
send(msg);
|
|
43
|
+
done();
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
done(e);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
node.on('close', function() {
|
|
51
|
+
if (node.connection) node.connection.close();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
RED.nodes.registerType('periph-hx710b', HX710BNode);
|
|
56
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-hx711', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
gpioChip: { value: '0', required: true, validate: RED.validators.number() },
|
|
8
|
+
doutPin: { value: '5', required: true, validate: RED.validators.number() },
|
|
9
|
+
pdSckPin: { value: '6', required: true, validate: RED.validators.number() },
|
|
10
|
+
gain: { value: '128' },
|
|
11
|
+
scaleFactor: { value: '1.0' },
|
|
12
|
+
tareOffset: { value: '0' }
|
|
13
|
+
},
|
|
14
|
+
inputs: 1,
|
|
15
|
+
outputs: 1,
|
|
16
|
+
icon: 'font-awesome/fa-weight-hanging',
|
|
17
|
+
label: function() { return this.name || 'HX711'; },
|
|
18
|
+
paletteLabel: 'HX711'
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script type="text/html" data-template-name="periph-hx711">
|
|
23
|
+
<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)
|
|
26
|
+
</div>
|
|
27
|
+
<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)
|
|
30
|
+
</div>
|
|
31
|
+
<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)
|
|
34
|
+
</div>
|
|
35
|
+
<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">
|
|
38
|
+
<option value="128">128 — Channel A (default)</option>
|
|
39
|
+
<option value="64">64 — Channel A</option>
|
|
40
|
+
<option value="32">32 — Channel B</option>
|
|
41
|
+
</select>
|
|
42
|
+
</div>
|
|
43
|
+
<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
|
|
46
|
+
</div>
|
|
47
|
+
<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>
|
|
50
|
+
</div>
|
|
51
|
+
<div class="form-row">
|
|
52
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
53
|
+
<input type="text" id="node-input-name" placeholder="HX711">
|
|
54
|
+
</div>
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<script type="text/html" data-help-name="periph-hx711">
|
|
58
|
+
<p>Reads weight from an HX711 24-bit ADC connected to a load cell via two GPIO pins.</p>
|
|
59
|
+
<p>Any input message triggers a raw ADC read. Sending <code>msg.payload = "tare"</code> captures
|
|
60
|
+
the current reading as the zero offset instead of producing output.</p>
|
|
61
|
+
|
|
62
|
+
<h3>Inputs</h3>
|
|
63
|
+
<dl class="message-properties">
|
|
64
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
65
|
+
<dd>Any message triggers a weight reading. If <code>payload</code> is the string
|
|
66
|
+
<code>"tare"</code>, the node captures the current average (10 readings) as the
|
|
67
|
+
zero offset and produces no output message.</dd>
|
|
68
|
+
</dl>
|
|
69
|
+
|
|
70
|
+
<h3>Outputs</h3>
|
|
71
|
+
<dl class="message-properties">
|
|
72
|
+
<dt>payload.raw <span class="property-type">number</span></dt>
|
|
73
|
+
<dd>Signed 24-bit ADC value (-8 388 608 to +8 388 607).</dd>
|
|
74
|
+
<dt>payload.weight <span class="property-type">number</span></dt>
|
|
75
|
+
<dd>Calibrated weight: <code>(raw - tareOffset) / scaleFactor</code>.
|
|
76
|
+
Returns <code>0.0</code> when scale factor is 1.0 and offset is 0.</dd>
|
|
77
|
+
</dl>
|
|
78
|
+
|
|
79
|
+
<h3>Details</h3>
|
|
80
|
+
<p><b>GPIO chip</b> is the gpiochip index (check with <code>gpiodetect</code>); <b>DOUT line</b> and
|
|
81
|
+
<b>PD_SCK line</b> are gpiod line offsets on that chip (check with <code>gpioinfo</code> — matches
|
|
82
|
+
the BCM GPIO number directly on Raspberry Pi's <code>pinctrl-bcm2711</code>).</p>
|
|
83
|
+
<p><b>Gain</b> selects the input channel and amplifier gain: 128 and 64 use Channel A;
|
|
84
|
+
32 uses Channel B (fixed gain).</p>
|
|
85
|
+
<p><b>Scale factor</b> is the number of ADC counts per unit weight. Calibrate by placing a
|
|
86
|
+
known weight on the scale: <code>factor = (readAverage() - tareOffset) / knownWeight</code>.</p>
|
|
87
|
+
<p><b>Tare offset</b> sets the initial zero point. You can also zero the scale at any time
|
|
88
|
+
by injecting a message with <code>payload = "tare"</code>.</p>
|
|
89
|
+
</script>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { Default } = require('opengpio');
|
|
5
|
+
const { HX711Connection } = require('periph/src/connection/hx711');
|
|
6
|
+
const { HX711Full } = require('periph/src/chips/adc_dac/hx711');
|
|
7
|
+
|
|
8
|
+
function HX711Node(config) {
|
|
9
|
+
RED.nodes.createNode(this, config);
|
|
10
|
+
const node = this;
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const chip = parseInt(config.gpioChip || 0);
|
|
14
|
+
const dout = Default.input({ chip, line: parseInt(config.doutPin) });
|
|
15
|
+
const pd_sck = Default.output({ chip, line: parseInt(config.pdSckPin) });
|
|
16
|
+
node.connection = new HX711Connection(dout, pd_sck);
|
|
17
|
+
node.driver = new HX711Full(node.connection);
|
|
18
|
+
|
|
19
|
+
const gain = parseInt(config.gain || 128);
|
|
20
|
+
if (gain !== 128) node.driver.setGain(gain);
|
|
21
|
+
node.driver._offset = parseInt(config.tareOffset || 0);
|
|
22
|
+
node.driver.setScale(parseFloat(config.scaleFactor || 1.0));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
node.error('HX711 init failed: ' + e.message);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
node.on('input', function(msg, send, done) {
|
|
28
|
+
if (!node.driver) { done(); return; }
|
|
29
|
+
try {
|
|
30
|
+
if (msg.payload === 'tare') {
|
|
31
|
+
node.driver.tare(10);
|
|
32
|
+
done();
|
|
33
|
+
} else {
|
|
34
|
+
const raw = node.driver.readRaw();
|
|
35
|
+
const weight = (raw - node.driver.getOffset()) / node.driver.getScale();
|
|
36
|
+
msg.payload = { raw, weight };
|
|
37
|
+
send(msg);
|
|
38
|
+
done();
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
done(e);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
node.on('close', function() {
|
|
46
|
+
if (node.connection) node.connection.close();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
RED.nodes.registerType('periph-hx711', HX711Node);
|
|
51
|
+
};
|
package/nodes/mcp4725/mcp4725.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = function(RED) {
|
|
4
|
-
const {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { MCP4725Full } = require('periph/src/chips/adc_dac/mcp4725');
|
|
6
6
|
|
|
7
7
|
function MCP4725DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
11
|
-
const
|
|
12
|
-
node.driver
|
|
13
|
-
node.
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new MCP4725Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
14
|
} catch (e) {
|
|
15
15
|
node.error('MCP4725 init failed: ' + e.message);
|
|
16
16
|
}
|
|
17
17
|
node.on('close', function() {
|
|
18
|
-
if (node.
|
|
18
|
+
if (node.connection) node.connection.close();
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
RED.nodes.registerType('mcp4725-device', MCP4725DeviceNode);
|
|
@@ -26,7 +26,7 @@ module.exports = function(RED) {
|
|
|
26
26
|
node.device = RED.nodes.getNode(config.device);
|
|
27
27
|
node.inputMode = config.inputMode || 'fraction';
|
|
28
28
|
|
|
29
|
-
node.on('input', function(msg, send, done) {
|
|
29
|
+
node.on('input', async function(msg, send, done) {
|
|
30
30
|
if (!node.device || !node.device.driver) {
|
|
31
31
|
node.error('No MCP4725 device configured', msg);
|
|
32
32
|
done();
|
|
@@ -36,9 +36,9 @@ module.exports = function(RED) {
|
|
|
36
36
|
const dac = node.device.driver;
|
|
37
37
|
const raw = parseFloat(msg.payload);
|
|
38
38
|
if (node.inputMode === 'raw') {
|
|
39
|
-
dac.set_raw(raw);
|
|
39
|
+
await dac.set_raw(raw);
|
|
40
40
|
} else {
|
|
41
|
-
dac.set_voltage(raw);
|
|
41
|
+
await dac.set_voltage(raw);
|
|
42
42
|
}
|
|
43
43
|
done();
|
|
44
44
|
} catch (e) {
|
|
@@ -47,4 +47,4 @@ module.exports = function(RED) {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
RED.nodes.registerType('periph-mcp4725', MCP4725WriteNode);
|
|
50
|
-
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('mcp4728-device', {
|
|
3
|
+
category: 'config',
|
|
4
|
+
defaults: {
|
|
5
|
+
name: { value: '' },
|
|
6
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
7
|
+
address: { value: '60', required: true }
|
|
8
|
+
},
|
|
9
|
+
label: function() {
|
|
10
|
+
return this.name || ('MCP4728 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script type="text/html" data-template-name="mcp4728-device">
|
|
16
|
+
<div class="form-row">
|
|
17
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
18
|
+
<input type="text" id="node-config-input-name" placeholder="MCP4728">
|
|
19
|
+
</div>
|
|
20
|
+
<div class="form-row">
|
|
21
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
22
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
23
|
+
</div>
|
|
24
|
+
<div class="form-row">
|
|
25
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
26
|
+
<input type="text" id="node-config-input-address" placeholder="60" style="width:80px"> default: 60 (0x60)
|
|
27
|
+
</div>
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<script type="text/javascript">
|
|
31
|
+
RED.nodes.registerType('periph-mcp4728', {
|
|
32
|
+
category: 'Peripheral',
|
|
33
|
+
color: '#C084FC',
|
|
34
|
+
defaults: {
|
|
35
|
+
name: { value: '' },
|
|
36
|
+
device: { value: '', type: 'mcp4728-device', required: true },
|
|
37
|
+
channel: { value: 'A' },
|
|
38
|
+
inputMode: { value: 'fraction' },
|
|
39
|
+
vref: { value: 'external' },
|
|
40
|
+
gain: { value: 'x1' },
|
|
41
|
+
persist: { value: false }
|
|
42
|
+
},
|
|
43
|
+
inputs: 1,
|
|
44
|
+
outputs: 0,
|
|
45
|
+
icon: 'font-awesome/fa-wave-square',
|
|
46
|
+
label: function() { return this.name || 'MCP4728'; },
|
|
47
|
+
paletteLabel: 'MCP4728'
|
|
48
|
+
});
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<script type="text/html" data-template-name="periph-mcp4728">
|
|
52
|
+
<div class="form-row">
|
|
53
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
54
|
+
<input type="text" id="node-input-device">
|
|
55
|
+
</div>
|
|
56
|
+
<div class="form-row">
|
|
57
|
+
<label for="node-input-channel"><i class="fa fa-sitemap"></i> Channel</label>
|
|
58
|
+
<select id="node-input-channel" style="width:100px">
|
|
59
|
+
<option value="A">A</option>
|
|
60
|
+
<option value="B">B</option>
|
|
61
|
+
<option value="C">C</option>
|
|
62
|
+
<option value="D">D</option>
|
|
63
|
+
</select>
|
|
64
|
+
</div>
|
|
65
|
+
<div class="form-row">
|
|
66
|
+
<label for="node-input-inputMode"><i class="fa fa-cog"></i> Input mode</label>
|
|
67
|
+
<select id="node-input-inputMode" style="width:150px">
|
|
68
|
+
<option value="fraction">fraction (0.0–1.0)</option>
|
|
69
|
+
<option value="raw">raw (0–4095)</option>
|
|
70
|
+
</select>
|
|
71
|
+
</div>
|
|
72
|
+
<div class="form-row">
|
|
73
|
+
<label for="node-input-vref"><i class="fa fa-bolt"></i> V_REF</label>
|
|
74
|
+
<select id="node-input-vref" style="width:150px">
|
|
75
|
+
<option value="external">External (V_DD)</option>
|
|
76
|
+
<option value="internal">Internal (2.048 V)</option>
|
|
77
|
+
</select>
|
|
78
|
+
</div>
|
|
79
|
+
<div class="form-row">
|
|
80
|
+
<label for="node-input-gain"><i class="fa fa-arrows-h"></i> Gain</label>
|
|
81
|
+
<select id="node-input-gain" style="width:100px">
|
|
82
|
+
<option value="x1">×1</option>
|
|
83
|
+
<option value="x2">×2</option>
|
|
84
|
+
</select>
|
|
85
|
+
</div>
|
|
86
|
+
<div class="form-row">
|
|
87
|
+
<label for="node-input-persist"><i class="fa fa-save"></i> Persist to EEPROM</label>
|
|
88
|
+
<input type="checkbox" id="node-input-persist" style="width:auto;margin-top:0">
|
|
89
|
+
</div>
|
|
90
|
+
<div class="form-row">
|
|
91
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
92
|
+
<input type="text" id="node-input-name" placeholder="MCP4728">
|
|
93
|
+
</div>
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<script type="text/html" data-help-name="periph-mcp4728">
|
|
97
|
+
<p>Sets the output voltage of one channel (A–D) of an MCP4728 quad-channel 12-bit DAC over I²C.</p>
|
|
98
|
+
<p>Any input message triggers a DAC write. The device is configured via an <b>mcp4728-device</b> config node. Pass a 4-element array as <code>msg.payload</code> to update all four channels simultaneously via Fast Write.</p>
|
|
99
|
+
|
|
100
|
+
<h3>Inputs</h3>
|
|
101
|
+
<dl class="message-properties">
|
|
102
|
+
<dt>payload <span class="property-type">number | number[4]</span></dt>
|
|
103
|
+
<dd>When input mode is <code>fraction</code>: value between 0.0 and 1.0 representing the output as a fraction of the configured full-scale. When input mode is <code>raw</code>: raw 12-bit DAC code (0–4095). When <code>payload</code> is an array of 4 numbers, the array is applied to channels A–D simultaneously.</dd>
|
|
104
|
+
</dl>
|
|
105
|
+
|
|
106
|
+
<h3>Details</h3>
|
|
107
|
+
<p>Configure bus number and I²C address (default <code>0x60</code>) in the device config node. The input mode determines whether incoming values are interpreted as normalized fractions or raw 12-bit codes. Selecting <i>Persist to EEPROM</i> uses Single Write instead of Multi-Write and updates the nonvolatile EEPROM; the value then survives a power cycle (takes up to 50 ms).</p>
|
|
108
|
+
</script>
|