periph 1.5.2 → 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
package/README.md CHANGED
@@ -54,16 +54,19 @@ Each chip exposes two classes:
54
54
  | AM2320 | Environmental sensor | `periph/src/chips/environmental/am2320` |
55
55
  | APA102 | LED driver | `periph/src/chips/led/apa102` |
56
56
  | APDS-9930 | Light sensor | `periph/src/chips/light/apds-9930` |
57
+ | APDS9250 | Light sensor | `periph/src/chips/light/apds9250` |
57
58
  | APDS9960 | Light sensor | `periph/src/chips/light/apds9960` |
58
59
  | AS5600 | Magnetometer | `periph/src/chips/magnetometer/as5600` |
59
60
  | AS7262 | Color sensor | `periph/src/chips/color/as7262` |
60
61
  | AT24C02N | Memory | `periph/src/chips/memory/at24c02n` |
61
62
  | AT24C64 | Memory | `periph/src/chips/memory/at24c64` |
62
63
  | AXP2101 | Power monitor | `periph/src/chips/power/axp2101` |
64
+ | BH1750 | Light sensor | `periph/src/chips/light/bh1750` |
63
65
  | BMA150 | Accelerometer | `periph/src/chips/accelerometer/bma150` |
64
66
  | BMA180 | Accelerometer | `periph/src/chips/accelerometer/bma180` |
65
67
  | BME280 | Environmental sensor | `periph/src/chips/environmental/bme280` |
66
68
  | BME680 | Environmental sensor | `periph/src/chips/environmental/bme680` |
69
+ | BME688 | Environmental sensor | `periph/src/chips/environmental/bme688` |
67
70
  | BMP085 | Pressure sensor | `periph/src/chips/pressure/bmp085` |
68
71
  | BMP180 | Pressure sensor | `periph/src/chips/pressure/bmp180` |
69
72
  | BMP280 | Pressure sensor | `periph/src/chips/pressure/bmp280` |
@@ -88,7 +91,9 @@ Each chip exposes two classes:
88
91
  | HS30XX | Humidity sensor | `periph/src/chips/humidity/hs30xx` |
89
92
  | HS40XX | Humidity sensor | `periph/src/chips/humidity/hs40xx` |
90
93
  | HT16K33 | LED driver | `periph/src/chips/led/ht16k33` |
94
+ | HTS221 | Humidity sensor | `periph/src/chips/humidity/hts221` |
91
95
  | HTU21DF | Humidity sensor | `periph/src/chips/humidity/htu21df` |
96
+ | HTU31D | Humidity sensor | `periph/src/chips/humidity/htu31d` |
92
97
  | HX710A | ADC/DAC | `periph/src/chips/adc_dac/hx710a` |
93
98
  | HX710B | ADC/DAC | `periph/src/chips/adc_dac/hx710b` |
94
99
  | HX711 | ADC/DAC | `periph/src/chips/adc_dac/hx711` |
@@ -100,6 +105,7 @@ Each chip exposes two classes:
100
105
  | INA260 | Power monitor | `periph/src/chips/power/ina260` |
101
106
  | INA3221 | Power monitor | `periph/src/chips/power/ina3221` |
102
107
  | IS31FL3731 | LED driver | `periph/src/chips/led/is31fl3731` |
108
+ | ISL29125 | Color sensor | `periph/src/chips/color/isl29125` |
103
109
  | L3G4200D | Gyroscope | `periph/src/chips/gyroscope/l3g4200d` |
104
110
  | L3GD20H | Gyroscope | `periph/src/chips/gyroscope/l3gd20h` |
105
111
  | LC709203F | Power monitor | `periph/src/chips/power/lc709203f` |
@@ -125,10 +131,13 @@ Each chip exposes two classes:
125
131
  | MFRC522 | RFID/NFC | `periph/src/chips/rfid/mfrc522` |
126
132
  | MMA8451Q | Accelerometer | `periph/src/chips/accelerometer/mma8451q` |
127
133
  | MPL115A2 | Pressure sensor | `periph/src/chips/pressure/mpl115a2` |
134
+ | MPL3115A2 | Pressure sensor | `periph/src/chips/pressure/mpl3115a2` |
128
135
  | MPR121 | Other | `periph/src/chips/other/mpr121` |
129
136
  | MPU6050 | IMU | `periph/src/chips/imu/mpu6050` |
130
137
  | MPU9250 | IMU | `periph/src/chips/imu/mpu9250` |
131
138
  | MPU9255 | IMU | `periph/src/chips/imu/mpu9255` |
139
+ | MS5607 | Pressure sensor | `periph/src/chips/pressure/ms5607` |
140
+ | MS5611 | Pressure sensor | `periph/src/chips/pressure/ms5611` |
132
141
  | MX25L12845E | Memory | `periph/src/chips/memory/mx25l12845e` |
133
142
  | NEO6 | GNSS/GPS | `periph/src/chips/gnss/neo6` |
134
143
  | NEOPIXELRGBBASE | LED driver | `periph/src/chips/led/_NeoPixelRGBBase` |
@@ -150,9 +159,12 @@ Each chip exposes two classes:
150
159
  | QMI8658A | IMU | `periph/src/chips/imu/qmi8658a` |
151
160
  | RDA5807M | Comms | `periph/src/chips/comms/rda5807m` |
152
161
  | RFM9X | Comms | `periph/src/chips/comms/rfm9x` |
162
+ | SAA1064 | LED driver | `periph/src/chips/led/saa1064` |
153
163
  | SD_SPI | Memory | `periph/src/chips/memory/sd_spi` |
154
164
  | SH1106 | Display driver | `periph/src/chips/display/sh1106` |
155
165
  | SHT31 | Humidity sensor | `periph/src/chips/humidity/sht31` |
166
+ | SHTC3 | Humidity sensor | `periph/src/chips/humidity/shtc3` |
167
+ | SI1132 | Light sensor | `periph/src/chips/light/si1132` |
156
168
  | SI7021 | Humidity sensor | `periph/src/chips/humidity/si7021` |
157
169
  | SK6812RGBW | LED driver | `periph/src/chips/led/sk6812rgbw` |
158
170
  | SSD1305 | Display driver | `periph/src/chips/display/ssd1305` |
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ // Complete example: every API method of the Full driver.
4
+
5
+ const { I2CConnection } = require('periph/src/connection/i2c');
6
+ const { ISL29125Full } = require('periph/src/chips/color/isl29125');
7
+
8
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
9
+
10
+ (async () => {
11
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
12
+ const connection = new I2CConnection(bus, ISL29125Full.I2C_ADDRESS);
13
+ const sensor = new ISL29125Full(connection); // Create ISL29125 Full driver, (connection)
14
+ await sensor.init(); // Check DEVICE_ID, start RGB conversion, () → void
15
+
16
+ console.log('device id', (await sensor.deviceId()).toString(16)); // Read DEVICE_ID, () → number
17
+ // 0x7D for the ISL29125
18
+ console.log(await sensor.read()); // Read the three channels, () → {red, green, blue}
19
+ console.log(await sensor.readRed()); // Read the red channel, () → number
20
+ console.log(await sensor.readGreen()); // Read the green channel, () → number
21
+ console.log(await sensor.readBlue()); // Read the blue channel, () → number
22
+ console.log(await sensor.readRgb()); // Block-read without waiting, () → {red, green, blue}
23
+ console.log(await sensor.dataReady()); // Query CONVENF, () → boolean
24
+ // clears the status flags on the chip
25
+ await sensor.setMode('green'); // Select the channels, (mode) → void
26
+ // power_down, standby, green, red, blue, rgb, green_red, green_blue
27
+ await sensor.setMode('rgb');
28
+ await sensor.setRange(375); // Set the full-scale range, (lux) → void
29
+ // 375 or 10000
30
+ await sensor.setRange(10000);
31
+ await sensor.setResolution(12); // Set the ADC resolution, (bits) → void
32
+ // 12 or 16
33
+ await sensor.setResolution(16);
34
+ await sensor.setSync(false); // Select the conversion start, (external) → void
35
+ // true: rising edge of INT starts the conversion
36
+ await sensor.setIrCompensation(true, 0x3F); // Set the IR compensation, (offset, adjust) → void
37
+ // adjust 0-63; offset selects codes 106-169
38
+ await sensor.setThresholds(1000, 50000); // Set the threshold window, (low, high) → void
39
+ console.log(await sensor.getThresholds()); // Read the window, () → {low, high}
40
+ await sensor.setInterruptChannel('green'); // Choose the monitored channel, (channel) → void
41
+ // none, green, red or blue
42
+ await sensor.setPersistence(2); // Set the persistence, (count) → void
43
+ // 1, 2, 4 or 8 integration cycles
44
+ await sensor.enableInterrupt(ISL29125Full.SOURCE_THRESHOLD); // Enable the interrupt, (source) → void
45
+ // SOURCE_THRESHOLD or SOURCE_CONVERSION
46
+ await sensor.onInterrupt((s) => console.log('interrupt', s.toString(16))); // Subscribe, (callback, options) → void
47
+ await sleep(2000);
48
+ await sensor.offInterrupt(); // Unsubscribe, () → void
49
+ console.log((await sensor.pollInterrupt()).toString(16)); // Read and clear STATUS, () → number
50
+ await sensor.disableInterrupt(ISL29125Full.SOURCE_CONVERSION); // Disable the interrupt, (source) → void
51
+ console.log((await sensor.status()).toString(16)); // Raw STATUS, () → number
52
+ await sensor.setMode('power_down');
53
+ await sensor.softReset(); // Software reset, () → void
54
+ // all registers to defaults
55
+
56
+ await connection.close();
57
+ })();
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ // Demo: a colour sampler.
4
+ // Prints the device ID, samples R/G/B for 10 s and shows the colour as
5
+ // #rrggbb, compares the 375 lux and 10 000 lux ranges and the 12/16-bit
6
+ // resolutions, varies the IR compensation, reads green only, arms a threshold
7
+ // interrupt on green with persistence 2 and finishes with power-down and soft
8
+ // reset.
9
+
10
+ const { I2CConnection } = require('periph/src/connection/i2c');
11
+ const { ISL29125Full } = require('periph/src/chips/color/isl29125');
12
+
13
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
14
+ const hex2 = (v) => v.toString(16).padStart(2, '0');
15
+
16
+ function colour(c) {
17
+ const top = Math.max(c.red, c.green, c.blue, 1);
18
+ return '#' + [c.red, c.green, c.blue].map((v) => hex2(Math.floor(v * 255 / top))).join('');
19
+ }
20
+
21
+ (async () => {
22
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
23
+ const connection = new I2CConnection(bus, ISL29125Full.I2C_ADDRESS);
24
+ const sensor = new ISL29125Full(connection); // Create ISL29125 Full driver, (connection)
25
+ await sensor.init(); // Check DEVICE_ID, start RGB conversion, () → void
26
+
27
+ console.log('device id', (await sensor.deviceId()).toString(16)); // Read DEVICE_ID, () → number
28
+
29
+ for (let i = 0; i < 20; i++) {
30
+ const c = await sensor.read(); // Read the three channels, () → {red, green, blue}
31
+ console.log(colour(c), c.red, c.green, c.blue);
32
+ await sleep(500);
33
+ }
34
+
35
+ for (const lux of [375, 10000]) {
36
+ await sensor.setRange(lux); // Set the range, (lux) → void
37
+ await sleep(400);
38
+ console.log(lux, 'lux range', await sensor.readRgb()); // Read without waiting, () → {red, green, blue}
39
+ }
40
+ for (const bits of [12, 16]) {
41
+ await sensor.setResolution(bits); // Set the resolution, (bits) → void
42
+ await sleep(400);
43
+ console.log(bits, 'bit full scale', 2 ** bits - 1, await sensor.readRgb());
44
+ }
45
+ await sensor.setRange(10000);
46
+
47
+ for (const adjust of [0, 0x20, 0x3F]) {
48
+ await sensor.setIrCompensation(false, adjust); // Set the IR compensation, (offset, adjust) → void
49
+ await sleep(400);
50
+ console.log('IR compensation', adjust, await sensor.readRgb());
51
+ }
52
+ await sensor.setIrCompensation(true, 0x3F);
53
+
54
+ await sensor.setMode('green'); // Green only, (mode) → void
55
+ await sleep(300);
56
+ console.log('green only', await sensor.readGreen()); // Read green, () → number
57
+ await sensor.setMode('rgb');
58
+ console.log('ready', await sensor.dataReady()); // Query CONVENF, () → boolean
59
+
60
+ const base = await sensor.readGreen();
61
+ await sensor.setThresholds(Math.max(0, base - (base >> 2)), Math.min(0xFFFF, base + (base >> 2))); // Set the window, (low, high) → void
62
+ console.log('window', await sensor.getThresholds()); // Read the window, () → {low, high}
63
+ await sensor.setInterruptChannel('green'); // Choose the channel, (channel) → void
64
+ await sensor.setPersistence(2); // Set the persistence, (count) → void
65
+ await sensor.enableInterrupt(ISL29125Full.SOURCE_THRESHOLD); // Enable the interrupt, (source) → void
66
+ for (let i = 0; i < 20; i++) {
67
+ await sleep(500);
68
+ const st = await sensor.pollInterrupt(); // Read and clear STATUS, () → number
69
+ if (st & ISL29125Full.STATUS_THRESHOLD) console.log('window crossed, green', await sensor.readGreen());
70
+ }
71
+ await sensor.disableInterrupt(ISL29125Full.SOURCE_THRESHOLD); // Disable the interrupt, (source) → void
72
+ console.log((await sensor.status()).toString(16)); // Raw STATUS, () → number
73
+ await sensor.setMode('power_down'); // Power down, (mode) → void
74
+ await sensor.softReset(); // Software reset, () → void
75
+
76
+ await connection.close();
77
+ })();
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ // Minimal example: read red, green and blue counts once a second.
4
+
5
+ const { I2CConnection } = require('periph/src/connection/i2c');
6
+ const { ISL29125Minimal } = require('periph/src/chips/color/isl29125');
7
+
8
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
9
+
10
+ (async () => {
11
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
12
+ const connection = new I2CConnection(bus, ISL29125Minimal.I2C_ADDRESS);
13
+ const sensor = new ISL29125Minimal(connection); // Create ISL29125 driver, (connection)
14
+ await sensor.init(); // Check DEVICE_ID, start RGB conversion, () → void
15
+
16
+ for (let i = 0; i < 10; i++) {
17
+ const c = await sensor.read(); // Read the three channels, () → {red, green, blue} counts
18
+ console.log('R', c.red, 'G', c.green, 'B', c.blue);
19
+ await sleep(1000);
20
+ }
21
+
22
+ await connection.close();
23
+ })();
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+ const { I2CConnection } = require('../../../src/connection/i2c');
3
+ const { BME688Full } = require('../../../src/chips/environmental/bme688');
4
+
5
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
6
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
7
+
8
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
9
+ const bme = new BME688Full(connection); // Create BME688 driver, (connection)
10
+
11
+ (async () => {
12
+ const cid = await bme.chipId(); // Read chip ID, () → number
13
+ // returns 0x61 for BME688
14
+ console.log('chip_id=' + cid.toString(16));
15
+ const vid = await bme.variantId(); // Read variant ID, () → number
16
+ // returns 0x01 for the BME688 (tells it apart from the BME680)
17
+ console.log('variant_id=' + vid.toString(16));
18
+ await bme.configure(BME688Full.OSRS_X1, BME688Full.OSRS_X1, BME688Full.OSRS_X1, BME688Full.MODE_SLEEP, BME688Full.FILTER_0); // Configure chip, (osrsT 0–5, osrsP 0–5, osrsH 0–5, mode 0/1/2, filter 0–7) → undefined
19
+ // writes ctrl_hum, config, ctrl_meas in correct order
20
+ await bme.setOversampling(BME688Full.OSRS_X4, BME688Full.OSRS_X2, BME688Full.OSRS_X1); // Set oversampling, (osrsT 0–5, osrsP 0–5, osrsH 0–5) → undefined
21
+ // changes conversion time vs resolution trade-off
22
+ await bme.setFilter(BME688Full.FILTER_7); // Set IIR filter, (coeff 0–7) → undefined
23
+ // applies to temperature and pressure only
24
+ await bme.setHeater(320, 150); // Configure heater profile 0, (tempC, durationMs) → undefined
25
+ // sets target temperature and on-time for gas measurement
26
+ await bme.setHeaterProfile(1, 200, 100); // Configure heater profile 1, (index 0–9, tempC, durationMs) → undefined
27
+ await bme.selectHeaterProfile(0); // Select active profile, (index 0–9) → undefined
28
+ await bme.setGasEnabled(true); // Enable gas conversion, (enabled) → undefined
29
+ await bme.setHeaterOff(false); // Control heater override, (off) → undefined
30
+ await bme.setAmbientTemperature(25.0); // Override ambient for heater calc, (tempC) → undefined
31
+ // re-applies the active heater profile
32
+ const st = await bme.status(); // Read status register, () → number
33
+ // bit 7 = new_data, bit 6 = gas_measuring, bit 5 = measuring
34
+ const r = await bme.readAll(); // Read all sensors in one cycle, () → object
35
+ // returns {temperature, pressure, humidity, gasResistance}
36
+ const gv = await bme.gasValid(); // Check gas validity, () → boolean
37
+ const hs = await bme.heaterStable(); // Check heater stability, () → boolean
38
+ await bme.startParallel([[320, 1], [250, 2]], 100); // Start parallel mode, (steps=[[tempC, repeats]] 1–10 entries, sharedWaitMs) → undefined
39
+ // programs res_heat_x, gas_wait_x, gas_wait_shared, nb_conv, then mode=parallel
40
+ const fields = await bme.readParallel(); // Read new data fields, () → array of objects
41
+ // keys: step, subIndex, temperature, pressure, humidity, gasResistance, gasValid, heaterStable
42
+ await bme.stopParallel(); // Leave parallel mode, () → undefined
43
+ await bme.reset(); // Soft reset chip, () → undefined
44
+ // re-reads calibration and re-applies configuration
45
+ console.log(`T=${r.temperature.toFixed(1)} C, P=${r.pressure.toFixed(1)} hPa, RH=${r.humidity.toFixed(1)} %, R_gas=${r.gasResistance.toFixed(0)} Ohm`);
46
+ await connection.close();
47
+ console.log('===DONE: 0 passed, 0 failed===');
48
+ })();
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+ const { I2CConnection } = require('../../../src/connection/i2c');
3
+ const { BME688Full } = require('../../../src/chips/environmental/bme688');
4
+
5
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
6
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
7
+
8
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
9
+
10
+ function dewPoint(t, rh) {
11
+ // Magnus formula, SI units (degC, %RH)
12
+ const g = Math.log(Math.max(rh, 0.01) / 100) + 17.62 * t / (243.12 + t);
13
+ return 243.12 * g / (17.62 - g);
14
+ }
15
+
16
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
17
+
18
+ (async () => {
19
+ // --- Room air probe with parallel mode ---
20
+ // Part 1: ten forced-mode readings (T, RH, hPa, Ohm, dew point), one per 5 s.
21
+ // Part 2: parallel mode with a 3-step heater profile (320, 250 and 180 degC;
22
+ // repeats 1, 2, 1; shared wait 100 ms) for one minute, printing the gas
23
+ // resistance of every heater step, then back to sleep.
24
+ const bme = new BME688Full(connection); // Create BME688 driver, (connection)
25
+ await bme.configure(BME688Full.OSRS_X2, BME688Full.OSRS_X16, BME688Full.OSRS_X1, BME688Full.MODE_SLEEP, BME688Full.FILTER_15); // Configure chip, (osrsT=×2, osrsP=×16, osrsH=×1, mode=sleep, filter=15) → undefined
26
+ await bme.setHeater(320, 150); // Configure heater profile 0, (tempC=320, durationMs=150) → undefined
27
+
28
+ console.log('--- forced mode ---');
29
+ for (let n = 0; n < 10; n++) {
30
+ const r = await bme.readAll(); // Read all sensors in one cycle, () → object
31
+ console.log(`${n}: ${r.temperature.toFixed(1)} C, ${r.humidity.toFixed(1)} %RH, ${r.pressure.toFixed(1)} hPa, ${r.gasResistance.toFixed(0)} Ohm, dew ${dewPoint(r.temperature, r.humidity).toFixed(1)} C`);
32
+ await sleep(5000);
33
+ }
34
+
35
+ console.log('--- parallel mode ---');
36
+ await bme.startParallel([[320, 1], [250, 2], [180, 1]], 100); // Start parallel mode, (steps=[[tempC, repeats]], sharedWaitMs=100) → undefined
37
+ for (let n = 0; n < 60; n++) {
38
+ for (const f of await bme.readParallel()) { // Read the new data fields, () → array of objects
39
+ console.log(`step ${f.step} #${f.subIndex}: ${f.temperature.toFixed(1)} C, ${f.humidity.toFixed(1)} %RH, ${f.gasResistance.toFixed(0)} Ohm (valid=${f.gasValid}, stable=${f.heaterStable})`);
40
+ }
41
+ await sleep(1000);
42
+ }
43
+ await bme.stopParallel(); // Back to sleep, () → undefined
44
+
45
+ await connection.close();
46
+ console.log('===DONE: 0 passed, 0 failed===');
47
+ })();
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+ const { I2CConnection } = require('../../../src/connection/i2c');
3
+ const { BME688Minimal } = require('../../../src/chips/environmental/bme688');
4
+
5
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
6
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
7
+
8
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
9
+ const bme = new BME688Minimal(connection); // Create BME688 driver, (connection)
10
+
11
+ (async () => {
12
+ for (let i = 0; i < 5; i++) {
13
+ const t = await bme.temperature(); // Read temperature, () → number °C
14
+ const p = await bme.pressure(); // Read pressure, () → number hPa
15
+ const h = await bme.humidity(); // Read humidity, () → number %RH
16
+ const g = await bme.gasResistance(); // Read gas resistance, () → number Ω
17
+ console.log(`${t.toFixed(1)} C, ${p.toFixed(1)} hPa, ${h.toFixed(1)} %RH, ${g.toFixed(0)} Ohm`);
18
+ }
19
+ await connection.close();
20
+ console.log('===DONE: 0 passed, 0 failed===');
21
+ })();
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { HTS221Full } = require('../../../src/chips/humidity/hts221');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5F', 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=0x5F) → Connection
11
+ const sensor = new HTS221Full(connection); // Create HTS221 driver, (connection) → void
12
+
13
+ async function main() {
14
+ await sensor.init(); // Read calibration and start one-shot mode, () → void
15
+ // decodes the per-device two-point calibration
16
+ console.log('who am i 0x' + (await sensor.whoAmI()).toString(16)); // Read WHO_AM_I, () → number (0xBC)
17
+ // identifies the chip on the bus
18
+ const m = await sensor.read(); // Read temperature and humidity, () → {temperature_c °C, humidity_pct %rH}
19
+ // one-shot conversion, converted with the calibration
20
+ console.log(m.temperature_c.toFixed(2) + ' C', m.humidity_pct.toFixed(1) + ' %rH');
21
+ console.log('humidity', (await sensor.readHumidity()).toFixed(1)); // Read humidity only, () → number %rH
22
+ // one-shot conversion, clamped to 0–100
23
+ console.log('temperature', (await sensor.readTemperature()).toFixed(2)); // Read temperature only, () → number °C
24
+ // one-shot conversion
25
+ console.log('raw humidity', await sensor.readRawHumidity()); // Read raw humidity, () → number
26
+ // signed 16-bit ADC output
27
+ console.log('raw temperature', await sensor.readRawTemperature()); // Read raw temperature, () → number
28
+ // signed 16-bit ADC output
29
+ console.log('calibration', await sensor.readCalibration()); // Read calibration, () → object
30
+ // decoded two-point coefficients
31
+ console.log('dew point', (await sensor.dewPoint()).toFixed(2)); // Compute dew point, () → number °C
32
+ // Magnus formula over one measurement
33
+ console.log('status', await sensor.status()); // Read STATUS_REG, () → number
34
+ // H_DA = 0x02, T_DA = 0x01
35
+ console.log('data ready', await sensor.dataReady()); // Check data available, () → boolean
36
+ // both H_DA and T_DA set
37
+
38
+ await sensor.setOutputDataRate(1); // Set output data rate, (hz 0|1|7|12.5) → void
39
+ // continuous sampling at 1 Hz
40
+ console.log('rate', await sensor.getOutputDataRate(), 'Hz'); // Get output data rate, () → number Hz
41
+ // decodes CTRL_REG1.ODR
42
+ await sleep(1200);
43
+ const c = await sensor.readContinuous(); // Read latest sample, () → {temperature_c °C, humidity_pct %rH}
44
+ // no conversion is started
45
+ console.log('continuous', c);
46
+ await sensor.setOutputDataRate(0); // Set output data rate, (hz 0|1|7|12.5) → void
47
+ // back to one-shot mode
48
+
49
+ await sensor.setAveraging(32, 64); // Set averaging, (temperatureSamples 2–256, humiditySamples 4–512) → void
50
+ // more samples lower the noise and lengthen the conversion
51
+ console.log('averaging', await sensor.getAveraging()); // Get averaging, () → [number, number]
52
+ // [temperature samples, humidity samples]
53
+ await sensor.setAveraging(16, 32);
54
+ await sensor.setBlockDataUpdate(true); // Set block data update, (enabled) → void
55
+ // keeps LSB/MSB of one sample consistent
56
+
57
+ await sensor.setHeater(true); // Switch the heater, (on) → void
58
+ // drives off condensation; do not measure while on
59
+ console.log('heater on:', await sensor.isHeaterOn()); // Heater state, () → boolean
60
+ // reads CTRL_REG2.HEATER
61
+ await sensor.setHeater(false);
62
+
63
+ await sensor.configureDrdy(true, true, false); // Configure DRDY pin, (enabled, activeHigh=true, openDrain=false) → void
64
+ // routes data-ready to the DRDY pin
65
+ console.log('poll', await sensor.pollInterrupt()); // Poll interrupt status, () → number
66
+ // STATUS_REG; flags clear when data is read
67
+ await sensor.configureDrdy(false);
68
+
69
+ await sensor.powerDown(); // Power down, () → void
70
+ // clears CTRL_REG1.PD
71
+ await sensor.powerUp(); // Power up, () → void
72
+ // sets CTRL_REG1.PD
73
+ await sensor.onInterrupt((status) => console.log('DRDY status', status)); // Subscribe to data-ready, (callback, intPin=null) → void
74
+ // edge on the pin or a polling timer
75
+ await sleep(2000);
76
+ await sensor.offInterrupt(); // Unsubscribe, () → void
77
+ // disables the DRDY output
78
+ await sensor.reboot(); // Reload trimming, () → void
79
+ // sets BOOT, waits, re-reads the calibration
80
+ connection.close();
81
+ }
82
+
83
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,94 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { HTS221Full } = require('../../../src/chips/humidity/hts221');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5F', 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=0x5F) → Connection
11
+ const sensor = new HTS221Full(connection); // Create HTS221 driver, (connection) → void
12
+
13
+ async function main() {
14
+ await sensor.init(); // Read calibration and start one-shot mode, () → void
15
+
16
+ // --- Identify the chip and show the factory calibration ---
17
+ // Every HTS221 stores its own two-point calibration; the driver read it
18
+ // during init() and uses it for every conversion.
19
+ console.log('who am i 0x' + (await sensor.whoAmI()).toString(16)); // Read WHO_AM_I, () → number (0xBC)
20
+ console.log('calibration', await sensor.readCalibration()); // Read calibration, () → object
21
+
22
+ // --- One-shot hygrometer: 10 readings, 2 s apart ---
23
+ // Each read() starts a conversion; the dew point shows what the pair
24
+ // means for condensation risk.
25
+ for (let i = 0; i < 10; i++) {
26
+ const m = await sensor.read(); // Read temperature and humidity, () → {temperature_c °C, humidity_pct %rH}
27
+ const dew = await sensor.dewPoint(); // Compute dew point, () → number °C
28
+ console.log(m.temperature_c.toFixed(2) + ' C ' + m.humidity_pct.toFixed(1) + ' %rH dew ' + dew.toFixed(2) + ' C');
29
+ console.log('raw', await sensor.readRawHumidity(), await sensor.readRawTemperature()); // Read raw outputs, () → number
30
+ console.log('h', (await sensor.readHumidity()).toFixed(1), 't', (await sensor.readTemperature()).toFixed(2)); // Read single values, () → number
31
+ await sleep(2000);
32
+ }
33
+
34
+ // --- Continuous sampling at 1 Hz and 12.5 Hz ---
35
+ // dataReady() paces the loop; the sample count per second follows the rate.
36
+ await sensor.setBlockDataUpdate(true); // Set block data update, (enabled) → void
37
+ for (const hz of [1, 12.5]) {
38
+ await sensor.setOutputDataRate(hz); // Set output data rate, (hz 0|1|7|12.5) → void
39
+ console.log('rate', await sensor.getOutputDataRate(), 'Hz'); // Get output data rate, () → number Hz
40
+ let count = 0;
41
+ const end = Date.now() + 3000;
42
+ while (Date.now() < end) {
43
+ if (await sensor.dataReady()) { // Check data available, () → boolean
44
+ await sensor.readContinuous(); // Read latest sample, () → object
45
+ count++;
46
+ }
47
+ await sleep(5);
48
+ }
49
+ console.log((count / 3).toFixed(1) + ' samples/s');
50
+ }
51
+ await sensor.setOutputDataRate(0); // Set output data rate, (hz 0|1|7|12.5) → void
52
+
53
+ // --- Noise at lowest and highest averaging ---
54
+ // Ten one-shot samples each; the spread of the raw humidity shrinks as
55
+ // the averaging grows.
56
+ for (const [t, h] of [[2, 4], [256, 512]]) {
57
+ await sensor.setAveraging(t, h); // Set averaging, (temperatureSamples, humiditySamples) → void
58
+ console.log('averaging', await sensor.getAveraging()); // Get averaging, () → [number, number]
59
+ const raws = [];
60
+ for (let i = 0; i < 10; i++) raws.push(await sensor.readRawHumidity()); // Read raw humidity, () → number
61
+ console.log('raw humidity spread', Math.max(...raws) - Math.min(...raws));
62
+ }
63
+ await sensor.setAveraging(16, 32); // Set averaging, (temperatureSamples, humiditySamples) → void
64
+
65
+ // --- Heater: drive off condensation for 10 s ---
66
+ // Humidity falls and temperature rises while the heater runs; measure
67
+ // before and after, never during, then let the sensor cool.
68
+ const before = await sensor.read(); // Read temperature and humidity, () → object
69
+ await sensor.setHeater(true); // Switch the heater, (on) → void
70
+ console.log('heater on:', await sensor.isHeaterOn()); // Heater state, () → boolean
71
+ await sleep(10000);
72
+ await sensor.setHeater(false); // Switch the heater, (on) → void
73
+ const after = await sensor.read(); // Read temperature and humidity, () → object
74
+ console.log('before', before, 'after', after);
75
+
76
+ // --- Data-ready notification for 5 s ---
77
+ // Uses the DRDY pin when the connection has one, otherwise a polling timer.
78
+ await sensor.configureDrdy(true, true, false); // Configure DRDY pin, (enabled, activeHigh=true, openDrain=false) → void
79
+ await sensor.setOutputDataRate(1); // Set output data rate, (hz 0|1|7|12.5) → void
80
+ await sensor.onInterrupt((status) => console.log('DRDY status', status)); // Subscribe to data-ready, (callback, intPin=null) → void
81
+ await sleep(5000);
82
+ await sensor.offInterrupt(); // Unsubscribe, () → void
83
+ console.log('poll', await sensor.pollInterrupt(), 'status', await sensor.status()); // Poll interrupt status, () → number
84
+ await sensor.setOutputDataRate(0);
85
+
86
+ // --- Power cycle and reload ---
87
+ await sensor.powerDown(); // Power down, () → void
88
+ await sensor.powerUp(); // Power up, () → void
89
+ await sensor.reboot(); // Reload trimming, () → void
90
+ console.log('done:', (await sensor.read()).temperature_c.toFixed(2), 'C');
91
+ connection.close();
92
+ }
93
+
94
+ 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 { HTS221Minimal } = require('../../../src/chips/humidity/hts221');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5F', 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=0x5F) → Connection
11
+ const sensor = new HTS221Minimal(connection); // Create HTS221 driver, (connection) → void
12
+
13
+ async function main() {
14
+ await sensor.init(); // Read calibration and start one-shot mode, () → void
15
+ while (true) {
16
+ const m = await sensor.read(); // Read temperature and humidity, () → {temperature_c: number °C, humidity_pct: number %rH}
17
+ console.log('%s C, %s %%rH', m.temperature_c.toFixed(2), m.humidity_pct.toFixed(1));
18
+ await sleep(2000);
19
+ }
20
+ }
21
+
22
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { HTU31DFull } = require('../../../src/chips/humidity/htu31d');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 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=0x40) → Connection
11
+ const sensor = new HTU31DFull(connection); // Create HTU31D driver, (connection) → void
12
+
13
+ async function main() {
14
+ await sensor.init(); // Soft reset, () → void
15
+ // 0x1E, waits 15 ms; highest resolution, heater off
16
+ const m = await sensor.read(); // Read temperature and humidity, () → {temperature_c: number °C, humidity_pct: number %RH}
17
+ // OSR 3 / 3 by default, both CRCs verified, humidity clamped 0-100
18
+ console.log(m);
19
+ console.log(await sensor.readHumidity()); // Read humidity only, () → number %RH
20
+ console.log(await sensor.readTemperature()); // Read temperature only, () → number °C
21
+ console.log(await sensor.readRaw()); // Read raw codes, () → [t_raw, rh_raw]
22
+ // 16-bit unsigned
23
+
24
+ sensor.setResolution(1, 2); // Set oversampling, (osrRh 0-3, osrT 0-3) → void
25
+ // higher OSR = finer resolution, longer conversion
26
+ console.log(sensor.getResolution()); // Get oversampling, () → [osrRh, osrT]
27
+ console.log(sensor.conversionTime()); // Typical conversion time, () → number s
28
+ sensor.setResolution(3, 3);
29
+
30
+ await sensor.startConversion(); // Start a conversion, () → void
31
+ // non-blocking; wait conversionTime() before reading
32
+ await sleep(30);
33
+ console.log(await sensor.readResult()); // Read last conversion result, () → {temperature_c, humidity_pct}
34
+
35
+ await sensor.setHeater(true); // Switch the heater, (on) → void
36
+ // 0x04; readings drift while the heater runs
37
+ console.log(await sensor.isHeaterOn()); // Heater state, () → boolean
38
+ await sensor.setHeater(false);
39
+ console.log((await sensor.diagnostic()).toString(16)); // Read the diagnostic byte, () → number
40
+ console.log(await sensor.diagnosticFlags()); // Named diagnostic flags, () → object
41
+ console.log((await sensor.serialNumber()).toString(16)); // Read the serial number, () → number
42
+ // 24-bit, CRC verified
43
+ console.log(await sensor.dewPoint()); // Compute dew point, () → number °C
44
+ // one measurement, Magnus formula
45
+ await sensor.softReset(); // Soft reset, () → void
46
+ // 0x1E, waits 15 ms; heater off, OSR 3 / 3
47
+ connection.close();
48
+ }
49
+
50
+ main().catch(err => { console.error(err); process.exit(1); });