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.
Files changed (79) hide show
  1. package/README.md +18 -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/gas/ccs811/complete.js +87 -0
  9. package/examples/gas/ccs811/demo.js +108 -0
  10. package/examples/gas/ccs811/minimal.js +20 -0
  11. package/examples/gas/rrh46410/complete.js +78 -0
  12. package/examples/gas/rrh46410/demo.js +86 -0
  13. package/examples/gas/rrh46410/minimal.js +21 -0
  14. package/examples/humidity/hts221/complete.js +83 -0
  15. package/examples/humidity/hts221/demo.js +94 -0
  16. package/examples/humidity/hts221/minimal.js +22 -0
  17. package/examples/humidity/htu31d/complete.js +50 -0
  18. package/examples/humidity/htu31d/demo.js +65 -0
  19. package/examples/humidity/htu31d/minimal.js +22 -0
  20. package/examples/humidity/shtc3/complete.js +48 -0
  21. package/examples/humidity/shtc3/demo.js +45 -0
  22. package/examples/humidity/shtc3/minimal.js +22 -0
  23. package/examples/led/saa1064/complete.js +51 -0
  24. package/examples/led/saa1064/demo.js +54 -0
  25. package/examples/led/saa1064/minimal.js +23 -0
  26. package/examples/light/apds9250/complete.js +71 -0
  27. package/examples/light/apds9250/demo.js +79 -0
  28. package/examples/light/apds9250/minimal.js +23 -0
  29. package/examples/light/bh1750/complete.js +46 -0
  30. package/examples/light/bh1750/demo.js +52 -0
  31. package/examples/light/bh1750/minimal.js +22 -0
  32. package/examples/light/si1132/complete.js +70 -0
  33. package/examples/light/si1132/demo.js +73 -0
  34. package/examples/light/si1132/minimal.js +22 -0
  35. package/examples/light/si1133/complete.js +89 -0
  36. package/examples/light/si1133/demo.js +93 -0
  37. package/examples/light/si1133/minimal.js +22 -0
  38. package/examples/light/si1145/complete.js +93 -0
  39. package/examples/light/si1145/demo.js +98 -0
  40. package/examples/light/si1145/minimal.js +22 -0
  41. package/examples/pressure/mpl3115a2/complete.js +49 -0
  42. package/examples/pressure/mpl3115a2/demo.js +48 -0
  43. package/examples/pressure/mpl3115a2/minimal.js +22 -0
  44. package/examples/pressure/ms5607/complete.js +49 -0
  45. package/examples/pressure/ms5607/demo.js +65 -0
  46. package/examples/pressure/ms5607/minimal.js +22 -0
  47. package/examples/pressure/ms5611/complete.js +49 -0
  48. package/examples/pressure/ms5611/demo.js +65 -0
  49. package/examples/pressure/ms5611/minimal.js +22 -0
  50. package/examples/pressure/spl06/complete.js +81 -0
  51. package/examples/pressure/spl06/demo.js +106 -0
  52. package/examples/pressure/spl06/minimal.js +22 -0
  53. package/examples/rfid/pn532/complete.js +99 -0
  54. package/examples/rfid/pn532/demo.js +121 -0
  55. package/examples/rfid/pn532/minimal.js +22 -0
  56. package/package.json +1 -1
  57. package/src/chips/color/isl29125.js +379 -0
  58. package/src/chips/environmental/bme688.js +573 -0
  59. package/src/chips/gas/ccs811.js +400 -0
  60. package/src/chips/gas/rrh46410.js +534 -0
  61. package/src/chips/humidity/hts221.js +369 -0
  62. package/src/chips/humidity/htu31d.js +242 -0
  63. package/src/chips/humidity/shtc3.js +239 -0
  64. package/src/chips/led/saa1064.js +241 -0
  65. package/src/chips/light/apds9250.js +431 -0
  66. package/src/chips/light/bh1750.js +196 -0
  67. package/src/chips/light/si1132.js +416 -0
  68. package/src/chips/light/si1133.js +583 -0
  69. package/src/chips/light/si1145.js +630 -0
  70. package/src/chips/pressure/mpl3115a2.js +459 -0
  71. package/src/chips/pressure/ms5607.js +290 -0
  72. package/src/chips/pressure/ms5611.js +290 -0
  73. package/src/chips/pressure/spl06.js +461 -0
  74. package/src/chips/rfid/pn532.js +513 -0
  75. package/src/connection/i2c.js +46 -13
  76. package/src/connection/smbus.js +21 -8
  77. package/src/discovery/registry.js +18 -18
  78. package/examples/gpio/.gitkeep +0 -0
  79. 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` |
@@ -72,6 +75,7 @@ Each chip exposes two classes:
72
75
  | BNO055 | IMU | `periph/src/chips/imu/bno055` |
73
76
  | CAT24C512 | Memory | `periph/src/chips/memory/cat24c512` |
74
77
  | CAT5171 | ADC/DAC | `periph/src/chips/adc_dac/cat5171` |
78
+ | CCS811 | Gas sensor | `periph/src/chips/gas/ccs811` |
75
79
  | CS43L22 | ADC/DAC | `periph/src/chips/adc_dac/cs43l22` |
76
80
  | DHT11 | Humidity sensor | `periph/src/chips/humidity/dht11` |
77
81
  | DRV2605 | Motor driver | `periph/src/chips/motor/drv2605` |
@@ -88,7 +92,9 @@ Each chip exposes two classes:
88
92
  | HS30XX | Humidity sensor | `periph/src/chips/humidity/hs30xx` |
89
93
  | HS40XX | Humidity sensor | `periph/src/chips/humidity/hs40xx` |
90
94
  | HT16K33 | LED driver | `periph/src/chips/led/ht16k33` |
95
+ | HTS221 | Humidity sensor | `periph/src/chips/humidity/hts221` |
91
96
  | HTU21DF | Humidity sensor | `periph/src/chips/humidity/htu21df` |
97
+ | HTU31D | Humidity sensor | `periph/src/chips/humidity/htu31d` |
92
98
  | HX710A | ADC/DAC | `periph/src/chips/adc_dac/hx710a` |
93
99
  | HX710B | ADC/DAC | `periph/src/chips/adc_dac/hx710b` |
94
100
  | HX711 | ADC/DAC | `periph/src/chips/adc_dac/hx711` |
@@ -100,6 +106,7 @@ Each chip exposes two classes:
100
106
  | INA260 | Power monitor | `periph/src/chips/power/ina260` |
101
107
  | INA3221 | Power monitor | `periph/src/chips/power/ina3221` |
102
108
  | IS31FL3731 | LED driver | `periph/src/chips/led/is31fl3731` |
109
+ | ISL29125 | Color sensor | `periph/src/chips/color/isl29125` |
103
110
  | L3G4200D | Gyroscope | `periph/src/chips/gyroscope/l3g4200d` |
104
111
  | L3GD20H | Gyroscope | `periph/src/chips/gyroscope/l3gd20h` |
105
112
  | LC709203F | Power monitor | `periph/src/chips/power/lc709203f` |
@@ -125,10 +132,13 @@ Each chip exposes two classes:
125
132
  | MFRC522 | RFID/NFC | `periph/src/chips/rfid/mfrc522` |
126
133
  | MMA8451Q | Accelerometer | `periph/src/chips/accelerometer/mma8451q` |
127
134
  | MPL115A2 | Pressure sensor | `periph/src/chips/pressure/mpl115a2` |
135
+ | MPL3115A2 | Pressure sensor | `periph/src/chips/pressure/mpl3115a2` |
128
136
  | MPR121 | Other | `periph/src/chips/other/mpr121` |
129
137
  | MPU6050 | IMU | `periph/src/chips/imu/mpu6050` |
130
138
  | MPU9250 | IMU | `periph/src/chips/imu/mpu9250` |
131
139
  | MPU9255 | IMU | `periph/src/chips/imu/mpu9255` |
140
+ | MS5607 | Pressure sensor | `periph/src/chips/pressure/ms5607` |
141
+ | MS5611 | Pressure sensor | `periph/src/chips/pressure/ms5611` |
132
142
  | MX25L12845E | Memory | `periph/src/chips/memory/mx25l12845e` |
133
143
  | NEO6 | GNSS/GPS | `periph/src/chips/gnss/neo6` |
134
144
  | NEOPIXELRGBBASE | LED driver | `periph/src/chips/led/_NeoPixelRGBBase` |
@@ -147,14 +157,22 @@ Each chip exposes two classes:
147
157
  | PCF8578 | Display driver | `periph/src/chips/display/pcf8578` |
148
158
  | PCF8579 | Display driver | `periph/src/chips/display/pcf8579` |
149
159
  | PCF8591 | ADC/DAC | `periph/src/chips/adc_dac/pcf8591` |
160
+ | PN532 | RFID/NFC | `periph/src/chips/rfid/pn532` |
150
161
  | QMI8658A | IMU | `periph/src/chips/imu/qmi8658a` |
151
162
  | RDA5807M | Comms | `periph/src/chips/comms/rda5807m` |
152
163
  | RFM9X | Comms | `periph/src/chips/comms/rfm9x` |
164
+ | RRH46410 | Gas sensor | `periph/src/chips/gas/rrh46410` |
165
+ | SAA1064 | LED driver | `periph/src/chips/led/saa1064` |
153
166
  | SD_SPI | Memory | `periph/src/chips/memory/sd_spi` |
154
167
  | SH1106 | Display driver | `periph/src/chips/display/sh1106` |
155
168
  | SHT31 | Humidity sensor | `periph/src/chips/humidity/sht31` |
169
+ | SHTC3 | Humidity sensor | `periph/src/chips/humidity/shtc3` |
170
+ | SI1132 | Light sensor | `periph/src/chips/light/si1132` |
171
+ | SI1133 | Light sensor | `periph/src/chips/light/si1133` |
172
+ | SI1145 | Light sensor | `periph/src/chips/light/si1145` |
156
173
  | SI7021 | Humidity sensor | `periph/src/chips/humidity/si7021` |
157
174
  | SK6812RGBW | LED driver | `periph/src/chips/led/sk6812rgbw` |
175
+ | SPL06 | Pressure sensor | `periph/src/chips/pressure/spl06` |
158
176
  | SSD1305 | Display driver | `periph/src/chips/display/ssd1305` |
159
177
  | SSD1306 | Display driver | `periph/src/chips/display/ssd1306` |
160
178
  | SSD1331 | Display driver | `periph/src/chips/display/ssd1331` |
@@ -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,87 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { CCS811Full } = require('../../../src/chips/gas/ccs811');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5A', 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=0x5A) → Connection
11
+ // Default address 0x5A (ADDR low); 0x5B with ADDR high.
12
+ const sensor = new CCS811Full(connection); // Create CCS811 driver, (connection) → void
13
+ // Constructor stores the connection only; no bus traffic yet.
14
+
15
+ async function main() {
16
+ await sensor.init(); // Check HW_ID, start application, mode 1, () → void
17
+ // Verifies HW_ID 0x81, writes APP_START if the chip is in boot mode, selects 1 s sampling.
18
+
19
+ console.log(await sensor.hardwareVersion()); // Hardware ID and version, () → [hw_id, hw_version]
20
+ // HW_ID is 0x81, HW_VERSION 0x1X.
21
+ console.log(await sensor.firmwareVersion()); // Firmware versions, () → {boot: [major, minor, trivial], app: [...]}
22
+ // Bootloader and application firmware, each major.minor.trivial.
23
+ console.log((await sensor.status()).toString(16)); // STATUS register, () → number
24
+ // Bit 7 FW_MODE, bit 4 APP_VALID, bit 3 DATA_READY, bit 0 ERROR.
25
+ console.log((await sensor.error()).toString(16)); // ERROR_ID register, () → number
26
+ // Zero unless STATUS.ERROR is set.
27
+
28
+ console.log(await sensor.read()); // Next sample, () → {eco2_ppm: number ppm, tvoc_ppb: number ppb}
29
+ // Waits for DATA_READY, then reads eCO2 and TVOC.
30
+ console.log(await sensor.readEco2()); // eCO2 only, () → number ppm
31
+ // Equivalent CO2 estimated from the VOC level, 400–8192 ppm.
32
+ console.log(await sensor.readTvoc()); // TVOC only, () → number ppb
33
+ // Total volatile organic compounds, 0–1187 ppb.
34
+ console.log(await sensor.readRaw()); // Raw sensor data, () → [current_ua µA, voltage_v V]
35
+ // Sense current and the voltage across the sensor.
36
+ console.log(await sensor.dataReady()); // New sample waiting, () → boolean
37
+ // False right after a read, because reading the result clears DATA_READY.
38
+
39
+ await sensor.setEnvironment(45.0, 22.5); // Compensation data, (humidityRh %, temperatureC °C) → void
40
+ // Real ambient values improve accuracy; the chip assumes 50 %RH and 25 °C otherwise.
41
+ console.log(await sensor.readNtc()); // NTC circuit voltages, () → [v_ref_mv mV, v_ntc_mv mV]
42
+ // Only meaningful with a reference resistor and NTC wired to the AUX pin.
43
+ try {
44
+ console.log(await sensor.ntcResistance(100000)); // NTC resistance, (rRefOhm Ω) → number Ω
45
+ // V_NTC × R_REF / V_REF; map it to °C with the thermistor's curve.
46
+ } catch (e) {
47
+ console.log('no NTC circuit:', e.message);
48
+ }
49
+
50
+ await sensor.setThresholds(1000, 2000, 50); // Threshold boundaries, (lowMediumPpm=1500, mediumHighPpm=2500, hysteresisPpm=50) → void
51
+ // eCO2 zones used by the threshold interrupt.
52
+ const baseline = await sensor.getBaseline(); // Algorithm baseline, () → number
53
+ // Save it to non-volatile storage about once a day.
54
+ console.log(baseline.toString(16));
55
+ await sensor.setBaseline(baseline); // Restore baseline, (baseline) → void
56
+ // Restore a saved value only after about 20 min of warm-up.
57
+
58
+ await sensor.enableInterrupt(CCS811Full.SOURCE_DATA_READY); // nINT on new data, (source) → void
59
+ // Sets INT_DATARDY and keeps the drive mode.
60
+ await sensor.onInterrupt(async (st) => { // Subscribe, (callback, intPin=null) → void
61
+ console.log('interrupt status 0x%s', st.toString(16), await sensor.read());
62
+ });
63
+ // Without an INT pin the driver polls STATUS; reading the sample releases nINT.
64
+ await sleep(3000);
65
+ await sensor.offInterrupt(); // Unsubscribe, () → void
66
+ // Stops the pin handler or polling timer.
67
+ console.log((await sensor.pollInterrupt()).toString(16)); // STATUS without releasing nINT, () → number
68
+ // DATA_READY shows whether a sample is pending.
69
+ await sensor.disableInterrupt(CCS811Full.SOURCE_DATA_READY); // nINT off, (source) → void
70
+ // Clears INT_DATARDY.
71
+
72
+ await sensor.setMode(4); // Drive mode, (mode 0–4) → void
73
+ // Mode 4: raw data every 250 ms, no eCO2/TVOC updates.
74
+ await sleep(500);
75
+ console.log(await sensor.readRaw()); // Raw sensor data, () → [current_ua µA, voltage_v V]
76
+ // RAW_DATA keeps updating in mode 4.
77
+ await sensor.setMode(0); // Drive mode, (mode 0–4) → void
78
+ // Idle before switching to another mode.
79
+ await sensor.setMode(1); // Drive mode, (mode 0–4) → void
80
+ // Back to one sample per second.
81
+
82
+ await sensor.softReset(); // Software reset, () → void
83
+ // SW_RESET into boot mode, then APP_START and mode 1 again.
84
+ await connection.close();
85
+ }
86
+
87
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { CCS811Full } = require('../../../src/chips/gas/ccs811');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5A', 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=0x5A) → Connection
11
+ const sensor = new CCS811Full(connection); // Create CCS811 driver, (connection) → void
12
+
13
+ function classify(eco2) {
14
+ if (eco2 < 1000) return 'good';
15
+ if (eco2 <= 1500) return 'fair';
16
+ return 'poor';
17
+ }
18
+
19
+ async function main() {
20
+ await sensor.init(); // Check HW_ID, start application, mode 1, () → void
21
+
22
+ // --- Identity ---
23
+ // HW_ID 0x81 identifies the CCS81x family; the firmware versions tell which
24
+ // algorithm revision computes eCO2 and TVOC.
25
+ console.log('hardware', await sensor.hardwareVersion()); // Hardware ID and version, () → [hw_id, hw_version]
26
+ console.log('firmware', await sensor.firmwareVersion()); // Firmware versions, () → {boot, app}
27
+ const st = await sensor.status(); // STATUS, () → number
28
+ const err = await sensor.error(); // ERROR_ID, () → number
29
+ console.log('status 0x%s, error 0x%s', st.toString(16), err.toString(16));
30
+
31
+ // --- Air-quality monitor: 30 s at 1 Hz ---
32
+ // Mode 1 delivers a sample every second. Values settle after about 20 min of
33
+ // warm-up; a brand-new sensor needs a 48 h burn-in.
34
+ for (let i = 0; i < 30; i++) {
35
+ const m = await sensor.read(); // Next sample, () → {eco2_ppm ppm, tvoc_ppb ppb}
36
+ console.log('%d s eCO2 %d ppm TVOC %d ppb %s', i, m.eco2_ppm, m.tvoc_ppb, classify(m.eco2_ppm));
37
+ }
38
+ console.log('eCO2 %d ppm', await sensor.readEco2()); // eCO2 only, () → number ppm
39
+ console.log('TVOC %d ppb', await sensor.readTvoc()); // TVOC only, () → number ppb
40
+
41
+ // --- Environment compensation ---
42
+ // Feeding the real temperature and humidity (e.g. from a BME280) corrects the
43
+ // algorithm; without it the chip assumes 25 °C and 50 %RH.
44
+ await sensor.setEnvironment(40.0, 23.0); // Compensation data, (humidityRh %, temperatureC °C) → void
45
+ const [vRef] = await sensor.readNtc(); // NTC voltages, () → [v_ref_mv mV, v_ntc_mv mV]
46
+ if (vRef) {
47
+ console.log('NTC %s ohm', (await sensor.ntcResistance(10000)).toFixed(0)); // NTC resistance, (rRefOhm Ω) → number Ω
48
+ } else {
49
+ console.log('no NTC circuit fitted');
50
+ }
51
+
52
+ // --- Threshold interrupt: only report zone changes ---
53
+ // With INT_THRESH the chip raises nINT only when eCO2 crosses 1000 or
54
+ // 2000 ppm by more than the hysteresis. Polling STATUS here shows each sample.
55
+ await sensor.setThresholds(1000, 2000, 50); // Zone boundaries, (lowMediumPpm, mediumHighPpm, hysteresisPpm) → void
56
+ await sensor.enableInterrupt(CCS811Full.SOURCE_THRESHOLD); // Threshold interrupt, (source) → void
57
+ for (let i = 0; i < 5; i++) {
58
+ while (!((await sensor.pollInterrupt()) & CCS811Full.STATUS_DATA_READY)) { // STATUS, () → number
59
+ await sleep(100);
60
+ }
61
+ console.log('event', await sensor.read()); // Reading releases nINT, () → {eco2_ppm, tvoc_ppb}
62
+ }
63
+ await sensor.disableInterrupt(CCS811Full.SOURCE_THRESHOLD); // Threshold interrupt off, (source) → void
64
+
65
+ // --- Data-ready callback ---
66
+ // The callback gets the STATUS byte; without an INT pin the driver polls.
67
+ await sensor.enableInterrupt(CCS811Full.SOURCE_DATA_READY); // Data-ready interrupt, (source) → void
68
+ await sensor.onInterrupt(async (s) => { // Subscribe, (callback, intPin=null) → void
69
+ console.log('callback 0x%s', s.toString(16), await sensor.read());
70
+ });
71
+ await sleep(3000);
72
+ await sensor.offInterrupt(); // Unsubscribe, () → void
73
+ await sensor.disableInterrupt(CCS811Full.SOURCE_DATA_READY); // Data-ready interrupt off, (source) → void
74
+
75
+ // --- Raw sensor data ---
76
+ // The MOx sensor's current and voltage give its resistance; the algorithm
77
+ // derives eCO2 and TVOC from it.
78
+ const [current, voltage] = await sensor.readRaw(); // Raw data, () → [current_ua µA, voltage_v V]
79
+ const r = current ? voltage / (current * 1e-6) : 0;
80
+ console.log('raw %d uA, %s V, %s ohm', current, voltage.toFixed(3), r.toFixed(0));
81
+
82
+ // --- Slower sampling: mode 2 (every 10 s) ---
83
+ // Pulse heating saves power; pass through idle when changing modes.
84
+ await sensor.setMode(0); // Idle, (mode) → void
85
+ await sensor.setMode(2); // Every 10 s, (mode) → void
86
+ for (let i = 0; i < 2; i++) {
87
+ const m = await sensor.read(); // Next sample, () → {eco2_ppm, tvoc_ppb}
88
+ console.log('mode 2', m, 'ready', await sensor.dataReady()); // Ready flag, () → boolean
89
+ }
90
+ await sensor.setMode(0); // Idle, (mode) → void
91
+ await sensor.setMode(1); // Back to every second, (mode) → void
92
+
93
+ // --- Baseline ---
94
+ // Save the baseline daily and restore it after a power cycle, but only after
95
+ // about 20 min of warm-up; otherwise the chip relearns it from scratch.
96
+ const baseline = await sensor.getBaseline(); // Baseline, () → number
97
+ console.log('baseline 0x%s', baseline.toString(16).padStart(4, '0'));
98
+ await sensor.setBaseline(baseline); // Restore baseline, (baseline) → void
99
+
100
+ // --- Wrap up ---
101
+ // A soft reset puts the chip into boot mode; the driver starts the
102
+ // application again in mode 1.
103
+ await sensor.softReset(); // Software reset, () → void
104
+ console.log('status after reset 0x%s', (await sensor.status()).toString(16)); // STATUS, () → number
105
+ await connection.close();
106
+ }
107
+
108
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { CCS811Minimal } = require('../../../src/chips/gas/ccs811');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5A', 16);
8
+
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x5A) → Connection
10
+ const sensor = new CCS811Minimal(connection); // Create CCS811 driver, (connection) → void
11
+
12
+ async function main() {
13
+ await sensor.init(); // Check HW_ID, start application, mode 1, () → void
14
+ while (true) {
15
+ const m = await sensor.read(); // Wait for the next sample, () → {eco2_ppm: number ppm, tvoc_ppb: number ppb}
16
+ console.log('eCO2 %d ppm, TVOC %d ppb', m.eco2_ppm, m.tvoc_ppb);
17
+ }
18
+ }
19
+
20
+ main().catch(err => { console.error(err); process.exit(1); });