node-red-contrib-periph-adc-dac 1.3.2 → 1.3.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.
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { ADS1113Full } = require('periph/src/chips/adc_dac/ads1113');
6
+
7
+ function ADS1113Node(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 ADS1113Full(connection);
13
+ node.connection = connection;
14
+ node.ready = (async () => {
15
+ await node.driver.setDataRate(parseInt(config.dataRate));
16
+ })();
17
+ } catch (e) {
18
+ node.error('ADS1113 init failed: ' + e.message);
19
+ }
20
+ node.on('input', async function(msg, send, done) {
21
+ if (!node.driver) { done(); return; }
22
+ try {
23
+ await node.ready;
24
+ const driver = node.driver;
25
+ const raw = await driver.readRaw();
26
+ msg.payload = { raw, voltage: raw * driver.lsb() };
27
+ send(msg);
28
+ done();
29
+ } catch (e) {
30
+ done(e);
31
+ }
32
+ });
33
+ node.on('close', function() {
34
+ if (node.connection) node.connection.close();
35
+ });
36
+ }
37
+ RED.nodes.registerType('periph-ads1113', ADS1113Node);
38
+ };
@@ -0,0 +1,78 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-ads1114', {
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
+ gain: { value: '2' },
10
+ dataRate: { value: '4' }
11
+ },
12
+ inputs: 1,
13
+ outputs: 1,
14
+ icon: 'font-awesome/fa-microchip',
15
+ label: function() { return this.name || 'ADS1114'; },
16
+ paletteLabel: 'ADS1114'
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="periph-ads1114">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
+ <input type="text" id="node-input-name" placeholder="ADS1114">
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
27
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-address">Address (hex)</label>
31
+ <input type="text" id="node-input-address" placeholder="48" style="width:80px"> &nbsp;48–4B (ADDR strap), default 48
32
+ </div>
33
+ <div class="form-row">
34
+ <label for="node-input-gain"><i class="fa fa-cog"></i> Gain</label>
35
+ <select id="node-input-gain" style="width:140px">
36
+ <option value="0">±6.144 V</option>
37
+ <option value="1">±4.096 V</option>
38
+ <option value="2">±2.048 V</option>
39
+ <option value="3">±1.024 V</option>
40
+ <option value="4">±0.512 V</option>
41
+ <option value="5">±0.256 V</option>
42
+ </select>
43
+ </div>
44
+ <div class="form-row">
45
+ <label for="node-input-dataRate"><i class="fa fa-clock-o"></i> Data rate</label>
46
+ <select id="node-input-dataRate" style="width:140px">
47
+ <option value="0">8 SPS</option>
48
+ <option value="1">16 SPS</option>
49
+ <option value="2">32 SPS</option>
50
+ <option value="3">64 SPS</option>
51
+ <option value="4">128 SPS</option>
52
+ <option value="5">250 SPS</option>
53
+ <option value="6">475 SPS</option>
54
+ <option value="7">860 SPS</option>
55
+ </select>
56
+ </div>
57
+ </script>
58
+
59
+ <script type="text/html" data-help-name="periph-ads1114">
60
+ <p>Reads the ADS1114 16-bit ΔΣ ADC (one differential input (AIN0 − AIN1) with programmable gain) over I²C. Default address is <code>0x48</code>; <code>0x48</code>–<code>0x4B</code> are valid depending on the ADDR strap.</p>
61
+
62
+ <h3>Inputs</h3>
63
+ <dl class="message-properties">
64
+ <dt>payload <span class="property-type">any</span></dt>
65
+ <dd>Any incoming message triggers a single-shot conversion.</dd>
66
+ </dl>
67
+
68
+ <h3>Outputs</h3>
69
+ <dl class="message-properties">
70
+ <dt>payload.raw <span class="property-type">number</span></dt>
71
+ <dd>Signed 16-bit conversion code.</dd>
72
+ <dt>payload.voltage <span class="property-type">number</span></dt>
73
+ <dd>Input voltage in volts (raw × LSB of the configured range).</dd>
74
+ </dl>
75
+
76
+ <h3>Configuration</h3>
77
+ <p>I²C bus and address, gain (full-scale range), data rate.</p>
78
+ </script>
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { ADS1114Full } = require('periph/src/chips/adc_dac/ads1114');
6
+
7
+ function ADS1114Node(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 ADS1114Full(connection);
13
+ node.connection = connection;
14
+ node.ready = (async () => {
15
+ await node.driver.setGain(parseInt(config.gain));
16
+ await node.driver.setDataRate(parseInt(config.dataRate));
17
+ })();
18
+ } catch (e) {
19
+ node.error('ADS1114 init failed: ' + e.message);
20
+ }
21
+ node.on('input', async function(msg, send, done) {
22
+ if (!node.driver) { done(); return; }
23
+ try {
24
+ await node.ready;
25
+ const driver = node.driver;
26
+ const raw = await driver.readRaw();
27
+ msg.payload = { raw, voltage: raw * driver.lsb() };
28
+ send(msg);
29
+ done();
30
+ } catch (e) {
31
+ done(e);
32
+ }
33
+ });
34
+ node.on('close', function() {
35
+ if (node.connection) node.connection.close();
36
+ });
37
+ }
38
+ RED.nodes.registerType('periph-ads1114', ADS1114Node);
39
+ };
@@ -0,0 +1,91 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-ads1115', {
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
+ gain: { value: '2' },
10
+ dataRate: { value: '4' },
11
+ channel: { value: '0' }
12
+ },
13
+ inputs: 1,
14
+ outputs: 1,
15
+ icon: 'font-awesome/fa-microchip',
16
+ label: function() { return this.name || 'ADS1115'; },
17
+ paletteLabel: 'ADS1115'
18
+ });
19
+ </script>
20
+
21
+ <script type="text/html" data-template-name="periph-ads1115">
22
+ <div class="form-row">
23
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
24
+ <input type="text" id="node-input-name" placeholder="ADS1115">
25
+ </div>
26
+ <div class="form-row">
27
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
28
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
29
+ </div>
30
+ <div class="form-row">
31
+ <label for="node-input-address">Address (hex)</label>
32
+ <input type="text" id="node-input-address" placeholder="48" style="width:80px"> &nbsp;48–4B (ADDR strap), default 48
33
+ </div>
34
+ <div class="form-row">
35
+ <label for="node-input-gain"><i class="fa fa-cog"></i> Gain</label>
36
+ <select id="node-input-gain" style="width:140px">
37
+ <option value="0">±6.144 V</option>
38
+ <option value="1">±4.096 V</option>
39
+ <option value="2">±2.048 V</option>
40
+ <option value="3">±1.024 V</option>
41
+ <option value="4">±0.512 V</option>
42
+ <option value="5">±0.256 V</option>
43
+ </select>
44
+ </div>
45
+ <div class="form-row">
46
+ <label for="node-input-dataRate"><i class="fa fa-clock-o"></i> Data rate</label>
47
+ <select id="node-input-dataRate" style="width:140px">
48
+ <option value="0">8 SPS</option>
49
+ <option value="1">16 SPS</option>
50
+ <option value="2">32 SPS</option>
51
+ <option value="3">64 SPS</option>
52
+ <option value="4">128 SPS</option>
53
+ <option value="5">250 SPS</option>
54
+ <option value="6">475 SPS</option>
55
+ <option value="7">860 SPS</option>
56
+ </select>
57
+ </div>
58
+ <div class="form-row">
59
+ <label for="node-input-channel">Default channel</label>
60
+ <select id="node-input-channel" style="width:80px">
61
+ <option value="0">AIN0</option><option value="1">AIN1</option><option value="2">AIN2</option><option value="3">AIN3</option>
62
+ </select>
63
+ </div>
64
+ </script>
65
+
66
+ <script type="text/html" data-help-name="periph-ads1115">
67
+ <p>Reads the ADS1115 16-bit ΔΣ ADC (four single-ended or two differential inputs with programmable gain) over I²C. Default address is <code>0x48</code>; <code>0x48</code>–<code>0x4B</code> are valid depending on the ADDR strap.</p>
68
+
69
+ <h3>Inputs</h3>
70
+ <dl class="message-properties">
71
+ <dt>payload <span class="property-type">any</span></dt>
72
+ <dd>Any incoming message triggers a single-shot conversion.</dd>
73
+ <dt>msg.channel <span class="property-type">number</span> (optional)</dt>
74
+ <dd>Single-ended input 0–3; overrides the configured default channel.</dd>
75
+ <dt>msg.differential <span class="property-type">string</span> (optional)</dt>
76
+ <dd><code>"0-1"</code>, <code>"0-3"</code>, <code>"1-3"</code> or <code>"2-3"</code>: a differential conversion instead of a single-ended one.</dd>
77
+ </dl>
78
+
79
+ <h3>Outputs</h3>
80
+ <dl class="message-properties">
81
+ <dt>payload.channel <span class="property-type">number</span></dt>
82
+ <dd>Single-ended input that was read (absent for differential reads, which carry <code>payload.pair</code> instead).</dd>
83
+ <dt>payload.raw <span class="property-type">number</span></dt>
84
+ <dd>Signed 16-bit conversion code.</dd>
85
+ <dt>payload.voltage <span class="property-type">number</span></dt>
86
+ <dd>Input voltage in volts (raw × LSB of the configured range).</dd>
87
+ </dl>
88
+
89
+ <h3>Configuration</h3>
90
+ <p>I²C bus and address, gain (full-scale range), data rate, and the default channel.</p>
91
+ </script>
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { ADS1115Full } = require('periph/src/chips/adc_dac/ads1115');
6
+
7
+ function ADS1115Node(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 ADS1115Full(connection);
13
+ node.connection = connection;
14
+ node.ready = (async () => {
15
+ await node.driver.setGain(parseInt(config.gain));
16
+ await node.driver.setDataRate(parseInt(config.dataRate));
17
+ })();
18
+ } catch (e) {
19
+ node.error('ADS1115 init failed: ' + e.message);
20
+ }
21
+ node.on('input', async function(msg, send, done) {
22
+ if (!node.driver) { done(); return; }
23
+ try {
24
+ await node.ready;
25
+ const driver = node.driver;
26
+ const pairs = { '0-1': 0, '0-3': 1, '1-3': 2, '2-3': 3 };
27
+ if (msg.differential !== undefined) {
28
+ const pair = pairs[msg.differential];
29
+ if (pair === undefined) throw new Error('msg.differential must be 0-1, 0-3, 1-3 or 2-3');
30
+ const raw = await driver.readDifferentialRaw(pair);
31
+ msg.payload = { pair: msg.differential, raw, voltage: raw * driver.lsb() };
32
+ } else {
33
+ const channel = msg.channel !== undefined ? parseInt(msg.channel) : parseInt(config.channel);
34
+ const raw = await driver.readRaw(channel);
35
+ msg.payload = { channel: Math.max(0, Math.min(3, channel)), raw, voltage: raw * driver.lsb() };
36
+ }
37
+ send(msg);
38
+ done();
39
+ } catch (e) {
40
+ done(e);
41
+ }
42
+ });
43
+ node.on('close', function() {
44
+ if (node.connection) node.connection.close();
45
+ });
46
+ }
47
+ RED.nodes.registerType('periph-ads1115', ADS1115Node);
48
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-adc-dac",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Node-RED nodes for ADC and DAC chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -12,15 +12,22 @@
12
12
  ],
13
13
  "node-red": {
14
14
  "nodes": {
15
+ "ad5243": "nodes/ad5243/ad5243.js",
16
+ "ad5248": "nodes/ad5248/ad5248.js",
17
+ "ad7705": "nodes/ad7705/ad7705.js",
18
+ "ad7706": "nodes/ad7706/ad7706.js",
19
+ "ads1013": "nodes/ads1013/ads1013.js",
20
+ "ads1014": "nodes/ads1014/ads1014.js",
21
+ "ads1113": "nodes/ads1113/ads1113.js",
22
+ "ads1114": "nodes/ads1114/ads1114.js",
23
+ "ads1115": "nodes/ads1115/ads1115.js",
15
24
  "hx710a": "nodes/hx710a/hx710a.js",
16
25
  "hx710b": "nodes/hx710b/hx710b.js",
17
26
  "hx711": "nodes/hx711/hx711.js",
27
+ "hy3131": "nodes/hy3131/hy3131.js",
18
28
  "mcp4725": "nodes/mcp4725/mcp4725.js",
19
29
  "mcp4728": "nodes/mcp4728/mcp4728.js",
20
- "pcf8591": "nodes/pcf8591/pcf8591.js",
21
- "ad7705": "nodes/ad7705/ad7705.js",
22
- "ad7706": "nodes/ad7706/ad7706.js",
23
- "hy3131": "nodes/hy3131/hy3131.js"
30
+ "pcf8591": "nodes/pcf8591/pcf8591.js"
24
31
  }
25
32
  },
26
33
  "dependencies": {