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.
- package/README.md +8 -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/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/package.json +12 -5
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-ad5243', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
rab: { value: '10000', required: true },
|
|
9
|
+
rwiper: { value: '160', required: true, validate: RED.validators.number() }
|
|
10
|
+
},
|
|
11
|
+
inputs: 1,
|
|
12
|
+
outputs: 1,
|
|
13
|
+
icon: 'font-awesome/fa-sliders',
|
|
14
|
+
label: function() { return this.name || 'AD5243'; },
|
|
15
|
+
paletteLabel: 'AD5243'
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script type="text/html" data-template-name="periph-ad5243">
|
|
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="AD5243">
|
|
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><i class="fa fa-at"></i> I²C address</label>
|
|
30
|
+
<span>0x2F (fixed, no address pins)</span>
|
|
31
|
+
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-input-rab"><i class="fa fa-sliders"></i> RAB</label>
|
|
34
|
+
<select id="node-input-rab" style="width:120px">
|
|
35
|
+
<option value="2500">2.5 kΩ</option>
|
|
36
|
+
<option value="10000">10 kΩ</option>
|
|
37
|
+
<option value="50000">50 kΩ</option>
|
|
38
|
+
<option value="100000">100 kΩ</option>
|
|
39
|
+
</select>
|
|
40
|
+
</div>
|
|
41
|
+
<div class="form-row">
|
|
42
|
+
<label for="node-input-rwiper"><i class="fa fa-sliders"></i> Wiper RW</label>
|
|
43
|
+
<input type="number" id="node-input-rwiper" min="0" style="width:80px"> Ω (typ. 160 Ω)
|
|
44
|
+
</div>
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<script type="text/html" data-help-name="periph-ad5243">
|
|
48
|
+
<p>Sets and reads the two 256-position wipers of an AD5243 dual I²C digital potentiometer. Wiper values are volatile: both channels power up at midscale (128).</p>
|
|
49
|
+
|
|
50
|
+
<h3>Inputs</h3>
|
|
51
|
+
<dl class="message-properties">
|
|
52
|
+
<dt>payload.channel <span class="property-type">number</span></dt>
|
|
53
|
+
<dd>Channel to act on: <code>0</code> or <code>1</code>.</dd>
|
|
54
|
+
<dt>payload.code <span class="property-type">number</span></dt>
|
|
55
|
+
<dd>With <code>channel</code>: wiper position 0–255 (clamped).</dd>
|
|
56
|
+
<dt>payload.ohms <span class="property-type">number</span></dt>
|
|
57
|
+
<dd>With <code>channel</code> (and no <code>code</code>): target W–B resistance in ohms, set to the nearest code.</dd>
|
|
58
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
59
|
+
<dd>Any other message reads back both channels.</dd>
|
|
60
|
+
</dl>
|
|
61
|
+
|
|
62
|
+
<h3>Outputs</h3>
|
|
63
|
+
<dl class="message-properties">
|
|
64
|
+
<dt>payload.channel, payload.code, payload.resistance <span class="property-type">number</span></dt>
|
|
65
|
+
<dd>After a set: the channel, the wiper code read back, and the resulting W–B resistance in ohms.</dd>
|
|
66
|
+
<dt>payload.wiper <span class="property-type">number[2]</span></dt>
|
|
67
|
+
<dd>After any other message: wiper codes of channels 0 and 1.</dd>
|
|
68
|
+
<dt>payload.resistance <span class="property-type">number[2]</span></dt>
|
|
69
|
+
<dd>After any other message: W–B resistances (Ω) of channels 0 and 1.</dd>
|
|
70
|
+
</dl>
|
|
71
|
+
|
|
72
|
+
<h3>Configuration</h3>
|
|
73
|
+
<p>Set the Linux I²C bus number, the part's end-to-end resistance RAB (2.5, 10, 50 or 100 kΩ, as ordered) and the wiper resistance RW. The address is fixed at 0x2F. Absolute resistance is only accurate to the part's tolerance (±20 %); ratios are exact.</p>
|
|
74
|
+
</script>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { AD5243Full } = require('periph/src/chips/adc_dac/ad5243');
|
|
6
|
+
|
|
7
|
+
function AD5243Node(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const rAb = parseFloat(config.rab) || 10000.0;
|
|
13
|
+
const rWiper = config.rwiper === '' || config.rwiper === undefined ? 160.0 : parseFloat(config.rwiper);
|
|
14
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), AD5243Full.I2C_ADDRESS);
|
|
15
|
+
node.driver = new AD5243Full(connection, rAb, rWiper);
|
|
16
|
+
node.connection = connection;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
node.error('AD5243 init failed: ' + e.message);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
node.on('input', async function(msg, send, done) {
|
|
22
|
+
if (!node.driver) { done(); return; }
|
|
23
|
+
try {
|
|
24
|
+
const p = msg.payload;
|
|
25
|
+
if (p && typeof p === 'object' && (p.channel === 0 || p.channel === 1)) {
|
|
26
|
+
if (typeof p.code === 'number') {
|
|
27
|
+
await node.driver.setWiper(p.channel, p.code);
|
|
28
|
+
} else if (typeof p.ohms === 'number') {
|
|
29
|
+
await node.driver.setResistance(p.channel, p.ohms);
|
|
30
|
+
} else {
|
|
31
|
+
done(new Error('payload needs code or ohms'));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const code = await node.driver.getWiper(p.channel);
|
|
35
|
+
const resistance = await node.driver.getResistance(p.channel);
|
|
36
|
+
msg.payload = { channel: p.channel, code, resistance };
|
|
37
|
+
} else {
|
|
38
|
+
const c1 = await node.driver.getWiper(0);
|
|
39
|
+
const c2 = await node.driver.getWiper(1);
|
|
40
|
+
const r1 = await node.driver.getResistance(0);
|
|
41
|
+
const r2 = await node.driver.getResistance(1);
|
|
42
|
+
msg.payload = { wiper: [c1, c2], resistance: [r1, r2] };
|
|
43
|
+
}
|
|
44
|
+
send(msg);
|
|
45
|
+
done();
|
|
46
|
+
} catch (e) {
|
|
47
|
+
done(e);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
node.on('close', async function(removed, done) {
|
|
52
|
+
try {
|
|
53
|
+
if (node.connection) await node.connection.close();
|
|
54
|
+
} catch (e) {
|
|
55
|
+
// bus may already be gone; nothing more to do on close
|
|
56
|
+
} finally {
|
|
57
|
+
done();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
RED.nodes.registerType('periph-ad5243', AD5243Node);
|
|
62
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('ad5248-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '2C', required: true },
|
|
9
|
+
rab: { value: '10000', required: true, validate: RED.validators.number() },
|
|
10
|
+
rwiper: { value: '160', required: true, validate: RED.validators.number() }
|
|
11
|
+
},
|
|
12
|
+
label: function() {
|
|
13
|
+
return this.name || ('AD5248 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script type="text/html" data-template-name="ad5248-device">
|
|
19
|
+
<div class="form-row">
|
|
20
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
21
|
+
<input type="text" id="node-config-input-name" placeholder="AD5248">
|
|
22
|
+
</div>
|
|
23
|
+
<div class="form-row">
|
|
24
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
25
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
26
|
+
</div>
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
29
|
+
<select id="node-config-input-address" style="width:100px">
|
|
30
|
+
<option value="2C">0x2C (AD1=0, AD0=0)</option>
|
|
31
|
+
<option value="2D">0x2D (AD1=0, AD0=1)</option>
|
|
32
|
+
<option value="2E">0x2E (AD1=1, AD0=0)</option>
|
|
33
|
+
<option value="2F">0x2F (AD1=1, AD0=1)</option>
|
|
34
|
+
</select>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="form-row">
|
|
37
|
+
<label for="node-config-input-rab">RAB (Ω)</label>
|
|
38
|
+
<select id="node-config-input-rab" style="width:100px">
|
|
39
|
+
<option value="2500">2.5 kΩ</option>
|
|
40
|
+
<option value="10000">10 kΩ</option>
|
|
41
|
+
<option value="50000">50 kΩ</option>
|
|
42
|
+
<option value="100000">100 kΩ</option>
|
|
43
|
+
</select>
|
|
44
|
+
</div>
|
|
45
|
+
<div class="form-row">
|
|
46
|
+
<label for="node-config-input-rwiper">Wiper R (Ω)</label>
|
|
47
|
+
<input type="number" id="node-config-input-rwiper" min="0" style="width:100px"> typical 160 Ω at 5 V
|
|
48
|
+
</div>
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<!-- Node: set or read the wiper -->
|
|
52
|
+
<script type="text/javascript">
|
|
53
|
+
RED.nodes.registerType('periph-ad5248', {
|
|
54
|
+
category: 'Peripheral',
|
|
55
|
+
color: '#C084FC',
|
|
56
|
+
defaults: {
|
|
57
|
+
name: { value: '' },
|
|
58
|
+
device: { value: '', type: 'ad5248-device', required: true }
|
|
59
|
+
},
|
|
60
|
+
inputs: 1,
|
|
61
|
+
outputs: 1,
|
|
62
|
+
icon: 'font-awesome/fa-sliders',
|
|
63
|
+
label: function() { return this.name || 'AD5248'; },
|
|
64
|
+
paletteLabel: 'AD5248'
|
|
65
|
+
});
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<script type="text/html" data-template-name="periph-ad5248">
|
|
69
|
+
<div class="form-row">
|
|
70
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
71
|
+
<input type="text" id="node-input-device">
|
|
72
|
+
</div>
|
|
73
|
+
<div class="form-row">
|
|
74
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
75
|
+
<input type="text" id="node-input-name" placeholder="AD5248">
|
|
76
|
+
</div>
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<script type="text/html" data-help-name="periph-ad5248">
|
|
80
|
+
<p>Sets or reads the two 256-position wipers of an AD5248 dual digital rheostat over I²C.
|
|
81
|
+
The device is configured via an <b>ad5248-device</b> config node.</p>
|
|
82
|
+
|
|
83
|
+
<h3>Inputs</h3>
|
|
84
|
+
<dl class="message-properties">
|
|
85
|
+
<dt>payload.channel <span class="property-type">number</span></dt>
|
|
86
|
+
<dd>Channel 0 or 1.</dd>
|
|
87
|
+
<dt>payload.code <span class="property-type">number</span></dt>
|
|
88
|
+
<dd>Wiper position 0–255. Takes precedence over <code>ohms</code>.</dd>
|
|
89
|
+
<dt>payload.ohms <span class="property-type">number</span></dt>
|
|
90
|
+
<dd>Target wiper-to-B resistance in ohms; the nearest reachable code is used.</dd>
|
|
91
|
+
</dl>
|
|
92
|
+
<p>Any other message reads both channels back.</p>
|
|
93
|
+
|
|
94
|
+
<h3>Outputs</h3>
|
|
95
|
+
<dl class="message-properties">
|
|
96
|
+
<dt>payload.channel, payload.code, payload.resistance</dt>
|
|
97
|
+
<dd>After a write: the channel, the resulting wiper code and its W–B resistance (Ω).</dd>
|
|
98
|
+
<dt>payload.wiper <span class="property-type">array</span></dt>
|
|
99
|
+
<dd>After a read: <code>[code1, code2]</code>.</dd>
|
|
100
|
+
<dt>payload.resistance <span class="property-type">array</span></dt>
|
|
101
|
+
<dd>After a read: <code>[R1, R2]</code> in ohms.</dd>
|
|
102
|
+
</dl>
|
|
103
|
+
|
|
104
|
+
<h3>Configuration</h3>
|
|
105
|
+
<p>Set the I²C bus number and address (<code>0x2C</code>–<code>0x2F</code>, selected by the AD0/AD1 pins),
|
|
106
|
+
the end-to-end resistance RAB (2.5 / 10 / 50 / 100 kΩ) and the wiper resistance RW. The wiper
|
|
107
|
+
values are volatile and return to midscale (128) at every power-up.</p>
|
|
108
|
+
</script>
|
|
@@ -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>
|