node-red-contrib-periph-adc-dac 1.3.2 → 1.4.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 -0
- package/examples/ad5243/demo.json +116 -0
- package/examples/ad5248/demo.json +125 -0
- package/examples/ads1013/demo.json +76 -0
- package/examples/ads1014/demo.json +77 -0
- package/examples/ads1113/demo.json +60 -0
- package/examples/ads1114/demo.json +61 -0
- package/examples/ads1115/demo.json +119 -0
- package/examples/es8311/demo.json +173 -0
- package/examples/mcp4xxx/demo.json +206 -0
- package/nodes/ad5243/ad5243.html +74 -0
- package/nodes/ad5243/ad5243.js +62 -0
- package/nodes/ad5248/ad5248.html +108 -0
- package/nodes/ad5248/ad5248.js +64 -0
- package/nodes/ads1013/ads1013.html +70 -0
- package/nodes/ads1013/ads1013.js +48 -0
- package/nodes/ads1014/ads1014.html +82 -0
- package/nodes/ads1014/ads1014.js +49 -0
- package/nodes/ads1113/ads1113.html +66 -0
- package/nodes/ads1113/ads1113.js +38 -0
- package/nodes/ads1114/ads1114.html +78 -0
- package/nodes/ads1114/ads1114.js +39 -0
- package/nodes/ads1115/ads1115.html +91 -0
- package/nodes/ads1115/ads1115.js +48 -0
- package/nodes/es8311/es8311.html +111 -0
- package/nodes/es8311/es8311.js +57 -0
- package/nodes/mcp4xxx/mcp4xxx.html +167 -0
- package/nodes/mcp4xxx/mcp4xxx.js +96 -0
- package/package.json +14 -5
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { AD5248Full } = require('periph/src/chips/adc_dac/ad5248');
|
|
6
|
+
|
|
7
|
+
function AD5248DeviceNode(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 AD5248Full(connection, parseFloat(config.rab || '10000'), parseFloat(config.rwiper || '160'));
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
node.error('AD5248 init failed: ' + e.message);
|
|
16
|
+
}
|
|
17
|
+
node.on('close', function() {
|
|
18
|
+
if (node.connection) node.connection.close();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
RED.nodes.registerType('ad5248-device', AD5248DeviceNode);
|
|
22
|
+
|
|
23
|
+
function AD5248Node(config) {
|
|
24
|
+
RED.nodes.createNode(this, config);
|
|
25
|
+
const node = this;
|
|
26
|
+
node.device = RED.nodes.getNode(config.device);
|
|
27
|
+
|
|
28
|
+
node.on('input', async function(msg, send, done) {
|
|
29
|
+
if (!node.device || !node.device.driver) {
|
|
30
|
+
node.error('No AD5248 device configured', msg);
|
|
31
|
+
done();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const d = node.device.driver;
|
|
36
|
+
const p = msg.payload;
|
|
37
|
+
if (p && typeof p === 'object' && p.channel !== undefined &&
|
|
38
|
+
(p.code !== undefined || p.ohms !== undefined)) {
|
|
39
|
+
const channel = parseInt(p.channel);
|
|
40
|
+
if (p.code !== undefined) {
|
|
41
|
+
await d.setWiper(channel, parseInt(p.code));
|
|
42
|
+
} else {
|
|
43
|
+
await d.setResistance(channel, parseFloat(p.ohms));
|
|
44
|
+
}
|
|
45
|
+
msg.payload = {
|
|
46
|
+
channel: channel,
|
|
47
|
+
code: await d.getWiper(channel),
|
|
48
|
+
resistance: await d.getResistance(channel)
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
msg.payload = {
|
|
52
|
+
wiper: [await d.getWiper(0), await d.getWiper(1)],
|
|
53
|
+
resistance: [await d.getResistance(0), await d.getResistance(1)]
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
send(msg);
|
|
57
|
+
done();
|
|
58
|
+
} catch (e) {
|
|
59
|
+
done(e);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
RED.nodes.registerType('periph-ad5248', AD5248Node);
|
|
64
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-ads1013', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x48' },
|
|
9
|
+
dataRate: { value: '4' }
|
|
10
|
+
},
|
|
11
|
+
inputs: 1,
|
|
12
|
+
outputs: 1,
|
|
13
|
+
icon: 'font-awesome/fa-tachometer',
|
|
14
|
+
label: function() { return this.name || 'ADS1013'; },
|
|
15
|
+
paletteLabel: 'ADS1013'
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script type="text/html" data-template-name="periph-ads1013">
|
|
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="ADS1013">
|
|
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"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
30
|
+
<select id="node-input-address" style="width:120px">
|
|
31
|
+
<option value="0x48">0x48 (ADDR = GND)</option>
|
|
32
|
+
<option value="0x49">0x49 (ADDR = VDD)</option>
|
|
33
|
+
<option value="0x4A">0x4A (ADDR = SDA)</option>
|
|
34
|
+
<option value="0x4B">0x4B (ADDR = SCL)</option>
|
|
35
|
+
</select>
|
|
36
|
+
</div>
|
|
37
|
+
<div class="form-row">
|
|
38
|
+
<label for="node-input-dataRate"><i class="fa fa-clock-o"></i> Data rate</label>
|
|
39
|
+
<select id="node-input-dataRate" style="width:160px">
|
|
40
|
+
<option value="0">128 SPS</option>
|
|
41
|
+
<option value="1">250 SPS</option>
|
|
42
|
+
<option value="2">490 SPS</option>
|
|
43
|
+
<option value="3">920 SPS</option>
|
|
44
|
+
<option value="4">1600 SPS</option>
|
|
45
|
+
<option value="5">2400 SPS</option>
|
|
46
|
+
<option value="6">3300 SPS</option>
|
|
47
|
+
</select>
|
|
48
|
+
</div>
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<script type="text/html" data-help-name="periph-ads1013">
|
|
52
|
+
<p>Reads the voltage AIN0 − AIN1 from an ADS1013 12-bit ADC over I²C using a single-shot conversion.</p>
|
|
53
|
+
|
|
54
|
+
<h3>Inputs</h3>
|
|
55
|
+
<dl class="message-properties">
|
|
56
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
57
|
+
<dd>Any incoming message triggers one single-shot conversion.</dd>
|
|
58
|
+
</dl>
|
|
59
|
+
|
|
60
|
+
<h3>Outputs</h3>
|
|
61
|
+
<dl class="message-properties">
|
|
62
|
+
<dt>payload.raw <span class="property-type">number</span></dt>
|
|
63
|
+
<dd>12-bit two's-complement conversion code, −2048…2047.</dd>
|
|
64
|
+
<dt>payload.voltage <span class="property-type">number</span></dt>
|
|
65
|
+
<dd>Voltage AIN0 − AIN1 in volts (<code>raw × 0.001</code>).</dd>
|
|
66
|
+
</dl>
|
|
67
|
+
|
|
68
|
+
<h3>Configuration</h3>
|
|
69
|
+
<p>Set the I²C bus number and the address selected by the ADDR strap (<code>0x48</code>–<code>0x4B</code>) and the data rate (128–3300 SPS). The range is fixed at ±2.048 V. Wire AIN1 to GND for a single-ended measurement.</p>
|
|
70
|
+
</script>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { ADS1013Full } = require('periph/src/chips/adc_dac/ads1013');
|
|
6
|
+
|
|
7
|
+
function ADS1013Node(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const address = parseInt(config.address, 16) || ADS1013Full.I2C_ADDRESS;
|
|
13
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), address);
|
|
14
|
+
node.driver = new ADS1013Full(connection);
|
|
15
|
+
node.connection = connection;
|
|
16
|
+
node.ready = (async () => {
|
|
17
|
+
await node.driver.setDataRate(parseInt(config.dataRate, 10));
|
|
18
|
+
})();
|
|
19
|
+
node.ready.catch((e) => node.error('ADS1013 init failed: ' + e.message));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
node.error('ADS1013 init failed: ' + e.message);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
node.on('input', async function(msg, send, done) {
|
|
25
|
+
if (!node.driver) { done(); return; }
|
|
26
|
+
try {
|
|
27
|
+
await node.ready;
|
|
28
|
+
const raw = await node.driver.readRaw();
|
|
29
|
+
msg.payload = { raw, voltage: raw * node.driver.lsb() };
|
|
30
|
+
send(msg);
|
|
31
|
+
done();
|
|
32
|
+
} catch (e) {
|
|
33
|
+
done(e);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
node.on('close', async function(removed, done) {
|
|
38
|
+
try {
|
|
39
|
+
if (node.connection) await node.connection.close();
|
|
40
|
+
} catch (e) {
|
|
41
|
+
// bus may already be gone; nothing more to do on close
|
|
42
|
+
} finally {
|
|
43
|
+
done();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
RED.nodes.registerType('periph-ads1013', ADS1013Node);
|
|
48
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-ads1014', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x48' },
|
|
9
|
+
gain: { value: '2' },
|
|
10
|
+
dataRate: { value: '4' }
|
|
11
|
+
},
|
|
12
|
+
inputs: 1,
|
|
13
|
+
outputs: 1,
|
|
14
|
+
icon: 'font-awesome/fa-tachometer',
|
|
15
|
+
label: function() { return this.name || 'ADS1014'; },
|
|
16
|
+
paletteLabel: 'ADS1014'
|
|
17
|
+
});
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script type="text/html" data-template-name="periph-ads1014">
|
|
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="ADS1014">
|
|
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"> (Linux /dev/i2c-N)
|
|
28
|
+
</div>
|
|
29
|
+
<div class="form-row">
|
|
30
|
+
<label for="node-input-address"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
31
|
+
<select id="node-input-address" style="width:120px">
|
|
32
|
+
<option value="0x48">0x48 (ADDR = GND)</option>
|
|
33
|
+
<option value="0x49">0x49 (ADDR = VDD)</option>
|
|
34
|
+
<option value="0x4A">0x4A (ADDR = SDA)</option>
|
|
35
|
+
<option value="0x4B">0x4B (ADDR = SCL)</option>
|
|
36
|
+
</select>
|
|
37
|
+
</div>
|
|
38
|
+
<div class="form-row">
|
|
39
|
+
<label for="node-input-gain"><i class="fa fa-sliders"></i> Gain</label>
|
|
40
|
+
<select id="node-input-gain" style="width:200px">
|
|
41
|
+
<option value="0">±6.144 V (3 mV/LSB)</option>
|
|
42
|
+
<option value="1">±4.096 V (2 mV/LSB)</option>
|
|
43
|
+
<option value="2">±2.048 V (1 mV/LSB)</option>
|
|
44
|
+
<option value="3">±1.024 V (0.5 mV/LSB)</option>
|
|
45
|
+
<option value="4">±0.512 V (0.25 mV/LSB)</option>
|
|
46
|
+
<option value="5">±0.256 V (0.125 mV/LSB)</option>
|
|
47
|
+
</select>
|
|
48
|
+
</div>
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-dataRate"><i class="fa fa-clock-o"></i> Data rate</label>
|
|
51
|
+
<select id="node-input-dataRate" style="width:160px">
|
|
52
|
+
<option value="0">128 SPS</option>
|
|
53
|
+
<option value="1">250 SPS</option>
|
|
54
|
+
<option value="2">490 SPS</option>
|
|
55
|
+
<option value="3">920 SPS</option>
|
|
56
|
+
<option value="4">1600 SPS</option>
|
|
57
|
+
<option value="5">2400 SPS</option>
|
|
58
|
+
<option value="6">3300 SPS</option>
|
|
59
|
+
</select>
|
|
60
|
+
</div>
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<script type="text/html" data-help-name="periph-ads1014">
|
|
64
|
+
<p>Reads the voltage AIN0 − AIN1 from an ADS1014 12-bit ADC over I²C using a single-shot conversion.</p>
|
|
65
|
+
|
|
66
|
+
<h3>Inputs</h3>
|
|
67
|
+
<dl class="message-properties">
|
|
68
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
69
|
+
<dd>Any incoming message triggers one single-shot conversion.</dd>
|
|
70
|
+
</dl>
|
|
71
|
+
|
|
72
|
+
<h3>Outputs</h3>
|
|
73
|
+
<dl class="message-properties">
|
|
74
|
+
<dt>payload.raw <span class="property-type">number</span></dt>
|
|
75
|
+
<dd>12-bit two's-complement conversion code, −2048…2047.</dd>
|
|
76
|
+
<dt>payload.voltage <span class="property-type">number</span></dt>
|
|
77
|
+
<dd>Voltage AIN0 − AIN1 in volts (<code>raw × full-scale / 2048</code>).</dd>
|
|
78
|
+
</dl>
|
|
79
|
+
|
|
80
|
+
<h3>Configuration</h3>
|
|
81
|
+
<p>Set the I²C bus number and the address selected by the ADDR strap (<code>0x48</code>–<code>0x4B</code>), the PGA gain (full-scale range, ±6.144 V to ±0.256 V) and the data rate (128–3300 SPS). Wire AIN1 to GND for a single-ended measurement.</p>
|
|
82
|
+
</script>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { ADS1014Full } = require('periph/src/chips/adc_dac/ads1014');
|
|
6
|
+
|
|
7
|
+
function ADS1014Node(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const address = parseInt(config.address, 16) || ADS1014Full.I2C_ADDRESS;
|
|
13
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), address);
|
|
14
|
+
node.driver = new ADS1014Full(connection);
|
|
15
|
+
node.connection = connection;
|
|
16
|
+
node.ready = (async () => {
|
|
17
|
+
await node.driver.setGain(parseInt(config.gain, 10));
|
|
18
|
+
await node.driver.setDataRate(parseInt(config.dataRate, 10));
|
|
19
|
+
})();
|
|
20
|
+
node.ready.catch((e) => node.error('ADS1014 init failed: ' + e.message));
|
|
21
|
+
} catch (e) {
|
|
22
|
+
node.error('ADS1014 init failed: ' + e.message);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
node.on('input', async function(msg, send, done) {
|
|
26
|
+
if (!node.driver) { done(); return; }
|
|
27
|
+
try {
|
|
28
|
+
await node.ready;
|
|
29
|
+
const raw = await node.driver.readRaw();
|
|
30
|
+
msg.payload = { raw, voltage: raw * node.driver.lsb() };
|
|
31
|
+
send(msg);
|
|
32
|
+
done();
|
|
33
|
+
} catch (e) {
|
|
34
|
+
done(e);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
node.on('close', async function(removed, done) {
|
|
39
|
+
try {
|
|
40
|
+
if (node.connection) await node.connection.close();
|
|
41
|
+
} catch (e) {
|
|
42
|
+
// bus may already be gone; nothing more to do on close
|
|
43
|
+
} finally {
|
|
44
|
+
done();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
RED.nodes.registerType('periph-ads1014', ADS1014Node);
|
|
49
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-ads1113', {
|
|
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
|
+
dataRate: { value: '4' }
|
|
10
|
+
},
|
|
11
|
+
inputs: 1,
|
|
12
|
+
outputs: 1,
|
|
13
|
+
icon: 'font-awesome/fa-microchip',
|
|
14
|
+
label: function() { return this.name || 'ADS1113'; },
|
|
15
|
+
paletteLabel: 'ADS1113'
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script type="text/html" data-template-name="periph-ads1113">
|
|
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="ADS1113">
|
|
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"> 48–4B (ADDR strap), default 48
|
|
31
|
+
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-input-dataRate"><i class="fa fa-clock-o"></i> Data rate</label>
|
|
34
|
+
<select id="node-input-dataRate" style="width:140px">
|
|
35
|
+
<option value="0">8 SPS</option>
|
|
36
|
+
<option value="1">16 SPS</option>
|
|
37
|
+
<option value="2">32 SPS</option>
|
|
38
|
+
<option value="3">64 SPS</option>
|
|
39
|
+
<option value="4">128 SPS</option>
|
|
40
|
+
<option value="5">250 SPS</option>
|
|
41
|
+
<option value="6">475 SPS</option>
|
|
42
|
+
<option value="7">860 SPS</option>
|
|
43
|
+
</select>
|
|
44
|
+
</div>
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<script type="text/html" data-help-name="periph-ads1113">
|
|
48
|
+
<p>Reads the ADS1113 16-bit ΔΣ ADC (one differential input (AIN0 − AIN1), fixed ±2.048 V) over I²C. Default address is <code>0x48</code>; <code>0x48</code>–<code>0x4B</code> are valid depending on the ADDR strap.</p>
|
|
49
|
+
|
|
50
|
+
<h3>Inputs</h3>
|
|
51
|
+
<dl class="message-properties">
|
|
52
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
53
|
+
<dd>Any incoming message triggers a single-shot conversion.</dd>
|
|
54
|
+
</dl>
|
|
55
|
+
|
|
56
|
+
<h3>Outputs</h3>
|
|
57
|
+
<dl class="message-properties">
|
|
58
|
+
<dt>payload.raw <span class="property-type">number</span></dt>
|
|
59
|
+
<dd>Signed 16-bit conversion code.</dd>
|
|
60
|
+
<dt>payload.voltage <span class="property-type">number</span></dt>
|
|
61
|
+
<dd>Input voltage in volts (raw × LSB of the configured range).</dd>
|
|
62
|
+
</dl>
|
|
63
|
+
|
|
64
|
+
<h3>Configuration</h3>
|
|
65
|
+
<p>I²C bus and address, data rate.</p>
|
|
66
|
+
</script>
|
|
@@ -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"> (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"> 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"> (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"> 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>
|