node-red-contrib-periph-adc-dac 1.1.0 → 1.2.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 +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/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 +13 -6
- package/nodes/hx711/hx711.js +9 -8
- package/nodes/mcp4725/mcp4725.html +1 -1
- package/nodes/mcp4725/mcp4725.js +9 -9
- package/nodes/mcp4728/mcp4728.html +1 -1
- package/nodes/mcp4728/mcp4728.js +11 -11
- package/nodes/pcf8591/pcf8591.html +68 -0
- package/nodes/pcf8591/pcf8591.js +37 -0
- package/package.json +11 -2
|
@@ -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
|
+
};
|
package/nodes/hx711/hx711.html
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
2
|
RED.nodes.registerType('periph-hx711', {
|
|
3
3
|
category: 'Peripheral',
|
|
4
|
-
color: '#
|
|
4
|
+
color: '#C084FC',
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: '' },
|
|
7
|
+
gpioChip: { value: '0', required: true, validate: RED.validators.number() },
|
|
7
8
|
doutPin: { value: '5', required: true, validate: RED.validators.number() },
|
|
8
9
|
pdSckPin: { value: '6', required: true, validate: RED.validators.number() },
|
|
9
10
|
gain: { value: '128' },
|
|
@@ -20,12 +21,16 @@
|
|
|
20
21
|
|
|
21
22
|
<script type="text/html" data-template-name="periph-hx711">
|
|
22
23
|
<div class="form-row">
|
|
23
|
-
<label for="node-input-
|
|
24
|
-
<input type="number" id="node-input-
|
|
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)
|
|
25
26
|
</div>
|
|
26
27
|
<div class="form-row">
|
|
27
|
-
<label for="node-input-
|
|
28
|
-
<input type="number" id="node-input-
|
|
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)
|
|
29
34
|
</div>
|
|
30
35
|
<div class="form-row">
|
|
31
36
|
<label for="node-input-gain"><i class="fa fa-sliders-h"></i> Gain</label>
|
|
@@ -72,7 +77,9 @@
|
|
|
72
77
|
</dl>
|
|
73
78
|
|
|
74
79
|
<h3>Details</h3>
|
|
75
|
-
<p><b>
|
|
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>
|
|
76
83
|
<p><b>Gain</b> selects the input channel and amplifier gain: 128 and 64 use Channel A;
|
|
77
84
|
32 uses Channel B (fixed gain).</p>
|
|
78
85
|
<p><b>Scale factor</b> is the number of ADC counts per unit weight. Calibrate by placing a
|
package/nodes/hx711/hx711.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = function(RED) {
|
|
4
|
-
const
|
|
5
|
-
const {
|
|
6
|
-
const { HX711Full }
|
|
4
|
+
const { Default } = require('opengpio');
|
|
5
|
+
const { HX711Connection } = require('periph/src/connection/hx711');
|
|
6
|
+
const { HX711Full } = require('periph/src/chips/adc_dac/hx711');
|
|
7
7
|
|
|
8
8
|
function HX711Node(config) {
|
|
9
9
|
RED.nodes.createNode(this, config);
|
|
10
10
|
const node = this;
|
|
11
11
|
|
|
12
12
|
try {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
node.
|
|
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);
|
|
17
18
|
|
|
18
19
|
const gain = parseInt(config.gain || 128);
|
|
19
20
|
if (gain !== 128) node.driver.setGain(gain);
|
|
@@ -42,7 +43,7 @@ module.exports = function(RED) {
|
|
|
42
43
|
});
|
|
43
44
|
|
|
44
45
|
node.on('close', function() {
|
|
45
|
-
if (node.
|
|
46
|
+
if (node.connection) node.connection.close();
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
|
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
|
+
};
|
package/nodes/mcp4728/mcp4728.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 { MCP4728Full } = require('periph/src/chips/adc_dac/mcp4728');
|
|
6
6
|
|
|
7
7
|
function MCP4728DeviceNode(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 MCP4728Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
14
|
} catch (e) {
|
|
15
15
|
node.error('MCP4728 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('mcp4728-device', MCP4728DeviceNode);
|
|
@@ -30,7 +30,7 @@ module.exports = function(RED) {
|
|
|
30
30
|
node.gain = (config.gain === 'x2') ? 2 : 1;
|
|
31
31
|
node.persist = !!config.persist;
|
|
32
32
|
|
|
33
|
-
node.on('input', function(msg, send, done) {
|
|
33
|
+
node.on('input', async function(msg, send, done) {
|
|
34
34
|
if (!node.device || !node.device.driver) {
|
|
35
35
|
node.error('No MCP4728 device configured', msg);
|
|
36
36
|
done();
|
|
@@ -45,7 +45,7 @@ module.exports = function(RED) {
|
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
if (Array.isArray(msg.payload) && msg.payload.length === 4) {
|
|
48
|
-
dac.set_all(msg.payload);
|
|
48
|
+
await dac.set_all(msg.payload);
|
|
49
49
|
} else {
|
|
50
50
|
const v = parseFloat(msg.payload);
|
|
51
51
|
if (Number.isNaN(v)) {
|
|
@@ -54,11 +54,11 @@ module.exports = function(RED) {
|
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
if (node.inputMode === 'raw') {
|
|
57
|
-
if (node.persist) dac.set_raw_eeprom(chIdx, v, node.vref, node.gain);
|
|
58
|
-
else dac.set_raw(chIdx, v);
|
|
57
|
+
if (node.persist) await dac.set_raw_eeprom(chIdx, v, node.vref, node.gain);
|
|
58
|
+
else await dac.set_raw(chIdx, v);
|
|
59
59
|
} else {
|
|
60
|
-
if (node.persist) dac.set_voltage_eeprom(chIdx, v, node.vref, node.gain);
|
|
61
|
-
else dac.set_voltage(chIdx, v);
|
|
60
|
+
if (node.persist) await dac.set_voltage_eeprom(chIdx, v, node.vref, node.gain);
|
|
61
|
+
else await dac.set_voltage(chIdx, v);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
done();
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-pcf8591', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '48', required: true },
|
|
9
|
+
inputMode: { value: '4 single-ended' }
|
|
10
|
+
},
|
|
11
|
+
inputs: 1,
|
|
12
|
+
outputs: 1,
|
|
13
|
+
icon: 'font-awesome/fa-microchip',
|
|
14
|
+
label: function() { return this.name || 'PCF8591'; },
|
|
15
|
+
paletteLabel: 'PCF8591'
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script type="text/html" data-template-name="periph-pcf8591">
|
|
20
|
+
<div class="form-row">
|
|
21
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
22
|
+
<input type="text" id="node-input-name" placeholder="PCF8591">
|
|
23
|
+
</div>
|
|
24
|
+
<div class="form-row">
|
|
25
|
+
<label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
26
|
+
<input type="number" id="node-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
27
|
+
</div>
|
|
28
|
+
<div class="form-row">
|
|
29
|
+
<label for="node-input-address">Address (hex)</label>
|
|
30
|
+
<input type="text" id="node-input-address" placeholder="48" style="width:80px"> default: 48 (0x48)
|
|
31
|
+
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-input-inputMode"><i class="fa fa-cog"></i> Input mode</label>
|
|
34
|
+
<select id="node-input-inputMode" style="width:200px">
|
|
35
|
+
<option value="4 single-ended">4 single-ended</option>
|
|
36
|
+
<option value="3 differential">3 differential</option>
|
|
37
|
+
<option value="mixed">mixed</option>
|
|
38
|
+
<option value="2 differential">2 differential</option>
|
|
39
|
+
</select>
|
|
40
|
+
</div>
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<script type="text/html" data-help-name="periph-pcf8591">
|
|
44
|
+
<p>Reads the four analog inputs of a PCF8591 8-bit ADC/DAC over I²C. Default address is <code>0x48</code>; any address in the range <code>0x48</code>–<code>0x4F</code> is valid depending on the A0/A1/A2 pin states.</p>
|
|
45
|
+
|
|
46
|
+
<h3>Inputs</h3>
|
|
47
|
+
<dl class="message-properties">
|
|
48
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
49
|
+
<dd>Any incoming message triggers a read of all four channels.</dd>
|
|
50
|
+
<dt>payload.dac <span class="property-type">number</span> (optional)</dt>
|
|
51
|
+
<dd>If set, the value (0–255) is written to the on-chip DAC before the ADC read.</dd>
|
|
52
|
+
</dl>
|
|
53
|
+
|
|
54
|
+
<h3>Outputs</h3>
|
|
55
|
+
<dl class="message-properties">
|
|
56
|
+
<dt>payload.ch0 <span class="property-type">number</span></dt>
|
|
57
|
+
<dd>Raw 8-bit ADC value of channel 0 (0–255).</dd>
|
|
58
|
+
<dt>payload.ch1 <span class="property-type">number</span></dt>
|
|
59
|
+
<dd>Raw 8-bit ADC value of channel 1 (0–255).</dd>
|
|
60
|
+
<dt>payload.ch2 <span class="property-type">number</span></dt>
|
|
61
|
+
<dd>Raw 8-bit ADC value of channel 2 (0–255).</dd>
|
|
62
|
+
<dt>payload.ch3 <span class="property-type">number</span></dt>
|
|
63
|
+
<dd>Raw 8-bit ADC value of channel 3 (0–255).</dd>
|
|
64
|
+
</dl>
|
|
65
|
+
|
|
66
|
+
<h3>Configuration</h3>
|
|
67
|
+
<p>Set the I²C bus number, the chip's 7-bit address (default <code>0x48</code>), and the analog input mode (default: 4 single-ended inputs).</p>
|
|
68
|
+
</script>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { PCF8591Full } = require('periph/src/chips/adc_dac/pcf8591');
|
|
6
|
+
|
|
7
|
+
function PCF8591Node(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new PCF8591Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
node.error('PCF8591 init failed: ' + e.message);
|
|
16
|
+
}
|
|
17
|
+
node.on('input', async function(msg, send, done) {
|
|
18
|
+
if (!node.driver) { done(); return; }
|
|
19
|
+
try {
|
|
20
|
+
const driver = node.driver;
|
|
21
|
+
if (msg.payload && msg.payload.dac !== undefined) {
|
|
22
|
+
await driver.set_dac(msg.payload.dac);
|
|
23
|
+
}
|
|
24
|
+
const all = await driver.read_all();
|
|
25
|
+
msg.payload = { ch0: all[0], ch1: all[1], ch2: all[2], ch3: all[3] };
|
|
26
|
+
send(msg);
|
|
27
|
+
done();
|
|
28
|
+
} catch (e) {
|
|
29
|
+
done(e);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
node.on('close', function() {
|
|
33
|
+
if (node.connection) node.connection.close();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
RED.nodes.registerType('periph-pcf8591', PCF8591Node);
|
|
37
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-adc-dac",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Node-RED nodes for ADC and DAC chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -12,12 +12,21 @@
|
|
|
12
12
|
],
|
|
13
13
|
"node-red": {
|
|
14
14
|
"nodes": {
|
|
15
|
+
"hx710a": "nodes/hx710a/hx710a.js",
|
|
16
|
+
"hx710b": "nodes/hx710b/hx710b.js",
|
|
17
|
+
"hx711": "nodes/hx711/hx711.js",
|
|
15
18
|
"mcp4725": "nodes/mcp4725/mcp4725.js",
|
|
16
|
-
"mcp4728": "nodes/mcp4728/mcp4728.js"
|
|
19
|
+
"mcp4728": "nodes/mcp4728/mcp4728.js",
|
|
20
|
+
"pcf8591": "nodes/pcf8591/pcf8591.js",
|
|
21
|
+
"ad7705": "nodes/ad7705/ad7705.js",
|
|
22
|
+
"ad7706": "nodes/ad7706/ad7706.js"
|
|
17
23
|
}
|
|
18
24
|
},
|
|
19
25
|
"dependencies": {
|
|
20
26
|
"periph": "*"
|
|
21
27
|
},
|
|
28
|
+
"optionalDependencies": {
|
|
29
|
+
"opengpio": "^2.0.2"
|
|
30
|
+
},
|
|
22
31
|
"license": "MIT"
|
|
23
32
|
}
|