periph 1.5.0 → 1.5.2
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 +19 -0
- package/examples/color/as7262/complete.js +60 -0
- package/examples/color/as7262/demo.js +65 -0
- package/examples/color/as7262/minimal.js +23 -0
- package/examples/environmental/aht10/complete.js +37 -0
- package/examples/environmental/aht10/demo.js +43 -0
- package/examples/environmental/aht10/minimal.js +12 -0
- package/examples/environmental/aht20/complete.js +41 -0
- package/examples/environmental/aht20/demo.js +49 -0
- package/examples/environmental/aht20/minimal.js +12 -0
- package/examples/environmental/am2320/complete.js +34 -0
- package/examples/environmental/am2320/demo.js +46 -0
- package/examples/environmental/am2320/minimal.js +21 -0
- package/examples/humidity/hdc1008/complete.js +39 -0
- package/examples/humidity/hdc1008/demo.js +46 -0
- package/examples/humidity/hdc1008/minimal.js +22 -0
- package/examples/humidity/hdc1080/complete.js +34 -0
- package/examples/humidity/hdc1080/demo.js +46 -0
- package/examples/humidity/hdc1080/minimal.js +22 -0
- package/examples/humidity/hs30xx/complete.js +43 -0
- package/examples/humidity/hs30xx/demo.js +40 -0
- package/examples/humidity/hs30xx/minimal.js +21 -0
- package/examples/humidity/hs40xx/complete.js +54 -0
- package/examples/humidity/hs40xx/demo.js +38 -0
- package/examples/humidity/hs40xx/minimal.js +21 -0
- package/examples/io_expander/tca9554/complete.js +63 -0
- package/examples/io_expander/tca9554/demo.js +58 -0
- package/examples/io_expander/tca9554/minimal.js +20 -0
- package/examples/led/ht16k33/complete.js +45 -0
- package/examples/led/ht16k33/demo.js +54 -0
- package/examples/led/ht16k33/minimal.js +24 -0
- package/examples/led/is31fl3731/complete.js +60 -0
- package/examples/led/is31fl3731/demo.js +72 -0
- package/examples/led/is31fl3731/minimal.js +26 -0
- package/examples/led/pca9685/complete.js +43 -0
- package/examples/led/pca9685/demo.js +77 -0
- package/examples/led/pca9685/minimal.js +24 -0
- package/examples/power/ina260/complete.js +38 -0
- package/examples/power/ina260/demo.js +32 -0
- package/examples/power/ina260/minimal.js +11 -0
- package/examples/power/lc709203f/complete.js +57 -0
- package/examples/power/lc709203f/demo.js +34 -0
- package/examples/power/lc709203f/minimal.js +11 -0
- package/examples/power/lm25066/complete.js +54 -0
- package/examples/power/lm25066/demo.js +41 -0
- package/examples/power/lm25066/minimal.js +12 -0
- package/examples/power/ltc4151/complete.js +40 -0
- package/examples/power/ltc4151/demo.js +49 -0
- package/examples/power/ltc4151/minimal.js +11 -0
- package/examples/power/max17048/complete.js +68 -0
- package/examples/power/max17048/demo.js +56 -0
- package/examples/power/max17048/minimal.js +19 -0
- package/examples/pressure/lps22hb/complete.js +43 -0
- package/examples/pressure/lps22hb/demo.js +43 -0
- package/examples/pressure/lps22hb/minimal.js +19 -0
- package/examples/pressure/mpl115a2/complete.js +25 -0
- package/examples/pressure/mpl115a2/demo.js +30 -0
- package/examples/pressure/mpl115a2/minimal.js +20 -0
- package/package.json +1 -1
- package/src/chips/color/as7262.js +419 -0
- package/src/chips/environmental/aht10.js +186 -0
- package/src/chips/environmental/aht20.js +226 -0
- package/src/chips/environmental/am2320.js +237 -0
- package/src/chips/humidity/hdc1008.js +262 -0
- package/src/chips/humidity/hdc1080.js +208 -0
- package/src/chips/humidity/hs30xx.js +254 -0
- package/src/chips/humidity/hs40xx.js +382 -0
- package/src/chips/io_expander/tca9554.js +407 -0
- package/src/chips/led/ht16k33.js +273 -0
- package/src/chips/led/is31fl3731.js +501 -0
- package/src/chips/led/pca9685.js +350 -0
- package/src/chips/power/ina260.js +229 -0
- package/src/chips/power/lc709203f.js +376 -0
- package/src/chips/power/lm25066.js +370 -0
- package/src/chips/power/ltc4151.js +297 -0
- package/src/chips/power/max17048.js +302 -0
- package/src/chips/pressure/lps22hb.js +257 -0
- package/src/chips/pressure/mpl115a2.js +171 -0
- package/src/discovery/registry.js +56 -14
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { LTC4151Full } = require('../../../src/chips/power/ltc4151');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x6A); // Create I²C connection, (bus=1, addr=0x6A) → Connection
|
|
7
|
+
const ltc = new LTC4151Full(connection, 0.02); // Create LTC4151 driver, (connection, rSense=0.02 Ω) → void
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
console.log(await ltc.voltage()); // Read supply voltage, () → number V
|
|
11
|
+
// VIN code × 25 mV
|
|
12
|
+
console.log(await ltc.current()); // Read load current, () → number A
|
|
13
|
+
// sense voltage / rSense
|
|
14
|
+
console.log(await ltc.power()); // Read load power, () → number W
|
|
15
|
+
// one block read of SENSE and VIN
|
|
16
|
+
console.log(await ltc.senseVoltage()); // Read SENSE+ − SENSE−, () → number V
|
|
17
|
+
console.log(await ltc.adinVoltage()); // Read ADIN pin voltage, () → number V
|
|
18
|
+
console.log(await ltc.readAll()); // Consistent read of all channels, () → {vin, senseV, current, power, adin}
|
|
19
|
+
console.log(await ltc.readRaw(LTC4151Full.VIN)); // Read raw 12-bit code, (channel 0–2) → number
|
|
20
|
+
|
|
21
|
+
ltc.setSenseResistor(0.01); // Change sense resistor, (ohms) → void
|
|
22
|
+
console.log(ltc.getSenseResistor()); // Read sense resistor, () → number Ω
|
|
23
|
+
ltc.setSenseResistor(0.02);
|
|
24
|
+
|
|
25
|
+
console.log(await ltc.snapshot(LTC4151Full.SENSE)); // One snapshot conversion, (channel 0–2) → number V
|
|
26
|
+
// returns to continuous scan afterwards
|
|
27
|
+
console.log(await ltc.isSnapshotMode()); // Snapshot mode active, () → boolean
|
|
28
|
+
console.log(await ltc.isBusy(LTC4151Full.VIN)); // Channel busy, (channel 0–2) → boolean
|
|
29
|
+
await ltc.setContinuous(); // Back to continuous scan, () → void
|
|
30
|
+
|
|
31
|
+
await ltc.setStuckBusTimer(true); // Stuck-bus reset timer, (enabled) → void
|
|
32
|
+
await ltc.setPageRw(true); // I²C page read/write, (enabled) → void
|
|
33
|
+
console.log('0x' + (await ltc.readControl()).toString(16)); // Read CONTROL, () → number
|
|
34
|
+
await ltc.writeControl(0x0C); // Write CONTROL, (value) → void
|
|
35
|
+
// test mode bit 4 is always masked to 0
|
|
36
|
+
|
|
37
|
+
console.log(LTC4151Full.temperatureFromAdin(900, 1200)); // NTC example circuit, (adinCode, vinCode) → number °C
|
|
38
|
+
|
|
39
|
+
await connection.close();
|
|
40
|
+
})();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { LTC4151Full } = require('../../../src/chips/power/ltc4151');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(1, 0x6A); // Create I²C connection, (bus=1, addr=0x6A) → Connection
|
|
9
|
+
const ltc = new LTC4151Full(connection, 0.02); // Create LTC4151 driver, (connection, rSense=0.02 Ω) → void
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
// --- High-side supply monitor: continuous scan once per second for 20 s ---
|
|
13
|
+
for (let n = 0; n < 20; n++) {
|
|
14
|
+
const d = await ltc.readAll(); // Consistent read of all channels, () → {vin, senseV, current, power, adin}
|
|
15
|
+
console.log(`${d.vin.toFixed(2)} V ${(d.senseV * 1000).toFixed(2)} mV ${d.current.toFixed(4)} A ${d.power.toFixed(3)} W adin ${d.adin.toFixed(3)} V`);
|
|
16
|
+
await sleep(1000);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// --- Compare snapshot conversion times: SENSE ~67 ms, VIN / ADIN ~33 ms ---
|
|
20
|
+
for (const [name, ch] of [['SENSE', LTC4151Full.SENSE], ['VIN', LTC4151Full.VIN], ['ADIN', LTC4151Full.ADIN]]) {
|
|
21
|
+
const t0 = Date.now();
|
|
22
|
+
const value = await ltc.snapshot(ch); // One snapshot conversion, (channel 0–2) → number V
|
|
23
|
+
console.log(`${name} snapshot ${value.toFixed(4)} V in ${Date.now() - t0} ms`);
|
|
24
|
+
}
|
|
25
|
+
console.log('snapshot mode after snapshot:', await ltc.isSnapshotMode()); // Snapshot mode active, () → boolean
|
|
26
|
+
|
|
27
|
+
// --- Toggle the stuck-bus timer and page read/write ---
|
|
28
|
+
await ltc.setStuckBusTimer(false); // Stuck-bus reset timer, (enabled) → void
|
|
29
|
+
await ltc.setPageRw(false); // I²C page read/write, (enabled) → void
|
|
30
|
+
console.log('CONTROL (timer off, page off): 0x' + (await ltc.readControl()).toString(16)); // Read CONTROL, () → number
|
|
31
|
+
await ltc.setStuckBusTimer(true);
|
|
32
|
+
await ltc.setPageRw(true);
|
|
33
|
+
console.log('CONTROL (restored): 0x' + (await ltc.readControl()).toString(16));
|
|
34
|
+
|
|
35
|
+
// --- NTC temperature from a made-up ADIN / VIN code pair ---
|
|
36
|
+
console.log('temperature', LTC4151Full.temperatureFromAdin(900, 1200).toFixed(1), '°C'); // NTC example circuit, (adinCode, vinCode) → number °C
|
|
37
|
+
|
|
38
|
+
// --- 5 s min / max / average power tally ---
|
|
39
|
+
const samples = [];
|
|
40
|
+
const end = Date.now() + 5000;
|
|
41
|
+
while (Date.now() < end) {
|
|
42
|
+
samples.push(await ltc.power()); // Read load power, () → number W
|
|
43
|
+
await sleep(200);
|
|
44
|
+
}
|
|
45
|
+
const avg = samples.reduce((a, b) => a + b, 0) / samples.length;
|
|
46
|
+
console.log(`power min ${Math.min(...samples).toFixed(3)} W, max ${Math.max(...samples).toFixed(3)} W, avg ${avg.toFixed(3)} W`);
|
|
47
|
+
|
|
48
|
+
await connection.close();
|
|
49
|
+
})();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { LTC4151Minimal } = require('../../../src/chips/power/ltc4151');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x6A); // Create I²C connection, (bus=1, addr=0x6A) → Connection
|
|
7
|
+
const ltc = new LTC4151Minimal(connection, 0.02); // Create LTC4151 driver, (connection, rSense=0.02 Ω) → void
|
|
8
|
+
|
|
9
|
+
setInterval(async () => {
|
|
10
|
+
console.log(await ltc.voltage(), await ltc.current(), await ltc.power()); // Read V / A / W, () → number each
|
|
11
|
+
}, 1000);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { MAX17048Full } = require('../../../src/chips/power/max17048');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const connection = new I2CConnection(1, 0x36); // Create I²C connection, (bus, addr=0x36) → Connection
|
|
10
|
+
const gauge = new MAX17048Full(connection, 1); // Create MAX17048 driver, (connection, cells)
|
|
11
|
+
// cells = 1 (MAX17048) or 2 (MAX17049)
|
|
12
|
+
|
|
13
|
+
console.log(await gauge.voltage()); // Cell voltage, () → Promise<number> V
|
|
14
|
+
console.log(await gauge.percent()); // State of charge, () → Promise<number> %
|
|
15
|
+
console.log(await gauge.rawVoltage()); // VCELL register, () → Promise<number>
|
|
16
|
+
console.log(await gauge.rawSoc()); // SOC register, () → Promise<number>
|
|
17
|
+
console.log(await gauge.chargeRate()); // Charge/discharge rate, () → Promise<number> %/h
|
|
18
|
+
console.log(await gauge.version()); // VERSION register, () → Promise<number>
|
|
19
|
+
console.log(await gauge.chipId()); // Factory ID, () → Promise<number>
|
|
20
|
+
|
|
21
|
+
await gauge.setRcomp(0x97); // RCOMP, (value) → Promise<void>
|
|
22
|
+
console.log(await gauge.getRcomp()); // () → Promise<number>
|
|
23
|
+
await gauge.compensateTemperature(25.0); // RCOMP from the temperature, (celsius) → Promise<void>
|
|
24
|
+
|
|
25
|
+
await gauge.setAlertSoc(10); // Empty alert threshold, (percent) → Promise<void>; 1-32 %
|
|
26
|
+
console.log(await gauge.getAlertSoc()); // () → Promise<number> %
|
|
27
|
+
await gauge.setSocChangeAlert(true); // Alert on 1 % SOC change, (enabled) → Promise<void>
|
|
28
|
+
await gauge.setVoltageAlert(3.3, 4.25); // Voltage window, (minV, maxV) → Promise<void>
|
|
29
|
+
// 0 / 5.1 V disable the respective limit
|
|
30
|
+
console.log(await gauge.getVoltageAlert()); // () → Promise<{minV, maxV}>
|
|
31
|
+
await gauge.setResetVoltage(3.0); // Reset voltage, (volts) → Promise<void>
|
|
32
|
+
console.log(await gauge.getResetVoltage()); // () → Promise<number> V
|
|
33
|
+
await gauge.enableVoltageResetAlert(true); // Voltage reset asserts ALRT, (enabled) → Promise<void>
|
|
34
|
+
await gauge.setComparatorDisabled(false); // Hibernate comparator off, (disabled) → Promise<void>
|
|
35
|
+
|
|
36
|
+
await gauge.setHibernateThresholds(26.624, 0.06); // Hibernate thresholds, (hibThrPctPerH, actThrV) → Promise<void>
|
|
37
|
+
console.log(await gauge.getHibernateThresholds()); // () → Promise<{hibThrPctPerH, actThrV}>
|
|
38
|
+
await gauge.disableHibernate(); // Never hibernate, () → Promise<void>
|
|
39
|
+
await gauge.forceHibernate(); // Always hibernate, () → Promise<void>
|
|
40
|
+
await gauge.setHibernateThresholds(26.624, 0.06); // Restore the defaults
|
|
41
|
+
console.log(await gauge.isHibernating()); // Hibernate status, () → Promise<boolean>
|
|
42
|
+
|
|
43
|
+
console.log(await gauge.readStatus()); // STATUS register, () → Promise<number>
|
|
44
|
+
await gauge.clearStatus(MAX17048Full.SOURCE_RESET); // Clear flags and ALRT, (mask) → Promise<void>
|
|
45
|
+
console.log(await gauge.readConfig()); // CONFIG register, () → Promise<number>
|
|
46
|
+
await gauge.writeConfig(await gauge.readConfig()); // Write CONFIG, (value) → Promise<void>
|
|
47
|
+
|
|
48
|
+
console.log(await gauge.pollInterrupt()); // Alert sources, () → Promise<number>
|
|
49
|
+
// SOURCE_RESET / _OVERVOLTAGE / _UNDERVOLTAGE
|
|
50
|
+
// / _VRESET / _LOW_SOC / _SOC_CHANGE
|
|
51
|
+
await gauge.enableInterrupt(MAX17048Full.SOURCE_SOC_CHANGE); // Enable a source, (source) → Promise<void>
|
|
52
|
+
await gauge.disableInterrupt(MAX17048Full.SOURCE_SOC_CHANGE); // Disable a source, (source) → Promise<void>
|
|
53
|
+
await gauge.onInterrupt((status) => console.log('alert', status.toString(16))); // Subscribe to ALRT, (callback, {intPin}) → Promise<void>
|
|
54
|
+
await sleep(2000);
|
|
55
|
+
await gauge.offInterrupt(); // Unsubscribe, () → Promise<void>
|
|
56
|
+
|
|
57
|
+
await gauge.enableSleep(true); // Allow sleep mode, (enabled) → Promise<void>
|
|
58
|
+
await gauge.sleep(); // Sleep, () → Promise<void>
|
|
59
|
+
await gauge.wake(); // Wake up, () → Promise<void>
|
|
60
|
+
await gauge.enableSleep(false);
|
|
61
|
+
|
|
62
|
+
await gauge.quickStart(); // Restart the SOC estimate, () → Promise<void>
|
|
63
|
+
// only if the first SOC is clearly wrong
|
|
64
|
+
await gauge.reset(); // Power-on reset, () → Promise<void>; waits 1 s
|
|
65
|
+
await connection.close();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
main();
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { MAX17048Full } = require('../../../src/chips/power/max17048');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const connection = new I2CConnection(1, 0x36); // Create I²C connection, (bus, addr=0x36) → Connection
|
|
10
|
+
const gauge = new MAX17048Full(connection, 1); // Create MAX17048 driver, single Li-ion/LiPo cell
|
|
11
|
+
|
|
12
|
+
console.log(`version 0x${(await gauge.version()).toString(16)}, id 0x${(await gauge.chipId()).toString(16)}`);
|
|
13
|
+
await gauge.clearStatus(MAX17048Full.SOURCE_RESET); // Clear the reset indicator, (mask) → Promise<void>
|
|
14
|
+
|
|
15
|
+
// Battery fuel gauge: one line per second for 30 s
|
|
16
|
+
for (let n = 0; n < 30; n++) {
|
|
17
|
+
const v = await gauge.voltage();
|
|
18
|
+
const p = await gauge.percent();
|
|
19
|
+
const r = await gauge.chargeRate();
|
|
20
|
+
console.log(`${v.toFixed(3)} V ${p.toFixed(1)} % ${r.toFixed(1)} %/h`);
|
|
21
|
+
await sleep(1000);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
await gauge.setAlertSoc(10); // Low-SOC alert at 10 %, (percent) → Promise<void>
|
|
25
|
+
await gauge.setVoltageAlert(3.3, 4.25); // Voltage window 3.3-4.25 V, (minV, maxV) → Promise<void>
|
|
26
|
+
await gauge.onInterrupt((status) => console.log('alert 0x' + status.toString(16))); // Subscribe to ALRT, (callback, {intPin}) → Promise<void>
|
|
27
|
+
await sleep(5000);
|
|
28
|
+
await gauge.offInterrupt();
|
|
29
|
+
console.log('poll_interrupt:', await gauge.pollInterrupt()); // Without an ALRT pin, () → Promise<number>
|
|
30
|
+
|
|
31
|
+
for (const celsius of [5, 35]) {
|
|
32
|
+
await gauge.compensateTemperature(celsius); // RCOMP for the temperature, (celsius) → Promise<void>
|
|
33
|
+
console.log(`RCOMP at ${celsius} C: 0x${(await gauge.getRcomp()).toString(16)}`);
|
|
34
|
+
}
|
|
35
|
+
await gauge.compensateTemperature(20);
|
|
36
|
+
|
|
37
|
+
await gauge.disableHibernate(); // Never hibernate, () → Promise<void>
|
|
38
|
+
console.log('hibernating:', await gauge.isHibernating());
|
|
39
|
+
await gauge.setHibernateThresholds(26.624, 0.06); // Back to the defaults
|
|
40
|
+
|
|
41
|
+
await gauge.enableSleep(true); // Sleep round trip, (enabled) → Promise<void>
|
|
42
|
+
await gauge.sleep();
|
|
43
|
+
await sleep(1000);
|
|
44
|
+
await gauge.wake();
|
|
45
|
+
await gauge.enableSleep(false);
|
|
46
|
+
console.log('after wake:', (await gauge.voltage()).toFixed(3), 'V');
|
|
47
|
+
|
|
48
|
+
if (process.argv.includes('--quick-start')) {
|
|
49
|
+
await gauge.quickStart(); // Restart the SOC estimate, () → Promise<void>
|
|
50
|
+
await sleep(1000);
|
|
51
|
+
console.log('SOC after quick start:', (await gauge.percent()).toFixed(1), '%');
|
|
52
|
+
}
|
|
53
|
+
await connection.close();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
main();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { MAX17048Minimal } = require('../../../src/chips/power/max17048');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const connection = new I2CConnection(1, 0x36); // Create I²C connection, (bus, addr=0x36) → Connection
|
|
10
|
+
const gauge = new MAX17048Minimal(connection, 1); // Create MAX17048 driver, (connection, cells)
|
|
11
|
+
|
|
12
|
+
while (true) {
|
|
13
|
+
console.log((await gauge.voltage()).toFixed(3), 'V', // Cell voltage, () → Promise<number> V
|
|
14
|
+
(await gauge.percent()).toFixed(1), '%'); // State of charge, () → Promise<number> %
|
|
15
|
+
await sleep(1000);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
main();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { LPS22HBFull } = require('../../../src/chips/pressure/lps22hb');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5C', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const lps = new LPS22HBFull(connection); // Create LPS22HB driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const cid = await lps._readReg(0x0F, 1); // Read chip ID, (reg, n) → number
|
|
13
|
+
// returns 0xB1 for LPS22HB
|
|
14
|
+
console.log('chip_id=' + cid[0].toString(16));
|
|
15
|
+
await lps.configure(LPS22HBFull.ODR_10_HZ, 1, 1, LPS22HBFull.LPFP_BW_ODR_20, 0, 0); // Configure chip, (odr 0–5, bdu 0/1, enLpfp 0/1, lpfpCfg 0/1, lcEn 0/1, sim 0/1) → undefined
|
|
16
|
+
// writes CTRL_REG1 and updates LC_EN bit in RES_CONF
|
|
17
|
+
const sample = await lps.oneShot(); // Single-shot read, () → {pressure_Pa: number, temperature_C: number}
|
|
18
|
+
// triggers a one-shot conversion and waits for both ADCs to settle
|
|
19
|
+
const st = await lps.status(); // Read status register, () → number
|
|
20
|
+
await lps.setPressureOffset(0.0); // Set pressure offset, (offsetHPa) → undefined
|
|
21
|
+
// writes the reference-pressure correction into RPDS_L/RPDS_H
|
|
22
|
+
await lps.setAutozero(); // Enable AUTOZERO, () → undefined
|
|
23
|
+
// current pressure becomes the new zero reference
|
|
24
|
+
await lps.clearAutozero(); // Disable AUTOZERO, () → undefined
|
|
25
|
+
await lps.setAutorifp(); // Enable AUTOIFP, () → undefined
|
|
26
|
+
await lps.clearAutorifp(); // Disable AUTOIFP, () → undefined
|
|
27
|
+
await lps.configureInterrupt(1, 0, 0, 0, LPS22HBFull.INT_S_DATA_SIGNALS, 0, 0); // Configure INT pin, (drdy 0/1, fFth 0/1, fOvr 0/1, fFss5 0/1, intS 0–3, activeLow 0/1, openDrain 0/1) → undefined
|
|
28
|
+
// writes CTRL_REG3 with the selected routing and signal polarity
|
|
29
|
+
await lps.configurePressureInterrupt(1, 1, 5.0, 1); // Configure pressure interrupt, (highEn 0/1, lowEn 0/1, thresholdHPa, latch 0/1) → undefined
|
|
30
|
+
// programs THS_P_L/THS_P_H and arm bits in INTERRUPT_CFG
|
|
31
|
+
await lps.enableFifo(LPS22HBFull.FIFO_MODE_BYPASS, 0); // Enable FIFO, (mode 0–7, watermark 0–31) → undefined
|
|
32
|
+
await lps.disableFifo(); // Disable FIFO, () → undefined
|
|
33
|
+
const fs = await lps.fifoStatus(); // Read FIFO status, () → number
|
|
34
|
+
await lps.resetLpf(); // Reset low-pass filter, () → undefined
|
|
35
|
+
await lps.reset(); // Soft reset chip, () → undefined
|
|
36
|
+
// writes CTRL_REG2 BOOT bit and re-applies CTRL_REG1 default
|
|
37
|
+
await lps.reboot(); // Reboot chip, () → undefined
|
|
38
|
+
// writes CTRL_REG2 BOOT and waits for INT_SOURCE BOOT to clear
|
|
39
|
+
const isrc = await lps.interruptStatus(); // Read interrupt source, () → number
|
|
40
|
+
console.log(`T=${sample.temperature_C.toFixed(2)} C, P=${sample.pressure_Pa.toFixed(1)} Pa, status=0x${st.toString(16)}, fifo=0x${fs.toString(16)}, intSrc=0x${isrc.toString(16)}`);
|
|
41
|
+
await connection.close();
|
|
42
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
43
|
+
})();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { LPS22HBFull } = require('../../../src/chips/pressure/lps22hb');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5C', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
|
|
10
|
+
// --- Altimeter preset: 10 Hz ODR with ODR/20 LPF ---
|
|
11
|
+
// 10 Hz gives a fresh pressure sample every 100 ms, and the on-chip low-pass
|
|
12
|
+
// filter at ODR/20 (~0.5 Hz cutoff) suppresses door-slam / ventilation noise.
|
|
13
|
+
const lps = new LPS22HBFull(connection); // Create LPS22HB driver, (connection)
|
|
14
|
+
|
|
15
|
+
(async () => {
|
|
16
|
+
await lps.configure(LPS22HBFull.ODR_10_HZ, 1, 1, LPS22HBFull.LPFP_BW_ODR_20, 0, 0); // Configure chip, (odr=10Hz, bdu=1, enLpfp=1, lpfpCfg=ODR/20, lcEn=0, sim=0) → undefined
|
|
17
|
+
|
|
18
|
+
// --- Settle, then log altitude at 1 Hz for 10 s ---
|
|
19
|
+
// The first AUTOZERO locks the local zero reference; later samples drift
|
|
20
|
+
// relative to it, giving floor-to-floor relative altitude changes.
|
|
21
|
+
await lps.setAutozero(); // Enable AUTOZERO, () → undefined
|
|
22
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
23
|
+
|
|
24
|
+
const alts = [];
|
|
25
|
+
for (let n = 0; n < 10; n++) {
|
|
26
|
+
const sample = await lps.oneShot(); // Single-shot read, () → {pressure_Pa: number, temperature_C: number}
|
|
27
|
+
const alt = 44330 * (1 - Math.pow(sample.pressure_Pa / 101325, 1 / 5.255));
|
|
28
|
+
alts.push(alt);
|
|
29
|
+
console.log(`${n}s: T=${sample.temperature_C.toFixed(2)} C, P=${sample.pressure_Pa.toFixed(1)} Pa, alt=${alt.toFixed(2)} m`);
|
|
30
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// --- Refresh the AUTOZERO every 10 s to track weather drift ---
|
|
34
|
+
// Atmospheric pressure changes by ~1 hPa per 8 m of equivalent altitude,
|
|
35
|
+
// so an unattended sensor will wander several metres over 10 minutes if
|
|
36
|
+
// the reference isn't periodically re-zeroed.
|
|
37
|
+
await lps.setAutozero(); // Enable AUTOZERO, () → undefined
|
|
38
|
+
|
|
39
|
+
console.log(`Altimeter: min=${Math.min(...alts).toFixed(2)} max=${Math.max(...alts).toFixed(2)} span=${(Math.max(...alts) - Math.min(...alts)).toFixed(2)} m`);
|
|
40
|
+
|
|
41
|
+
await connection.close();
|
|
42
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
43
|
+
})();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { LPS22HBMinimal } = require('../../../src/chips/pressure/lps22hb');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5C', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const lps = new LPS22HBMinimal(connection); // Create LPS22HB driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
for (let i = 0; i < 5; i++) {
|
|
13
|
+
const t = await lps.temperature(); // Read temperature, () → number °C
|
|
14
|
+
const p = await lps.pressure(); // Read pressure, () → number Pa
|
|
15
|
+
console.log(`${t.toFixed(2)} C, ${p.toFixed(1)} Pa`);
|
|
16
|
+
}
|
|
17
|
+
await connection.close();
|
|
18
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
19
|
+
})();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { MPL115A2Full } = require('../../../src/chips/pressure/mpl115a2');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x60', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const baro = new MPL115A2Full(connection); // Create MPL115A2 driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const k = await baro.coefficients(); // Read cached coefficients, () → {a0, b1, b2, c12}
|
|
13
|
+
await baro.reloadCoefficients(); // Re-read coefficient block, () → void
|
|
14
|
+
// use after a power cycle
|
|
15
|
+
const data = await baro.read(); // One conversion, () → {pressure_pa, temperature_c}
|
|
16
|
+
const raw = await baro.readRaw(); // One conversion, () → {padc, tadc} 10-bit counts
|
|
17
|
+
const p = await baro.compensate(raw.padc, raw.tadc); // Compensate raw counts, (padc, tadc) → float Pa
|
|
18
|
+
// pure function, no bus access
|
|
19
|
+
const hpa = await baro.pressureHpa(); // Read pressure, () → float hPa
|
|
20
|
+
const alt = await baro.altitude(); // Compute altitude, (seaLevelPa=101325) → float m
|
|
21
|
+
// barometric formula, informative
|
|
22
|
+
console.log('coef', k, data, raw, p, hpa, alt);
|
|
23
|
+
await connection.close();
|
|
24
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
25
|
+
})();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { MPL115A2Full } = require('../../../src/chips/pressure/mpl115a2');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x60', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const baro = new MPL115A2Full(connection); // Create MPL115A2 driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
console.log('Coefficients:', await baro.coefficients()); // Read cached coefficients, () → {a0, b1, b2, c12}
|
|
13
|
+
|
|
14
|
+
// --- Barometer log ---
|
|
15
|
+
// Reads the pressure every 2 s for 30 s, printing Pa, hPa, approximate
|
|
16
|
+
// altitude and the raw counts, then the min/max of the run.
|
|
17
|
+
const values = [];
|
|
18
|
+
for (let n = 0; n < 15; n++) {
|
|
19
|
+
const pa = await baro.readPressure(); // Read pressure, () → float Pa
|
|
20
|
+
const hpa = await baro.pressureHpa(); // Read pressure, () → float hPa
|
|
21
|
+
const alt = await baro.altitude(); // Compute altitude, (seaLevelPa=101325) → float m
|
|
22
|
+
const raw = await baro.readRaw(); // One conversion, () → {padc, tadc}
|
|
23
|
+
values.push(pa);
|
|
24
|
+
console.log(`${n * 2}s: ${pa.toFixed(0)} Pa, ${hpa.toFixed(2)} hPa, alt=${alt.toFixed(1)} m, raw=(${raw.padc}, ${raw.tadc})`);
|
|
25
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
26
|
+
}
|
|
27
|
+
console.log(`Summary: min=${Math.min(...values).toFixed(0)} Pa, max=${Math.max(...values).toFixed(0)} Pa`);
|
|
28
|
+
await connection.close();
|
|
29
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
30
|
+
})();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { MPL115A2Minimal } = require('../../../src/chips/pressure/mpl115a2');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x60', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const baro = new MPL115A2Minimal(connection); // Create MPL115A2 driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
for (let i = 0; i < 5; i++) {
|
|
13
|
+
const p = await baro.readPressure(); // Read pressure, () → float Pa
|
|
14
|
+
const t = await baro.readTemperature(); // Read temperature, () → float C (approximate)
|
|
15
|
+
console.log(`${p.toFixed(0)} Pa, ${t.toFixed(1)} C`);
|
|
16
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
17
|
+
}
|
|
18
|
+
await connection.close();
|
|
19
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
20
|
+
})();
|