periph 1.5.4 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/examples/gas/ccs811/complete.js +87 -0
- package/examples/gas/ccs811/demo.js +108 -0
- package/examples/gas/ccs811/minimal.js +20 -0
- package/examples/gas/rrh46410/complete.js +78 -0
- package/examples/gas/rrh46410/demo.js +86 -0
- package/examples/gas/rrh46410/minimal.js +21 -0
- package/examples/gas/rrh62000/complete.js +74 -0
- package/examples/gas/rrh62000/demo.js +87 -0
- package/examples/gas/rrh62000/minimal.js +22 -0
- package/examples/gas/scd30/complete.js +73 -0
- package/examples/gas/scd30/demo.js +102 -0
- package/examples/gas/scd30/minimal.js +20 -0
- package/examples/gas/scd40/complete.js +76 -0
- package/examples/gas/scd40/demo.js +109 -0
- package/examples/gas/scd40/minimal.js +20 -0
- package/examples/light/si1133/complete.js +89 -0
- package/examples/light/si1133/demo.js +93 -0
- package/examples/light/si1133/minimal.js +22 -0
- package/examples/light/si1145/complete.js +93 -0
- package/examples/light/si1145/demo.js +98 -0
- package/examples/light/si1145/minimal.js +22 -0
- package/examples/light/tsl2561/complete.js +74 -0
- package/examples/light/tsl2561/demo.js +46 -0
- package/examples/light/tsl2561/minimal.js +22 -0
- package/examples/light/tsl2591/complete.js +90 -0
- package/examples/light/tsl2591/demo.js +119 -0
- package/examples/light/tsl2591/minimal.js +22 -0
- package/examples/light/vcnl4040/complete.js +102 -0
- package/examples/light/vcnl4040/demo.js +125 -0
- package/examples/light/vcnl4040/minimal.js +25 -0
- package/examples/light/vcnl4200/complete.js +101 -0
- package/examples/light/vcnl4200/demo.js +126 -0
- package/examples/light/vcnl4200/minimal.js +25 -0
- package/examples/pressure/spl06/complete.js +81 -0
- package/examples/pressure/spl06/demo.js +106 -0
- package/examples/pressure/spl06/minimal.js +22 -0
- package/examples/rfid/pn532/complete.js +99 -0
- package/examples/rfid/pn532/demo.js +121 -0
- package/examples/rfid/pn532/minimal.js +22 -0
- package/examples/rfid/st25dv/complete.js +94 -0
- package/examples/rfid/st25dv/demo.js +121 -0
- package/examples/rfid/st25dv/minimal.js +21 -0
- package/examples/rtc/bq32000/complete.js +53 -0
- package/examples/rtc/bq32000/demo.js +77 -0
- package/examples/rtc/bq32000/minimal.js +20 -0
- package/examples/rtc/ds1307/complete.js +54 -0
- package/examples/rtc/ds1307/demo.js +96 -0
- package/examples/rtc/ds1307/minimal.js +20 -0
- package/examples/rtc/ds1371/complete.js +53 -0
- package/examples/rtc/ds1371/demo.js +85 -0
- package/examples/rtc/ds1371/minimal.js +25 -0
- package/package.json +1 -1
- package/src/chips/gas/ccs811.js +400 -0
- package/src/chips/gas/rrh46410.js +534 -0
- package/src/chips/gas/rrh62000.js +418 -0
- package/src/chips/gas/scd30.js +368 -0
- package/src/chips/gas/scd40.js +451 -0
- package/src/chips/light/si1133.js +583 -0
- package/src/chips/light/si1145.js +630 -0
- package/src/chips/light/tsl2561.js +445 -0
- package/src/chips/light/tsl2591.js +561 -0
- package/src/chips/light/vcnl4040.js +576 -0
- package/src/chips/light/vcnl4200.js +592 -0
- package/src/chips/pressure/spl06.js +461 -0
- package/src/chips/rfid/pn532.js +513 -0
- package/src/chips/rfid/st25dv.js +628 -0
- package/src/chips/rtc/bq32000.js +334 -0
- package/src/chips/rtc/ds1307.js +327 -0
- package/src/chips/rtc/ds1371.js +453 -0
- package/src/connection/i2c.js +46 -13
- package/src/connection/smbus.js +21 -8
- package/src/discovery/registry.js +17 -17
package/README.md
CHANGED
|
@@ -73,12 +73,16 @@ Each chip exposes two classes:
|
|
|
73
73
|
| BMP384 | Pressure sensor | `periph/src/chips/pressure/bmp384` |
|
|
74
74
|
| BMP581 | Pressure sensor | `periph/src/chips/pressure/bmp581` |
|
|
75
75
|
| BNO055 | IMU | `periph/src/chips/imu/bno055` |
|
|
76
|
+
| BQ32000 | RTC | `periph/src/chips/rtc/bq32000` |
|
|
76
77
|
| CAT24C512 | Memory | `periph/src/chips/memory/cat24c512` |
|
|
77
78
|
| CAT5171 | ADC/DAC | `periph/src/chips/adc_dac/cat5171` |
|
|
79
|
+
| CCS811 | Gas sensor | `periph/src/chips/gas/ccs811` |
|
|
78
80
|
| CS43L22 | ADC/DAC | `periph/src/chips/adc_dac/cs43l22` |
|
|
79
81
|
| DHT11 | Humidity sensor | `periph/src/chips/humidity/dht11` |
|
|
80
82
|
| DRV2605 | Motor driver | `periph/src/chips/motor/drv2605` |
|
|
81
83
|
| DRV8830 | Motor driver | `periph/src/chips/motor/drv8830` |
|
|
84
|
+
| DS1307 | RTC | `periph/src/chips/rtc/ds1307` |
|
|
85
|
+
| DS1371 | RTC | `periph/src/chips/rtc/ds1371` |
|
|
82
86
|
| DS1881 | ADC/DAC | `periph/src/chips/adc_dac/ds1881` |
|
|
83
87
|
| DS3231 | RTC | `periph/src/chips/rtc/ds3231` |
|
|
84
88
|
| DS3502 | ADC/DAC | `periph/src/chips/adc_dac/ds3502` |
|
|
@@ -156,20 +160,29 @@ Each chip exposes two classes:
|
|
|
156
160
|
| PCF8578 | Display driver | `periph/src/chips/display/pcf8578` |
|
|
157
161
|
| PCF8579 | Display driver | `periph/src/chips/display/pcf8579` |
|
|
158
162
|
| PCF8591 | ADC/DAC | `periph/src/chips/adc_dac/pcf8591` |
|
|
163
|
+
| PN532 | RFID/NFC | `periph/src/chips/rfid/pn532` |
|
|
159
164
|
| QMI8658A | IMU | `periph/src/chips/imu/qmi8658a` |
|
|
160
165
|
| RDA5807M | Comms | `periph/src/chips/comms/rda5807m` |
|
|
161
166
|
| RFM9X | Comms | `periph/src/chips/comms/rfm9x` |
|
|
167
|
+
| RRH46410 | Gas sensor | `periph/src/chips/gas/rrh46410` |
|
|
168
|
+
| RRH62000 | Gas sensor | `periph/src/chips/gas/rrh62000` |
|
|
162
169
|
| SAA1064 | LED driver | `periph/src/chips/led/saa1064` |
|
|
170
|
+
| SCD30 | Gas sensor | `periph/src/chips/gas/scd30` |
|
|
171
|
+
| SCD40 | Gas sensor | `periph/src/chips/gas/scd40` |
|
|
163
172
|
| SD_SPI | Memory | `periph/src/chips/memory/sd_spi` |
|
|
164
173
|
| SH1106 | Display driver | `periph/src/chips/display/sh1106` |
|
|
165
174
|
| SHT31 | Humidity sensor | `periph/src/chips/humidity/sht31` |
|
|
166
175
|
| SHTC3 | Humidity sensor | `periph/src/chips/humidity/shtc3` |
|
|
167
176
|
| SI1132 | Light sensor | `periph/src/chips/light/si1132` |
|
|
177
|
+
| SI1133 | Light sensor | `periph/src/chips/light/si1133` |
|
|
178
|
+
| SI1145 | Light sensor | `periph/src/chips/light/si1145` |
|
|
168
179
|
| SI7021 | Humidity sensor | `periph/src/chips/humidity/si7021` |
|
|
169
180
|
| SK6812RGBW | LED driver | `periph/src/chips/led/sk6812rgbw` |
|
|
181
|
+
| SPL06 | Pressure sensor | `periph/src/chips/pressure/spl06` |
|
|
170
182
|
| SSD1305 | Display driver | `periph/src/chips/display/ssd1305` |
|
|
171
183
|
| SSD1306 | Display driver | `periph/src/chips/display/ssd1306` |
|
|
172
184
|
| SSD1331 | Display driver | `periph/src/chips/display/ssd1331` |
|
|
185
|
+
| ST25DV | RFID/NFC | `periph/src/chips/rfid/st25dv` |
|
|
173
186
|
| ST7036 | Display driver | `periph/src/chips/display/st7036` |
|
|
174
187
|
| TCA9554 | IO expander | `periph/src/chips/io_expander/tca9554` |
|
|
175
188
|
| TMC2130 | Motor driver | `periph/src/chips/motor/tmc2130` |
|
|
@@ -179,9 +192,13 @@ Each chip exposes two classes:
|
|
|
179
192
|
| TMP102 | Temperature sensor | `periph/src/chips/temperature/tmp102` |
|
|
180
193
|
| TMP117 | Temperature sensor | `periph/src/chips/temperature/tmp117` |
|
|
181
194
|
| TPIC6B595 | IO expander | `periph/src/chips/io_expander/tpic6b595` |
|
|
195
|
+
| TSL2561 | Light sensor | `periph/src/chips/light/tsl2561` |
|
|
196
|
+
| TSL2591 | Light sensor | `periph/src/chips/light/tsl2591` |
|
|
182
197
|
| UC1611S | Display driver | `periph/src/chips/display/uc1611s` |
|
|
183
198
|
| UC8159 | Display driver | `periph/src/chips/display/uc8159` |
|
|
184
199
|
| UC8276C | Display driver | `periph/src/chips/display/uc8276c` |
|
|
200
|
+
| VCNL4040 | Light sensor | `periph/src/chips/light/vcnl4040` |
|
|
201
|
+
| VCNL4200 | Light sensor | `periph/src/chips/light/vcnl4200` |
|
|
185
202
|
| VL53L0X | Time-of-flight | `periph/src/chips/tof/vl53l0x` |
|
|
186
203
|
| VL53L1X | Time-of-flight | `periph/src/chips/tof/vl53l1x` |
|
|
187
204
|
| VL6180X | Time-of-flight | `periph/src/chips/tof/vl6180x` |
|
|
@@ -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); });
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { RRH46410Full } = require('../../../src/chips/gas/rrh46410');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x38', 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=0x38) → Connection
|
|
11
|
+
// The module has the fixed address 0x38 and stretches the I²C clock.
|
|
12
|
+
const sensor = new RRH46410Full(connection); // Create RRH46410 driver, (connection) → void
|
|
13
|
+
// Constructor stores the connection only; no bus traffic yet.
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
await sensor.init(); // Check product ID, start IAQ 2nd Gen mode, () → void
|
|
17
|
+
// Retries Get Product ID for up to 1 s, verifies 0x2310, selects IAQ 2nd Gen (3 s samples).
|
|
18
|
+
|
|
19
|
+
console.log(await sensor.productId()); // Product ID and firmware, () → {productId, firmware: [major, minor, patch]}
|
|
20
|
+
// The product ID is always 0x2310.
|
|
21
|
+
console.log(await sensor.trackingNumber()); // ASIC tracking number, () → Buffer (6)
|
|
22
|
+
// Unique per module.
|
|
23
|
+
console.log(await sensor.getMode()); // Operation mode, () → number
|
|
24
|
+
// 1 = IAQ 2nd Gen after init.
|
|
25
|
+
|
|
26
|
+
await sensor.setHumidity(45.0); // Ambient humidity, (percent %RH) → void
|
|
27
|
+
// Sent as round(percent / 100 × 255); the module assumes 50 %RH otherwise.
|
|
28
|
+
console.log(await sensor.read()); // Next sample, () → {iaq, tvoc_mg_m3 mg/m³, etoh_ppm ppm, eco2_ppm ppm, relative_iaq, sample, warmed_up}
|
|
29
|
+
// Waits for the sample counter to change; values are fixed during the warm-up.
|
|
30
|
+
console.log(await sensor.waitForSample(4.0)); // Wait for a new sample, (timeout s) → boolean
|
|
31
|
+
// True when the counter changed (or INT went high) within the timeout.
|
|
32
|
+
console.log(await sensor.readResults()); // Latest result, () → object|null
|
|
33
|
+
// Does not wait; null before the first sample of the mode.
|
|
34
|
+
console.log(RRH46410Full.airQualityLabel(2.4)); // UBA rating, (iaq) → string
|
|
35
|
+
// "very good", "good", "medium", "poor" or "bad".
|
|
36
|
+
console.log(sensor.samplePeriod(), sensor.warmupSamples()); // Mode timing, (mode=null) → number s / number
|
|
37
|
+
// 3 s and 100 samples in IAQ 2nd Gen mode.
|
|
38
|
+
console.log(sensor.status()); // Last status byte, () → object
|
|
39
|
+
// Error bits and the operation-mode error code (0xA = sensor damaged).
|
|
40
|
+
|
|
41
|
+
await sensor.onInterrupt((r) => console.log('sample', r.sample, r.iaq)); // Subscribe, (callback, intPin=null) → void
|
|
42
|
+
// Rising edge on INT, or a 200 ms poll comparing the sample counter.
|
|
43
|
+
await sleep(7000);
|
|
44
|
+
await sensor.offInterrupt(); // Unsubscribe, () → void
|
|
45
|
+
// Stops the pin handler or polling timer.
|
|
46
|
+
console.log(await sensor.pollInterrupt()); // New sample pending, () → boolean
|
|
47
|
+
// INT level if wired, otherwise a counter comparison.
|
|
48
|
+
|
|
49
|
+
await sensor.setMode(RRH46410Full.MODE_PBAQ); // Operation mode, (mode) → void
|
|
50
|
+
// PBAQ: TVOC and ethanol only, every 5 s; restarts the warm-up.
|
|
51
|
+
console.log(await sensor.read()); // Next sample, () → {tvoc_mg_m3, etoh_ppm, sample, warmed_up}
|
|
52
|
+
// PBAQ results have a finer resolution (raw / 1000).
|
|
53
|
+
await sensor.setMode(RRH46410Full.MODE_ULP); // Operation mode, (mode) → void
|
|
54
|
+
// ULP: one sample every 90 s at 0.23 mW.
|
|
55
|
+
console.log(sensor.samplePeriod(), sensor.warmupSamples()); // Mode timing, (mode=null) → number s / number
|
|
56
|
+
// 90 s and 10 samples.
|
|
57
|
+
|
|
58
|
+
await sensor.configGpio(0x03); // GPIO directions, (directions) → void
|
|
59
|
+
// Bit 0 = GPIO1 output, bit 1 = GPIO2 output.
|
|
60
|
+
await sensor.setGpio(0x01); // Drive high, (mask) → void
|
|
61
|
+
// GPIO1 high.
|
|
62
|
+
console.log((await sensor.getGpio()).toString(2)); // GPIO levels, () → number
|
|
63
|
+
// Bits 0–3 = GPIO1–GPIO4.
|
|
64
|
+
await sensor.clearGpio(0x01); // Drive low, (mask) → void
|
|
65
|
+
// GPIO1 low.
|
|
66
|
+
|
|
67
|
+
console.log(await sensor.sendCommand(0x10, [], 1)); // Raw request, (command, params=[], responseLen=0) → Buffer
|
|
68
|
+
// Checksums added and verified; here Get Operation Mode.
|
|
69
|
+
// await sensor.cleanSensor(true); // One-time cleaning, (confirm=false) → void
|
|
70
|
+
// Runs for one minute, once in the sensor's lifetime; left disabled here.
|
|
71
|
+
await sensor.suspend(); // Suspend mode, () → void
|
|
72
|
+
// Stops measuring, about 0.7 µA.
|
|
73
|
+
await sensor.reset(); // Reset, () → void
|
|
74
|
+
// Waits 500 ms and verifies the product ID; the module restarts in SUSPEND.
|
|
75
|
+
await connection.close();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { RRH46410Full } = require('../../../src/chips/gas/rrh46410');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x38', 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=0x38) → Connection
|
|
11
|
+
const sensor = new RRH46410Full(connection); // Create RRH46410 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Check product ID, start IAQ 2nd Gen mode, () → void
|
|
15
|
+
|
|
16
|
+
// --- Identity ---
|
|
17
|
+
// Get Product ID returns 0x2310 and the firmware version; the tracking number
|
|
18
|
+
// identifies the individual module.
|
|
19
|
+
const { productId, firmware } = await sensor.productId(); // Product ID and firmware, () → {productId, firmware}
|
|
20
|
+
console.log('product 0x%s, firmware %s', productId.toString(16), firmware.join('.'));
|
|
21
|
+
console.log('tracking', (await sensor.trackingNumber()).toString('hex')); // Tracking number, () → Buffer
|
|
22
|
+
console.log('mode', await sensor.getMode()); // Operation mode, () → number
|
|
23
|
+
|
|
24
|
+
// --- Humidity compensation ---
|
|
25
|
+
// The MOx element reacts to humidity; feeding the real value (e.g. from a
|
|
26
|
+
// humidity sensor) improves the results. The module assumes 50 %RH.
|
|
27
|
+
await sensor.setHumidity(42.0); // Ambient humidity, (percent %RH) → void
|
|
28
|
+
|
|
29
|
+
// --- Indoor air-quality monitor ---
|
|
30
|
+
// A new sample arrives every 3 s; the first 100 samples (about 5 min) are the
|
|
31
|
+
// warm-up during which the values stay fixed.
|
|
32
|
+
const warmup = sensor.warmupSamples(); // Warm-up length, (mode=null) → number samples
|
|
33
|
+
console.log('sample period %d s, warm-up %d samples', sensor.samplePeriod(), warmup); // Sample period, (mode=null) → number s
|
|
34
|
+
for (let i = 0; i < 20; i++) {
|
|
35
|
+
const r = await sensor.read(); // Next sample, () → object
|
|
36
|
+
const progress = r.warmed_up ? 'ok' : `warm-up ${Math.min(100, Math.floor(r.sample * 100 / warmup))}%`;
|
|
37
|
+
console.log('IAQ %s (%s) TVOC %s mg/m3 EtOH %s ppm eCO2 %d ppm rel %d %s', r.iaq.toFixed(1),
|
|
38
|
+
sensor.airQualityLabel(r.iaq), r.tvoc_mg_m3.toFixed(2), // UBA rating, (iaq) → string
|
|
39
|
+
r.etoh_ppm.toFixed(2), r.eco2_ppm, r.relative_iaq, progress);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// --- Interrupt instead of polling ---
|
|
43
|
+
// With INT wired the driver reacts to its rising edge; otherwise it polls the
|
|
44
|
+
// sample counter. The callback receives the decoded result.
|
|
45
|
+
await sensor.onInterrupt((r) => console.log('INT sample %d IAQ %s', r.sample, r.iaq.toFixed(1))); // Subscribe, (callback, intPin=null) → void
|
|
46
|
+
await sleep(10000);
|
|
47
|
+
await sensor.offInterrupt(); // Unsubscribe, () → void
|
|
48
|
+
while (!(await sensor.pollInterrupt())) await sleep(500); // New sample pending, () → boolean
|
|
49
|
+
if (await sensor.waitForSample(4.0)) { // Wait for a new sample, (timeout s) → boolean
|
|
50
|
+
console.log('latest', await sensor.readResults()); // Latest result, () → object|null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// --- Other operation modes ---
|
|
54
|
+
// PBAQ reports TVOC and ethanol for public buildings; ULP saves power with
|
|
55
|
+
// one sample every 90 s. Each mode change restarts the warm-up.
|
|
56
|
+
for (const [mode, name] of [[RRH46410Full.MODE_PBAQ, 'PBAQ'], [RRH46410Full.MODE_ULP, 'ULP']]) {
|
|
57
|
+
await sensor.setMode(mode); // Operation mode, (mode) → void
|
|
58
|
+
console.log('%s: sample every %d s, warm-up %d samples (%d min)', name, sensor.samplePeriod(),
|
|
59
|
+
sensor.warmupSamples(), sensor.samplePeriod() * sensor.warmupSamples() / 60); // Mode timing, (mode=null) → number
|
|
60
|
+
}
|
|
61
|
+
await sensor.setMode(RRH46410Full.MODE_PBAQ); // Operation mode, (mode) → void
|
|
62
|
+
console.log('PBAQ', await sensor.read()); // Next sample, () → {tvoc_mg_m3, etoh_ppm, sample, warmed_up}
|
|
63
|
+
|
|
64
|
+
// --- GPIOs ---
|
|
65
|
+
// GPIO1 and GPIO2 can drive an indicator LED or a fan relay.
|
|
66
|
+
await sensor.configGpio(0x03); // Both outputs, (directions) → void
|
|
67
|
+
for (let i = 0; i < 3; i++) {
|
|
68
|
+
await sensor.setGpio(0x01); // GPIO1 high, (mask) → void
|
|
69
|
+
await sleep(200);
|
|
70
|
+
await sensor.clearGpio(0x01); // GPIO1 low, (mask) → void
|
|
71
|
+
await sleep(200);
|
|
72
|
+
}
|
|
73
|
+
console.log('GPIO levels', (await sensor.getGpio()).toString(2)); // GPIO levels, () → number
|
|
74
|
+
console.log('status', sensor.status()); // Last status byte, () → object
|
|
75
|
+
console.log('raw mode', (await sensor.sendCommand(0x10, [], 1))[0]); // Raw request, (command, params, responseLen) → Buffer
|
|
76
|
+
|
|
77
|
+
// --- Wrap up ---
|
|
78
|
+
// cleanSensor(true) runs the 1-minute cleaning once in the sensor's lifetime;
|
|
79
|
+
// it is skipped here. Suspend stops measuring; reset restarts the module in SUSPEND.
|
|
80
|
+
await sensor.suspend(); // Suspend mode, () → void
|
|
81
|
+
await sensor.reset(); // Reset, () → void
|
|
82
|
+
console.log('mode after reset', await sensor.getMode()); // Operation mode, () → number
|
|
83
|
+
await connection.close();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { RRH46410Minimal } = require('../../../src/chips/gas/rrh46410');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x38', 16);
|
|
8
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x38) → Connection
|
|
10
|
+
const sensor = new RRH46410Minimal(connection); // Create RRH46410 driver, (connection) → void
|
|
11
|
+
|
|
12
|
+
async function main() {
|
|
13
|
+
await sensor.init(); // Check product ID, start IAQ 2nd Gen mode, () → void
|
|
14
|
+
while (true) {
|
|
15
|
+
const r = await sensor.read(); // Wait for the next sample, () → {iaq, tvoc_mg_m3 mg/m³, etoh_ppm ppm, eco2_ppm ppm, relative_iaq, sample, warmed_up}
|
|
16
|
+
console.log('IAQ %s TVOC %s mg/m3 EtOH %s ppm eCO2 %d ppm %s', r.iaq.toFixed(1), r.tvoc_mg_m3.toFixed(2),
|
|
17
|
+
r.etoh_ppm.toFixed(2), r.eco2_ppm, r.warmed_up ? 'ok' : 'warming up');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { RRH62000Full } = require('../../../src/chips/gas/rrh62000');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x69', 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=0x69) → Connection
|
|
11
|
+
// The module has the fixed address 0x69; SEL (pin 5) must be at GND for I²C.
|
|
12
|
+
const sensor = new RRH62000Full(connection); // Create RRH62000 driver, (connection, {accessIntervalMs=1000}) → void
|
|
13
|
+
// Starts the start-up timers: I²C after 1 s, valid data after 3.3 s.
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
await sensor.init(); // Wait for start-up, check firmware version, () → void
|
|
17
|
+
// Reads the firmware version as a presence check.
|
|
18
|
+
|
|
19
|
+
console.log(await sensor.firmwareVersion()); // Firmware version, () → [major, minor]
|
|
20
|
+
// Every access is at least 1 s after the previous one (tRD); the driver waits.
|
|
21
|
+
console.log(await sensor.algorithmVersion()); // TVOC algorithm version, () → [major, minor, patch]
|
|
22
|
+
// Version of the ZMOD4410 algorithm in the module.
|
|
23
|
+
console.log((await sensor.uniqueId()).toString('hex')); // Unique ID, () → Buffer (6)
|
|
24
|
+
// Identifies the individual module.
|
|
25
|
+
|
|
26
|
+
console.log(await sensor.read()); // Main values, () → {pm1_ug_m3, pm2_5_ug_m3, pm10_ug_m3, temperature_c, humidity_rh, tvoc, eco2_ppm, iaq}
|
|
27
|
+
// Waits for DATA, reads the 37-byte block, checks the CRC; PM uses the KCl reference.
|
|
28
|
+
console.log(await sensor.readAll()); // Complete block, () → object
|
|
29
|
+
// Status flags, 5 number-concentration bins (cm⁻³), PM KCl and smoke, T, RH, TVOC, eCO₂, IAQ.
|
|
30
|
+
console.log(await sensor.readStatus()); // Status flags, () → {raw, high_concentration, dust_accumulation, fan_speed, fan}
|
|
31
|
+
// Reads the current block without waiting for new data.
|
|
32
|
+
console.log(await sensor.readParticles()); // Particle values, () → object
|
|
33
|
+
// PM1/2.5/10 (KCl and cigarette smoke, µg/m³) and the number bins (cm⁻³).
|
|
34
|
+
console.log(await sensor.dataReady()); // New sample available, () → boolean
|
|
35
|
+
// DATA (0x40); a sample arrives every 3 s.
|
|
36
|
+
|
|
37
|
+
await sensor.setMovingAverage(20); // Moving average, (count 1–60) → void
|
|
38
|
+
// More averages: smoother values, slower response (24 s at 10).
|
|
39
|
+
console.log(await sensor.getMovingAverage()); // Moving average, () → number
|
|
40
|
+
// 20.
|
|
41
|
+
await sensor.setFanSpeed(80); // Fan speed, (percent 60–100) → void
|
|
42
|
+
// Lower speed is quieter; the default is 86 %.
|
|
43
|
+
console.log(await sensor.getFanSpeed()); // Fan speed, () → number %
|
|
44
|
+
// 80.
|
|
45
|
+
await sensor.setCleaningInterval(3 * 24 * 3600); // Cleaning interval, (seconds, multiple of 30) → void
|
|
46
|
+
// Written as a 16-bit count of 30 s units, high byte first.
|
|
47
|
+
console.log(await sensor.getCleaningInterval()); // Cleaning interval, () → number s
|
|
48
|
+
// 259200.
|
|
49
|
+
await sensor.setCleaningTime(15); // Cleaning time, (seconds 0–60) → void
|
|
50
|
+
// How long the fan runs at full speed during the automatic cleaning.
|
|
51
|
+
console.log(await sensor.getCleaningTime()); // Cleaning time, () → number s
|
|
52
|
+
// 15.
|
|
53
|
+
|
|
54
|
+
await sensor.startCleaning(); // Start fan cleaning, () → void
|
|
55
|
+
// Blows dust out of the air channel.
|
|
56
|
+
await sleep(15000);
|
|
57
|
+
console.log(await sensor.cleaningDone()); // Cleaning status, () → boolean
|
|
58
|
+
// CSTATUS (0x74): true when completed.
|
|
59
|
+
console.log(await sensor.readMoxResistance()); // MOX resistance, () → number Ω
|
|
60
|
+
// Raw resistance of the TVOC sensing element.
|
|
61
|
+
|
|
62
|
+
await sensor.sleep(); // Sleep, () → void
|
|
63
|
+
// Stops the fan and the measurement.
|
|
64
|
+
await sleep(5000);
|
|
65
|
+
await sensor.wake(); // Wake up, () → void
|
|
66
|
+
// The next access waits 1 s, the next measurement 3.3 s.
|
|
67
|
+
await sensor.softReset(); // Reset, () → void
|
|
68
|
+
// Same as power-on: restarts the start-up timers.
|
|
69
|
+
console.log(await sensor.read()); // Main values, () → object
|
|
70
|
+
// First sample after the reset.
|
|
71
|
+
await connection.close();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { RRH62000Full } = require('../../../src/chips/gas/rrh62000');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x69', 16);
|
|
8
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
function iaqLabel(iaq) {
|
|
11
|
+
if (iaq < 2) return 'very good';
|
|
12
|
+
if (iaq < 3) return 'good';
|
|
13
|
+
if (iaq < 4) return 'medium';
|
|
14
|
+
if (iaq < 5) return 'poor';
|
|
15
|
+
return 'bad';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x69) → Connection
|
|
19
|
+
const sensor = new RRH62000Full(connection); // Create RRH62000 driver, (connection, {accessIntervalMs=1000}) → void
|
|
20
|
+
|
|
21
|
+
async function main() {
|
|
22
|
+
await sensor.init(); // Wait for start-up, check firmware version, () → void
|
|
23
|
+
|
|
24
|
+
// --- Identity and settings ---
|
|
25
|
+
// The module may only be accessed once per second; every call below waits
|
|
26
|
+
// for that interval, so this section takes several seconds.
|
|
27
|
+
console.log('firmware %s', (await sensor.firmwareVersion()).join('.')); // Firmware version, () → [major, minor]
|
|
28
|
+
console.log('algorithm %s', (await sensor.algorithmVersion()).join('.')); // Algorithm version, () → [major, minor, patch]
|
|
29
|
+
console.log('unique ID %s', (await sensor.uniqueId()).toString('hex')); // Unique ID, () → Buffer
|
|
30
|
+
console.log('moving average %d, fan %d %%, cleaning every %d s for %d s',
|
|
31
|
+
await sensor.getMovingAverage(), await sensor.getFanSpeed(), // Moving average, () → number / Fan speed, () → number %
|
|
32
|
+
await sensor.getCleaningInterval(), await sensor.getCleaningTime()); // Cleaning interval, () → number s / Cleaning time, () → number s
|
|
33
|
+
|
|
34
|
+
// --- Room air-quality station ---
|
|
35
|
+
// A complete sample arrives every 3 s. The IAQ index follows the German UBA
|
|
36
|
+
// scale; PM2.5 uses the KCl reference. Allow up to 48 h of conditioning on
|
|
37
|
+
// first use before trusting TVOC and eCO2.
|
|
38
|
+
const end = Date.now() + 30000;
|
|
39
|
+
while (Date.now() < end) {
|
|
40
|
+
const m = await sensor.readAll(); // Complete block, () → object
|
|
41
|
+
console.log('IAQ %s (%s) PM2.5 %s ug/m3 eCO2 %d ppm TVOC %d ug/m3 %s C %s %%RH',
|
|
42
|
+
m.iaq.toFixed(2), iaqLabel(m.iaq), m.pm2_5_ug_m3.toFixed(1), m.eco2_ppm, m.tvoc,
|
|
43
|
+
m.temperature_c.toFixed(1), m.humidity_rh.toFixed(1));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// --- Particle counts and status ---
|
|
47
|
+
// Number concentrations count particles from the bin size up to 10 µm per cm³.
|
|
48
|
+
const p = await sensor.readParticles(); // Particle values, () → object
|
|
49
|
+
console.log('particles/cm3 >0.3um %s >0.5um %s >1um %s >2.5um %s >4um %s',
|
|
50
|
+
p.nc_0_3.toFixed(1), p.nc_0_5.toFixed(1), p.nc_1.toFixed(1), p.nc_2_5.toFixed(1), p.nc_4.toFixed(1));
|
|
51
|
+
console.log('PM2.5 KCl %s / smoke %s ug/m3', p.pm2_5_ug_m3.toFixed(1), p.pm2_5_smoke_ug_m3.toFixed(1));
|
|
52
|
+
console.log('status', await sensor.readStatus()); // Status flags, () → object
|
|
53
|
+
console.log('new data pending:', await sensor.dataReady()); // New sample available, () → boolean
|
|
54
|
+
|
|
55
|
+
// --- Quieter, smoother operation ---
|
|
56
|
+
// 30 moving averages smooth the PM values (slower response); 70 % fan speed
|
|
57
|
+
// is quieter.
|
|
58
|
+
await sensor.setMovingAverage(30); // Moving average, (count 1–60) → void
|
|
59
|
+
await sensor.setFanSpeed(70); // Fan speed, (percent 60–100) → void
|
|
60
|
+
console.log('moving average %d, fan %d %%', await sensor.getMovingAverage(), await sensor.getFanSpeed());
|
|
61
|
+
|
|
62
|
+
// --- Fan cleaning ---
|
|
63
|
+
// A manual cleaning blows dust out of the air channel; the automatic
|
|
64
|
+
// cleaning is shortened to every 3 days for 10 s.
|
|
65
|
+
await sensor.startCleaning(); // Start fan cleaning, () → void
|
|
66
|
+
for (let i = 0; i < 30; i++) {
|
|
67
|
+
if (await sensor.cleaningDone()) { // Cleaning status, () → boolean
|
|
68
|
+
console.log('cleaning done');
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
await sensor.setCleaningInterval(3 * 24 * 3600); // Cleaning interval, (seconds) → void
|
|
73
|
+
await sensor.setCleaningTime(10); // Cleaning time, (seconds) → void
|
|
74
|
+
console.log('cleaning every %d s', await sensor.getCleaningInterval());
|
|
75
|
+
|
|
76
|
+
// --- Sleep, diagnostics, reset ---
|
|
77
|
+
// Sleep stops the fan; after wake-up the first valid sample takes 3.3 s.
|
|
78
|
+
await sensor.sleep(); // Sleep, () → void
|
|
79
|
+
await sleep(5000);
|
|
80
|
+
await sensor.wake(); // Wake up, () → void
|
|
81
|
+
console.log('MOX resistance %d ohm', await sensor.readMoxResistance()); // MOX resistance, () → number Ω
|
|
82
|
+
await sensor.softReset(); // Reset, () → void
|
|
83
|
+
console.log('after reset', await sensor.read()); // Main values, () → object
|
|
84
|
+
await connection.close();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
main().catch(err => { console.error(err); process.exit(1); });
|