node-red-contrib-periph-adc-dac 1.0.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/examples/mcp4725/demo.json +124 -0
- package/index.js +11 -0
- package/nodes/.gitkeep +0 -0
- package/nodes/mcp4725/mcp4725.html +77 -0
- package/nodes/mcp4725/mcp4725.js +50 -0
- package/package.json +22 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-mcp4725-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "MCP4725 DAC Demo",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Sends a sequence of five evenly spaced fraction values (0.0, 0.25, 0.5, 0.75, 1.0) to the MCP4725 at 1-second intervals, demonstrating the DAC stepping through five output levels. Each value is printed to the debug panel as both the fraction and the approximate voltage assuming 3.3 V supply."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-mcp4725",
|
|
11
|
+
"type": "mcp4725-device",
|
|
12
|
+
"name": "MCP4725",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "60"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "inj-0",
|
|
18
|
+
"type": "inject",
|
|
19
|
+
"name": "0.0",
|
|
20
|
+
"topic": "",
|
|
21
|
+
"payload": "0.0",
|
|
22
|
+
"payloadType": "num",
|
|
23
|
+
"repeat": "",
|
|
24
|
+
"crontab": "",
|
|
25
|
+
"once": false,
|
|
26
|
+
"onceDelay": 0.1,
|
|
27
|
+
"z": "tab-mcp4725-demo",
|
|
28
|
+
"x": 120,
|
|
29
|
+
"y": 100,
|
|
30
|
+
"wires": [["mcp4725"]]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "inj-1",
|
|
34
|
+
"type": "inject",
|
|
35
|
+
"name": "0.25",
|
|
36
|
+
"topic": "",
|
|
37
|
+
"payload": "0.25",
|
|
38
|
+
"payloadType": "num",
|
|
39
|
+
"repeat": "",
|
|
40
|
+
"crontab": "",
|
|
41
|
+
"once": false,
|
|
42
|
+
"onceDelay": 0.1,
|
|
43
|
+
"z": "tab-mcp4725-demo",
|
|
44
|
+
"x": 120,
|
|
45
|
+
"y": 180,
|
|
46
|
+
"wires": [["mcp4725"]]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"id": "inj-2",
|
|
50
|
+
"type": "inject",
|
|
51
|
+
"name": "0.5",
|
|
52
|
+
"topic": "",
|
|
53
|
+
"payload": "0.5",
|
|
54
|
+
"payloadType": "num",
|
|
55
|
+
"repeat": "",
|
|
56
|
+
"crontab": "",
|
|
57
|
+
"once": false,
|
|
58
|
+
"onceDelay": 0.1,
|
|
59
|
+
"z": "tab-mcp4725-demo",
|
|
60
|
+
"x": 120,
|
|
61
|
+
"y": 260,
|
|
62
|
+
"wires": [["mcp4725"]]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "inj-3",
|
|
66
|
+
"type": "inject",
|
|
67
|
+
"name": "0.75",
|
|
68
|
+
"topic": "",
|
|
69
|
+
"payload": "0.75",
|
|
70
|
+
"payloadType": "num",
|
|
71
|
+
"repeat": "",
|
|
72
|
+
"crontab": "",
|
|
73
|
+
"once": false,
|
|
74
|
+
"onceDelay": 0.1,
|
|
75
|
+
"z": "tab-mcp4725-demo",
|
|
76
|
+
"x": 120,
|
|
77
|
+
"y": 340,
|
|
78
|
+
"wires": [["mcp4725"]]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"id": "inj-4",
|
|
82
|
+
"type": "inject",
|
|
83
|
+
"name": "1.0",
|
|
84
|
+
"topic": "",
|
|
85
|
+
"payload": "1.0",
|
|
86
|
+
"payloadType": "num",
|
|
87
|
+
"repeat": "",
|
|
88
|
+
"crontab": "",
|
|
89
|
+
"once": false,
|
|
90
|
+
"onceDelay": 0.1,
|
|
91
|
+
"z": "tab-mcp4725-demo",
|
|
92
|
+
"x": 120,
|
|
93
|
+
"y": 420,
|
|
94
|
+
"wires": [["mcp4725"]]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"id": "mcp4725",
|
|
98
|
+
"type": "periph-mcp4725",
|
|
99
|
+
"name": "MCP4725",
|
|
100
|
+
"device": "cfg-mcp4725",
|
|
101
|
+
"inputMode": "fraction",
|
|
102
|
+
"z": "tab-mcp4725-demo",
|
|
103
|
+
"x": 340,
|
|
104
|
+
"y": 260,
|
|
105
|
+
"wires": []
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"id": "dbg-output",
|
|
109
|
+
"type": "debug",
|
|
110
|
+
"name": "",
|
|
111
|
+
"active": true,
|
|
112
|
+
"tosidebar": true,
|
|
113
|
+
"console": false,
|
|
114
|
+
"tostatus": false,
|
|
115
|
+
"complete": "false",
|
|
116
|
+
"targetType": "msg",
|
|
117
|
+
"statusVal": "",
|
|
118
|
+
"statusType": "auto",
|
|
119
|
+
"z": "tab-mcp4725-demo",
|
|
120
|
+
"x": 560,
|
|
121
|
+
"y": 260,
|
|
122
|
+
"wires": []
|
|
123
|
+
}
|
|
124
|
+
]
|
package/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
module.exports = function(RED) {
|
|
5
|
+
const nodesDir = path.join(__dirname, 'nodes');
|
|
6
|
+
if (!fs.existsSync(nodesDir)) return;
|
|
7
|
+
fs.readdirSync(nodesDir).forEach(function(chip) {
|
|
8
|
+
const nodeFile = path.join(nodesDir, chip, chip + '.js');
|
|
9
|
+
if (fs.existsSync(nodeFile)) require(nodeFile)(RED);
|
|
10
|
+
});
|
|
11
|
+
};
|
package/nodes/.gitkeep
ADDED
|
File without changes
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('mcp4725-device', {
|
|
3
|
+
category: 'config',
|
|
4
|
+
defaults: {
|
|
5
|
+
name: { value: '' },
|
|
6
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
7
|
+
address: { value: '60', required: true }
|
|
8
|
+
},
|
|
9
|
+
label: function() {
|
|
10
|
+
return this.name || ('MCP4725 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script type="text/html" data-template-name="mcp4725-device">
|
|
16
|
+
<div class="form-row">
|
|
17
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
18
|
+
<input type="text" id="node-config-input-name" placeholder="MCP4725">
|
|
19
|
+
</div>
|
|
20
|
+
<div class="form-row">
|
|
21
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
22
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
23
|
+
</div>
|
|
24
|
+
<div class="form-row">
|
|
25
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
26
|
+
<input type="text" id="node-config-input-address" placeholder="60" style="width:80px"> default: 60 (0x60)
|
|
27
|
+
</div>
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<script type="text/javascript">
|
|
31
|
+
RED.nodes.registerType('periph-mcp4725', {
|
|
32
|
+
category: 'Peripheral',
|
|
33
|
+
color: '#a6bbcf',
|
|
34
|
+
defaults: {
|
|
35
|
+
name: { value: '' },
|
|
36
|
+
device: { value: '', type: 'mcp4725-device', required: true },
|
|
37
|
+
inputMode: { value: 'fraction' }
|
|
38
|
+
},
|
|
39
|
+
inputs: 1,
|
|
40
|
+
outputs: 0,
|
|
41
|
+
icon: 'font-awesome/fa-wave-square',
|
|
42
|
+
label: function() { return this.name || 'MCP4725'; },
|
|
43
|
+
paletteLabel: 'MCP4725'
|
|
44
|
+
});
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<script type="text/html" data-template-name="periph-mcp4725">
|
|
48
|
+
<div class="form-row">
|
|
49
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
50
|
+
<input type="text" id="node-input-device">
|
|
51
|
+
</div>
|
|
52
|
+
<div class="form-row">
|
|
53
|
+
<label for="node-input-inputMode"><i class="fa fa-cog"></i> Input mode</label>
|
|
54
|
+
<select id="node-input-inputMode" style="width:150px">
|
|
55
|
+
<option value="fraction">fraction (0.0–1.0)</option>
|
|
56
|
+
<option value="raw">raw (0–4095)</option>
|
|
57
|
+
</select>
|
|
58
|
+
</div>
|
|
59
|
+
<div class="form-row">
|
|
60
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
61
|
+
<input type="text" id="node-input-name" placeholder="MCP4725">
|
|
62
|
+
</div>
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<script type="text/html" data-help-name="periph-mcp4725">
|
|
66
|
+
<p>Sets the output voltage of an MCP4725 12-bit DAC over I²C.</p>
|
|
67
|
+
<p>Any input message triggers a DAC write. The device is configured via a <b>mcp4725-device</b> config node.</p>
|
|
68
|
+
|
|
69
|
+
<h3>Inputs</h3>
|
|
70
|
+
<dl class="message-properties">
|
|
71
|
+
<dt>payload <span class="property-type">number</span></dt>
|
|
72
|
+
<dd>When input mode is <code>fraction</code>: value between 0.0 and 1.0 representing the output as a fraction of V_DD. When input mode is <code>raw</code>: raw 12-bit DAC code (0–4095).</dd>
|
|
73
|
+
</dl>
|
|
74
|
+
|
|
75
|
+
<h3>Details</h3>
|
|
76
|
+
<p>Configure bus number and I²C address (default <code>0x60</code>) in the device config node. The input mode determines whether incoming values are interpreted as normalized fractions or raw 12-bit codes.</p>
|
|
77
|
+
</script>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CTransport } = require('periph/src/transport/i2c');
|
|
5
|
+
const { MCP4725Full } = require('periph/src/chips/adc_dac/mcp4725');
|
|
6
|
+
|
|
7
|
+
function MCP4725DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const transport = new I2CTransport(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new MCP4725Full(transport);
|
|
13
|
+
node.transport = transport;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
node.error('MCP4725 init failed: ' + e.message);
|
|
16
|
+
}
|
|
17
|
+
node.on('close', function() {
|
|
18
|
+
if (node.transport) node.transport.close();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
RED.nodes.registerType('mcp4725-device', MCP4725DeviceNode);
|
|
22
|
+
|
|
23
|
+
function MCP4725WriteNode(config) {
|
|
24
|
+
RED.nodes.createNode(this, config);
|
|
25
|
+
const node = this;
|
|
26
|
+
node.device = RED.nodes.getNode(config.device);
|
|
27
|
+
node.inputMode = config.inputMode || 'fraction';
|
|
28
|
+
|
|
29
|
+
node.on('input', function(msg, send, done) {
|
|
30
|
+
if (!node.device || !node.device.driver) {
|
|
31
|
+
node.error('No MCP4725 device configured', msg);
|
|
32
|
+
done();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const dac = node.device.driver;
|
|
37
|
+
const raw = parseFloat(msg.payload);
|
|
38
|
+
if (node.inputMode === 'raw') {
|
|
39
|
+
dac.set_raw(raw);
|
|
40
|
+
} else {
|
|
41
|
+
dac.set_voltage(raw);
|
|
42
|
+
}
|
|
43
|
+
done();
|
|
44
|
+
} catch (e) {
|
|
45
|
+
done(e);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
RED.nodes.registerType('periph-mcp4725', MCP4725WriteNode);
|
|
50
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-red-contrib-periph-adc-dac",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Node-RED nodes for ADC and DAC chips",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"node-red",
|
|
7
|
+
"adc-dac",
|
|
8
|
+
"i2c",
|
|
9
|
+
"spi",
|
|
10
|
+
"sensor",
|
|
11
|
+
"peripheral"
|
|
12
|
+
],
|
|
13
|
+
"node-red": {
|
|
14
|
+
"nodes": {
|
|
15
|
+
"mcp4725": "nodes/mcp4725/mcp4725.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"periph": "*"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT"
|
|
22
|
+
}
|