node-red-contrib-periph-motor 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
@@ -14,7 +14,9 @@ npm install node-red-contrib-periph-motor
14
14
 
15
15
  ## Nodes
16
16
 
17
- > **Coming soon.** Nodes will be added as chips in this category are implemented.
17
+ | Node | Kind | Description |
18
+ |------|------|-------------|
19
+ | `periph-drv8830` | input | Drives a brushed DC motor through a DRV8830 low-voltage H-bridge over I²C, and reports its fault status. The chip regulates the commanded voltage across the motor, so speed stays constant as the supply sags. |
18
20
 
19
21
  ## Links
20
22
 
@@ -0,0 +1,114 @@
1
+ [
2
+ {
3
+ "id": "tab-drv8830-demo",
4
+ "type": "tab",
5
+ "label": "DRV8830 Motor Ramp Demo",
6
+ "disabled": false,
7
+ "info": "A battery-powered motor controller. An Inject node ticks once per second into a Function node that ramps msg.payload.voltage from 0 to 3.0 V in 0.5 V steps, holds 3.0 V for 5 s, then reverses to -3.0 V — the DRV8830 regulates that average voltage across the motor, so speed stays constant while the battery sags. A second, independent Inject node polls every 2 s (any message) so the periph-drv8830 node emits its fault status; a Function node checks msg.payload.fault and, if set, sends {stop: true} followed by {clear_fault: true} back into the driver to recover, while a Debug node shows every status reading."
8
+ },
9
+ {
10
+ "id": "inj-ramp",
11
+ "type": "inject",
12
+ "name": "Ramp tick (1 s)",
13
+ "topic": "",
14
+ "payload": "",
15
+ "payloadType": "date",
16
+ "repeat": "1",
17
+ "crontab": "",
18
+ "once": true,
19
+ "onceDelay": 0.5,
20
+ "z": "tab-drv8830-demo",
21
+ "x": 140,
22
+ "y": 100,
23
+ "wires": [
24
+ [
25
+ "fn-ramp"
26
+ ]
27
+ ]
28
+ },
29
+ {
30
+ "id": "fn-ramp",
31
+ "type": "function",
32
+ "name": "ramp voltage",
33
+ "func": "// 0 -> 3.0 V in 0.5 V steps (1 s each), hold 5 s, then reverse at -3.0 V.\nconst seq = [0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, -3.0];\nlet i = context.get('step') || 0;\nif (i >= seq.length) return null;\ncontext.set('step', i + 1);\nmsg.payload = { voltage: seq[i] };\nreturn msg;",
34
+ "outputs": 1,
35
+ "noerr": 0,
36
+ "z": "tab-drv8830-demo",
37
+ "x": 330,
38
+ "y": 100,
39
+ "wires": [
40
+ [
41
+ "drv8830-node"
42
+ ]
43
+ ]
44
+ },
45
+ {
46
+ "id": "inj-poll",
47
+ "type": "inject",
48
+ "name": "Poll faults (2 s)",
49
+ "topic": "",
50
+ "payload": "",
51
+ "payloadType": "date",
52
+ "repeat": "2",
53
+ "crontab": "",
54
+ "once": false,
55
+ "onceDelay": 0.1,
56
+ "z": "tab-drv8830-demo",
57
+ "x": 150,
58
+ "y": 180,
59
+ "wires": [
60
+ [
61
+ "drv8830-node"
62
+ ]
63
+ ]
64
+ },
65
+ {
66
+ "id": "drv8830-node",
67
+ "type": "periph-drv8830",
68
+ "name": "DRV8830",
69
+ "bus": "1",
70
+ "address": "0x60",
71
+ "z": "tab-drv8830-demo",
72
+ "x": 540,
73
+ "y": 140,
74
+ "wires": [
75
+ [
76
+ "fn-guard"
77
+ ]
78
+ ]
79
+ },
80
+ {
81
+ "id": "fn-guard",
82
+ "type": "function",
83
+ "name": "stop + clear on fault",
84
+ "func": "// Recover from a fault: stop the motor first, then clear the latched fault.\nif (msg.payload && msg.payload.fault) {\n const names = ['ocp', 'uvlo', 'ots', 'ilimit'].filter((k) => msg.payload[k]);\n node.warn('DRV8830 fault: ' + names.join(', '));\n return [[{ payload: { stop: true } }, { payload: { clear_fault: true } }], msg];\n}\nreturn [null, msg];",
85
+ "outputs": 2,
86
+ "noerr": 0,
87
+ "z": "tab-drv8830-demo",
88
+ "x": 740,
89
+ "y": 140,
90
+ "wires": [
91
+ [
92
+ "drv8830-node"
93
+ ],
94
+ [
95
+ "dbg-status"
96
+ ]
97
+ ]
98
+ },
99
+ {
100
+ "id": "dbg-status",
101
+ "type": "debug",
102
+ "name": "fault status",
103
+ "active": true,
104
+ "tosidebar": true,
105
+ "console": false,
106
+ "tostatus": false,
107
+ "complete": "payload",
108
+ "targetType": "msg",
109
+ "z": "tab-drv8830-demo",
110
+ "x": 950,
111
+ "y": 160,
112
+ "wires": []
113
+ }
114
+ ]
@@ -0,0 +1,72 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-drv8830', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x60', required: true }
9
+ },
10
+ inputs: 1,
11
+ outputs: 1,
12
+ icon: 'font-awesome/fa-cog',
13
+ label: function() { return this.name || 'DRV8830'; },
14
+ paletteLabel: 'DRV8830'
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="periph-drv8830">
19
+ <div class="form-row">
20
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
21
+ <input type="text" id="node-input-name" placeholder="DRV8830">
22
+ </div>
23
+ <div class="form-row">
24
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
25
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-input-address"><i class="fa fa-at"></i> I²C address</label>
29
+ <select id="node-input-address" style="width:120px">
30
+ <option value="0x60">0x60</option>
31
+ <option value="0x61">0x61</option>
32
+ <option value="0x62">0x62</option>
33
+ <option value="0x63">0x63</option>
34
+ <option value="0x64">0x64</option>
35
+ <option value="0x65">0x65</option>
36
+ <option value="0x66">0x66</option>
37
+ <option value="0x67">0x67</option>
38
+ <option value="0x68">0x68</option>
39
+ </select>
40
+ &nbsp;(set by the A0/A1 straps)
41
+ </div>
42
+ </script>
43
+
44
+ <script type="text/html" data-help-name="periph-drv8830">
45
+ <p>Drives a brushed DC motor through a DRV8830 low-voltage H-bridge over I²C, and reports its fault status. The chip regulates the commanded <em>voltage</em> across the motor, so speed stays constant as the supply sags.</p>
46
+
47
+ <h3>Inputs</h3>
48
+ <dl class="message-properties">
49
+ <dt>payload.voltage <span class="property-type">number</span></dt>
50
+ <dd>Signed target voltage in V: positive = forward, negative = reverse, <code>0</code> = coast. Usable range 0.48–5.06 V; smaller magnitudes coast, larger ones are clamped.</dd>
51
+ <dt>payload.brake <span class="property-type">boolean</span></dt>
52
+ <dd><code>true</code> short-brakes the motor.</dd>
53
+ <dt>payload.stop <span class="property-type">boolean</span></dt>
54
+ <dd><code>true</code> puts the bridge in standby (coast).</dd>
55
+ <dt>payload.clear_fault <span class="property-type">boolean</span></dt>
56
+ <dd><code>true</code> clears the fault register, re-enabling a bridge latched off by an overcurrent or current-limit fault.</dd>
57
+ <dt>payload <span class="property-type">any</span></dt>
58
+ <dd>Any other message reads the fault register and emits it (the fault is not cleared).</dd>
59
+ </dl>
60
+
61
+ <h3>Outputs</h3>
62
+ <dl class="message-properties">
63
+ <dt>payload.fault <span class="property-type">boolean</span></dt>
64
+ <dd>Any fault condition exists.</dd>
65
+ <dt>payload.ocp / uvlo / ots / ilimit <span class="property-type">boolean</span></dt>
66
+ <dd>Fault source: overcurrent, undervoltage lockout, overtemperature, extended current limit.</dd>
67
+ </dl>
68
+ <p>Command messages (<code>voltage</code>, <code>brake</code>, <code>stop</code>, <code>clear_fault</code>) produce no output.</p>
69
+
70
+ <h3>Configuration</h3>
71
+ <p>Set the Linux I²C bus number and pick the device address (0x60–0x68) matching the board's A0/A1 strapping — it is fixed in hardware and cannot be probed. The motor is put in coast when the node is closed.</p>
72
+ </script>
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { DRV8830Full } = require('periph/src/chips/motor/drv8830');
6
+
7
+ function DRV8830Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+
11
+ try {
12
+ const address = parseInt(config.address, 16) || DRV8830Full.I2C_ADDRESS;
13
+ const connection = new I2CConnection(parseInt(config.bus, 10), address);
14
+ node.driver = new DRV8830Full(connection);
15
+ node.connection = connection;
16
+ node.driver.init().catch((e) => node.error('DRV8830 init failed: ' + e.message));
17
+ } catch (e) {
18
+ node.error('DRV8830 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') {
26
+ if (p.clear_fault === true) { await node.driver.clearFault(); done(); return; }
27
+ if (p.brake === true) { await node.driver.brake(); done(); return; }
28
+ if (p.stop === true) { await node.driver.stop(); done(); return; }
29
+ if (typeof p.voltage === 'number') { await node.driver.drive(p.voltage); done(); return; }
30
+ }
31
+ msg.payload = await node.driver.readFault();
32
+ send(msg);
33
+ done();
34
+ } catch (e) {
35
+ done(e);
36
+ }
37
+ });
38
+
39
+ node.on('close', async function(removed, done) {
40
+ try {
41
+ if (node.driver) await node.driver.stop();
42
+ if (node.connection) await node.connection.close();
43
+ } catch (e) {
44
+ // bus may already be gone; nothing more to do on close
45
+ } finally {
46
+ done();
47
+ }
48
+ });
49
+ }
50
+ RED.nodes.registerType('periph-drv8830', DRV8830Node);
51
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-motor",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Node-RED nodes for motor driver chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -11,7 +11,9 @@
11
11
  "peripheral"
12
12
  ],
13
13
  "node-red": {
14
- "nodes": {}
14
+ "nodes": {
15
+ "drv8830": "nodes/drv8830/drv8830.js"
16
+ }
15
17
  },
16
18
  "dependencies": {
17
19
  "periph": "*"
package/examples/.gitkeep DELETED
File without changes
package/nodes/.gitkeep DELETED
File without changes