node-red-contrib-periph-imu 1.1.0 → 1.2.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 -3
- package/examples/mpu9250/demo.json +71 -0
- package/examples/mpu9255/demo.json +122 -0
- package/nodes/mpu6050/mpu6050.html +1 -1
- package/nodes/mpu6050/mpu6050.js +8 -8
- package/nodes/mpu9250/mpu9250.html +63 -0
- package/nodes/mpu9250/mpu9250.js +30 -0
- package/nodes/mpu9255/mpu9255.html +74 -0
- package/nodes/mpu9255/mpu9255.js +58 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,15 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
Node-RED nodes for IMU chips — part of the [Periph](https://github.com/tuhde/Periph) library.
|
|
4
4
|
|
|
5
|
-
> **Coming soon.** Nodes will be added as chips in this category are implemented.
|
|
6
|
-
|
|
7
5
|
## Install
|
|
8
6
|
|
|
7
|
+
Open Node-RED, go to **Manage Palette → Install** and search for `node-red-contrib-periph-imu`.
|
|
8
|
+
|
|
9
|
+
Or from the command line in your Node-RED user directory:
|
|
10
|
+
|
|
9
11
|
```sh
|
|
10
12
|
npm install node-red-contrib-periph-imu
|
|
11
13
|
```
|
|
12
14
|
|
|
15
|
+
## Nodes
|
|
16
|
+
|
|
17
|
+
| Node | Kind | Description |
|
|
18
|
+
|------|------|-------------|
|
|
19
|
+
| `mpu6050-device` | config | I²C bus and address for a MPU6050 |
|
|
20
|
+
| `mpu6050` | input | Reads 3-axis acceleration and 3-axis angular rate from an MPU6050 IMU over I²C. |
|
|
21
|
+
|
|
13
22
|
## Links
|
|
14
23
|
|
|
15
24
|
- [GitHub](https://github.com/tuhde/Periph)
|
|
16
|
-
- [
|
|
25
|
+
- [periph JS driver](https://www.npmjs.com/package/periph)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "inject-100ms",
|
|
4
|
+
"type": "inject",
|
|
5
|
+
"z": "mpu9250-demo",
|
|
6
|
+
"name": "100ms timer",
|
|
7
|
+
"props": [{"p": "payload"}],
|
|
8
|
+
"repeat": "100",
|
|
9
|
+
"crontab": "",
|
|
10
|
+
"once": false,
|
|
11
|
+
"onceDelay": 0.1,
|
|
12
|
+
"topic": "",
|
|
13
|
+
"payloadType": "date",
|
|
14
|
+
"x": 180,
|
|
15
|
+
"y": 160,
|
|
16
|
+
"wires": [["mpu9250-node"]]
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "mpu9250-node",
|
|
20
|
+
"type": "periph-mpu9250",
|
|
21
|
+
"z": "mpu9250-demo",
|
|
22
|
+
"name": "MPU9250",
|
|
23
|
+
"connection": "i2c-conn-1",
|
|
24
|
+
"addr": "0x68",
|
|
25
|
+
"gyroFs": "1",
|
|
26
|
+
"accelFs": "1",
|
|
27
|
+
"enableMag": true,
|
|
28
|
+
"x": 400,
|
|
29
|
+
"y": 160,
|
|
30
|
+
"wires": [["function-tilt"]]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "function-tilt",
|
|
34
|
+
"type": "function",
|
|
35
|
+
"z": "mpu9250-demo",
|
|
36
|
+
"name": "Compute tilt & heading",
|
|
37
|
+
"func": "const { ax, ay, az, gx, gy, gz, mx, my, mz } = msg.payload;\nconst roll = Math.atan2(ay, az) * 180 / Math.PI;\nconst pitch = Math.atan2(-ax, Math.sqrt(ay*ay + az*az)) * 180 / Math.PI;\nconst heading = Math.atan2(my, mx) * 180 / Math.PI;\nmsg.payload = { roll, pitch, heading, gyroMag: Math.sqrt(gx*gx + gy*gy + gz*gz) };\nreturn msg;",
|
|
38
|
+
"outputs": 1,
|
|
39
|
+
"noerr": 0,
|
|
40
|
+
"initialize": "",
|
|
41
|
+
"finalize": "",
|
|
42
|
+
"libs": [],
|
|
43
|
+
"x": 650,
|
|
44
|
+
"y": 160,
|
|
45
|
+
"wires": [["debug-out"]]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"id": "debug-out",
|
|
49
|
+
"type": "debug",
|
|
50
|
+
"z": "mpu9250-demo",
|
|
51
|
+
"name": "Tilt & heading",
|
|
52
|
+
"active": true,
|
|
53
|
+
"tosidebar": true,
|
|
54
|
+
"console": false,
|
|
55
|
+
"tostatus": false,
|
|
56
|
+
"complete": "payload",
|
|
57
|
+
"targetType": "msg",
|
|
58
|
+
"statusVal": "",
|
|
59
|
+
"statusType": "auto",
|
|
60
|
+
"x": 900,
|
|
61
|
+
"y": 160,
|
|
62
|
+
"wires": []
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "i2c-conn-1",
|
|
66
|
+
"type": "periph-i2c-connection",
|
|
67
|
+
"z": "",
|
|
68
|
+
"name": "I2C bus 1",
|
|
69
|
+
"bus": "1"
|
|
70
|
+
}
|
|
71
|
+
]
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "inject-100ms",
|
|
4
|
+
"type": "inject",
|
|
5
|
+
"z": "mpu9255-demo",
|
|
6
|
+
"name": "100ms timer",
|
|
7
|
+
"props": [{"p": "payload"}],
|
|
8
|
+
"repeat": "100",
|
|
9
|
+
"crontab": "",
|
|
10
|
+
"once": false,
|
|
11
|
+
"onceDelay": 0.1,
|
|
12
|
+
"topic": "",
|
|
13
|
+
"payloadType": "date",
|
|
14
|
+
"x": 180,
|
|
15
|
+
"y": 160,
|
|
16
|
+
"wires": [["mpu9255-node"]]
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "mpu9255-node",
|
|
20
|
+
"type": "periph-mpu9255",
|
|
21
|
+
"z": "mpu9255-demo",
|
|
22
|
+
"name": "MPU9255",
|
|
23
|
+
"connection": "i2c-conn-1",
|
|
24
|
+
"addr": "0x68",
|
|
25
|
+
"gyroFs": "1",
|
|
26
|
+
"accelFs": "1",
|
|
27
|
+
"enableMag": true,
|
|
28
|
+
"enableWom": false,
|
|
29
|
+
"womThreshold": "64",
|
|
30
|
+
"x": 400,
|
|
31
|
+
"y": 160,
|
|
32
|
+
"wires": [["function-tilt"]]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "inject-1s",
|
|
36
|
+
"type": "inject",
|
|
37
|
+
"z": "mpu9255-demo",
|
|
38
|
+
"name": "1s timer (WoM)",
|
|
39
|
+
"props": [{"p": "payload"}],
|
|
40
|
+
"repeat": "1",
|
|
41
|
+
"crontab": "",
|
|
42
|
+
"once": false,
|
|
43
|
+
"onceDelay": 0.1,
|
|
44
|
+
"topic": "",
|
|
45
|
+
"payloadType": "date",
|
|
46
|
+
"x": 180,
|
|
47
|
+
"y": 240,
|
|
48
|
+
"wires": [["mpu9255-node-wom"]]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "mpu9255-node-wom",
|
|
52
|
+
"type": "periph-mpu9255",
|
|
53
|
+
"z": "mpu9255-demo",
|
|
54
|
+
"name": "MPU9255 (WoM)",
|
|
55
|
+
"connection": "i2c-conn-1",
|
|
56
|
+
"addr": "0x68",
|
|
57
|
+
"gyroFs": "0",
|
|
58
|
+
"accelFs": "0",
|
|
59
|
+
"enableMag": false,
|
|
60
|
+
"enableWom": true,
|
|
61
|
+
"womThreshold": "64",
|
|
62
|
+
"x": 400,
|
|
63
|
+
"y": 240,
|
|
64
|
+
"wires": [["debug-wom"]]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "function-tilt",
|
|
68
|
+
"type": "function",
|
|
69
|
+
"z": "mpu9255-demo",
|
|
70
|
+
"name": "Compute tilt & heading",
|
|
71
|
+
"func": "const { ax, ay, az, gx, gy, gz, mx, my, mz } = msg.payload;\nconst roll = Math.atan2(ay, az) * 180 / Math.PI;\nconst pitch = Math.atan2(-ax, Math.sqrt(ay*ay + az*az)) * 180 / Math.PI;\nconst heading = Math.atan2(my, mx) * 180 / Math.PI;\nmsg.payload = { roll, pitch, heading, gyroMag: Math.sqrt(gx*gx + gy*gy + gz*gz) };\nreturn msg;",
|
|
72
|
+
"outputs": 1,
|
|
73
|
+
"noerr": 0,
|
|
74
|
+
"initialize": "",
|
|
75
|
+
"finalize": "",
|
|
76
|
+
"libs": [],
|
|
77
|
+
"x": 650,
|
|
78
|
+
"y": 160,
|
|
79
|
+
"wires": [["debug-out"]]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"id": "debug-out",
|
|
83
|
+
"type": "debug",
|
|
84
|
+
"z": "mpu9255-demo",
|
|
85
|
+
"name": "Tilt & heading",
|
|
86
|
+
"active": true,
|
|
87
|
+
"tosidebar": true,
|
|
88
|
+
"console": false,
|
|
89
|
+
"tostatus": false,
|
|
90
|
+
"complete": "payload",
|
|
91
|
+
"targetType": "msg",
|
|
92
|
+
"statusVal": "",
|
|
93
|
+
"statusType": "auto",
|
|
94
|
+
"x": 900,
|
|
95
|
+
"y": 160,
|
|
96
|
+
"wires": []
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"id": "debug-wom",
|
|
100
|
+
"type": "debug",
|
|
101
|
+
"z": "mpu9255-demo",
|
|
102
|
+
"name": "Motion events",
|
|
103
|
+
"active": true,
|
|
104
|
+
"tosidebar": true,
|
|
105
|
+
"console": false,
|
|
106
|
+
"tostatus": false,
|
|
107
|
+
"complete": "payload",
|
|
108
|
+
"targetType": "msg",
|
|
109
|
+
"statusVal": "",
|
|
110
|
+
"statusType": "auto",
|
|
111
|
+
"x": 650,
|
|
112
|
+
"y": 240,
|
|
113
|
+
"wires": []
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"id": "i2c-conn-1",
|
|
117
|
+
"type": "periph-i2c-connection",
|
|
118
|
+
"z": "",
|
|
119
|
+
"name": "I2C bus 1",
|
|
120
|
+
"bus": "1"
|
|
121
|
+
}
|
|
122
|
+
]
|
package/nodes/mpu6050/mpu6050.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = function(RED) {
|
|
4
|
-
const {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { MPU6050Full } = require('periph/src/chips/imu/mpu6050');
|
|
6
6
|
|
|
7
7
|
function MPU6050DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
11
|
-
const
|
|
12
|
-
node.driver
|
|
13
|
-
node.
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new MPU6050Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
14
|
if (config.gyroFs) node.driver.configureGyro(parseInt(config.gyroFs));
|
|
15
15
|
if (config.accelFs) node.driver.configureAccel(parseInt(config.accelFs));
|
|
16
16
|
} catch (e) {
|
|
17
17
|
node.error('MPU6050 init failed: ' + e.message);
|
|
18
18
|
}
|
|
19
19
|
node.on('close', function() {
|
|
20
|
-
if (node.
|
|
20
|
+
if (node.connection) node.connection.close();
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
RED.nodes.registerType('mpu6050-device', MPU6050DeviceNode);
|
|
@@ -27,7 +27,7 @@ module.exports = function(RED) {
|
|
|
27
27
|
const node = this;
|
|
28
28
|
node.device = RED.nodes.getNode(config.device);
|
|
29
29
|
|
|
30
|
-
node.on('input', function(msg, send, done) {
|
|
30
|
+
node.on('input', async function(msg, send, done) {
|
|
31
31
|
if (!node.device || !node.device.driver) {
|
|
32
32
|
node.error('No MPU6050 device configured', msg);
|
|
33
33
|
done();
|
|
@@ -35,8 +35,8 @@ module.exports = function(RED) {
|
|
|
35
35
|
}
|
|
36
36
|
try {
|
|
37
37
|
const d = node.device.driver;
|
|
38
|
-
const [ax, ay, az] = d.accel();
|
|
39
|
-
const [gx, gy, gz] = d.gyro();
|
|
38
|
+
const [ax, ay, az] = await d.accel();
|
|
39
|
+
const [gx, gy, gz] = await d.gyro();
|
|
40
40
|
msg.payload = { ax, ay, az, gx, gy, gz };
|
|
41
41
|
send(msg);
|
|
42
42
|
done();
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script type="text/html" data-template-name="periph-mpu9250">
|
|
2
|
+
<div class="form-row">
|
|
3
|
+
<label for="node-input-connection"><i class="fa fa-link"></i> I2C Connection</label>
|
|
4
|
+
<input type="text" id="node-input-connection" placeholder="Select I2C connection node">
|
|
5
|
+
</div>
|
|
6
|
+
<div class="form-row">
|
|
7
|
+
<label for="node-input-addr"><i class="fa fa-tag"></i> I2C Address</label>
|
|
8
|
+
<select id="node-input-addr">
|
|
9
|
+
<option value="0x68">0x68 (AD0 = GND)</option>
|
|
10
|
+
<option value="0x69">0x69 (AD0 = VCC)</option>
|
|
11
|
+
</select>
|
|
12
|
+
</div>
|
|
13
|
+
<div class="form-row">
|
|
14
|
+
<label for="node-input-gyroFs"><i class="fa fa-cog"></i> Gyro Full-Scale</label>
|
|
15
|
+
<select id="node-input-gyroFs">
|
|
16
|
+
<option value="0">±250 dps</option>
|
|
17
|
+
<option value="1">±500 dps</option>
|
|
18
|
+
<option value="2">±1000 dps</option>
|
|
19
|
+
<option value="3">±2000 dps</option>
|
|
20
|
+
</select>
|
|
21
|
+
</div>
|
|
22
|
+
<div class="form-row">
|
|
23
|
+
<label for="node-input-accelFs"><i class="fa fa-cog"></i> Accel Full-Scale</label>
|
|
24
|
+
<select id="node-input-accelFs">
|
|
25
|
+
<option value="0">±2 g</option>
|
|
26
|
+
<option value="1">±4 g</option>
|
|
27
|
+
<option value="2">±8 g</option>
|
|
28
|
+
<option value="3">±16 g</option>
|
|
29
|
+
</select>
|
|
30
|
+
</div>
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-input-enableMag"><i class="fa fa-magnet"></i> Enable Magnetometer</label>
|
|
33
|
+
<input type="checkbox" id="node-input-enableMag">
|
|
34
|
+
</div>
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<script type="text/html" data-help-name="periph-mpu9250">
|
|
38
|
+
<p>Reads bus voltage, load current, and power from an MPU-9250 9-axis MotionTracking device.</p>
|
|
39
|
+
<h3>Inputs</h3>
|
|
40
|
+
<dl class="message-properties">
|
|
41
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
42
|
+
<dd>Any incoming message triggers a measurement.</dd>
|
|
43
|
+
</dl>
|
|
44
|
+
<h3>Outputs</h3>
|
|
45
|
+
<dl class="message-properties">
|
|
46
|
+
<dt>payload.ax <span class="property-type">number</span></dt>
|
|
47
|
+
<dd>X acceleration in m/s².</dd>
|
|
48
|
+
<dt>payload.ay <span class="property-type">number</span></dt>
|
|
49
|
+
<dd>Y acceleration in m/s².</dd>
|
|
50
|
+
<dt>payload.az <span class="property-type">number</span></dt>
|
|
51
|
+
<dd>Z acceleration in m/s².</dd>
|
|
52
|
+
<dt>payload.gx <span class="property-type">number</span></dt>
|
|
53
|
+
<dd>X angular rate in rad/s.</dd>
|
|
54
|
+
<dt>payload.gy <span class="property-type">number</span></dt>
|
|
55
|
+
<dd>Y angular rate in rad/s.</dd>
|
|
56
|
+
<dt>payload.gz <span class="property-type">number</span></dt>
|
|
57
|
+
<dd>Z angular rate in rad/s.</dd>
|
|
58
|
+
</dl>
|
|
59
|
+
<h3>Configuration</h3>
|
|
60
|
+
<p>Select the I²C connection node, the chip's 7-bit address (default <code>0x68</code>),
|
|
61
|
+
the gyroscope full-scale range (±250/±500/±1000/±2000 dps), the accelerometer full-scale range (±2/±4/±8/±16 g),
|
|
62
|
+
and whether to enable the magnetometer.</p>
|
|
63
|
+
</script>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
function MPU9250Node(config) {
|
|
5
|
+
RED.nodes.createNode(this, config);
|
|
6
|
+
const node = this;
|
|
7
|
+
|
|
8
|
+
const connection = RED.nodes.getNode(config.connection);
|
|
9
|
+
if (!connection) {
|
|
10
|
+
node.error('No I2C connection configured');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { MPU9250Minimal } = require('periph/src/chips/imu/mpu9250');
|
|
15
|
+
const sensor = new MPU9250Minimal(connection);
|
|
16
|
+
|
|
17
|
+
this.on('input', async function(msg) {
|
|
18
|
+
try {
|
|
19
|
+
const [ax, ay, az] = await sensor.accel();
|
|
20
|
+
const [gx, gy, gz] = await sensor.gyro();
|
|
21
|
+
msg.payload = { ax, ay, az, gx, gy, gz };
|
|
22
|
+
node.send(msg);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
node.error('MPU9250 read failed: ' + err.message, msg);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
RED.nodes.registerType('periph-mpu9250', MPU9250Node);
|
|
30
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script type="text/html" data-template-name="periph-mpu9255">
|
|
2
|
+
<div class="form-row">
|
|
3
|
+
<label for="node-input-connection"><i class="fa fa-link"></i> I2C Connection</label>
|
|
4
|
+
<input type="text" id="node-input-connection" placeholder="Select I2C connection node">
|
|
5
|
+
</div>
|
|
6
|
+
<div class="form-row">
|
|
7
|
+
<label for="node-input-addr"><i class="fa fa-tag"></i> I2C Address</label>
|
|
8
|
+
<select id="node-input-addr">
|
|
9
|
+
<option value="0x68">0x68 (AD0 = GND)</option>
|
|
10
|
+
<option value="0x69">0x69 (AD0 = VCC)</option>
|
|
11
|
+
</select>
|
|
12
|
+
</div>
|
|
13
|
+
<div class="form-row">
|
|
14
|
+
<label for="node-input-gyroFs"><i class="fa fa-cog"></i> Gyro Full-Scale</label>
|
|
15
|
+
<select id="node-input-gyroFs">
|
|
16
|
+
<option value="0">±250 dps</option>
|
|
17
|
+
<option value="1">±500 dps</option>
|
|
18
|
+
<option value="2">±1000 dps</option>
|
|
19
|
+
<option value="3">±2000 dps</option>
|
|
20
|
+
</select>
|
|
21
|
+
</div>
|
|
22
|
+
<div class="form-row">
|
|
23
|
+
<label for="node-input-accelFs"><i class="fa fa-cog"></i> Accel Full-Scale</label>
|
|
24
|
+
<select id="node-input-accelFs">
|
|
25
|
+
<option value="0">±2 g</option>
|
|
26
|
+
<option value="1">±4 g</option>
|
|
27
|
+
<option value="2">±8 g</option>
|
|
28
|
+
<option value="3">±16 g</option>
|
|
29
|
+
</select>
|
|
30
|
+
</div>
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-input-enableMag"><i class="fa fa-magnet"></i> Enable Magnetometer</label>
|
|
33
|
+
<input type="checkbox" id="node-input-enableMag">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-input-enableWom"><i class="fa fa-bell"></i> Enable Wake-on-Motion</label>
|
|
37
|
+
<input type="checkbox" id="node-input-enableWom">
|
|
38
|
+
</div>
|
|
39
|
+
<div class="form-row">
|
|
40
|
+
<label for="node-input-womThreshold"><i class="fa fa-cog"></i> WoM Threshold (mg)</label>
|
|
41
|
+
<input type="number" id="node-input-womThreshold" min="4" max="1020" step="4" value="64">
|
|
42
|
+
</div>
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<script type="text/html" data-help-name="periph-mpu9255">
|
|
46
|
+
<p>Reads acceleration and angular rate from an MPU-9255 9-axis MotionTracking device.</p>
|
|
47
|
+
<h3>Inputs</h3>
|
|
48
|
+
<dl class="message-properties">
|
|
49
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
50
|
+
<dd>Any incoming message triggers a measurement.</dd>
|
|
51
|
+
</dl>
|
|
52
|
+
<h3>Outputs</h3>
|
|
53
|
+
<dl class="message-properties">
|
|
54
|
+
<dt>payload.ax <span class="property-type">number</span></dt>
|
|
55
|
+
<dd>X acceleration in m/s².</dd>
|
|
56
|
+
<dt>payload.ay <span class="property-type">number</span></dt>
|
|
57
|
+
<dd>Y acceleration in m/s².</dd>
|
|
58
|
+
<dt>payload.az <span class="property-type">number</span></dt>
|
|
59
|
+
<dd>Z acceleration in m/s².</dd>
|
|
60
|
+
<dt>payload.gx <span class="property-type">number</span></dt>
|
|
61
|
+
<dd>X angular rate in rad/s.</dd>
|
|
62
|
+
<dt>payload.gy <span class="property-type">number</span></dt>
|
|
63
|
+
<dd>Y angular rate in rad/s.</dd>
|
|
64
|
+
<dt>payload.gz <span class="property-type">number</span></dt>
|
|
65
|
+
<dd>Z angular rate in rad/s.</dd>
|
|
66
|
+
<dt>payload.motion <span class="property-type">boolean</span></dt>
|
|
67
|
+
<dd>True when wake-on-motion fires (only set when WoM is enabled).</dd>
|
|
68
|
+
</dl>
|
|
69
|
+
<h3>Configuration</h3>
|
|
70
|
+
<p>Select the I²C connection node, the chip's 7-bit address (default <code>0x68</code>),
|
|
71
|
+
the gyroscope full-scale range (±250/±500/±1000/±2000 dps), the accelerometer full-scale range (±2/±4/±8/±16 g),
|
|
72
|
+
whether to enable the magnetometer (requires the AK8963 connection wired separately),
|
|
73
|
+
and whether to enable wake-on-motion with a configurable threshold in mg.</p>
|
|
74
|
+
</script>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
function MPU9255Node(config) {
|
|
5
|
+
RED.nodes.createNode(this, config);
|
|
6
|
+
const node = this;
|
|
7
|
+
|
|
8
|
+
const connection = RED.nodes.getNode(config.connection);
|
|
9
|
+
if (!connection) {
|
|
10
|
+
node.error('No I2C connection configured');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const enableMag = !!config.enableMag;
|
|
15
|
+
const enableWom = !!config.enableWom;
|
|
16
|
+
const womThreshold = parseInt(config.womThreshold, 10) || 64;
|
|
17
|
+
|
|
18
|
+
let sensor;
|
|
19
|
+
try {
|
|
20
|
+
if (enableMag) {
|
|
21
|
+
const { MPU9255Full } = require('periph/src/chips/imu/mpu9255');
|
|
22
|
+
sensor = new MPU9255Full(connection, null);
|
|
23
|
+
// Note: the magnetometer (AK8963 at 0x0C) lives on its own
|
|
24
|
+
// connection bound to that address; this Minimal-only node
|
|
25
|
+
// does not wire it. For full mag support, use the Full API
|
|
26
|
+
// directly via a function node.
|
|
27
|
+
} else {
|
|
28
|
+
const { MPU9255Minimal } = require('periph/src/chips/imu/mpu9255');
|
|
29
|
+
sensor = new MPU9255Minimal(connection);
|
|
30
|
+
}
|
|
31
|
+
if (enableWom) {
|
|
32
|
+
sensor.configure_wake_on_motion && sensor.configure_wake_on_motion(womThreshold, 31.25);
|
|
33
|
+
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
node.error('MPU9255 init failed: ' + err.message);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.on('input', async function(msg) {
|
|
40
|
+
try {
|
|
41
|
+
const [ax, ay, az] = await sensor.accel();
|
|
42
|
+
const [gx, gy, gz] = await sensor.gyro();
|
|
43
|
+
const out = { ax, ay, az, gx, gy, gz };
|
|
44
|
+
if (enableWom && typeof sensor.motion_detected === 'function') {
|
|
45
|
+
if (await sensor.motion_detected()) {
|
|
46
|
+
out.motion = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
msg.payload = out;
|
|
50
|
+
node.send(msg);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
node.error('MPU9255 read failed: ' + err.message, msg);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
RED.nodes.registerType('periph-mpu9255', MPU9255Node);
|
|
58
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-imu",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Node-RED nodes for IMU chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
],
|
|
13
13
|
"node-red": {
|
|
14
14
|
"nodes": {
|
|
15
|
-
"mpu6050": "nodes/mpu6050/mpu6050.js"
|
|
15
|
+
"mpu6050": "nodes/mpu6050/mpu6050.js",
|
|
16
|
+
"mpu9250": "nodes/mpu9250/mpu9250.js",
|
|
17
|
+
"mpu9255": "nodes/mpu9255/mpu9255.js"
|
|
16
18
|
}
|
|
17
19
|
},
|
|
18
20
|
"dependencies": {
|