periph 1.6.0 → 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 +11 -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/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/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/rrh62000.js +418 -0
- package/src/chips/gas/scd30.js +368 -0
- package/src/chips/gas/scd40.js +451 -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/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/discovery/registry.js +11 -11
package/README.md
CHANGED
|
@@ -73,6 +73,7 @@ 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` |
|
|
78
79
|
| CCS811 | Gas sensor | `periph/src/chips/gas/ccs811` |
|
|
@@ -80,6 +81,8 @@ Each chip exposes two classes:
|
|
|
80
81
|
| DHT11 | Humidity sensor | `periph/src/chips/humidity/dht11` |
|
|
81
82
|
| DRV2605 | Motor driver | `periph/src/chips/motor/drv2605` |
|
|
82
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` |
|
|
83
86
|
| DS1881 | ADC/DAC | `periph/src/chips/adc_dac/ds1881` |
|
|
84
87
|
| DS3231 | RTC | `periph/src/chips/rtc/ds3231` |
|
|
85
88
|
| DS3502 | ADC/DAC | `periph/src/chips/adc_dac/ds3502` |
|
|
@@ -162,7 +165,10 @@ Each chip exposes two classes:
|
|
|
162
165
|
| RDA5807M | Comms | `periph/src/chips/comms/rda5807m` |
|
|
163
166
|
| RFM9X | Comms | `periph/src/chips/comms/rfm9x` |
|
|
164
167
|
| RRH46410 | Gas sensor | `periph/src/chips/gas/rrh46410` |
|
|
168
|
+
| RRH62000 | Gas sensor | `periph/src/chips/gas/rrh62000` |
|
|
165
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` |
|
|
166
172
|
| SD_SPI | Memory | `periph/src/chips/memory/sd_spi` |
|
|
167
173
|
| SH1106 | Display driver | `periph/src/chips/display/sh1106` |
|
|
168
174
|
| SHT31 | Humidity sensor | `periph/src/chips/humidity/sht31` |
|
|
@@ -176,6 +182,7 @@ Each chip exposes two classes:
|
|
|
176
182
|
| SSD1305 | Display driver | `periph/src/chips/display/ssd1305` |
|
|
177
183
|
| SSD1306 | Display driver | `periph/src/chips/display/ssd1306` |
|
|
178
184
|
| SSD1331 | Display driver | `periph/src/chips/display/ssd1331` |
|
|
185
|
+
| ST25DV | RFID/NFC | `periph/src/chips/rfid/st25dv` |
|
|
179
186
|
| ST7036 | Display driver | `periph/src/chips/display/st7036` |
|
|
180
187
|
| TCA9554 | IO expander | `periph/src/chips/io_expander/tca9554` |
|
|
181
188
|
| TMC2130 | Motor driver | `periph/src/chips/motor/tmc2130` |
|
|
@@ -185,9 +192,13 @@ Each chip exposes two classes:
|
|
|
185
192
|
| TMP102 | Temperature sensor | `periph/src/chips/temperature/tmp102` |
|
|
186
193
|
| TMP117 | Temperature sensor | `periph/src/chips/temperature/tmp117` |
|
|
187
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` |
|
|
188
197
|
| UC1611S | Display driver | `periph/src/chips/display/uc1611s` |
|
|
189
198
|
| UC8159 | Display driver | `periph/src/chips/display/uc8159` |
|
|
190
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` |
|
|
191
202
|
| VL53L0X | Time-of-flight | `periph/src/chips/tof/vl53l0x` |
|
|
192
203
|
| VL53L1X | Time-of-flight | `periph/src/chips/tof/vl53l1x` |
|
|
193
204
|
| VL6180X | Time-of-flight | `periph/src/chips/tof/vl6180x` |
|
|
@@ -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); });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { RRH62000Minimal } = 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
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x69) → Connection
|
|
10
|
+
const sensor = new RRH62000Minimal(connection); // Create RRH62000 driver, (connection, {accessIntervalMs=1000}) → void
|
|
11
|
+
|
|
12
|
+
async function main() {
|
|
13
|
+
await sensor.init(); // Wait for start-up, check firmware version, () → void
|
|
14
|
+
while (true) {
|
|
15
|
+
const r = await sensor.read(); // Wait for a new sample, () → {pm1_ug_m3, pm2_5_ug_m3, pm10_ug_m3 µg/m³, temperature_c °C, humidity_rh %RH, tvoc µg/m³, eco2_ppm ppm, iaq}
|
|
16
|
+
console.log('PM1 %s PM2.5 %s PM10 %s ug/m3 %s C %s %%RH TVOC %d ug/m3 eCO2 %d ppm IAQ %s',
|
|
17
|
+
r.pm1_ug_m3.toFixed(1), r.pm2_5_ug_m3.toFixed(1), r.pm10_ug_m3.toFixed(1), r.temperature_c.toFixed(2),
|
|
18
|
+
r.humidity_rh.toFixed(2), r.tvoc, r.eco2_ppm, r.iaq.toFixed(2));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { SCD30Full } = require('../../../src/chips/gas/scd30');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x61', 16);
|
|
8
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x61) → Connection
|
|
10
|
+
// The module has the fixed address 0x61; the bus must support clock stretching (≤ 100 kHz).
|
|
11
|
+
const sensor = new SCD30Full(connection); // Create SCD30 driver, (connection) → void
|
|
12
|
+
// No bus access yet.
|
|
13
|
+
|
|
14
|
+
async function main() {
|
|
15
|
+
await sensor.init(); // Read firmware/interval, start measuring, () → void
|
|
16
|
+
// Starts the continuous measurement without pressure compensation; stored settings are kept.
|
|
17
|
+
console.log(await sensor.firmwareVersion()); // Firmware version, () → [major, minor]
|
|
18
|
+
// Command 0xD100.
|
|
19
|
+
console.log(await sensor.read()); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
20
|
+
// Polls the data-ready status, then reads 18 bytes with six CRCs.
|
|
21
|
+
console.log(await sensor.readCo2()); // CO₂ of a fresh sample, () → number ppm
|
|
22
|
+
// Each single-value call waits for its own sample (one interval).
|
|
23
|
+
console.log(await sensor.readTemperature()); // Temperature of a fresh sample, () → number °C
|
|
24
|
+
// The temperature offset has already been subtracted.
|
|
25
|
+
console.log(await sensor.readHumidity()); // Humidity of a fresh sample, () → number %RH
|
|
26
|
+
// Compensated for the temperature offset.
|
|
27
|
+
console.log(await sensor.dataReady()); // New sample available, () → boolean
|
|
28
|
+
// Command 0x0202; usually false right after a read.
|
|
29
|
+
console.log(await sensor.readMeasurement()); // Current sample without waiting, () → [co2_ppm, temperature_c, humidity_rh]
|
|
30
|
+
// Call after dataReady(); otherwise the values may be stale.
|
|
31
|
+
|
|
32
|
+
await sensor.stop(); // Stop measuring, () → void
|
|
33
|
+
// Command 0x0104.
|
|
34
|
+
await sensor.start(101325); // Start measuring, (pressurePa=0 or 70000–140000) → void
|
|
35
|
+
// Pressure compensation with 1013 mbar; overrides the altitude until the next start.
|
|
36
|
+
await sensor.start(); // Start measuring, (pressurePa=0) → void
|
|
37
|
+
// 0 switches the pressure compensation off again.
|
|
38
|
+
|
|
39
|
+
await sensor.setInterval(5); // Measurement interval, (seconds 2–1800) → void
|
|
40
|
+
// Stored in non-volatile memory; read() waits up to the interval plus 1 s.
|
|
41
|
+
console.log(await sensor.getInterval()); // Measurement interval, () → number s
|
|
42
|
+
// 5.
|
|
43
|
+
await sensor.setInterval(2); // Measurement interval, (seconds 2–1800) → void
|
|
44
|
+
// Back to the default.
|
|
45
|
+
await sensor.setAutoCalibration(false); // Automatic self-calibration, (enabled) → void
|
|
46
|
+
// ASC needs fresh air (≈ 400 ppm) regularly; off is the module default.
|
|
47
|
+
console.log(await sensor.getAutoCalibration()); // Automatic self-calibration, () → boolean
|
|
48
|
+
// false.
|
|
49
|
+
console.log(await sensor.getForcedCalibration()); // FRC reference, () → number ppm
|
|
50
|
+
// 400 unless a forced recalibration was applied.
|
|
51
|
+
// await sensor.setForcedCalibration(420); // Forced recalibration, (ppm 400–2000) → void
|
|
52
|
+
// Only at a known reference concentration after ≥ 2 minutes of stable measurement.
|
|
53
|
+
await sensor.setTemperatureOffset(1.5); // Temperature offset, (kelvin 0–655.35) → void
|
|
54
|
+
// Compensates self-heating; sent in 0.01 K units.
|
|
55
|
+
console.log(await sensor.getTemperatureOffset()); // Temperature offset, () → number K
|
|
56
|
+
// 1.5.
|
|
57
|
+
await sensor.setAltitude(250); // Altitude compensation, (metres) → void
|
|
58
|
+
// Used while no pressure is given to start().
|
|
59
|
+
console.log(await sensor.getAltitude()); // Altitude compensation, () → number m
|
|
60
|
+
// 250.
|
|
61
|
+
|
|
62
|
+
console.log((await sensor.readWord(0x4600)).toString(16)); // Raw read, (command) → number
|
|
63
|
+
// Writes the command, waits 3 ms, reads one word and checks its CRC.
|
|
64
|
+
await sensor.writeWord(0x4600, 2); // Raw write, (command, value) → void
|
|
65
|
+
// Appends the argument and its CRC.
|
|
66
|
+
await sensor.softReset(); // Soft reset, () → void
|
|
67
|
+
// Waits 2 s and restarts the measurement; stored settings survive.
|
|
68
|
+
console.log(await sensor.read()); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
69
|
+
// First sample after the reset.
|
|
70
|
+
await connection.close();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { SCD30Full } = require('../../../src/chips/gas/scd30');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x61', 16);
|
|
8
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
function classify(co2) {
|
|
11
|
+
if (co2 < 1000) return 'good';
|
|
12
|
+
if (co2 <= 1500) return 'moderate';
|
|
13
|
+
return 'poor';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x61) → Connection
|
|
17
|
+
const sensor = new SCD30Full(connection); // Create SCD30 driver, (connection) → void
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
await sensor.init(); // Read firmware/interval, start measuring, () → void
|
|
21
|
+
|
|
22
|
+
/* --- Identity and settings ---
|
|
23
|
+
* All settings live in the module's non-volatile memory; the driver does not
|
|
24
|
+
* rewrite them on start-up, so this shows what earlier sessions left behind. */
|
|
25
|
+
const [major, minor] = await sensor.firmwareVersion(); // Firmware version, () → [major, minor]
|
|
26
|
+
console.log(`firmware ${major}.${minor}, interval ${await sensor.getInterval()} s, ` + // Measurement interval, () → number s
|
|
27
|
+
`ASC ${await sensor.getAutoCalibration()}, FRC ${await sensor.getForcedCalibration()} ppm, ` + // ASC, () → boolean / FRC reference, () → number ppm
|
|
28
|
+
`offset ${(await sensor.getTemperatureOffset()).toFixed(2)} K, altitude ${await sensor.getAltitude()} m`); // Temperature offset, () → number K / Altitude, () → number m
|
|
29
|
+
|
|
30
|
+
/* --- Room air-quality monitor ---
|
|
31
|
+
* Outdoor air is about 420 ppm; above 1000 ppm a room feels stuffy, above
|
|
32
|
+
* 1500 ppm it should be ventilated. A sample arrives every 2 s. */
|
|
33
|
+
const end = Date.now() + 30000;
|
|
34
|
+
while (Date.now() < end) {
|
|
35
|
+
const r = await sensor.read(); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
36
|
+
console.log(`CO2 ${r.co2_ppm.toFixed(0)} ppm (${classify(r.co2_ppm)}) ${r.temperature_c.toFixed(2)} C ${r.humidity_rh.toFixed(1)} %RH`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* --- Self-heating compensation ---
|
|
40
|
+
* The module warms itself by a few kelvin. The offset is subtracted from the
|
|
41
|
+
* temperature, and the humidity is recomputed for the corrected temperature. */
|
|
42
|
+
const before = await sensor.read(); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
43
|
+
const oldOffset = await sensor.getTemperatureOffset(); // Temperature offset, () → number K
|
|
44
|
+
await sensor.setTemperatureOffset(oldOffset + 2); // Temperature offset, (kelvin) → void
|
|
45
|
+
await sleep(4000);
|
|
46
|
+
const t = await sensor.readTemperature(); // Temperature of a fresh sample, () → number °C
|
|
47
|
+
const h = await sensor.readHumidity(); // Humidity of a fresh sample, () → number %RH
|
|
48
|
+
console.log(`offset +2 K: ${before.temperature_c.toFixed(2)} C -> ${t.toFixed(2)} C, ` +
|
|
49
|
+
`${before.humidity_rh.toFixed(1)} %RH -> ${h.toFixed(1)} %RH`);
|
|
50
|
+
await sensor.setTemperatureOffset(oldOffset); // Temperature offset, (kelvin) → void
|
|
51
|
+
|
|
52
|
+
/* --- Altitude and pressure compensation ---
|
|
53
|
+
* CO₂ absorption depends on the air density. Give the altitude once, or the
|
|
54
|
+
* current ambient pressure (in pascals) with every start. */
|
|
55
|
+
const oldAltitude = await sensor.getAltitude(); // Altitude compensation, () → number m
|
|
56
|
+
await sensor.setAltitude(500); // Altitude compensation, (metres) → void
|
|
57
|
+
console.log(`altitude 500 m: CO2 ${(await sensor.readCo2()).toFixed(0)} ppm`); // CO₂ of a fresh sample, () → number ppm
|
|
58
|
+
await sensor.start(95000); // Start measuring, (pressurePa) → void
|
|
59
|
+
console.log(`pressure 95000 Pa: CO2 ${(await sensor.readCo2()).toFixed(0)} ppm`); // CO₂ of a fresh sample, () → number ppm
|
|
60
|
+
await sensor.start(); // Start measuring, (pressurePa=0) → void
|
|
61
|
+
await sensor.setAltitude(oldAltitude); // Altitude compensation, (metres) → void
|
|
62
|
+
|
|
63
|
+
/* --- Automatic self-calibration ---
|
|
64
|
+
* ASC learns the 400 ppm baseline from the lowest readings of the past days;
|
|
65
|
+
* the sensor must see fresh air at least once a week. */
|
|
66
|
+
const asc = await sensor.getAutoCalibration(); // ASC, () → boolean
|
|
67
|
+
await sensor.setAutoCalibration(true); // ASC, (enabled) → void
|
|
68
|
+
console.log('ASC on:', await sensor.getAutoCalibration()); // ASC, () → boolean
|
|
69
|
+
await sensor.setAutoCalibration(asc); // ASC, (enabled) → void
|
|
70
|
+
|
|
71
|
+
/* --- Data-ready, stop and start --- */
|
|
72
|
+
console.log('data ready:', await sensor.dataReady()); // New sample available, () → boolean
|
|
73
|
+
await sensor.stop(); // Stop measuring, () → void
|
|
74
|
+
await sleep(3000);
|
|
75
|
+
console.log('stopped, data ready:', await sensor.dataReady()); // New sample available, () → boolean
|
|
76
|
+
await sensor.start(); // Start measuring, (pressurePa=0) → void
|
|
77
|
+
while (!(await sensor.dataReady())) await sleep(100); // New sample available, () → boolean
|
|
78
|
+
console.log('restarted:', await sensor.readMeasurement()); // Current sample without waiting, () → [co2_ppm, temperature_c, humidity_rh]
|
|
79
|
+
|
|
80
|
+
/* --- Slower interval ---
|
|
81
|
+
* A longer interval saves power; read() waits up to the interval plus 1 s. */
|
|
82
|
+
await sensor.setInterval(5); // Measurement interval, (seconds) → void
|
|
83
|
+
console.log(`interval ${await sensor.getInterval()} s: CO2 ${(await sensor.readCo2()).toFixed(0)} ppm`); // Measurement interval, () → number s / CO₂, () → number ppm
|
|
84
|
+
await sensor.setInterval(2); // Measurement interval, (seconds) → void
|
|
85
|
+
|
|
86
|
+
/* --- Forced recalibration ---
|
|
87
|
+
* FRC sets the current reading to a known reference concentration. Only do
|
|
88
|
+
* this with the sensor in reference gas (or fresh outdoor air) for at least
|
|
89
|
+
* 2 minutes; it is skipped here. */
|
|
90
|
+
const REFERENCE_GAS = false;
|
|
91
|
+
if (REFERENCE_GAS) await sensor.setForcedCalibration(420); // Forced recalibration, (ppm 400–2000) → void
|
|
92
|
+
console.log(`FRC reference ${await sensor.getForcedCalibration()} ppm (skipped)`); // FRC reference, () → number ppm
|
|
93
|
+
|
|
94
|
+
/* --- Raw commands and reset --- */
|
|
95
|
+
console.log('raw interval word:', await sensor.readWord(0x4600)); // Raw read, (command) → number
|
|
96
|
+
await sensor.writeWord(0x4600, await sensor.getInterval()); // Raw write, (command, value) → void
|
|
97
|
+
await sensor.softReset(); // Soft reset, () → void
|
|
98
|
+
console.log('after reset:', await sensor.read()); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
99
|
+
await connection.close();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
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 { SCD30Minimal } = require('../../../src/chips/gas/scd30');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x61', 16);
|
|
8
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x61) → Connection
|
|
10
|
+
const sensor = new SCD30Minimal(connection); // Create SCD30 driver, (connection) → void
|
|
11
|
+
|
|
12
|
+
async function main() {
|
|
13
|
+
await sensor.init(); // Read firmware/interval, start measuring, () → void
|
|
14
|
+
while (true) {
|
|
15
|
+
const r = await sensor.read(); // Wait for the next sample, () → {co2_ppm ppm, temperature_c °C, humidity_rh %RH}
|
|
16
|
+
console.log('CO2 %s ppm %s C %s %%RH', r.co2_ppm.toFixed(0), r.temperature_c.toFixed(2), r.humidity_rh.toFixed(1));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { SCD40Full } = require('../../../src/chips/gas/scd40');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x62', 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=0x62) → Connection
|
|
11
|
+
// The sensor has the fixed address 0x62; keep the bus at 100 kHz or below.
|
|
12
|
+
const sensor = new SCD40Full(connection); // Create SCD40 driver, (connection) → void
|
|
13
|
+
// No bus access yet.
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
await sensor.init(); // Stop, read serial, start periodic, () → void
|
|
17
|
+
// Stops a measurement left running (500 ms), then starts the 5 s periodic mode.
|
|
18
|
+
console.log((await sensor.serialNumber()).toString(16)); // Serial number, () → number (48 bit)
|
|
19
|
+
// Command 0x3682; idle only, so the driver stops and restarts the measurement.
|
|
20
|
+
console.log(await sensor.read()); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
21
|
+
// Polls the data-ready status every 100 ms (up to 6 s), then reads 9 bytes with three CRCs.
|
|
22
|
+
console.log(await sensor.readCo2()); // CO₂ of a fresh sample, () → number ppm
|
|
23
|
+
// Each single-value call waits for its own sample (5 s).
|
|
24
|
+
console.log(await sensor.readTemperature()); // Temperature of a fresh sample, () → number °C
|
|
25
|
+
// The temperature offset has already been subtracted.
|
|
26
|
+
console.log(await sensor.readHumidity()); // Humidity of a fresh sample, () → number %RH
|
|
27
|
+
// Compensated for the temperature offset.
|
|
28
|
+
console.log(await sensor.dataReady()); // New sample available, () → boolean
|
|
29
|
+
// Command 0xE4B8; usually false right after a read.
|
|
30
|
+
while (!(await sensor.dataReady())) await sleep(100); // New sample available, () → boolean
|
|
31
|
+
console.log(await sensor.readMeasurement()); // Sample without waiting, () → [co2_ppm, temperature_c, humidity_rh]
|
|
32
|
+
// Call after dataReady(); each sample can be read only once.
|
|
33
|
+
|
|
34
|
+
await sensor.setTemperatureOffset(4.0); // Temperature offset, (kelvin 0–175) → void
|
|
35
|
+
// Idle only: stops (500 ms, the pending sample is lost), writes, restarts.
|
|
36
|
+
console.log(await sensor.getTemperatureOffset()); // Temperature offset, () → number K
|
|
37
|
+
// About 4.0 (65536/175 steps).
|
|
38
|
+
await sensor.setAltitude(250); // Sensor altitude, (metres 0–65535) → void
|
|
39
|
+
// Pressure compensation from the altitude.
|
|
40
|
+
console.log(await sensor.getAltitude()); // Sensor altitude, () → number m
|
|
41
|
+
// 250.
|
|
42
|
+
await sensor.setAmbientPressure(101325); // Ambient pressure, (pressurePa) → void
|
|
43
|
+
// Sent as 1013 hPa; allowed during measurement, overrides the altitude until reinit().
|
|
44
|
+
await sensor.setAutoCalibration(true); // Automatic self-calibration, (enabled) → void
|
|
45
|
+
// ASC is on by default and needs fresh air (≈ 400 ppm) once a week.
|
|
46
|
+
console.log(await sensor.getAutoCalibration()); // Automatic self-calibration, () → boolean
|
|
47
|
+
// true.
|
|
48
|
+
// console.log(await sensor.forceRecalibration(420)); // Forced recalibration, (ppm) → number correction ppm
|
|
49
|
+
// Only after > 3 minutes in a known, homogeneous concentration.
|
|
50
|
+
// await sensor.persistSettings(); // Store settings in the EEPROM, () → void
|
|
51
|
+
// At least 2000 write cycles; use sparingly.
|
|
52
|
+
// await sensor.factoryReset(); // Factory reset, () → void
|
|
53
|
+
// Erases the stored settings and the calibration history.
|
|
54
|
+
|
|
55
|
+
await sensor.stopPeriodic(); // Stop measuring, () → void
|
|
56
|
+
// Command 0x3F86, waits 500 ms.
|
|
57
|
+
await sensor.startLowPowerPeriodic(); // Low-power periodic mode, () → void
|
|
58
|
+
// A sample about every 30 s; read() then waits up to 35 s.
|
|
59
|
+
console.log(await sensor.read()); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
60
|
+
// First low-power sample.
|
|
61
|
+
await sensor.startPeriodic(); // Standard periodic mode, () → void
|
|
62
|
+
// Stops the low-power mode first, then a sample every 5 s.
|
|
63
|
+
console.log(await sensor.selfTest()); // Self test, () → boolean
|
|
64
|
+
// Blocks 10 s; true means no malfunction.
|
|
65
|
+
console.log((await sensor.readWord(0xE4B8)).toString(16)); // Raw read, (command) → number
|
|
66
|
+
// Writes the command, waits 1 ms, reads one word and checks its CRC.
|
|
67
|
+
await sensor.writeWord(0xE000, 1013); // Raw write, (command, value) → void
|
|
68
|
+
// Appends the argument and its CRC; no idle handling.
|
|
69
|
+
await sensor.reinit(); // Reload settings from the EEPROM, () → void
|
|
70
|
+
// Unsaved settings (offset, altitude, pressure) are discarded.
|
|
71
|
+
console.log(await sensor.read()); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
72
|
+
// First sample after the reinit.
|
|
73
|
+
await connection.close();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { SCD40Full } = require('../../../src/chips/gas/scd40');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x62', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
function classify(co2) {
|
|
11
|
+
if (co2 < 1000) return 'good';
|
|
12
|
+
if (co2 <= 1500) return 'moderate';
|
|
13
|
+
return 'poor';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x62) → Connection
|
|
17
|
+
const sensor = new SCD40Full(connection); // Create SCD40 driver, (connection) → void
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
await sensor.init(); // Stop, read serial, start periodic, () → void
|
|
21
|
+
|
|
22
|
+
/* --- Identity and settings ---
|
|
23
|
+
* Settings live in RAM until persistSettings(); after power-up they are the
|
|
24
|
+
* EEPROM values (factory: offset 4 K, altitude 0 m, ASC on). */
|
|
25
|
+
console.log('serial %s', (await sensor.serialNumber()).toString(16).padStart(12, '0')); // Serial number, () → number
|
|
26
|
+
console.log('offset %s K, altitude %d m, ASC %s',
|
|
27
|
+
(await sensor.getTemperatureOffset()).toFixed(2), // Temperature offset, () → number K
|
|
28
|
+
await sensor.getAltitude(), // Altitude, () → number m
|
|
29
|
+
await sensor.getAutoCalibration()); // ASC, () → boolean
|
|
30
|
+
|
|
31
|
+
/* --- Room air-quality monitor ---
|
|
32
|
+
* Outdoor air is about 420 ppm; above 1000 ppm a room feels stuffy, above
|
|
33
|
+
* 1500 ppm it should be ventilated. A sample arrives every 5 s. */
|
|
34
|
+
const end = Date.now() + 30000;
|
|
35
|
+
while (Date.now() < end) {
|
|
36
|
+
const r = await sensor.read(); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
37
|
+
console.log('CO2 %s ppm (%s) %s C %s %%RH', r.co2_ppm.toFixed(0).padStart(4), classify(r.co2_ppm),
|
|
38
|
+
r.temperature_c.toFixed(2), r.humidity_rh.toFixed(1));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* --- Self-heating compensation ---
|
|
42
|
+
* The offset is subtracted from the temperature and the humidity is
|
|
43
|
+
* recomputed; CO2 is not affected. Every setting change costs one sample
|
|
44
|
+
* because the sensor has to be stopped (500 ms) and restarted. */
|
|
45
|
+
const before = await sensor.read(); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
46
|
+
const oldOffset = await sensor.getTemperatureOffset(); // Temperature offset, () → number K
|
|
47
|
+
await sensor.setTemperatureOffset(oldOffset + 4.0); // Temperature offset, (kelvin) → void
|
|
48
|
+
const t = await sensor.readTemperature(); // Temperature of a fresh sample, () → number °C
|
|
49
|
+
const rh = await sensor.readHumidity(); // Humidity of a fresh sample, () → number %RH
|
|
50
|
+
console.log('offset +4 K: %s C -> %s C, %s %%RH -> %s %%RH', before.temperature_c.toFixed(2), t.toFixed(2),
|
|
51
|
+
before.humidity_rh.toFixed(1), rh.toFixed(1));
|
|
52
|
+
await sensor.setTemperatureOffset(oldOffset); // Temperature offset, (kelvin) → void
|
|
53
|
+
|
|
54
|
+
/* --- Altitude and pressure compensation ---
|
|
55
|
+
* CO2 absorption depends on the air density. Give the altitude once (idle
|
|
56
|
+
* only), or feed the current ambient pressure in pascals at any time. */
|
|
57
|
+
const oldAltitude = await sensor.getAltitude(); // Altitude, () → number m
|
|
58
|
+
await sensor.setAltitude(500); // Altitude, (metres) → void
|
|
59
|
+
console.log('altitude 500 m: CO2 %s ppm', (await sensor.readCo2()).toFixed(0)); // CO₂ of a fresh sample, () → number ppm
|
|
60
|
+
await sensor.setAmbientPressure(95000); // Ambient pressure, (pressurePa) → void
|
|
61
|
+
console.log('pressure 95000 Pa: CO2 %s ppm', (await sensor.readCo2()).toFixed(0)); // CO₂ of a fresh sample, () → number ppm
|
|
62
|
+
await sensor.setAltitude(oldAltitude); // Altitude, (metres) → void
|
|
63
|
+
|
|
64
|
+
/* --- Data-ready --- */
|
|
65
|
+
console.log('data ready:', await sensor.dataReady()); // New sample available, () → boolean
|
|
66
|
+
while (!(await sensor.dataReady())) await sleep(100); // New sample available, () → boolean
|
|
67
|
+
console.log('sample:', await sensor.readMeasurement()); // Sample without waiting, () → [co2_ppm, temperature_c, humidity_rh]
|
|
68
|
+
|
|
69
|
+
/* --- Low-power periodic mode ---
|
|
70
|
+
* About one sample every 30 s at 3.2 mA instead of 15 mA average. */
|
|
71
|
+
await sensor.stopPeriodic(); // Stop measuring, () → void
|
|
72
|
+
await sensor.startLowPowerPeriodic(); // Low-power periodic mode, () → void
|
|
73
|
+
console.log('low power:', await sensor.read()); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
74
|
+
await sensor.startPeriodic(); // Standard periodic mode, () → void
|
|
75
|
+
|
|
76
|
+
/* --- Automatic self-calibration ---
|
|
77
|
+
* ASC learns the 400 ppm baseline from the lowest readings of the past
|
|
78
|
+
* week; in rooms that never see fresh air, disable it and use FRC. */
|
|
79
|
+
const asc = await sensor.getAutoCalibration(); // ASC, () → boolean
|
|
80
|
+
await sensor.setAutoCalibration(false); // ASC, (enabled) → void
|
|
81
|
+
console.log('ASC off:', !(await sensor.getAutoCalibration())); // ASC, () → boolean
|
|
82
|
+
await sensor.setAutoCalibration(asc); // ASC, (enabled) → void
|
|
83
|
+
|
|
84
|
+
/* --- Persisting settings ---
|
|
85
|
+
* Settings are lost at power-off unless stored; the EEPROM endures at least
|
|
86
|
+
* 2000 writes, so this is skipped by default. */
|
|
87
|
+
const PERSIST = false;
|
|
88
|
+
if (PERSIST) await sensor.persistSettings(); // Store settings in the EEPROM, () → void
|
|
89
|
+
console.log('persistSettings skipped');
|
|
90
|
+
|
|
91
|
+
/* --- Forced recalibration ---
|
|
92
|
+
* FRC sets the current reading to a known reference concentration. Only do
|
|
93
|
+
* this after > 3 minutes in reference gas (or fresh outdoor air); skipped. */
|
|
94
|
+
const REFERENCE_GAS = false;
|
|
95
|
+
if (REFERENCE_GAS) console.log('FRC correction %d ppm', await sensor.forceRecalibration(420)); // Forced recalibration, (ppm) → number ppm
|
|
96
|
+
console.log('forced recalibration skipped');
|
|
97
|
+
const FACTORY_RESET = false;
|
|
98
|
+
if (FACTORY_RESET) await sensor.factoryReset(); // Factory reset, () → void
|
|
99
|
+
|
|
100
|
+
/* --- Self test, raw access and reinit --- */
|
|
101
|
+
console.log('self test ok:', await sensor.selfTest()); // Self test (10 s), () → boolean
|
|
102
|
+
console.log('raw data-ready word: 0x%s', (await sensor.readWord(0xE4B8)).toString(16).padStart(4, '0')); // Raw read, (command) → number
|
|
103
|
+
await sensor.writeWord(0xE000, 1013); // Raw write, (command, value) → void
|
|
104
|
+
await sensor.reinit(); // Reload settings from the EEPROM, () → void
|
|
105
|
+
console.log('after reinit:', await sensor.read()); // Next sample, () → {co2_ppm, temperature_c, humidity_rh}
|
|
106
|
+
await connection.close();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
main().catch(err => { console.error(err); process.exit(1); });
|