periph 1.5.3 → 1.5.4

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.
Files changed (53) hide show
  1. package/README.md +12 -0
  2. package/examples/color/isl29125/complete.js +57 -0
  3. package/examples/color/isl29125/demo.js +77 -0
  4. package/examples/color/isl29125/minimal.js +23 -0
  5. package/examples/environmental/bme688/complete.js +48 -0
  6. package/examples/environmental/bme688/demo.js +47 -0
  7. package/examples/environmental/bme688/minimal.js +21 -0
  8. package/examples/humidity/hts221/complete.js +83 -0
  9. package/examples/humidity/hts221/demo.js +94 -0
  10. package/examples/humidity/hts221/minimal.js +22 -0
  11. package/examples/humidity/htu31d/complete.js +50 -0
  12. package/examples/humidity/htu31d/demo.js +65 -0
  13. package/examples/humidity/htu31d/minimal.js +22 -0
  14. package/examples/humidity/shtc3/complete.js +48 -0
  15. package/examples/humidity/shtc3/demo.js +45 -0
  16. package/examples/humidity/shtc3/minimal.js +22 -0
  17. package/examples/led/saa1064/complete.js +51 -0
  18. package/examples/led/saa1064/demo.js +54 -0
  19. package/examples/led/saa1064/minimal.js +23 -0
  20. package/examples/light/apds9250/complete.js +71 -0
  21. package/examples/light/apds9250/demo.js +79 -0
  22. package/examples/light/apds9250/minimal.js +23 -0
  23. package/examples/light/bh1750/complete.js +46 -0
  24. package/examples/light/bh1750/demo.js +52 -0
  25. package/examples/light/bh1750/minimal.js +22 -0
  26. package/examples/light/si1132/complete.js +70 -0
  27. package/examples/light/si1132/demo.js +73 -0
  28. package/examples/light/si1132/minimal.js +22 -0
  29. package/examples/pressure/mpl3115a2/complete.js +49 -0
  30. package/examples/pressure/mpl3115a2/demo.js +48 -0
  31. package/examples/pressure/mpl3115a2/minimal.js +22 -0
  32. package/examples/pressure/ms5607/complete.js +49 -0
  33. package/examples/pressure/ms5607/demo.js +65 -0
  34. package/examples/pressure/ms5607/minimal.js +22 -0
  35. package/examples/pressure/ms5611/complete.js +49 -0
  36. package/examples/pressure/ms5611/demo.js +65 -0
  37. package/examples/pressure/ms5611/minimal.js +22 -0
  38. package/package.json +1 -1
  39. package/src/chips/color/isl29125.js +379 -0
  40. package/src/chips/environmental/bme688.js +573 -0
  41. package/src/chips/humidity/hts221.js +369 -0
  42. package/src/chips/humidity/htu31d.js +242 -0
  43. package/src/chips/humidity/shtc3.js +239 -0
  44. package/src/chips/led/saa1064.js +241 -0
  45. package/src/chips/light/apds9250.js +431 -0
  46. package/src/chips/light/bh1750.js +196 -0
  47. package/src/chips/light/si1132.js +416 -0
  48. package/src/chips/pressure/mpl3115a2.js +459 -0
  49. package/src/chips/pressure/ms5607.js +290 -0
  50. package/src/chips/pressure/ms5611.js +290 -0
  51. package/src/discovery/registry.js +12 -12
  52. package/examples/gpio/.gitkeep +0 -0
  53. package/src/chips/gpio/.gitkeep +0 -0
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { Si1132Full } = require('../../../src/chips/light/si1132');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x60', 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=0x60) → Connection
11
+ const sensor = new Si1132Full(connection); // Create Si1132 driver, (connection) → void
12
+
13
+ async function main() {
14
+ await sensor.init(); // Verify PART_ID and start forced mode, () → void
15
+ // writes HW_KEY, UV coefficients and CHLIST
16
+ console.log(await sensor.read()); // Read UV index and ALS counts, () → {uv_index, visible, infrared}
17
+ // forced measurement of the enabled channels
18
+ console.log('uv index', await sensor.readUvIndex()); // Read UV index, () → number
19
+ // forced measurement, AUX_DATA / 100
20
+ console.log('visible', await sensor.readVisible()); // Read visible counts, () → number
21
+ // forced measurement, 16-bit raw count
22
+ console.log('infrared', await sensor.readInfrared()); // Read infrared counts, () → number
23
+ // forced measurement, 16-bit raw count
24
+ console.log('raw', await sensor.readRaw()); // Read data registers, () → {visible, infrared, aux}
25
+ // latest values, no measurement is started
26
+ console.log('temperature raw', await sensor.readTemperatureRaw()); // Read die temperature, () → number
27
+ // auxiliary channel, relative only
28
+ console.log('vdd raw', await sensor.readVddRaw()); // Read supply voltage, () → number
29
+ // auxiliary channel with AUX_ADCMUX = 0x75
30
+
31
+ await sensor.setChannels(true, true, true); // Select channels, (uv, visible, infrared, aux=false) → void
32
+ // writes CHLIST; uv and aux cannot be combined
33
+ await sensor.setGain(2, 2); // Set ADC gain, (visible 0–7, infrared 0–7) → void
34
+ // integration time x 2^n plus the recommended recovery count
35
+ await sensor.setGain(0, 0);
36
+ await sensor.setHighRange(false, false); // Set high signal range, (visible, infrared) → void
37
+ // true divides the sensitivity by 14.5 (direct sunlight)
38
+ await sensor.setAlignment(true, true); // Set data alignment, (visibleLow, infraredLow) → void
39
+ // true reports the least significant 16 bits
40
+ await sensor.setUvCoefficients([0x7B, 0x6B, 0x01, 0x00]); // Set UV coefficients, (ucoef 4 bytes) → void
41
+ // datasheet defaults for an open-air UV index
42
+ console.log('calibration', await sensor.readCalibration()); // Read factory calibration, () → number[12]
43
+ // GET_CAL then registers 0x22–0x2D
44
+
45
+ await sensor.force(); // Start a forced measurement, () → void
46
+ // ALS_FORCE without waiting
47
+ await sleep(50);
48
+ console.log('ready', await sensor.measurementReady()); // Check measurement done, () → boolean
49
+ // IRQ_STATUS.ALS_INT
50
+ console.log('response', await sensor.readResponse()); // Read command response, () → {counter, error}
51
+ // RESPONSE decoded, error 0 = none
52
+ console.log('poll', await sensor.pollInterrupt()); // Poll interrupt status, () → number
53
+ // reads IRQ_STATUS and clears it
54
+
55
+ await sensor.startAutonomous(0.5); // Start autonomous mode, (interval 0–2.05 s) → void
56
+ // MEAS_RATE in 31.25 µs steps then ALS_AUTO
57
+ await sensor.onInterrupt((status) => console.log('INT status 0x' + status.toString(16))); // Subscribe to measurements, (callback, intPin=null) → void
58
+ // falling edge on INT, else polling
59
+ await sleep(2000);
60
+ await sensor.offInterrupt(); // Unsubscribe, () → void
61
+ await sensor.pause(); // Pause autonomous mode, () → void
62
+ // ALS_PAUSE
63
+ await sensor.setI2cAddress(0x60); // Set I²C address, (address 7-bit) → void
64
+ // I2C_ADDR parameter then BUSADDR, volatile
65
+ await sensor.reset(); // Reset the chip, () → void
66
+ // RESET, waits, writes HW_KEY again
67
+ connection.close();
68
+ }
69
+
70
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { Si1132Full } = require('../../../src/chips/light/si1132');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x60', 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=0x60) → Connection
11
+ const sensor = new Si1132Full(connection); // Create Si1132 driver, (connection) → void
12
+
13
+ async function main() {
14
+ await sensor.init(); // Verify PART_ID and start forced mode, () → void
15
+
16
+ // --- Identify the chip and show the factory calibration ---
17
+ // The calibration bytes belong to the Silicon Labs Si114x calibration
18
+ // structure; they let you correct part-to-part variation of the UV index.
19
+ console.log('calibration', await sensor.readCalibration()); // Read factory calibration, () → number[12]
20
+
21
+ // --- UV and light monitor: 20 readings, 1 s apart ---
22
+ // Index, visible and infrared counts side by side show whether the
23
+ // light is sunlight (high infrared share) or artificial.
24
+ for (let i = 0; i < 20; i++) {
25
+ const m = await sensor.read(); // Read UV index and ALS counts, () → {uv_index, visible, infrared}
26
+ console.log('UV %s vis %d ir %d', m.uv_index.toFixed(2), m.visible, m.infrared);
27
+ console.log('raw', await sensor.readRaw()); // Read data registers, () → {visible, infrared, aux}
28
+ await sleep(1000);
29
+ }
30
+
31
+ // --- Effect of gain and of the high-range bits on the same light ---
32
+ // Each gain step doubles the integration time (and the count); the high
33
+ // range divides the sensitivity by 14.5 for direct sunlight.
34
+ for (const gain of [0, 2, 4]) {
35
+ await sensor.setGain(gain, gain); // Set ADC gain, (visible 0–7, infrared 0–7) → void
36
+ console.log('gain', gain, await sensor.read()); // Read UV index and ALS counts, () → object
37
+ }
38
+ await sensor.setGain(0, 0); // Set ADC gain, (visible 0–7, infrared 0–7) → void
39
+ await sensor.setHighRange(true, true); // Set high signal range, (visible, infrared) → void
40
+ console.log('high range', await sensor.read()); // Read UV index and ALS counts, () → object
41
+ await sensor.setHighRange(false, false); // Set high signal range, (visible, infrared) → void
42
+ await sensor.setAlignment(false, false); // Set data alignment, (visibleLow, infraredLow) → void
43
+ await sensor.setUvCoefficients([0x7B, 0x6B, 0x01, 0x00]); // Set UV coefficients, (ucoef 4 bytes) → void
44
+
45
+ // --- Auxiliary channels ---
46
+ // The temperature value is relative only; the VDD count tracks the supply.
47
+ console.log('temperature raw', await sensor.readTemperatureRaw()); // Read die temperature, () → number
48
+ console.log('vdd raw', await sensor.readVddRaw()); // Read supply voltage, () → number
49
+
50
+ // --- Autonomous mode at 0.5 s with the interrupt ---
51
+ // Every completed measurement raises INT; the callback prints the status.
52
+ await sensor.startAutonomous(0.5); // Start autonomous mode, (interval 0–2.05 s) → void
53
+ await sensor.onInterrupt((status) => console.log('INT 0x' + status.toString(16))); // Subscribe to measurements, (callback, intPin=null) → void
54
+ await sleep(5000);
55
+ await sensor.offInterrupt(); // Unsubscribe, () → void
56
+ await sensor.pause(); // Pause autonomous mode, () → void
57
+ console.log('ready', await sensor.measurementReady(), 'response', await sensor.readResponse()); // Check measurement done / read RESPONSE, () → boolean / object
58
+ await sensor.enableInterrupt(); // Enable the INT pin, () → void
59
+ await sensor.force(); // Start a forced measurement, () → void
60
+ await sleep(50);
61
+ console.log('poll', await sensor.pollInterrupt()); // Poll interrupt status, () → number
62
+ await sensor.disableInterrupt(); // Disable the INT pin, () → void
63
+
64
+ // --- UV only, then shut down ---
65
+ // Dropping the ALS channels shortens each measurement.
66
+ await sensor.setChannels(true, false, false); // Select channels, (uv, visible, infrared, aux=false) → void
67
+ console.log('UV only', (await sensor.readUvIndex()).toFixed(2)); // Read UV index, () → number
68
+ await sensor.setI2cAddress(0x60); // Set I²C address, (address 7-bit) → void
69
+ await sensor.reset(); // Reset the chip, () → void
70
+ connection.close();
71
+ }
72
+
73
+ 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 { Si1132Minimal } = require('../../../src/chips/light/si1132');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x60', 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=0x60) → Connection
11
+ const sensor = new Si1132Minimal(connection); // Create Si1132 driver, (connection) → void
12
+
13
+ async function main() {
14
+ await sensor.init(); // Verify PART_ID and start forced mode, () → void
15
+ while (true) {
16
+ const m = await sensor.read(); // Read UV index and ALS counts, () → {uv_index: number, visible: number counts, infrared: number counts}
17
+ console.log('UV %s, visible %d, infrared %d', m.uv_index.toFixed(2), m.visible, m.infrared);
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 { MPL3115A2Full } = require('../../../src/chips/pressure/mpl3115a2');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x60', 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=0x60) → Connection
11
+ const sensor = new MPL3115A2Full(connection); // Create MPL3115A2 driver, (connection) → void
12
+
13
+ async function main() {
14
+ await sensor.init(); // Reset and apply defaults, () → void
15
+ console.log('who_am_i 0x%s', (await sensor.whoAmI()).toString(16)); // Read WHO_AM_I, () → number (0xC4)
16
+ await sensor.setOversample(32); // Oversample ratio, (ratio 1/2/4/…/128) → void
17
+ console.log('oversample', sensor.getOversample()); // Current ratio, () → number
18
+ await sensor.setSeaLevelPressure(101325); // Sea-level reference, (pa) → void
19
+ await sensor.setOffsets(0, 0, 0); // Offset trims, (pressurePa, temperatureC, altitudeM) → void
20
+ console.log(await sensor.readPressure(), await sensor.readTemperature()); // One-shot values, () → number Pa / number °C
21
+ console.log(await sensor.read()); // Both together, () → {pressure_pa, temperature_c}
22
+ console.log(await sensor.readAltitude()); // Altimeter reading, () → number m
23
+ await sensor.setMode(false); // Back to barometer, (altimeter) → void
24
+ await sensor.startContinuous(0); // Periodic acquisition, (stepExp 0-15) → void
25
+ console.log('active', await sensor.isActive()); // Check ACTIVE mode, () → boolean
26
+ console.log(await sensor.readContinuous()); // Wait for PTDR and read, () → {value, temperature_c}
27
+ console.log(await sensor.dataReady(), await sensor.readDelta()); // Data ready / change since previous, () → boolean / [number, number]
28
+ await sensor.stopContinuous(); // Back to STANDBY, () → void
29
+ await sensor.setTarget(100000, 200, -5, 3); // Threshold targets, (value, window, temperatureC, temperatureWindow) → void
30
+ await sensor.loadCurrentAsTarget(); // Current output as target, () → void
31
+ console.log(await sensor.readMinMax()); // Captured extremes, () → {p_min, p_max, t_min, t_max}
32
+ await sensor.clearMinMax(); // Clear extremes, () → void
33
+ await sensor.fifoSetup(MPL3115A2Full.FIFO_CIRCULAR, 16); // Configure the FIFO, (mode 0/1/2, watermark 0-63) → void
34
+ console.log(await sensor.fifoStatus()); // FIFO state, () → [overflow, watermark, count]
35
+ console.log(await sensor.fifoRead()); // Drain the FIFO, () → [[value, temperature_c], …]
36
+ await sensor.fifoSetup(MPL3115A2Full.FIFO_OFF); // FIFO off, (mode, watermark = 0) → void
37
+ await sensor.setInterruptPins(false, false, false, false); // INT polarity / drive, (polarity1, openDrain1, polarity2, openDrain2) → void
38
+ await sensor.enableInterrupt(MPL3115A2Full.SOURCE_DRDY, 1); // Route a source to INT1, (source, pin 1/2) → void
39
+ console.log('INT_SOURCE 0x%s', (await sensor.pollInterrupt()).toString(16)); // Read INT_SOURCE, () → number
40
+ await sensor.onInterrupt((status) => console.log('INT 0x%s', status.toString(16)), { pin: 1 }); // Subscribe, (callback, {pin, intPin}) → void
41
+ await sleep(1000);
42
+ await sensor.offInterrupt(); // Unsubscribe, () → void
43
+ await sensor.disableInterrupt(MPL3115A2Full.SOURCE_DRDY); // Disable the source, (source) → void
44
+ await sensor.reset(); // Software reset and defaults, () → void
45
+ await connection.close();
46
+ console.log('===DONE: 0 passed, 0 failed===');
47
+ }
48
+
49
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { MPL3115A2Full } = require('../../../src/chips/pressure/mpl3115a2');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x60', 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=0x60) → Connection
11
+ const sensor = new MPL3115A2Full(connection); // Create MPL3115A2 driver, (connection) → void
12
+
13
+ async function main() {
14
+ await sensor.init(); // Reset and apply defaults, () → void
15
+
16
+ // --- Weather and altitude station ---
17
+ // Sets the local sea-level pressure, takes three barometer readings, switches to
18
+ // altimeter mode for three altitude readings, collects 16 samples in the circular
19
+ // FIFO and prints their minimum, maximum and mean, then arms a temperature
20
+ // threshold on INT1 and reports the captured extremes.
21
+ await sensor.setSeaLevelPressure(101325); // Sea-level reference, (pa) → void
22
+ for (let i = 0; i < 3; i++) {
23
+ const m = await sensor.read(); // Read pressure and temperature, () → {pressure_pa, temperature_c}
24
+ console.log('%s Pa %s C', m.pressure_pa.toFixed(2), m.temperature_c.toFixed(2));
25
+ await sleep(5000);
26
+ }
27
+ for (let i = 0; i < 3; i++) {
28
+ console.log('altitude %s m', (await sensor.readAltitude()).toFixed(2)); // Read altitude, () → number m
29
+ }
30
+ await sensor.setMode(false); // Back to barometer, (altimeter) → void
31
+ await sensor.setOversample(16); // Faster conversions, (ratio) → void
32
+ await sensor.fifoSetup(MPL3115A2Full.FIFO_CIRCULAR, 16); // Circular FIFO, watermark 16, (mode, watermark) → void
33
+ await sensor.startContinuous(0); // One sample per second, (stepExp 0-15) → void
34
+ while (!(await sensor.fifoStatus())[1]) await sleep(1000); // Wait for the watermark flag, () → [overflow, watermark, count]
35
+ const samples = await sensor.fifoRead(); // Drain the FIFO, () → [[value Pa, temperature_c °C], …]
36
+ const values = samples.map((s) => s[0]);
37
+ const mean = values.reduce((a, b) => a + b, 0) / values.length;
38
+ console.log('n=%d min %s max %s mean %s Pa', values.length, Math.min(...values).toFixed(2), Math.max(...values).toFixed(2), mean.toFixed(2));
39
+ await sensor.setTarget(0, 0, Math.trunc(samples[samples.length - 1][1]) + 1, 0); // Temperature target, (value, window, temperatureC, temperatureWindow) → void
40
+ await sensor.enableInterrupt(MPL3115A2Full.SOURCE_TTH, 1); // Route temperature threshold to INT1, (source, pin) → void
41
+ console.log('INT_SOURCE 0x%s', (await sensor.pollInterrupt()).toString(16)); // Read INT_SOURCE, () → number
42
+ await sensor.stopContinuous(); // Back to STANDBY, () → void
43
+ await sensor.fifoSetup(MPL3115A2Full.FIFO_OFF); // FIFO off, (mode) → void
44
+ console.log(await sensor.readMinMax()); // Captured extremes, () → {p_min, p_max, t_min, t_max}
45
+ await connection.close();
46
+ }
47
+
48
+ 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 { MPL3115A2Minimal } = require('../../../src/chips/pressure/mpl3115a2');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x60', 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=0x60) → Connection
11
+ const sensor = new MPL3115A2Minimal(connection); // Create MPL3115A2 driver, (connection) → void
12
+
13
+ async function main() {
14
+ await sensor.init(); // Reset and apply defaults, () → void
15
+ while (true) {
16
+ const m = await sensor.read(); // Read pressure and temperature, () → {pressure_pa: number Pa, temperature_c: number °C}
17
+ console.log('%s Pa, %s C', m.pressure_pa.toFixed(2), m.temperature_c.toFixed(2));
18
+ await sleep(2000);
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 { 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
+ 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(MS5607Full.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 { 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); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "periph",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "JavaScript drivers for peripheral chips (I2C, SPI)",
5
5
  "main": "src/index.js",
6
6
  "keywords": [