node-red-contrib-periph-adc-dac 1.2.0 → 1.3.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 CHANGED
@@ -23,6 +23,8 @@ npm install node-red-contrib-periph-adc-dac
23
23
  | `periph-hx710a` | input | Reads weight from an HX710A 24-bit ADC connected to a load cell via two GPIO pins. Also exposes the chip's on-chip temperature sensor as a raw ADC code. |
24
24
  | `periph-hx710b` | input | Reads weight from an HX710B 24-bit ADC connected to a load cell via two GPIO pins. Also exposes the chip's DVDD-AVDD supply-voltage-difference channel as a raw ADC code for battery-monitoring applications. |
25
25
  | `periph-hx711` | input | Reads weight from an HX711 24-bit ADC connected to a load cell via two GPIO pins. |
26
+ | `hy3131-device` | config | Bus configuration for a HY3131 |
27
+ | `periph-hy3131` | input | 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. |
26
28
  | `mcp4725-device` | config | I²C bus and address for a MCP4725 |
27
29
  | `periph-mcp4725` | output | Sets the output voltage of an MCP4725 12-bit DAC over I²C. |
28
30
  | `mcp4728-device` | config | I²C bus and address for a MCP4728 |
@@ -0,0 +1,94 @@
1
+ [
2
+ {
3
+ "id": "tab-hy3131-demo",
4
+ "type": "tab",
5
+ "label": "HY3131 Voltmeter Demo",
6
+ "disabled": false,
7
+ "info": "Bench voltmeter demo for the HY3131 DMM analog front end. An inject node fires every second and triggers an AD1 read of the 0–1.2 V source wired between PB2 and AGND (40 Hz output rate, chopper on). The payload {voltage, raw} goes to a debug node and a chart-ready function that extracts the voltage."
8
+ },
9
+ {
10
+ "id": "cfg-hy3131",
11
+ "type": "hy3131-device",
12
+ "name": "HY3131",
13
+ "bus": "0",
14
+ "device": "0",
15
+ "vref": "1.2",
16
+ "osr": "4",
17
+ "chop": "2",
18
+ "inputGain": "0"
19
+ },
20
+ {
21
+ "id": "inj-read",
22
+ "type": "inject",
23
+ "name": "read every 1s",
24
+ "topic": "",
25
+ "payload": "",
26
+ "payloadType": "date",
27
+ "repeat": "1",
28
+ "crontab": "",
29
+ "once": false,
30
+ "onceDelay": 0.1,
31
+ "z": "tab-hy3131-demo",
32
+ "x": 150,
33
+ "y": 120,
34
+ "wires": [
35
+ [
36
+ "hy3131"
37
+ ]
38
+ ]
39
+ },
40
+ {
41
+ "id": "hy3131",
42
+ "type": "periph-hy3131",
43
+ "name": "HY3131",
44
+ "device": "cfg-hy3131",
45
+ "z": "tab-hy3131-demo",
46
+ "x": 340,
47
+ "y": 120,
48
+ "wires": [
49
+ [
50
+ "fn-voltage",
51
+ "dbg-all"
52
+ ]
53
+ ]
54
+ },
55
+ {
56
+ "id": "fn-voltage",
57
+ "type": "function",
58
+ "name": "voltage",
59
+ "func": "return { topic: 'voltage', payload: msg.payload.voltage };",
60
+ "outputs": 1,
61
+ "z": "tab-hy3131-demo",
62
+ "x": 540,
63
+ "y": 80,
64
+ "wires": [
65
+ [
66
+ "dbg-voltage"
67
+ ]
68
+ ]
69
+ },
70
+ {
71
+ "id": "dbg-voltage",
72
+ "type": "debug",
73
+ "name": "voltage (V)",
74
+ "active": true,
75
+ "tosidebar": true,
76
+ "complete": "payload",
77
+ "z": "tab-hy3131-demo",
78
+ "x": 740,
79
+ "y": 80,
80
+ "wires": []
81
+ },
82
+ {
83
+ "id": "dbg-all",
84
+ "type": "debug",
85
+ "name": "HY3131 reading",
86
+ "active": true,
87
+ "tosidebar": true,
88
+ "complete": "payload",
89
+ "z": "tab-hy3131-demo",
90
+ "x": 740,
91
+ "y": 160,
92
+ "wires": []
93
+ }
94
+ ]
@@ -0,0 +1,113 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('hy3131-device', {
3
+ category: 'config',
4
+ defaults: {
5
+ name: { value: '' },
6
+ bus: { value: '0', required: true, validate: RED.validators.number() },
7
+ device: { value: '0', required: true, validate: RED.validators.number() },
8
+ vref: { value: '1.2', required: true },
9
+ osr: { value: '7', required: true },
10
+ chop: { value: '0', required: true },
11
+ inputGain: { value: '0', required: true }
12
+ },
13
+ label: function() {
14
+ return this.name || ('HY3131 @ SPI ' + this.bus + '.' + this.device);
15
+ }
16
+ });
17
+ </script>
18
+
19
+ <script type="text/html" data-template-name="hy3131-device">
20
+ <div class="form-row">
21
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
22
+ <input type="text" id="node-config-input-name" placeholder="HY3131">
23
+ </div>
24
+ <div class="form-row">
25
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> SPI bus</label>
26
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px">
27
+ </div>
28
+ <div class="form-row">
29
+ <label for="node-config-input-device"><i class="fa fa-microchip"></i> SPI device (CS)</label>
30
+ <input type="number" id="node-config-input-device" min="0" style="width:80px">
31
+ </div>
32
+ <div class="form-row">
33
+ <label for="node-config-input-vref">REFO (V)</label>
34
+ <input type="number" id="node-config-input-vref" step="0.01" style="width:80px">
35
+ </div>
36
+ <div class="form-row">
37
+ <label for="node-config-input-osr">AD1 OSR</label>
38
+ <select id="node-config-input-osr" style="width:160px">
39
+ <option value="0">256 (640 Hz)</option>
40
+ <option value="1">512 (320 Hz)</option>
41
+ <option value="2">1024 (160 Hz)</option>
42
+ <option value="3">2048 (80 Hz)</option>
43
+ <option value="4">4096 (40 Hz)</option>
44
+ <option value="5">8192 (20 Hz)</option>
45
+ <option value="6">16384 (10 Hz)</option>
46
+ <option value="7">32768 (5 Hz)</option>
47
+ </select>
48
+ </div>
49
+ <div class="form-row">
50
+ <label for="node-config-input-chop">AD1 chopper</label>
51
+ <select id="node-config-input-chop" style="width:160px">
52
+ <option value="0">Off</option>
53
+ <option value="2">On (offset cancelled)</option>
54
+ </select>
55
+ </div>
56
+ <div class="form-row">
57
+ <label for="node-config-input-inputGain">AD1 input gain</label>
58
+ <select id="node-config-input-inputGain" style="width:160px">
59
+ <option value="0">0.9</option>
60
+ <option value="1">1.8</option>
61
+ <option value="2">2.7</option>
62
+ <option value="3">3.6</option>
63
+ </select>
64
+ </div>
65
+ </script>
66
+
67
+ <script type="text/javascript">
68
+ RED.nodes.registerType('periph-hy3131', {
69
+ category: 'Peripheral',
70
+ color: '#C084FC',
71
+ defaults: {
72
+ name: { value: '' },
73
+ device: { value: '', type: 'hy3131-device', required: true }
74
+ },
75
+ inputs: 1,
76
+ outputs: 1,
77
+ icon: 'font-awesome/fa-wave-square',
78
+ label: function() { return this.name || 'HY3131'; },
79
+ paletteLabel: 'HY3131'
80
+ });
81
+ </script>
82
+
83
+ <script type="text/html" data-template-name="periph-hy3131">
84
+ <div class="form-row">
85
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
86
+ <input type="text" id="node-input-device">
87
+ </div>
88
+ <div class="form-row">
89
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
90
+ <input type="text" id="node-input-name" placeholder="HY3131">
91
+ </div>
92
+ </script>
93
+
94
+ <script type="text/html" data-help-name="periph-hy3131">
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
+
97
+ <h3>Inputs</h3>
98
+ <dl class="message-properties">
99
+ <dt>payload <span class="property-type">any</span></dt>
100
+ <dd>Any incoming message triggers a read (blocks until the next AD1 conversion, up to 2 s).</dd>
101
+ </dl>
102
+
103
+ <h3>Outputs</h3>
104
+ <dl class="message-properties">
105
+ <dt>payload.voltage <span class="property-type">number</span></dt>
106
+ <dd>Differential input voltage in V.</dd>
107
+ <dt>payload.raw <span class="property-type">number</span></dt>
108
+ <dd>Signed 24-bit AD1 code.</dd>
109
+ </dl>
110
+
111
+ <h3>Configuration</h3>
112
+ <p>Set the SPI bus and CS line (Linux <code>/dev/spidevBUS.DEVICE</code>), the REFO voltage (default 1.2 V, internal bandgap), the AD1 oversampling ratio (output rate), chopper and input gain. SPI Mode 0 at 1 MHz is used; the chip needs 3.3–3.6 V logic.</p>
113
+ </script>
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const SPIConnection = require('periph/src/connection/spi').SPIConnection;
5
+ const HY3131Full = require('periph/src/chips/adc_dac/hy3131').HY3131Full;
6
+
7
+ function HY3131DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const connection = new SPIConnection(
12
+ parseInt(config.bus),
13
+ parseInt(config.device),
14
+ { mode: 0, maxSpeedHz: 1_000_000 }
15
+ );
16
+ const vref = parseFloat(config.vref) || 1.2;
17
+ const chip = new HY3131Full(connection, vref);
18
+ chip.init()
19
+ .then(() => chip.configureAd1({
20
+ osr: parseInt(config.osr),
21
+ chop: parseInt(config.chop),
22
+ inputGain: parseInt(config.inputGain),
23
+ }))
24
+ .then(() => {
25
+ node.chip = chip;
26
+ node.connection = connection;
27
+ })
28
+ .catch((err) => node.error('HY3131 init failed: ' + err.message));
29
+ } catch (e) {
30
+ node.error('HY3131 init failed: ' + e.message);
31
+ }
32
+ node.on('close', function() {
33
+ if (node.connection) node.connection.close();
34
+ });
35
+ }
36
+ RED.nodes.registerType('hy3131-device', HY3131DeviceNode);
37
+
38
+ function HY3131Node(config) {
39
+ RED.nodes.createNode(this, config);
40
+ const node = this;
41
+ node.device = RED.nodes.getNode(config.device);
42
+
43
+ node.on('input', async function(msg, send, done) {
44
+ if (!node.device || !node.device.chip) {
45
+ done(new Error('No HY3131 device configured'));
46
+ return;
47
+ }
48
+ try {
49
+ const chip = node.device.chip;
50
+ const raw = await chip.readRaw();
51
+ msg.payload = { voltage: await chip.readVoltage(), raw };
52
+ send(msg); done();
53
+ } catch (e) { done(e); }
54
+ });
55
+ }
56
+ RED.nodes.registerType('periph-hy3131', HY3131Node);
57
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-adc-dac",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Node-RED nodes for ADC and DAC chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -19,7 +19,8 @@
19
19
  "mcp4728": "nodes/mcp4728/mcp4728.js",
20
20
  "pcf8591": "nodes/pcf8591/pcf8591.js",
21
21
  "ad7705": "nodes/ad7705/ad7705.js",
22
- "ad7706": "nodes/ad7706/ad7706.js"
22
+ "ad7706": "nodes/ad7706/ad7706.js",
23
+ "hy3131": "nodes/hy3131/hy3131.js"
23
24
  }
24
25
  },
25
26
  "dependencies": {