periph 1.5.3 → 1.6.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 +18 -0
- package/examples/color/isl29125/complete.js +57 -0
- package/examples/color/isl29125/demo.js +77 -0
- package/examples/color/isl29125/minimal.js +23 -0
- package/examples/environmental/bme688/complete.js +48 -0
- package/examples/environmental/bme688/demo.js +47 -0
- package/examples/environmental/bme688/minimal.js +21 -0
- package/examples/gas/ccs811/complete.js +87 -0
- package/examples/gas/ccs811/demo.js +108 -0
- package/examples/gas/ccs811/minimal.js +20 -0
- package/examples/gas/rrh46410/complete.js +78 -0
- package/examples/gas/rrh46410/demo.js +86 -0
- package/examples/gas/rrh46410/minimal.js +21 -0
- package/examples/humidity/hts221/complete.js +83 -0
- package/examples/humidity/hts221/demo.js +94 -0
- package/examples/humidity/hts221/minimal.js +22 -0
- package/examples/humidity/htu31d/complete.js +50 -0
- package/examples/humidity/htu31d/demo.js +65 -0
- package/examples/humidity/htu31d/minimal.js +22 -0
- package/examples/humidity/shtc3/complete.js +48 -0
- package/examples/humidity/shtc3/demo.js +45 -0
- package/examples/humidity/shtc3/minimal.js +22 -0
- package/examples/led/saa1064/complete.js +51 -0
- package/examples/led/saa1064/demo.js +54 -0
- package/examples/led/saa1064/minimal.js +23 -0
- package/examples/light/apds9250/complete.js +71 -0
- package/examples/light/apds9250/demo.js +79 -0
- package/examples/light/apds9250/minimal.js +23 -0
- package/examples/light/bh1750/complete.js +46 -0
- package/examples/light/bh1750/demo.js +52 -0
- package/examples/light/bh1750/minimal.js +22 -0
- package/examples/light/si1132/complete.js +70 -0
- package/examples/light/si1132/demo.js +73 -0
- package/examples/light/si1132/minimal.js +22 -0
- package/examples/light/si1133/complete.js +89 -0
- package/examples/light/si1133/demo.js +93 -0
- package/examples/light/si1133/minimal.js +22 -0
- package/examples/light/si1145/complete.js +93 -0
- package/examples/light/si1145/demo.js +98 -0
- package/examples/light/si1145/minimal.js +22 -0
- package/examples/pressure/mpl3115a2/complete.js +49 -0
- package/examples/pressure/mpl3115a2/demo.js +48 -0
- package/examples/pressure/mpl3115a2/minimal.js +22 -0
- package/examples/pressure/ms5607/complete.js +49 -0
- package/examples/pressure/ms5607/demo.js +65 -0
- package/examples/pressure/ms5607/minimal.js +22 -0
- package/examples/pressure/ms5611/complete.js +49 -0
- package/examples/pressure/ms5611/demo.js +65 -0
- package/examples/pressure/ms5611/minimal.js +22 -0
- package/examples/pressure/spl06/complete.js +81 -0
- package/examples/pressure/spl06/demo.js +106 -0
- package/examples/pressure/spl06/minimal.js +22 -0
- package/examples/rfid/pn532/complete.js +99 -0
- package/examples/rfid/pn532/demo.js +121 -0
- package/examples/rfid/pn532/minimal.js +22 -0
- package/package.json +1 -1
- package/src/chips/color/isl29125.js +379 -0
- package/src/chips/environmental/bme688.js +573 -0
- package/src/chips/gas/ccs811.js +400 -0
- package/src/chips/gas/rrh46410.js +534 -0
- package/src/chips/humidity/hts221.js +369 -0
- package/src/chips/humidity/htu31d.js +242 -0
- package/src/chips/humidity/shtc3.js +239 -0
- package/src/chips/led/saa1064.js +241 -0
- package/src/chips/light/apds9250.js +431 -0
- package/src/chips/light/bh1750.js +196 -0
- package/src/chips/light/si1132.js +416 -0
- package/src/chips/light/si1133.js +583 -0
- package/src/chips/light/si1145.js +630 -0
- package/src/chips/pressure/mpl3115a2.js +459 -0
- package/src/chips/pressure/ms5607.js +290 -0
- package/src/chips/pressure/ms5611.js +290 -0
- package/src/chips/pressure/spl06.js +461 -0
- package/src/chips/rfid/pn532.js +513 -0
- package/src/connection/i2c.js +46 -13
- package/src/connection/smbus.js +21 -8
- package/src/discovery/registry.js +18 -18
- package/examples/gpio/.gitkeep +0 -0
- package/src/chips/gpio/.gitkeep +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { MS5607Full } = require('../../../src/chips/pressure/ms5607');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x77', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x77) → Connection
|
|
11
|
+
const sensor = new MS5607Full(connection); // Create MS5607 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Reset, read PROM, verify CRC-4, () → void
|
|
15
|
+
|
|
16
|
+
// --- Calibration data ---
|
|
17
|
+
// Six coefficients and a CRC-4 are factory-programmed into the PROM.
|
|
18
|
+
console.log('PROM', (await sensor.readProm()).map((w) => '0x' + w.toString(16))); // Read the PROM words, () → number[8]
|
|
19
|
+
console.log('CRC ok', sensor.promCrcOk()); // Verify the PROM CRC-4, () → boolean
|
|
20
|
+
console.log('coefficients', sensor.coefficients()); // Calibration coefficients, () → [c1 .. c6]
|
|
21
|
+
console.log('serial', sensor.serialCode()); // Serial code, () → number
|
|
22
|
+
|
|
23
|
+
// --- Barometric altimeter / variometer: 20 s, one reading per second ---
|
|
24
|
+
const reference = await sensor.readPressure(); // Read pressure only, () → number Pa
|
|
25
|
+
let previous = null;
|
|
26
|
+
let lowest = 100.0;
|
|
27
|
+
for (let i = 0; i < 20; i++) {
|
|
28
|
+
const m = await sensor.read(); // Read temperature and pressure, () → {temperature_c: number °C, pressure_pa: number Pa}
|
|
29
|
+
lowest = Math.min(lowest, m.temperature_c);
|
|
30
|
+
const height = 44330.0 * (1.0 - Math.pow(m.pressure_pa / reference, 1.0 / 5.255));
|
|
31
|
+
const climb = previous === null ? 0.0 : height - previous;
|
|
32
|
+
previous = height;
|
|
33
|
+
console.log('%s C %s Pa %s m %s m/s', m.temperature_c.toFixed(2), m.pressure_pa.toFixed(1), height.toFixed(2), climb.toFixed(2));
|
|
34
|
+
await sleep(1000);
|
|
35
|
+
}
|
|
36
|
+
console.log('altitude vs standard sea level %s m', (await sensor.altitude()).toFixed(1)); // Altitude from pressure, (seaLevelPa=101325) → number m
|
|
37
|
+
|
|
38
|
+
// --- Noise and time versus oversampling: ten readings each ---
|
|
39
|
+
for (const osr of [256, 512, 1024, 2048, 4096]) {
|
|
40
|
+
sensor.setOversampling(osr); // Select oversampling ratio, (osr) → void
|
|
41
|
+
const start = Date.now();
|
|
42
|
+
const values = [];
|
|
43
|
+
for (let n = 0; n < 10; n++) values.push(await sensor.readPressure());
|
|
44
|
+
console.log('OSR %d %s ms/read spread %s Pa', osr, ((Date.now() - start) / 10).toFixed(1), (Math.max(...values) - Math.min(...values)).toFixed(1));
|
|
45
|
+
}
|
|
46
|
+
sensor.setOversampling(4096);
|
|
47
|
+
|
|
48
|
+
// --- Raw codes with and without the second-order correction ---
|
|
49
|
+
const [d1, d2] = await sensor.readRaw(); // Read raw ADC codes, () → [number, number]
|
|
50
|
+
console.log('raw', d1, d2);
|
|
51
|
+
console.log('first order ', sensor.compensate(d1, d2, false)); // Compensate raw codes, (d1, d2, secondOrder) → {temperature_c, pressure_pa}
|
|
52
|
+
console.log('second order', sensor.compensate(d1, d2));
|
|
53
|
+
console.log('lowest temperature seen %s C', lowest.toFixed(2));
|
|
54
|
+
|
|
55
|
+
// --- Non-blocking conversion ---
|
|
56
|
+
await sensor.startConversion(MS5607Full.PRESSURE); // Start a conversion, (kind, osr?) → void
|
|
57
|
+
await sleep(sensor.conversionTime() * 1000 + 1); // Max conversion time, (osr?) → number s
|
|
58
|
+
console.log('D1', await sensor.readAdc()); // Read the ADC result, () → number
|
|
59
|
+
|
|
60
|
+
// --- Finish with a reset ---
|
|
61
|
+
await sensor.reset(); // Reset and reload PROM, () → void
|
|
62
|
+
connection.close();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { MS5607Minimal } = require('../../../src/chips/pressure/ms5607');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x77', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x77) → Connection
|
|
11
|
+
const sensor = new MS5607Minimal(connection); // Create MS5607 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Reset, read PROM, verify CRC-4, () → void
|
|
15
|
+
while (true) {
|
|
16
|
+
const m = await sensor.read(); // Read temperature and pressure, () → {temperature_c: number °C, pressure_pa: number Pa}
|
|
17
|
+
console.log('%s C, %s Pa', m.temperature_c.toFixed(2), m.pressure_pa.toFixed(1));
|
|
18
|
+
await sleep(1000);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { MS5611Full } = require('../../../src/chips/pressure/ms5611');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x77', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x77) → Connection
|
|
11
|
+
const sensor = new MS5611Full(connection); // Create MS5611 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Reset, read PROM, verify CRC-4, () → void
|
|
15
|
+
|
|
16
|
+
console.log(await sensor.read()); // Read temperature and pressure, () → {temperature_c: number °C, pressure_pa: number Pa}
|
|
17
|
+
// OSR 4096, second-order compensation applied
|
|
18
|
+
console.log(await sensor.readPressure()); // Read pressure only, () → number Pa
|
|
19
|
+
console.log(await sensor.readTemperature()); // Read temperature only, () → number °C
|
|
20
|
+
// converts D2 only
|
|
21
|
+
const [d1, d2] = await sensor.readRaw(); // Read raw ADC codes, () → [number, number]
|
|
22
|
+
// [d1 pressure, d2 temperature], 24-bit
|
|
23
|
+
console.log(d1, d2);
|
|
24
|
+
console.log(sensor.compensate(d1, d2)); // Compensate raw codes, (d1, d2, secondOrder=true) → {temperature_c, pressure_pa}
|
|
25
|
+
// pure computation, no bus access
|
|
26
|
+
console.log(sensor.compensate(d1, d2, false));
|
|
27
|
+
sensor.setOversampling(1024); // Select oversampling ratio, (osr) → void
|
|
28
|
+
// 256, 512, 1024, 2048 or 4096
|
|
29
|
+
console.log(sensor.getOversampling()); // Current oversampling ratio, () → number
|
|
30
|
+
console.log(sensor.conversionTime()); // Max conversion time, (osr?) → number s
|
|
31
|
+
await sensor.startConversion(MS5611Full.TEMPERATURE); // Start a conversion, (kind, osr?) → void
|
|
32
|
+
// PRESSURE = D1, TEMPERATURE = D2; non-blocking
|
|
33
|
+
await sleep(sensor.conversionTime() * 1000 + 1);
|
|
34
|
+
console.log(await sensor.readAdc()); // Read the ADC result, () → number
|
|
35
|
+
// only after the conversion time, 24-bit
|
|
36
|
+
sensor.setOversampling(4096);
|
|
37
|
+
console.log(await sensor.readProm()); // Read the PROM words, () → number[8]
|
|
38
|
+
console.log(sensor.coefficients()); // Calibration coefficients, () → [c1 .. c6]
|
|
39
|
+
console.log(sensor.promCrcOk()); // Verify the PROM CRC-4, () → boolean
|
|
40
|
+
console.log(sensor.serialCode()); // Serial code, () → number
|
|
41
|
+
// PROM word 7 bits 15:4
|
|
42
|
+
console.log(await sensor.altitude()); // Altitude from pressure, (seaLevelPa=101325) → number m
|
|
43
|
+
// international barometric formula
|
|
44
|
+
await sensor.reset(); // Reset and reload PROM, () → void
|
|
45
|
+
// 0x1E, 3 ms wait
|
|
46
|
+
connection.close();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { MS5611Full } = require('../../../src/chips/pressure/ms5611');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x77', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x77) → Connection
|
|
11
|
+
const sensor = new MS5611Full(connection); // Create MS5611 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Reset, read PROM, verify CRC-4, () → void
|
|
15
|
+
|
|
16
|
+
// --- Calibration data ---
|
|
17
|
+
// Six coefficients and a CRC-4 are factory-programmed into the PROM.
|
|
18
|
+
console.log('PROM', (await sensor.readProm()).map((w) => '0x' + w.toString(16))); // Read the PROM words, () → number[8]
|
|
19
|
+
console.log('CRC ok', sensor.promCrcOk()); // Verify the PROM CRC-4, () → boolean
|
|
20
|
+
console.log('coefficients', sensor.coefficients()); // Calibration coefficients, () → [c1 .. c6]
|
|
21
|
+
console.log('serial', sensor.serialCode()); // Serial code, () → number
|
|
22
|
+
|
|
23
|
+
// --- Barometric altimeter / variometer: 20 s, one reading per second ---
|
|
24
|
+
const reference = await sensor.readPressure(); // Read pressure only, () → number Pa
|
|
25
|
+
let previous = null;
|
|
26
|
+
let lowest = 100.0;
|
|
27
|
+
for (let i = 0; i < 20; i++) {
|
|
28
|
+
const m = await sensor.read(); // Read temperature and pressure, () → {temperature_c: number °C, pressure_pa: number Pa}
|
|
29
|
+
lowest = Math.min(lowest, m.temperature_c);
|
|
30
|
+
const height = 44330.0 * (1.0 - Math.pow(m.pressure_pa / reference, 1.0 / 5.255));
|
|
31
|
+
const climb = previous === null ? 0.0 : height - previous;
|
|
32
|
+
previous = height;
|
|
33
|
+
console.log('%s C %s Pa %s m %s m/s', m.temperature_c.toFixed(2), m.pressure_pa.toFixed(1), height.toFixed(2), climb.toFixed(2));
|
|
34
|
+
await sleep(1000);
|
|
35
|
+
}
|
|
36
|
+
console.log('altitude vs standard sea level %s m', (await sensor.altitude()).toFixed(1)); // Altitude from pressure, (seaLevelPa=101325) → number m
|
|
37
|
+
|
|
38
|
+
// --- Noise and time versus oversampling: ten readings each ---
|
|
39
|
+
for (const osr of [256, 512, 1024, 2048, 4096]) {
|
|
40
|
+
sensor.setOversampling(osr); // Select oversampling ratio, (osr) → void
|
|
41
|
+
const start = Date.now();
|
|
42
|
+
const values = [];
|
|
43
|
+
for (let n = 0; n < 10; n++) values.push(await sensor.readPressure());
|
|
44
|
+
console.log('OSR %d %s ms/read spread %s Pa', osr, ((Date.now() - start) / 10).toFixed(1), (Math.max(...values) - Math.min(...values)).toFixed(1));
|
|
45
|
+
}
|
|
46
|
+
sensor.setOversampling(4096);
|
|
47
|
+
|
|
48
|
+
// --- Raw codes with and without the second-order correction ---
|
|
49
|
+
const [d1, d2] = await sensor.readRaw(); // Read raw ADC codes, () → [number, number]
|
|
50
|
+
console.log('raw', d1, d2);
|
|
51
|
+
console.log('first order ', sensor.compensate(d1, d2, false)); // Compensate raw codes, (d1, d2, secondOrder) → {temperature_c, pressure_pa}
|
|
52
|
+
console.log('second order', sensor.compensate(d1, d2));
|
|
53
|
+
console.log('lowest temperature seen %s C', lowest.toFixed(2));
|
|
54
|
+
|
|
55
|
+
// --- Non-blocking conversion ---
|
|
56
|
+
await sensor.startConversion(MS5611Full.PRESSURE); // Start a conversion, (kind, osr?) → void
|
|
57
|
+
await sleep(sensor.conversionTime() * 1000 + 1); // Max conversion time, (osr?) → number s
|
|
58
|
+
console.log('D1', await sensor.readAdc()); // Read the ADC result, () → number
|
|
59
|
+
|
|
60
|
+
// --- Finish with a reset ---
|
|
61
|
+
await sensor.reset(); // Reset and reload PROM, () → void
|
|
62
|
+
connection.close();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { MS5611Minimal } = require('../../../src/chips/pressure/ms5611');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x77', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x77) → Connection
|
|
11
|
+
const sensor = new MS5611Minimal(connection); // Create MS5611 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Reset, read PROM, verify CRC-4, () → void
|
|
15
|
+
while (true) {
|
|
16
|
+
const m = await sensor.read(); // Read temperature and pressure, () → {temperature_c: number °C, pressure_pa: number Pa}
|
|
17
|
+
console.log('%s C, %s Pa', m.temperature_c.toFixed(2), m.pressure_pa.toFixed(1));
|
|
18
|
+
await sleep(1000);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { SPL06Full } = require('../../../src/chips/pressure/spl06');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x77', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x77) → Connection
|
|
11
|
+
// Default address 0x77 (SDO high or open); 0x76 with SDO low.
|
|
12
|
+
const sensor = new SPL06Full(connection); // Create SPL06 driver, (connection) → void
|
|
13
|
+
// Stores the connection only; no bus traffic yet.
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
await sensor.init(); // Check ID, read coefficients, apply defaults, () → void
|
|
17
|
+
// ID 0x10, waits for COEF_RDY, 16x pressure / 1x external temperature.
|
|
18
|
+
console.log(sensor.coefficients()); // Decoded calibration, () → {c0, c1, c00, c10, c01, c11, c20, c21, c30}
|
|
19
|
+
// The nine factory coefficients used by every compensation.
|
|
20
|
+
console.log(await sensor.read()); // Temperature and pressure, () → {temperature_c °C, pressure_pa Pa}
|
|
21
|
+
// Command mode: one temperature, then one pressure measurement.
|
|
22
|
+
console.log(await sensor.readPressure()); // Pressure, () → number Pa
|
|
23
|
+
// Measures temperature first, because the compensation needs it.
|
|
24
|
+
console.log(await sensor.readTemperature()); // Temperature, () → number °C
|
|
25
|
+
// One temperature measurement only.
|
|
26
|
+
const [praw, traw] = await sensor.readRaw(); // Raw results, () → [praw, traw]
|
|
27
|
+
// Signed 24-bit values from the result registers.
|
|
28
|
+
console.log(sensor.compensate(praw, traw, 16, 1)); // Compensate raw values, (praw, traw, pOversampling, tOversampling) → {temperature_c, pressure_pa}
|
|
29
|
+
// Pure computation with the stored coefficients; no bus access.
|
|
30
|
+
console.log(await sensor.altitude(101325)); // Altitude, (seaLevelPa=101325) → number m
|
|
31
|
+
// International barometric formula against the given sea-level pressure.
|
|
32
|
+
|
|
33
|
+
await sensor.setPressureConfig(64, 4); // Pressure oversampling and rate, (oversampling=16, rate=1) → void
|
|
34
|
+
// 64x oversampling, 4 background readings per second; sets P_SHIFT.
|
|
35
|
+
await sensor.setTemperatureConfig(2, 4); // Temperature oversampling and rate, (oversampling=1, rate=1) → void
|
|
36
|
+
// 2x oversampling, 4 per second; always keeps the external sensor.
|
|
37
|
+
await sensor.startContinuous(true, true); // Background mode, (pressure=true, temperature=true) → void
|
|
38
|
+
// MEAS_CTRL = 111: the chip measures both on its own.
|
|
39
|
+
console.log(await sensor.readContinuous()); // Latest background result, () → {temperature_c, pressure_pa}
|
|
40
|
+
// Waits for both ready flags; does not start a measurement.
|
|
41
|
+
console.log(await sensor.dataReady()); // Ready flags, () → [pressureReady, temperatureReady]
|
|
42
|
+
// MEAS_CFG.PRS_RDY and TMP_RDY.
|
|
43
|
+
await sensor.stop(); // Standby, () → void
|
|
44
|
+
// MEAS_CTRL = 000.
|
|
45
|
+
|
|
46
|
+
await sensor.enableFifo(); // FIFO on, () → void
|
|
47
|
+
// Background results now queue in the 32-entry FIFO.
|
|
48
|
+
await sensor.startContinuous(); // Background mode, (pressure=true, temperature=true) → void
|
|
49
|
+
// Fill the FIFO for a second.
|
|
50
|
+
await sleep(1000);
|
|
51
|
+
await sensor.stop(); // Standby, () → void
|
|
52
|
+
// Stop adding entries.
|
|
53
|
+
console.log(await sensor.fifoStatus()); // FIFO state, () → [empty, full]
|
|
54
|
+
// FIFO_STS flags.
|
|
55
|
+
console.log(await sensor.readFifo()); // Drain FIFO, () → [{kind, value}]
|
|
56
|
+
// "pressure" in Pa or "temperature" in °C, in measured order.
|
|
57
|
+
await sensor.flushFifo(); // Flush FIFO, () → void
|
|
58
|
+
// Discards any remaining entries.
|
|
59
|
+
await sensor.disableFifo(); // FIFO off, () → void
|
|
60
|
+
// Results go to the result registers again.
|
|
61
|
+
|
|
62
|
+
await sensor.enableInterrupt(SPL06Full.SOURCE_PRESSURE); // Enable interrupt source, (source) → void
|
|
63
|
+
// Pressure-ready interrupt on SDO (active low).
|
|
64
|
+
console.log(await sensor.pollInterrupt()); // Read and clear INT_STS, () → number
|
|
65
|
+
// Bitmask of SOURCE_PRESSURE / SOURCE_TEMPERATURE / SOURCE_FIFO_FULL.
|
|
66
|
+
await sensor.onInterrupt((status) => console.log('INT', status)); // Subscribe, (callback, intPin=null) → void
|
|
67
|
+
// Uses the connection's INT pin, or a 5 ms polling timer without one.
|
|
68
|
+
await sensor.read(); // Trigger a measurement, () → {temperature_c, pressure_pa}
|
|
69
|
+
// The pressure result raises the interrupt.
|
|
70
|
+
await sleep(100);
|
|
71
|
+
await sensor.offInterrupt(); // Unsubscribe, () → void
|
|
72
|
+
// Removes this driver's handler only.
|
|
73
|
+
await sensor.disableInterrupt(SPL06Full.SOURCE_PRESSURE); // Disable interrupt source, (source) → void
|
|
74
|
+
// Clears CFG_REG.INT_PRS.
|
|
75
|
+
|
|
76
|
+
await sensor.reset(); // Soft reset, () → void
|
|
77
|
+
// RESET = 0x09, re-reads the coefficients and restores the init defaults.
|
|
78
|
+
await connection.close();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { SPL06Full } = require('../../../src/chips/pressure/spl06');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x77', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x77) → Connection
|
|
11
|
+
const sensor = new SPL06Full(connection); // Create SPL06 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
// --- Identity and calibration ---
|
|
15
|
+
// init() checks ID = 0x10; the nine coefficients are factory-trimmed per
|
|
16
|
+
// part and drive every compensated value below.
|
|
17
|
+
await sensor.init(); // Check ID, read coefficients, apply defaults, () → void
|
|
18
|
+
console.log('ID 0x10 verified', sensor.coefficients()); // Decoded calibration, () → {c0 … c30}
|
|
19
|
+
|
|
20
|
+
// --- Altimeter: 20 s at 1 Hz, altitude relative to the first reading ---
|
|
21
|
+
// The first pressure becomes the reference level, so the altitude column
|
|
22
|
+
// shows how far the sensor moved since start (about 12 Pa per metre).
|
|
23
|
+
const p0 = await sensor.readPressure(); // Reference pressure, () → number Pa
|
|
24
|
+
for (let i = 0; i < 20; i++) {
|
|
25
|
+
const m = await sensor.read(); // Temperature and pressure, () → {temperature_c °C, pressure_pa Pa}
|
|
26
|
+
const t = await sensor.readTemperature(); // Temperature only, () → number °C
|
|
27
|
+
const h = await sensor.altitude(p0); // Altitude vs. reference, (seaLevelPa) → number m
|
|
28
|
+
console.log(`${i} s ${m.temperature_c.toFixed(2)} C (${t.toFixed(2)} C) ${m.pressure_pa.toFixed(2)} Pa ${h.toFixed(2)} m`);
|
|
29
|
+
await sleep(1000);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// --- Oversampling: noise and measurement time at 1x, 16x and 128x ---
|
|
33
|
+
// More oversampling means less noise but longer measurements; above 8x
|
|
34
|
+
// the driver sets P_SHIFT automatically.
|
|
35
|
+
for (const osr of [1, 16, 128]) {
|
|
36
|
+
await sensor.setPressureConfig(osr, 1); // Pressure oversampling, (oversampling, rate) → void
|
|
37
|
+
const values = [];
|
|
38
|
+
const start = Date.now();
|
|
39
|
+
for (let j = 0; j < 10; j++) values.push(await sensor.readPressure()); // Pressure, () → number Pa
|
|
40
|
+
const per = (Date.now() - start) / 10;
|
|
41
|
+
const mean = values.reduce((a, b) => a + b, 0) / values.length;
|
|
42
|
+
const sd = Math.sqrt(values.reduce((a, v) => a + (v - mean) ** 2, 0) / values.length);
|
|
43
|
+
console.log(`${osr}x: mean ${mean.toFixed(2)} Pa sd ${sd.toFixed(2)} Pa ${per.toFixed(1)} ms per reading`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// --- Variometer: background mode at 8 Hz ---
|
|
47
|
+
// The chip measures on its own; readContinuous only fetches the latest
|
|
48
|
+
// results, so the host never waits for a conversion it started itself.
|
|
49
|
+
await sensor.setPressureConfig(16, 8); // 16x, 8 Hz, (oversampling, rate) → void
|
|
50
|
+
await sensor.setTemperatureConfig(1, 8); // 1x, 8 Hz, (oversampling, rate) → void
|
|
51
|
+
await sensor.startContinuous(true, true); // Background mode, (pressure, temperature) → void
|
|
52
|
+
let last = null;
|
|
53
|
+
for (let i = 0; i < 16; i++) {
|
|
54
|
+
const c = await sensor.readContinuous(); // Latest results, () → {temperature_c, pressure_pa}
|
|
55
|
+
if (last !== null) console.log(`${c.pressure_pa.toFixed(2)} Pa climb ${(-(c.pressure_pa - last) / 12 * 8).toFixed(2)} m/s`);
|
|
56
|
+
last = c.pressure_pa;
|
|
57
|
+
}
|
|
58
|
+
console.log('ready flags', await sensor.dataReady()); // Ready flags, () → [pressureReady, temperatureReady]
|
|
59
|
+
await sensor.stop(); // Standby, () → void
|
|
60
|
+
|
|
61
|
+
// --- FIFO: let the chip collect 32 results, then read them in one go ---
|
|
62
|
+
// Each entry's LSB marks it as pressure or temperature; the host can sleep
|
|
63
|
+
// while the chip fills the FIFO (32 entries = 2 s at 8 Hz for both).
|
|
64
|
+
await sensor.flushFifo(); // Empty the FIFO, () → void
|
|
65
|
+
await sensor.enableFifo(); // FIFO on, () → void
|
|
66
|
+
await sensor.startContinuous(); // Background mode, (pressure=true, temperature=true) → void
|
|
67
|
+
for (let i = 0; i < 50 && !(await sensor.fifoStatus())[1]; i++) { // Wait for full, () → [empty, full]
|
|
68
|
+
await sleep(100);
|
|
69
|
+
}
|
|
70
|
+
await sensor.stop(); // Standby, () → void
|
|
71
|
+
const entries = await sensor.readFifo(); // Drain FIFO, () → [{kind, value}]
|
|
72
|
+
const pressures = entries.filter((e) => e.kind === 'pressure').map((e) => e.value);
|
|
73
|
+
const pmean = pressures.reduce((a, b) => a + b, 0) / Math.max(pressures.length, 1);
|
|
74
|
+
console.log(`${entries.length} FIFO entries, ${pressures.length} pressure, mean ${pmean.toFixed(2)} Pa`);
|
|
75
|
+
await sensor.disableFifo(); // FIFO off, () → void
|
|
76
|
+
|
|
77
|
+
// --- Data-ready interrupt ---
|
|
78
|
+
// SDO doubles as the interrupt line; the callback receives the INT_STS bits.
|
|
79
|
+
// Without an INT pin on the connection the driver polls INT_STS instead.
|
|
80
|
+
await sensor.enableInterrupt(SPL06Full.SOURCE_PRESSURE); // Pressure-ready interrupt, (source) → void
|
|
81
|
+
await sensor.pollInterrupt(); // Clear stale status, () → number
|
|
82
|
+
await sensor.onInterrupt((status) => console.log(`interrupt 0x${status.toString(16)}`)); // Subscribe, (callback, intPin=null) → void
|
|
83
|
+
await sensor.startContinuous(true, true); // Background mode, (pressure, temperature) → void
|
|
84
|
+
await sleep(2000);
|
|
85
|
+
await sensor.offInterrupt(); // Unsubscribe, () → void
|
|
86
|
+
await sensor.disableInterrupt(SPL06Full.SOURCE_PRESSURE); // Disable source, (source) → void
|
|
87
|
+
await sensor.stop(); // Standby, () → void
|
|
88
|
+
|
|
89
|
+
// --- Compensation by hand ---
|
|
90
|
+
// compensate() turns raw register values into SI units with the stored
|
|
91
|
+
// coefficients; useful for logging raw data and converting it later.
|
|
92
|
+
await sensor.setPressureConfig(16, 1); // Back to 16x, (oversampling, rate) → void
|
|
93
|
+
await sensor.setTemperatureConfig(1, 1); // Back to 1x, (oversampling, rate) → void
|
|
94
|
+
const [praw, traw] = await sensor.readRaw(); // Raw results, () → [praw, traw]
|
|
95
|
+
console.log('raw', praw, traw, '->', sensor.compensate(praw, traw, 16, 1)); // Compensate, (praw, traw, pOversampling, tOversampling) → {temperature_c, pressure_pa}
|
|
96
|
+
|
|
97
|
+
// --- Wrap up ---
|
|
98
|
+
// Standby, empty FIFO and a soft reset leave the chip as after power-up
|
|
99
|
+
// (plus the driver defaults).
|
|
100
|
+
await sensor.stop(); // Standby, () → void
|
|
101
|
+
await sensor.flushFifo(); // Empty the FIFO, () → void
|
|
102
|
+
await sensor.reset(); // Soft reset and defaults, () → void
|
|
103
|
+
await connection.close();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { SPL06Minimal } = require('../../../src/chips/pressure/spl06');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x77', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x77) → Connection
|
|
11
|
+
const sensor = new SPL06Minimal(connection); // Create SPL06 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Check ID, read coefficients, apply defaults, () → void
|
|
15
|
+
while (true) {
|
|
16
|
+
const m = await sensor.read(); // Measure temperature and pressure, () → {temperature_c: number °C, pressure_pa: number Pa}
|
|
17
|
+
console.log('%s Pa, %s C', m.pressure_pa.toFixed(2), m.temperature_c.toFixed(2));
|
|
18
|
+
await sleep(1000);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { PN532Full } = require('../../../src/chips/rfid/pn532');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x24', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x24) → Connection
|
|
11
|
+
// The PN532 address is fixed; I0 low and I1 high select the I²C interface.
|
|
12
|
+
const reader = new PN532Full(connection); // Create PN532 driver, (connection) → void
|
|
13
|
+
// Constructor stores the connection only; no bus traffic yet.
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
await reader.init(); // Wake, check firmware, SAM normal mode, finite retries, () → void
|
|
17
|
+
// GetFirmwareVersion (IC 0x32), SAMConfiguration normal mode, MxRtyPassiveActivation = 2.
|
|
18
|
+
|
|
19
|
+
console.log(await reader.firmwareVersion()); // GetFirmwareVersion, () → {ic, version, revision, support, iso14443a, iso14443b, iso18092}
|
|
20
|
+
// IC 0x32, firmware 1.6 on current parts; the support bits list the protocols.
|
|
21
|
+
console.log(await reader.generalStatus()); // GetGeneralStatus, () → {error, field, targets, samStatus}
|
|
22
|
+
// Last error code, external field detected, active targets, SAM status.
|
|
23
|
+
console.log(await reader.selfTest()); // Diagnose, (test=0x00) → boolean
|
|
24
|
+
// Communication line test: the chip echoes an 8-byte pattern.
|
|
25
|
+
console.log(await reader.selfTest(0x01)); // Diagnose, (test=0x01) → boolean
|
|
26
|
+
// ROM checksum test.
|
|
27
|
+
|
|
28
|
+
console.log('UID', await reader.readUid()); // Detect a type A card, (timeout=1.0 s) → Buffer | null
|
|
29
|
+
// InListPassiveTarget at 106 kbps type A, then InRelease.
|
|
30
|
+
|
|
31
|
+
const targets = await reader.listPassiveTargets({ baud: PN532Full.BAUD_106_A, maxTargets: 1 }); // InListPassiveTarget, ({baud=BAUD_106_A, maxTargets=1, initiatorData=[], timeout=1.0 s}) → Target[]
|
|
32
|
+
// Keeps the target active; target.tg is the logical number for the next commands.
|
|
33
|
+
if (targets.length) {
|
|
34
|
+
const t = targets[0];
|
|
35
|
+
console.log(t);
|
|
36
|
+
await reader.deselect(t.tg); // InDeselect, (target=0) → void
|
|
37
|
+
// Puts the card to sleep but keeps its information in the PN532.
|
|
38
|
+
await reader.select(t.tg); // InSelect, (target=0) → void
|
|
39
|
+
// Wakes and reselects the deselected card.
|
|
40
|
+
if (t.uid.length === 7) {
|
|
41
|
+
console.log(await reader.ntagReadPage(t.tg, 4)); // NTAG READ, (target, page) → Buffer (16)
|
|
42
|
+
// Returns pages 4..7 (16 bytes).
|
|
43
|
+
await reader.ntagWritePage(t.tg, 4, [1, 2, 3, 4]); // NTAG WRITE, (target, page, data 4 bytes) → void
|
|
44
|
+
// Writes one 4-byte user page.
|
|
45
|
+
} else {
|
|
46
|
+
await reader.mifareAuthenticate(t.tg, 4, Buffer.alloc(6, 0xFF), t.uid); // MIFARE auth, (target, block, key 6 bytes, uid, keyB=false) → void
|
|
47
|
+
// Key A authentication of sector 1 with the transport key.
|
|
48
|
+
const data = await reader.mifareReadBlock(t.tg, 4); // MIFARE READ, (target, block) → Buffer (16)
|
|
49
|
+
// Reads block 4.
|
|
50
|
+
await reader.mifareWriteBlock(t.tg, 4, data); // MIFARE WRITE, (target, block, data 16 bytes) → void
|
|
51
|
+
// Writes the same 16 bytes back.
|
|
52
|
+
}
|
|
53
|
+
console.log(await reader.dataExchange(t.tg, [0x30, 0x00])); // InDataExchange, (target, data) → Buffer
|
|
54
|
+
// Raw READ of block/page 0 with PN532 framing and CRC.
|
|
55
|
+
await reader.release(t.tg); // InRelease, (target=0) → void
|
|
56
|
+
// Ends the session with the card.
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await reader.setRfField(false); // RFConfiguration item 1, (on, autoRfca=false) → void
|
|
60
|
+
// RF field off; a card in the field loses power.
|
|
61
|
+
await reader.setRfField(true); // RFConfiguration item 1, (on, autoRfca=false) → void
|
|
62
|
+
// RF field back on.
|
|
63
|
+
await reader.setMaxRetries({ passiveActivation: 2 }); // RFConfiguration item 5, ({passiveActivation=2, atr=0xFF, psl=1}) → void
|
|
64
|
+
// 0xFF would retry forever.
|
|
65
|
+
const txMode = await reader.readRegister(0x6302); // ReadRegister, (address) → number
|
|
66
|
+
// 0x6302 is CIU_TxMode in the PN532's SFR space.
|
|
67
|
+
await reader.writeRegister(0x6302, txMode); // WriteRegister, (address, value) → void
|
|
68
|
+
// Writes the value back unchanged.
|
|
69
|
+
console.log(await reader.sendCommand(0x02)); // Raw command, (command, data=[], timeout=1.0 s) → Buffer
|
|
70
|
+
// GetFirmwareVersion through the raw frame interface.
|
|
71
|
+
try {
|
|
72
|
+
console.log(await reader.communicateThru([0x26])); // InCommunicateThru, (data) → Buffer
|
|
73
|
+
// Raw RF exchange with the current target; fails without one.
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.log('communicateThru:', e.message);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
await reader.startCommand(0x02); // Command without waiting, (command, data=[]) → void
|
|
79
|
+
// Writes the frame and reads the ACK only.
|
|
80
|
+
console.log(await reader.waitReady(1.0)); // Wait for a frame, (timeout s) → boolean
|
|
81
|
+
// Polls the status byte every 1 ms.
|
|
82
|
+
console.log(await reader.pollInterrupt()); // Frame ready?, () → boolean
|
|
83
|
+
// A single status-byte read.
|
|
84
|
+
console.log(await reader.readResponse(0x02)); // Read the pending response, (command, timeout=1.0 s) → Buffer
|
|
85
|
+
// Header, NACK, full frame, checksums.
|
|
86
|
+
|
|
87
|
+
await reader.onInterrupt(() => console.log('frame ready')); // Subscribe to IRQ, (callback, intPin=null) → void
|
|
88
|
+
// Falling edge on IRQ, or a 10 ms status-byte poll without an IRQ pin.
|
|
89
|
+
await reader.sendCommand(0x02); // Raw command, (command, data=[], timeout=1.0 s) → Buffer
|
|
90
|
+
await sleep(100);
|
|
91
|
+
await reader.offInterrupt(); // Unsubscribe, () → void
|
|
92
|
+
// Stops the edge handler or the polling timer.
|
|
93
|
+
|
|
94
|
+
await reader.powerDown(); // PowerDown, (wakeupSources=0x20) → void
|
|
95
|
+
// Sleeps until the next I²C access; the driver retries the wake-up write.
|
|
96
|
+
connection.close();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
main().catch(err => { console.error(err); process.exit(1); });
|