periph 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 +18 -0
- package/examples/accelerometer/bma180/complete.js +83 -0
- package/examples/accelerometer/bma180/demo.js +47 -0
- package/examples/accelerometer/bma180/minimal.js +21 -0
- package/examples/accelerometer/fxos8700/complete.js +111 -0
- package/examples/accelerometer/fxos8700/demo.js +80 -0
- package/examples/accelerometer/fxos8700/minimal.js +20 -0
- package/examples/accelerometer/lis3dh/complete.js +123 -0
- package/examples/accelerometer/lis3dh/demo.js +99 -0
- package/examples/accelerometer/lis3dh/minimal.js +19 -0
- package/examples/accelerometer/lsm303/complete.js +82 -0
- package/examples/accelerometer/lsm303/demo.js +96 -0
- package/examples/accelerometer/lsm303/minimal.js +23 -0
- package/examples/accelerometer/mma8451q/complete.js +96 -0
- package/examples/accelerometer/mma8451q/demo.js +120 -0
- package/examples/accelerometer/mma8451q/minimal.js +20 -0
- package/examples/adc_dac/ad5243/complete.js +52 -0
- package/examples/adc_dac/ad5243/demo.js +50 -0
- package/examples/adc_dac/ad5243/minimal.js +23 -0
- package/examples/adc_dac/ad5248/complete.js +49 -0
- package/examples/adc_dac/ad5248/demo.js +42 -0
- package/examples/adc_dac/ad5248/minimal.js +21 -0
- package/examples/adc_dac/ads1013/complete.js +51 -0
- package/examples/adc_dac/ads1013/demo.js +51 -0
- package/examples/adc_dac/ads1013/minimal.js +21 -0
- package/examples/adc_dac/ads1014/complete.js +88 -0
- package/examples/adc_dac/ads1014/demo.js +52 -0
- package/examples/adc_dac/ads1014/minimal.js +21 -0
- package/examples/adc_dac/ads1113/complete.js +47 -0
- package/examples/adc_dac/ads1113/demo.js +39 -0
- package/examples/adc_dac/ads1113/minimal.js +20 -0
- package/examples/adc_dac/ads1114/complete.js +77 -0
- package/examples/adc_dac/ads1114/demo.js +47 -0
- package/examples/adc_dac/ads1114/minimal.js +20 -0
- package/examples/adc_dac/ads1115/complete.js +82 -0
- package/examples/adc_dac/ads1115/demo.js +55 -0
- package/examples/adc_dac/ads1115/minimal.js +20 -0
- package/examples/display/pcf8578/complete.js +58 -0
- package/examples/display/pcf8578/demo.js +62 -0
- package/examples/display/pcf8578/minimal.js +19 -0
- package/examples/display/pcf8579/complete.js +58 -0
- package/examples/display/pcf8579/demo.js +61 -0
- package/examples/display/pcf8579/minimal.js +19 -0
- package/examples/imu/icm20948/complete.js +114 -0
- package/examples/imu/icm20948/demo.js +79 -0
- package/examples/imu/icm20948/minimal.js +22 -0
- package/examples/io_expander/mcp23008/complete.js +70 -0
- package/examples/io_expander/mcp23008/demo.js +58 -0
- package/examples/io_expander/mcp23008/minimal.js +20 -0
- package/examples/memory/mb85rc/complete.js +40 -0
- package/examples/memory/mb85rc/demo.js +58 -0
- package/examples/memory/mb85rc/minimal.js +15 -0
- package/examples/motor/drv2605/complete.js +100 -0
- package/examples/motor/drv2605/demo.js +55 -0
- package/examples/motor/drv2605/minimal.js +24 -0
- package/package.json +1 -1
- package/src/chips/accelerometer/bma180.js +573 -0
- package/src/chips/accelerometer/fxos8700.js +1600 -0
- package/src/chips/accelerometer/lis3dh.js +1341 -0
- package/src/chips/accelerometer/lsm303.js +1471 -0
- package/src/chips/accelerometer/mma8451q.js +1406 -0
- package/src/chips/adc_dac/_ads111x_base.js +272 -0
- package/src/chips/adc_dac/ad5243.js +231 -0
- package/src/chips/adc_dac/ad5248.js +194 -0
- package/src/chips/adc_dac/ads1013.js +219 -0
- package/src/chips/adc_dac/ads1014.js +509 -0
- package/src/chips/adc_dac/ads1113.js +112 -0
- package/src/chips/adc_dac/ads1114.js +201 -0
- package/src/chips/adc_dac/ads1115.js +232 -0
- package/src/chips/display/pcf8578.js +452 -0
- package/src/chips/display/pcf8579.js +451 -0
- package/src/chips/imu/icm20948.js +849 -0
- package/src/chips/io_expander/mcp23008.js +558 -0
- package/src/chips/memory/mb85rc.js +166 -0
- package/src/chips/motor/drv2605.js +592 -0
- package/src/discovery/registry.js +20 -19
package/README.md
CHANGED
|
@@ -32,9 +32,16 @@ Each chip exposes two classes:
|
|
|
32
32
|
|------|----------|-------------|
|
|
33
33
|
| 23X1024 | Memory | `periph/src/chips/memory/_23x1024` |
|
|
34
34
|
| 24AA02UID | Memory | `periph/src/chips/memory/_24aa02uid` |
|
|
35
|
+
| AD5243 | ADC/DAC | `periph/src/chips/adc_dac/ad5243` |
|
|
36
|
+
| AD5248 | ADC/DAC | `periph/src/chips/adc_dac/ad5248` |
|
|
35
37
|
| AD7705 | ADC/DAC | `periph/src/chips/adc_dac/ad7705` |
|
|
36
38
|
| AD7706 | ADC/DAC | `periph/src/chips/adc_dac/ad7706` |
|
|
37
39
|
| ADE7953 | Power monitor | `periph/src/chips/power/ade7953` |
|
|
40
|
+
| ADS1013 | ADC/DAC | `periph/src/chips/adc_dac/ads1013` |
|
|
41
|
+
| ADS1014 | ADC/DAC | `periph/src/chips/adc_dac/ads1014` |
|
|
42
|
+
| ADS1113 | ADC/DAC | `periph/src/chips/adc_dac/ads1113` |
|
|
43
|
+
| ADS1114 | ADC/DAC | `periph/src/chips/adc_dac/ads1114` |
|
|
44
|
+
| ADS1115 | ADC/DAC | `periph/src/chips/adc_dac/ads1115` |
|
|
38
45
|
| ADXL345 | Accelerometer | `periph/src/chips/accelerometer/adxl345` |
|
|
39
46
|
| ADXL362 | Accelerometer | `periph/src/chips/accelerometer/adxl362` |
|
|
40
47
|
| AHT21 | Environmental sensor | `periph/src/chips/environmental/aht21` |
|
|
@@ -43,6 +50,7 @@ Each chip exposes two classes:
|
|
|
43
50
|
| APDS9960 | Light sensor | `periph/src/chips/light/apds9960` |
|
|
44
51
|
| AS5600 | Magnetometer | `periph/src/chips/magnetometer/as5600` |
|
|
45
52
|
| BMA150 | Accelerometer | `periph/src/chips/accelerometer/bma150` |
|
|
53
|
+
| BMA180 | Accelerometer | `periph/src/chips/accelerometer/bma180` |
|
|
46
54
|
| BME280 | Environmental sensor | `periph/src/chips/environmental/bme280` |
|
|
47
55
|
| BME680 | Environmental sensor | `periph/src/chips/environmental/bme680` |
|
|
48
56
|
| BMP085 | Pressure sensor | `periph/src/chips/pressure/bmp085` |
|
|
@@ -51,29 +59,37 @@ Each chip exposes two classes:
|
|
|
51
59
|
| BMP384 | Pressure sensor | `periph/src/chips/pressure/bmp384` |
|
|
52
60
|
| BMP581 | Pressure sensor | `periph/src/chips/pressure/bmp581` |
|
|
53
61
|
| DHT11 | Humidity sensor | `periph/src/chips/humidity/dht11` |
|
|
62
|
+
| DRV2605 | Motor driver | `periph/src/chips/motor/drv2605` |
|
|
54
63
|
| DRV8830 | Motor driver | `periph/src/chips/motor/drv8830` |
|
|
55
64
|
| DS3231 | RTC | `periph/src/chips/rtc/ds3231` |
|
|
56
65
|
| ENS160 | Gas sensor | `periph/src/chips/gas/ens160` |
|
|
66
|
+
| FXOS8700 | Accelerometer | `periph/src/chips/accelerometer/fxos8700` |
|
|
57
67
|
| HMC5883L | Magnetometer | `periph/src/chips/magnetometer/hmc5883l` |
|
|
58
68
|
| HX710A | ADC/DAC | `periph/src/chips/adc_dac/hx710a` |
|
|
59
69
|
| HX710B | ADC/DAC | `periph/src/chips/adc_dac/hx710b` |
|
|
60
70
|
| HX711 | ADC/DAC | `periph/src/chips/adc_dac/hx711` |
|
|
61
71
|
| HY3131 | ADC/DAC | `periph/src/chips/adc_dac/hy3131` |
|
|
72
|
+
| ICM20948 | IMU | `periph/src/chips/imu/icm20948` |
|
|
62
73
|
| IL0373 | Display driver | `periph/src/chips/display/il0373` |
|
|
63
74
|
| INA219 | Power monitor | `periph/src/chips/power/ina219` |
|
|
64
75
|
| INA226 | Power monitor | `periph/src/chips/power/ina226` |
|
|
65
76
|
| INA3221 | Power monitor | `periph/src/chips/power/ina3221` |
|
|
66
77
|
| L3G4200D | Gyroscope | `periph/src/chips/gyroscope/l3g4200d` |
|
|
67
78
|
| L3GD20H | Gyroscope | `periph/src/chips/gyroscope/l3gd20h` |
|
|
79
|
+
| LIS3DH | Accelerometer | `periph/src/chips/accelerometer/lis3dh` |
|
|
68
80
|
| LPS22DF | Pressure sensor | `periph/src/chips/pressure/lps22df` |
|
|
69
81
|
| LPS28DFW | Pressure sensor | `periph/src/chips/pressure/lps28dfw` |
|
|
70
82
|
| LPS33HW | Pressure sensor | `periph/src/chips/pressure/lps33hw` |
|
|
83
|
+
| LSM303 | Accelerometer | `periph/src/chips/accelerometer/lsm303` |
|
|
84
|
+
| MB85RC | Memory | `periph/src/chips/memory/mb85rc` |
|
|
85
|
+
| MCP23008 | IO expander | `periph/src/chips/io_expander/mcp23008` |
|
|
71
86
|
| MCP23017 | IO expander | `periph/src/chips/io_expander/mcp23017` |
|
|
72
87
|
| MCP2515 | Comms | `periph/src/chips/comms/mcp2515` |
|
|
73
88
|
| MCP4725 | ADC/DAC | `periph/src/chips/adc_dac/mcp4725` |
|
|
74
89
|
| MCP4728 | ADC/DAC | `periph/src/chips/adc_dac/mcp4728` |
|
|
75
90
|
| MCP9808 | Temperature sensor | `periph/src/chips/temperature/mcp9808` |
|
|
76
91
|
| MFRC522 | RFID/NFC | `periph/src/chips/rfid/mfrc522` |
|
|
92
|
+
| MMA8451Q | Accelerometer | `periph/src/chips/accelerometer/mma8451q` |
|
|
77
93
|
| MPR121 | Other | `periph/src/chips/other/mpr121` |
|
|
78
94
|
| MPU6050 | IMU | `periph/src/chips/imu/mpu6050` |
|
|
79
95
|
| MPU9250 | IMU | `periph/src/chips/imu/mpu9250` |
|
|
@@ -86,6 +102,8 @@ Each chip exposes two classes:
|
|
|
86
102
|
| PCF8574 | IO expander | `periph/src/chips/io_expander/pcf8574` |
|
|
87
103
|
| PCF8575 | IO expander | `periph/src/chips/io_expander/pcf8575` |
|
|
88
104
|
| PCF8576 | Display driver | `periph/src/chips/display/pcf8576` |
|
|
105
|
+
| PCF8578 | Display driver | `periph/src/chips/display/pcf8578` |
|
|
106
|
+
| PCF8579 | Display driver | `periph/src/chips/display/pcf8579` |
|
|
89
107
|
| PCF8591 | ADC/DAC | `periph/src/chips/adc_dac/pcf8591` |
|
|
90
108
|
| RDA5807M | Comms | `periph/src/chips/comms/rda5807m` |
|
|
91
109
|
| RFM9X | Comms | `periph/src/chips/comms/rfm9x` |
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../packages/periph/src/connection/i2c');
|
|
4
|
+
const { BMA180Full } = require('../../packages/periph/src/chips/accelerometer/bma180');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
11
|
+
const accel = new BMA180Full(connection); // Create BMA180 full driver, (connection)
|
|
12
|
+
await new Promise(r => setImmediate(r));
|
|
13
|
+
await new Promise(r => setImmediate(r));
|
|
14
|
+
|
|
15
|
+
await accel.setRange(8); // Set range, (range_g=8 g) → None
|
|
16
|
+
// selects ±8 g; LSB scale changes from 4096 to 1024 LSB/g
|
|
17
|
+
await accel.setBandwidth(40); // Set bandwidth, (bandwidth_hz=40 Hz) → None
|
|
18
|
+
// picks nearest low-pass value
|
|
19
|
+
await accel.setFilterMode(1); // Set filter mode, (mode=1 high-pass 1 Hz) → None
|
|
20
|
+
// bw code 1000 selects the high-pass filter
|
|
21
|
+
await accel.setMode(0); // Set mode, (mode=0 low-noise) → None
|
|
22
|
+
// mode_config in TCO_Z (0x30) bits 1:0
|
|
23
|
+
await accel.setResolution(14); // Set resolution, (bits=14) → None
|
|
24
|
+
// 14-bit readout (readout_12bit cleared)
|
|
25
|
+
|
|
26
|
+
const [rx, ry, rz] = await accel.readRaw(); // Read raw acceleration, () → [x, y, z] int counts
|
|
27
|
+
// burst-reads six LSB-then-MSB bytes, returns signed 14-bit counts
|
|
28
|
+
const t = await accel.readTemperature(); // Read temperature, () → float °C
|
|
29
|
+
// reads 8-bit register, returns 25.0 + (signed - 2) * 0.5 °C
|
|
30
|
+
const ready = await accel.newDataAvailable(); // Check new data, () → bool
|
|
31
|
+
// reads the new_data bits of the three LSB registers
|
|
32
|
+
|
|
33
|
+
await accel.setShadow(false); // Set shadow, (enabled=False) → None
|
|
34
|
+
// shadow_dis bit in GAIN_Y (0x33) — False enforces LSB-then-MSB
|
|
35
|
+
await accel.setSampleSkip(false); // Set sample skip, (enabled=False) → None
|
|
36
|
+
// smp_skip bit in OFFSET_LSB1 (0x35) bit 0
|
|
37
|
+
|
|
38
|
+
await accel.setLowG(0.3, 40, 0.05, 0x07, 0, true); // Configure low-g, (threshold_g=0.3, duration_ms=40, hysteresis_g=0.05, axes=0x07, counter=0, filtered=true) → None
|
|
39
|
+
// writes low_th, low_dur, low_hy; enables SOURCE_LOW_G
|
|
40
|
+
await accel.setHighG(1.8, 20, 0.1, 0x07, 0, true); // Configure high-g, (threshold_g=1.8, duration_ms=20, hysteresis_g=0.1, axes=0x07, counter=0, filtered=true) → None
|
|
41
|
+
// writes high_th, high_dur, high_hy; enables SOURCE_HIGH_G
|
|
42
|
+
await accel.setSlope(0.3, 3, 0x07, true); // Configure slope, (threshold_g=0.3, samples=3, axes=0x07, filtered=true) → None
|
|
43
|
+
// writes slope_th, slope_dur; enables SOURCE_SLOPE (exclusive with alert)
|
|
44
|
+
await accel.setAlert(false); // Set alert, (enabled=False) → None
|
|
45
|
+
// slope_alert off; clears SOURCE_ALERT
|
|
46
|
+
await accel.setTap(0.5, 250, 0x07, true); // Configure tap, (threshold_g=0.5, window_ms=250, axes=0x07, filtered=true) → None
|
|
47
|
+
// writes tapsens_th, tapsens_dur; enables SOURCE_TAP
|
|
48
|
+
|
|
49
|
+
await accel.setLatch(true); // Set latch, (enabled=True) → None
|
|
50
|
+
// lat_int bit in CTRL_REG3 (0x21) — clears by reset_int
|
|
51
|
+
|
|
52
|
+
const flags = await accel.pollInterrupt(); // Poll interrupt, () → int
|
|
53
|
+
// reads STATUS_REG3 — latched flags + first-axis
|
|
54
|
+
await accel.clearInterrupt(); // Clear interrupt, () → None
|
|
55
|
+
// writes reset_int to CTRL_REG0 (0x0D)
|
|
56
|
+
|
|
57
|
+
await accel.disableInterrupt(BMA180Full.SOURCE_LOW_G); // Disable interrupt, (source=SOURCE_LOW_G) → None
|
|
58
|
+
await accel.disableInterrupt(BMA180Full.SOURCE_HIGH_G);// Disable interrupt, (source=SOURCE_HIGH_G) → None
|
|
59
|
+
await accel.disableInterrupt(BMA180Full.SOURCE_SLOPE); // Disable interrupt, (source=SOURCE_SLOPE) → None
|
|
60
|
+
await accel.disableInterrupt(BMA180Full.SOURCE_TAP); // Disable interrupt, (source=SOURCE_TAP) → None
|
|
61
|
+
|
|
62
|
+
await accel.enableInterrupt(BMA180Full.SOURCE_NEW_DATA); // Enable interrupt, (source=SOURCE_NEW_DATA) → None
|
|
63
|
+
await accel.disableInterrupt(BMA180Full.SOURCE_NEW_DATA);// Disable interrupt, (source=SOURCE_NEW_DATA) → None
|
|
64
|
+
|
|
65
|
+
const onInt = (status) => console.log(`INT! status=0x${status.toString(16)}`);
|
|
66
|
+
accel.onInterrupt(onInt); // Subscribe to INT, (callback) → None
|
|
67
|
+
// INT pin rising → callback(onInt)
|
|
68
|
+
accel.offInterrupt(); // Unsubscribe from INT, () → None
|
|
69
|
+
// detaches the handler from the INT pin
|
|
70
|
+
|
|
71
|
+
const cd1 = await accel.readCustomer(0); // Read customer byte, (index=0) → int
|
|
72
|
+
await accel.writeCustomer(1, 0xA5); // Write customer byte, (index=1, value=0xA5) → None
|
|
73
|
+
|
|
74
|
+
await accel.calibrateOffset(0x07, 1); // Calibrate offset, (axes=0x07, mode=1 fine) → None
|
|
75
|
+
// in-field zero-g calibration (volatile)
|
|
76
|
+
|
|
77
|
+
await accel.sleep(); // Sleep, () → None
|
|
78
|
+
await accel.wake(); // Wake-up, () → None
|
|
79
|
+
|
|
80
|
+
console.log(`raw=(${rx},${ry},${rz}) temp=${t.toFixed(2)} ready=${ready} flags=0x${flags.toString(16)} cd1=0x${cd1.toString(16)}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
main().catch(e => { console.error(e); process.exit(2); });
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../packages/periph/src/connection/i2c');
|
|
4
|
+
const { BMA180Full } = require('../../packages/periph/src/chips/accelerometer/bma180');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
11
|
+
const accel = new BMA180Full(connection); // Create BMA180 full driver, (connection)
|
|
12
|
+
await new Promise(r => setImmediate(r));
|
|
13
|
+
await new Promise(r => setImmediate(r));
|
|
14
|
+
|
|
15
|
+
// --- Configure for tilt + tap + free-fall demo at low-noise, 40 Hz, ±2 g ---
|
|
16
|
+
await accel.setBandwidth(40); // Set bandwidth, (bandwidth_hz=40 Hz) → None
|
|
17
|
+
await accel.calibrateOffset(0x07, 1); // Calibrate offset, (axes=0x07, mode=1 fine) → None
|
|
18
|
+
|
|
19
|
+
// --- Arm tap and free-fall detection with latching so we never miss an event ---
|
|
20
|
+
await accel.setTap(0.5, 250); // Configure tap, (threshold_g=0.5, window_ms=250) → None
|
|
21
|
+
await accel.setLowG(0.3, 40); // Configure low-g, (threshold_g=0.3, duration_ms=40) → None
|
|
22
|
+
await accel.setLatch(true); // Set latch, (enabled=True) → None
|
|
23
|
+
|
|
24
|
+
// --- Print tilt + temperature every 100 ms; poll interrupts for tap/free-fall ---
|
|
25
|
+
const start = Date.now();
|
|
26
|
+
while (Date.now() - start < 60_000) {
|
|
27
|
+
const [x, y, z] = await accel.read(); // Read 3-axis acceleration, () → [x, y, z] g
|
|
28
|
+
const pitch = Math.atan2(x, Math.sqrt(y*y + z*z)) * 180 / Math.PI;
|
|
29
|
+
const roll = Math.atan2(y, Math.sqrt(x*x + z*z)) * 180 / Math.PI;
|
|
30
|
+
const mag = Math.sqrt(x*x + y*y + z*z);
|
|
31
|
+
const t = await accel.readTemperature(); // Read temperature, () → float °C
|
|
32
|
+
console.log(`pitch=${pitch.toFixed(1)} roll=${roll.toFixed(1)} |a|=${mag.toFixed(3)} g T=${t.toFixed(1)} C`);
|
|
33
|
+
|
|
34
|
+
const flags = await accel.pollInterrupt(); // Poll interrupt, () → int
|
|
35
|
+
if (flags & 0x10) {
|
|
36
|
+
console.log('DOUBLE TAP');
|
|
37
|
+
await accel.clearInterrupt(); // Clear interrupt, () → None
|
|
38
|
+
}
|
|
39
|
+
if (flags & 0x40) {
|
|
40
|
+
console.log('FREE FALL');
|
|
41
|
+
await accel.clearInterrupt(); // Clear interrupt, () → None
|
|
42
|
+
}
|
|
43
|
+
await new Promise(r => setTimeout(r, 100));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
main().catch(e => { console.error(e); process.exit(2); });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../packages/periph/src/connection/i2c');
|
|
4
|
+
const { BMA180Minimal } = require('../../packages/periph/src/chips/accelerometer/bma180');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
11
|
+
const accel = new BMA180Minimal(connection);
|
|
12
|
+
await new Promise(r => setImmediate(r));
|
|
13
|
+
await new Promise(r => setImmediate(r));
|
|
14
|
+
|
|
15
|
+
setInterval(async () => {
|
|
16
|
+
const [x, y, z] = await accel.read(); // Read 3-axis acceleration, () → [x, y, z] g
|
|
17
|
+
console.log(`x=${x.toFixed(3)} y=${y.toFixed(3)} z=${z.toFixed(3)} g`);
|
|
18
|
+
}, 100);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
main().catch(e => { console.error(e); process.exit(2); });
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { FXOS8700Full, FXOS8700Source } = require('periph/src/chips/accelerometer/fxos8700');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, 0x1E); // Open I²C bus, (busNumber, addr=0x1E) → I2CConnection
|
|
9
|
+
const compass = new FXOS8700Full(connection); // Create FXOS8700 Full driver, (connection) → FXOS8700Full
|
|
10
|
+
// verifies WHO_AM_I, resets and starts hybrid mode
|
|
11
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
await compass.init(); // Wait for initialization, () → Promise<void>
|
|
15
|
+
// resolves when the init sequence has finished
|
|
16
|
+
|
|
17
|
+
console.log('accel', await compass.readAccel()); // Read acceleration, () → Promise<{x, y, z}> g
|
|
18
|
+
// burst-reads 0x01-0x06, 14-bit left-justified
|
|
19
|
+
console.log('mag', await compass.readMag()); // Read magnetic field, () → Promise<{x, y, z}> uT
|
|
20
|
+
// burst-reads 0x33-0x38, 0.1 uT/LSB
|
|
21
|
+
console.log('hybrid', await compass.readHybrid()); // Read both sensors, () → Promise<{accel, mag}>
|
|
22
|
+
// one 12-byte burst from 0x01 (hyb_autoinc_mode)
|
|
23
|
+
console.log('raw accel', await compass.readRawAccel()); // Read raw accelerometer, () → Promise<{x, y, z}> counts
|
|
24
|
+
console.log('raw mag', await compass.readRawMag()); // Read raw magnetometer, () → Promise<{x, y, z}> counts
|
|
25
|
+
console.log('temperature', await compass.readTemperature()); // Read die temperature, () → Promise<float> °C
|
|
26
|
+
// int8(TEMP) × 0.96, relative only
|
|
27
|
+
console.log('new accel', await compass.newAccelData()); // Check accelerometer data ready, () → Promise<boolean>
|
|
28
|
+
console.log('new mag', await compass.newMagData()); // Check magnetometer data ready, () → Promise<boolean>
|
|
29
|
+
console.log('status', await compass.readStatus()); // Read STATUS, () → Promise<int>
|
|
30
|
+
console.log('mag status', await compass.readMagStatus()); // Read M_DR_STATUS, () → Promise<int>
|
|
31
|
+
console.log('system mode', await compass.readSystemMode()); // Read SYSMOD, () → Promise<int> 0 standby | 1 wake | 2 sleep
|
|
32
|
+
|
|
33
|
+
await compass.setMode(FXOS8700Full.MODE_HYBRID); // Select operating mode, (mode 0|1|2) → Promise<void>
|
|
34
|
+
// 0 accel only, 1 mag only, 2 hybrid
|
|
35
|
+
await compass.setRange(4); // Set accelerometer range, (rangeG 2|4|8) → Promise<void>
|
|
36
|
+
// rewrites XYZ_DATA_CFG.fs and the cached sensitivity
|
|
37
|
+
await compass.setDataRate(200); // Set system data rate, (rateHz 800..1.5625) → Promise<void>
|
|
38
|
+
// each sensor runs at half this rate in hybrid mode
|
|
39
|
+
await compass.setAccelOversampling(0, 0); // Set accelerometer oversampling, (mode 0..3, sleepMode=null) → Promise<void>
|
|
40
|
+
// MODS / SMODS in CTRL_REG2
|
|
41
|
+
await compass.setMagOversampling(7, 7); // Set magnetometer oversampling, (ratio 0..7, sleepRatio=null) → Promise<void>
|
|
42
|
+
// m_os / m_aslp_os
|
|
43
|
+
await compass.setLowNoise(false); // Set low-noise mode, (enabled boolean) → Promise<void>
|
|
44
|
+
// lnoise limits the range to ±4 g
|
|
45
|
+
await compass.setResolution(14); // Set accelerometer resolution, (bits 14|8) → Promise<void>
|
|
46
|
+
// 8 selects fast read (MSB only)
|
|
47
|
+
await compass.setHighPassOutput(false, 0); // Set high-pass output, (enabled boolean, cutoff=0) → Promise<void>
|
|
48
|
+
// hpf_out and sel
|
|
49
|
+
await compass.standby(); // Enter STANDBY, () → Promise<void>
|
|
50
|
+
// polls SYSMOD until 0 (up to 300 ms)
|
|
51
|
+
await compass.activate(); // Enter ACTIVE, () → Promise<void>
|
|
52
|
+
// waits the 2/ODR + 2 ms turn-on time
|
|
53
|
+
|
|
54
|
+
await compass.setAccelOffset(0, 0, 0); // Set accelerometer offsets, (xG, yG, zG) → Promise<void>
|
|
55
|
+
// OFF_X/Y/Z, 2 mg/LSB
|
|
56
|
+
console.log('accel offset', await compass.getAccelOffset()); // Get accelerometer offsets, () → Promise<{x, y, z}> g
|
|
57
|
+
await compass.setMagOffset(0, 0, 0); // Set hard-iron offsets, (xUt, yUt, zUt) → Promise<void>
|
|
58
|
+
// 15-bit values subtracted from the output
|
|
59
|
+
console.log('mag offset', await compass.getMagOffset()); // Get hard-iron offsets, () → Promise<{x, y, z}> uT
|
|
60
|
+
await compass.setMagRaw(false); // Select raw magnetometer output, (raw boolean) → Promise<void>
|
|
61
|
+
// false applies the hard-iron offsets
|
|
62
|
+
await compass.setMagAutoCalibration(true); // Hardware hard-iron calibration, (enabled boolean) → Promise<void>
|
|
63
|
+
// MAX/MIN midpoint → M_OFF_* every ODR cycle
|
|
64
|
+
await sleep(1000);
|
|
65
|
+
console.log('min/max', await compass.readMagMinMax()); // Read tracked min / max, () → Promise<{min, max}> uT
|
|
66
|
+
await compass.setMagAutoCalibration(false);
|
|
67
|
+
await compass.resetMagMinMax(); // Reset min / max tracker, () → Promise<void>
|
|
68
|
+
await compass.setMagReset(0); // Set automatic magnetic reset, (mode 0..3) → Promise<void>
|
|
69
|
+
// 0 every ODR cycle, 3 disabled
|
|
70
|
+
await compass.triggerMagReset(); // Trigger one-shot degauss, () → Promise<void>
|
|
71
|
+
console.log('one-shot', await compass.measureMagOnce()); // Measure once in STANDBY, () → Promise<{x, y, z}> uT
|
|
72
|
+
// m_ost, restores ACTIVE
|
|
73
|
+
console.log('heading', await compass.heading(2.5)); // Compute tilt-compensated heading, (declinationDeg=0) → Promise<float> degrees
|
|
74
|
+
// software compensation from one accel + one mag sample
|
|
75
|
+
|
|
76
|
+
await compass.setFifo(FXOS8700Full.FIFO_CIRCULAR, 16); // Configure FIFO, (mode 0..3, watermark=0) → Promise<void>
|
|
77
|
+
await compass.setFifoTrigger({ motion: true }); // Select FIFO trigger sources, ({transient, orientation, pulse, motion}) → Promise<void>
|
|
78
|
+
await compass.setFifoGate(false); // Set FIFO gate, (enabled boolean) → Promise<void>
|
|
79
|
+
await sleep(200);
|
|
80
|
+
console.log('fifo level', await compass.fifoLevel()); // Read FIFO level, () → Promise<int>
|
|
81
|
+
console.log('fifo status', await compass.readFifoStatus()); // Read FIFO status, () → Promise<{overflow, watermark, count}>
|
|
82
|
+
console.log('fifo', await compass.readFifo(4)); // Drain FIFO, (count=null) → Promise<[{x, y, z}]> g
|
|
83
|
+
await compass.setFifo(FXOS8700Full.FIFO_DISABLED);
|
|
84
|
+
|
|
85
|
+
await compass.setFreefallMotion(true, { thresholdG: 0.3, debounceMs: 60, latch: true }); // Configure freefall / motion, (motion, {axes=7, thresholdG=0.3, debounceMs=0, latch=false, debounceClear=false}) → Promise<void>
|
|
86
|
+
console.log('motion', await compass.readMotionSource()); // Read A_FFMT_SRC, () → Promise<int>
|
|
87
|
+
await compass.setTransient({ thresholdG: 0.4, debounceMs: 20 }); // Configure transient detector, ({axes=7, thresholdG=0.3, debounceMs=0, bypassHpf=false, latch=false}) → Promise<void>
|
|
88
|
+
console.log('transient', await compass.readTransientSource()); // Read TRANSIENT_SRC, () → Promise<int>
|
|
89
|
+
await compass.setPulse({ single: 0x04 }); // Configure tap detection, ({single=0, double=0, thresholdG=[0.5,0.5,0.5], timeLimitMs=30, latencyMs=100, windowMs=300, latch=false, doubleAbort=false, lpf=true, hpf=true}) → Promise<void>
|
|
90
|
+
console.log('pulse', await compass.readPulseSource()); // Read PULSE_SRC, () → Promise<int>
|
|
91
|
+
await compass.setOrientation({ enabled: true, debounceMs: 100 }); // Configure orientation detection, ({enabled=true, debounceMs=0, thresholdDeg=45, hysteresis=4, zLock=4, backFront=2}) → Promise<void>
|
|
92
|
+
console.log('orientation', await compass.readOrientation()); // Read orientation, () → Promise<{changed, lockout, portraitLandscape, back}>
|
|
93
|
+
await compass.setAutoSleep(true, { sleepRateHz: 12.5, timeoutS: 10, wakeSources: FXOS8700Source.SOURCE_FF_MT }); // Configure Auto-SLEEP, (enabled, {sleepRateHz=50, timeoutS=10, wakeSources=0}) → Promise<void>
|
|
94
|
+
|
|
95
|
+
await compass.setInterruptPins(false, false); // Configure INT pins, (activeHigh=false, openDrain=false) → Promise<void>
|
|
96
|
+
await compass.enableInterrupt(FXOS8700Source.SOURCE_FF_MT | FXOS8700Source.SOURCE_ORIENTATION, 1); // Enable and route interrupt, (source mask, pin 1|2) → Promise<void>
|
|
97
|
+
console.log('interrupts', await compass.pollInterrupt()); // Poll and clear interrupt sources, () → Promise<int>
|
|
98
|
+
await compass.onInterrupt((status) => console.log('INT', status), 1); // Subscribe to INT, (callback, pin=1) → Promise<void>
|
|
99
|
+
await sleep(1000);
|
|
100
|
+
await compass.offInterrupt(1); // Unsubscribe from INT, (pin=1) → Promise<void>
|
|
101
|
+
await compass.disableInterrupt(FXOS8700Source.SOURCE_FF_MT | FXOS8700Source.SOURCE_ORIENTATION); // Disable interrupt sources, (source mask) → Promise<void>
|
|
102
|
+
|
|
103
|
+
console.log('A_VECM_CFG', await compass.readRegister(0x5F, 1)); // Read raw registers, (reg, length=1) → Promise<Buffer>
|
|
104
|
+
await compass.writeRegister(0x5F, Buffer.from([0x00])); // Write raw registers, (reg, data) → Promise<void>
|
|
105
|
+
console.log('self-test', await compass.selfTest()); // Run accelerometer self-test, () → Promise<{ok, dx, dy, dz}> counts
|
|
106
|
+
// electrostatic test, checks X ≥ 192, Y ≥ 270, Z ≥ 1275
|
|
107
|
+
await compass.reset(); // Software reset, () → Promise<void>
|
|
108
|
+
// the NACK on the write is tolerated
|
|
109
|
+
await compass.reinit(); // Re-initialise, () → Promise<void>
|
|
110
|
+
await connection.close();
|
|
111
|
+
})();
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { FXOS8700Full, FXOS8700Source } = require('periph/src/chips/accelerometer/fxos8700');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, 0x1E); // Open I²C bus, (busNumber, addr=0x1E) → I2CConnection
|
|
9
|
+
const compass = new FXOS8700Full(connection); // Create FXOS8700 Full driver, (connection) → FXOS8700Full
|
|
10
|
+
|
|
11
|
+
const DIRECTIONS = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
|
|
12
|
+
'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'];
|
|
13
|
+
const ORIENTATIONS = ['PORTRAIT UP', 'PORTRAIT DOWN', 'LANDSCAPE RIGHT', 'LANDSCAPE LEFT'];
|
|
14
|
+
const DECLINATION = 3.0; // magnetic declination of the site in degrees
|
|
15
|
+
const RUN_SECONDS = 60;
|
|
16
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
17
|
+
|
|
18
|
+
(async () => {
|
|
19
|
+
await compass.init(); // Wait for initialization, () → Promise<void>
|
|
20
|
+
|
|
21
|
+
// --- Configure hybrid mode ---
|
|
22
|
+
// ±4 g keeps tilt maths precise while tolerating handling; magnetometer
|
|
23
|
+
// oversampling ratio 7 gives the lowest noise at this data rate.
|
|
24
|
+
await compass.setRange(4); // Set accelerometer range, (rangeG 2|4|8) → Promise<void>
|
|
25
|
+
await compass.setMagOversampling(7); // Set magnetometer oversampling, (ratio 0..7, sleepRatio=null) → Promise<void>
|
|
26
|
+
|
|
27
|
+
// --- Check the accelerometer ---
|
|
28
|
+
// The electrostatic self-test must move every axis by the datasheet minimum.
|
|
29
|
+
const st = await compass.selfTest(); // Run accelerometer self-test, () → Promise<{ok, dx, dy, dz}> counts
|
|
30
|
+
console.log('self-test', st.ok ? 'OK' : 'FAILED', st.dx, st.dy, st.dz);
|
|
31
|
+
|
|
32
|
+
// --- Calibrate the hard-iron offsets ---
|
|
33
|
+
// Auto-calibration writes the midpoint of the tracked min/max to the
|
|
34
|
+
// offset registers every cycle; rotate the board through all
|
|
35
|
+
// orientations meanwhile.
|
|
36
|
+
await compass.setMagAutoCalibration(true); // Hardware hard-iron calibration, (enabled boolean) → Promise<void>
|
|
37
|
+
console.log('Rotate the board in all directions for 15 s ...');
|
|
38
|
+
for (let s = 0; s < 15; s++) {
|
|
39
|
+
await sleep(1000);
|
|
40
|
+
const { min, max } = await compass.readMagMinMax(); // Read tracked min / max, () → Promise<{min, max}> uT
|
|
41
|
+
console.log(`span ${(max.x - min.x).toFixed(1)} ${(max.y - min.y).toFixed(1)} ${(max.z - min.z).toFixed(1)} uT`);
|
|
42
|
+
}
|
|
43
|
+
await compass.setMagAutoCalibration(false); // Hardware hard-iron calibration, (enabled boolean) → Promise<void>
|
|
44
|
+
console.log('offsets', await compass.getMagOffset()); // Get hard-iron offsets, () → Promise<{x, y, z}> uT
|
|
45
|
+
|
|
46
|
+
// --- Arm orientation and motion detection ---
|
|
47
|
+
// Orientation changes and motion are routed to INT1; Auto-SLEEP drops the
|
|
48
|
+
// chip to a low rate after 10 s without motion, and motion wakes it again.
|
|
49
|
+
await compass.setOrientation({ debounceMs: 100 }); // Configure orientation detection, ({enabled=true, debounceMs=0, thresholdDeg=45, hysteresis=4, zLock=4, backFront=2}) → Promise<void>
|
|
50
|
+
await compass.setFreefallMotion(true, { thresholdG: 0.3, debounceMs: 60, latch: true }); // Configure freefall / motion, (motion, {axes=7, thresholdG=0.3, debounceMs=0, latch=false, debounceClear=false}) → Promise<void>
|
|
51
|
+
await compass.setAutoSleep(true, { sleepRateHz: 12.5, timeoutS: 10, wakeSources: FXOS8700Source.SOURCE_FF_MT }); // Configure Auto-SLEEP, (enabled, {sleepRateHz=50, timeoutS=10, wakeSources=0}) → Promise<void>
|
|
52
|
+
await compass.enableInterrupt(FXOS8700Source.SOURCE_ORIENTATION | FXOS8700Source.SOURCE_FF_MT, 1); // Enable and route interrupt, (source mask, pin 1|2) → Promise<void>
|
|
53
|
+
|
|
54
|
+
// --- Print the heading ---
|
|
55
|
+
// Every 250 ms the tilt-compensated heading is shown with the board's
|
|
56
|
+
// pitch and roll; the temperature is printed once per second.
|
|
57
|
+
const start = Date.now();
|
|
58
|
+
let lastTemperature = 0;
|
|
59
|
+
while (Date.now() - start < RUN_SECONDS * 1000) {
|
|
60
|
+
const heading = await compass.heading(DECLINATION); // Compute tilt-compensated heading, (declinationDeg=0) → Promise<float> degrees
|
|
61
|
+
const { accel } = await compass.readHybrid(); // Read both sensors, () → Promise<{accel, mag}>
|
|
62
|
+
const roll = Math.atan2(accel.y, accel.z) * 180 / Math.PI;
|
|
63
|
+
const pitch = Math.atan2(-accel.x, Math.hypot(accel.y, accel.z)) * 180 / Math.PI;
|
|
64
|
+
console.log(`${heading.toFixed(1)} deg ${DIRECTIONS[Math.floor((heading + 11.25) / 22.5) % 16]} pitch ${pitch.toFixed(1)} roll ${roll.toFixed(1)}`);
|
|
65
|
+
const status = await compass.pollInterrupt(); // Poll and clear interrupt sources, () → Promise<int>
|
|
66
|
+
if (status & FXOS8700Source.SOURCE_ORIENTATION) {
|
|
67
|
+
const o = await compass.readOrientation(); // Read orientation, () → Promise<{changed, lockout, portraitLandscape, back}>
|
|
68
|
+
console.log(ORIENTATIONS[o.portraitLandscape]);
|
|
69
|
+
}
|
|
70
|
+
if (status & FXOS8700Source.SOURCE_FF_MT) {
|
|
71
|
+
console.log('MOTION', await compass.readSystemMode()); // Read SYSMOD, () → Promise<int> 0 standby | 1 wake | 2 sleep
|
|
72
|
+
}
|
|
73
|
+
if (Date.now() - lastTemperature >= 1000) {
|
|
74
|
+
lastTemperature = Date.now();
|
|
75
|
+
console.log(`temperature ${(await compass.readTemperature()).toFixed(1)} C`); // Read die temperature, () → Promise<float> °C
|
|
76
|
+
}
|
|
77
|
+
await sleep(250);
|
|
78
|
+
}
|
|
79
|
+
await connection.close();
|
|
80
|
+
})();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { FXOS8700Minimal } = require('periph/src/chips/accelerometer/fxos8700');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, 0x1E); // Open I²C bus, (busNumber, addr=0x1E) → I2CConnection
|
|
9
|
+
const compass = new FXOS8700Minimal(connection); // Create FXOS8700 driver, (connection) → FXOS8700Minimal
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
await compass.init(); // Wait for initialization, () → Promise<void>
|
|
13
|
+
while (true) {
|
|
14
|
+
const accel = await compass.readAccel(); // Read acceleration, () → Promise<{x:float, y:float, z:float}> g
|
|
15
|
+
const mag = await compass.readMag(); // Read magnetic field, () → Promise<{x:float, y:float, z:float}> uT
|
|
16
|
+
console.log(`accel x=${accel.x.toFixed(4)} y=${accel.y.toFixed(4)} z=${accel.z.toFixed(4)} g`);
|
|
17
|
+
console.log(`mag x=${mag.x.toFixed(2)} y=${mag.y.toFixed(2)} z=${mag.z.toFixed(2)} uT`);
|
|
18
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
19
|
+
}
|
|
20
|
+
})();
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { LIS3DHFull, LIS3DHSource } = require('periph/src/chips/accelerometer/lis3dh');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x18', 16);
|
|
8
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
10
|
+
const accel = new LIS3DHFull(connection); // Create LIS3DH Full driver, (connection)
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
// --- Operating mode, range and data rate -----------------------------
|
|
14
|
+
await accel.setMode(2); // Set operating mode, (mode) → None
|
|
15
|
+
// 2 = high-resolution (12-bit); the alternatives are 0 (low-power, 8-bit) and 1 (normal, 10-bit)
|
|
16
|
+
await accel.setRange(2); // Set full-scale range, (rangeG) → None
|
|
17
|
+
// ±2 g, i.e. 1 mg/LSB in high-resolution mode
|
|
18
|
+
await accel.setDataRate(100); // Set output data rate, (rateHz) → None
|
|
19
|
+
// 100 Hz; the chip converts 100 times per second
|
|
20
|
+
await accel.setAxes(true, true, true); // Enable measurement axes, (x, y, z) → None
|
|
21
|
+
// all three axes converted; a disabled axis reads 0
|
|
22
|
+
|
|
23
|
+
// --- Data reads -------------------------------------------------------
|
|
24
|
+
const acc = await accel.read(); // Read 3-axis acceleration, () → {x, y, z} g
|
|
25
|
+
// burst read of 0x28–0x2D scaled with the current sensitivity
|
|
26
|
+
const raw = await accel.readRaw(); // Read raw counts, () → {x, y, z}
|
|
27
|
+
// signed counts at the current resolution (12-bit in high-resolution mode)
|
|
28
|
+
const ready = await accel.newDataAvailable(); // Check new data, () → bool
|
|
29
|
+
// true once a complete X/Y/Z sample set is ready
|
|
30
|
+
const status = await accel.readStatus(); // Read status register, () → byte
|
|
31
|
+
// overrun and data-available flags of STATUS_REG (0x27)
|
|
32
|
+
|
|
33
|
+
// --- High-pass filter --------------------------------------------------
|
|
34
|
+
await accel.setHighPass({mode: 0, cutoff: 0, filterOutput: false, onIa1: true, onIa2: false, onClick: false});
|
|
35
|
+
// Configure high-pass filter, (mode, cutoff, filterOutput, onIa1, onIa2, onClick) → None
|
|
36
|
+
// HPM 00 (normal, reset by reading REFERENCE), applied to generator 1 only
|
|
37
|
+
const ref = await accel.resetHighPass(); // Reset high-pass filter, () → byte
|
|
38
|
+
// reads REFERENCE, which resets the filter in HPM 00
|
|
39
|
+
await accel.setReference(0x00); // Set high-pass reference, (value) → None
|
|
40
|
+
// REFERENCE = 0; only used with HPM = 01
|
|
41
|
+
|
|
42
|
+
// --- Auxiliary ADC and temperature --------------------------------------
|
|
43
|
+
await accel.enableAdc(true); // Enable auxiliary ADC, (enabled) → None
|
|
44
|
+
// ADC_EN = 1 in TEMP_CFG_REG
|
|
45
|
+
const adc1 = await accel.readAdc(1); // Read auxiliary ADC channel, (channel) → V
|
|
46
|
+
// channel 1 input voltage; 1.200 V centre, ±400 mV range
|
|
47
|
+
const temp = await accel.readTemperatureDelta(); // Read relative temperature, () → °C
|
|
48
|
+
// enables ADC_EN + TEMP_EN, then returns the 1 digit/°C delta
|
|
49
|
+
await accel.enableAdc(false); // Enable auxiliary ADC, (enabled) → None
|
|
50
|
+
// ADC_EN = 0 again
|
|
51
|
+
|
|
52
|
+
// --- FIFO ---------------------------------------------------------------
|
|
53
|
+
await accel.setFifo(2, 16, false); // Configure FIFO, (mode, watermark, triggerInt2) → None
|
|
54
|
+
// mode 2 = stream, watermark 16 samples, trigger source INT1
|
|
55
|
+
const level = await accel.fifoLevel(); // Read FIFO level, () → count
|
|
56
|
+
// number of unread sample sets (0-32)
|
|
57
|
+
const samples = await accel.readFifo(); // Drain the FIFO, (count) → [{x, y, z}]
|
|
58
|
+
// reads every buffered sample set; each one is a 6-byte burst
|
|
59
|
+
const fifo = await accel.readFifoStatus(); // Read FIFO status, () → {watermark, overrun, empty, level}
|
|
60
|
+
// decoded FIFO_SRC_REG flags
|
|
61
|
+
await accel.setFifo(0); // Configure FIFO, (mode, watermark, triggerInt2) → None
|
|
62
|
+
// back to bypass, which empties the buffer
|
|
63
|
+
|
|
64
|
+
// --- Inertial interrupt generators ---------------------------------------
|
|
65
|
+
await accel.setMotionInterrupt(1, 0x05, 0.5, 20, false);
|
|
66
|
+
// Configure motion interrupt, (generator, events, thresholdG, durationMs, andMode) → None
|
|
67
|
+
// generator 1, X-high + Z-high events, 0.5 g threshold, 20 ms duration, OR combination
|
|
68
|
+
await accel.setFreeFall(1, 0.35, 60); // Configure free fall, (generator, thresholdG, durationMs) → None
|
|
69
|
+
// all three axes below 0.35 g for 60 ms, AND combination
|
|
70
|
+
await accel.setOrientation(1, false, false); // Configure orientation, (generator, position, fourD) → None
|
|
71
|
+
// 6D movement recognition on generator 1
|
|
72
|
+
await accel.setLatch(1, true); // Latch generator interrupt, (generator, enabled) → None
|
|
73
|
+
// LIR_INT1 = 1: the interrupt stays high until INT1_SRC is read
|
|
74
|
+
const int1 = await accel.readInterruptSource(1); // Read interrupt source, (generator) → byte
|
|
75
|
+
// INT1_SRC; reading it clears the latched interrupt
|
|
76
|
+
|
|
77
|
+
// --- Click detection ------------------------------------------------------
|
|
78
|
+
await accel.setClick(0, 0x04, 0.5, 10, 20, 50, false);
|
|
79
|
+
// Configure click detection, (single, double, thresholdG, timeLimitMs, latencyMs, windowMs, latch) → None
|
|
80
|
+
// double click on Z, 0.5 g threshold, 10 ms time limit, 20 ms latency, 50 ms window
|
|
81
|
+
const click = await accel.readClickSource(); // Read click source, () → byte
|
|
82
|
+
// CLICK_SRC; reading it clears the click interrupt
|
|
83
|
+
|
|
84
|
+
// --- Sleep-to-wake activity -------------------------------------------------
|
|
85
|
+
await accel.setActivity(0.1, 100); // Configure activity, (thresholdG, durationMs) → None
|
|
86
|
+
// drop to the 10 Hz low-power state below 0.1 g for 100 ms
|
|
87
|
+
|
|
88
|
+
// --- Interrupt polarity and routing ------------------------------------------
|
|
89
|
+
await accel.setInterruptPolarity(false); // Set interrupt polarity, (activeLow) → None
|
|
90
|
+
// active-high INT1/INT2, the reset default
|
|
91
|
+
await accel.enableInterrupt(LIS3DHSource.SOURCE_DATA_READY, 1);
|
|
92
|
+
// Route interrupt source, (source, pin) → None
|
|
93
|
+
// new X/Y/Z sample sets on INT1
|
|
94
|
+
await accel.enableInterrupt(LIS3DHSource.SOURCE_CLICK, 1);
|
|
95
|
+
// Route interrupt source, (source, pin) → None
|
|
96
|
+
// click events on INT1
|
|
97
|
+
let notified = 0;
|
|
98
|
+
await accel.onInterrupt(status => { notified++; }, 1); // Subscribe to interrupts, (callback, pin) → None
|
|
99
|
+
// the callback receives the combined status int
|
|
100
|
+
const poll = await accel.pollInterrupt(); // Poll interrupt status, () → int
|
|
101
|
+
// combined status of every enabled source
|
|
102
|
+
await accel.offInterrupt(1); // Unsubscribe from interrupts, (pin) → None
|
|
103
|
+
// stops the delivery (and the 5 ms polling fallback)
|
|
104
|
+
await accel.disableInterrupt(LIS3DHSource.SOURCE_CLICK, 1);
|
|
105
|
+
// Unroute interrupt source, (source, pin) → None
|
|
106
|
+
// click events no longer reach INT1
|
|
107
|
+
|
|
108
|
+
// --- System functions ---------------------------------------------------------
|
|
109
|
+
const st = await accel.selfTest(1); // Run self-test, (mode) → bool
|
|
110
|
+
// electrostatic self-test 0; true when every axis moved 17-360 LSb
|
|
111
|
+
await accel.setSdoPullup(true); // Set SDO pull-up, (connected) → None
|
|
112
|
+
// keeps the pull-up on SDO/SA0
|
|
113
|
+
await accel.powerDown(); // Power down, () → None
|
|
114
|
+
// ODR = 0000 stops the conversions; the registers are retained
|
|
115
|
+
await accel.reboot(); // Reboot, () → None
|
|
116
|
+
// BOOT reloads the factory trim and re-runs the initialization
|
|
117
|
+
|
|
118
|
+
console.log(`acc=[${acc.x.toFixed(3)}, ${acc.y.toFixed(3)}, ${acc.z.toFixed(3)}] g raw=[${raw.x}, ${raw.y}, ${raw.z}] ready=${ready} status=0x${status.toString(16)}`);
|
|
119
|
+
console.log(`reference=0x${ref.toString(16)} adc1=${adc1.toFixed(4)} V temp=${temp} °C`);
|
|
120
|
+
console.log(`fifo level=${level} samples=${samples.length} status=${JSON.stringify(fifo)}`);
|
|
121
|
+
console.log(`int1=0x${int1.toString(16)} click=0x${click.toString(16)} poll=0x${poll.toString(16)} notified=${notified} selfTest=${st ? 'PASS' : 'FAIL'}`);
|
|
122
|
+
await connection.close();
|
|
123
|
+
})();
|