periph 1.1.0 → 1.2.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 +61 -12
- package/examples/accelerometer/adxl345/complete.js +52 -0
- package/examples/accelerometer/adxl345/demo.js +34 -0
- package/examples/accelerometer/adxl345/minimal.js +18 -0
- package/examples/accelerometer/adxl362/complete.js +57 -0
- package/examples/accelerometer/adxl362/demo.js +51 -0
- package/examples/accelerometer/adxl362/minimal.js +21 -0
- package/examples/adc_dac/ad7705/complete.js +32 -0
- package/examples/adc_dac/ad7705/demo.js +42 -0
- package/examples/adc_dac/ad7705/minimal.js +16 -0
- package/examples/adc_dac/ad7706/complete.js +35 -0
- package/examples/adc_dac/ad7706/demo.js +44 -0
- package/examples/adc_dac/ad7706/minimal.js +16 -0
- package/examples/adc_dac/hx710a/complete.js +45 -0
- package/examples/adc_dac/hx710a/demo.js +52 -0
- package/examples/adc_dac/hx710a/minimal.js +16 -0
- package/examples/adc_dac/hx710b/complete.js +45 -0
- package/examples/adc_dac/hx710b/demo.js +64 -0
- package/examples/adc_dac/hx710b/minimal.js +16 -0
- package/examples/adc_dac/hx711/complete.js +7 -7
- package/examples/adc_dac/hx711/demo.js +6 -6
- package/examples/adc_dac/hx711/minimal.js +7 -7
- package/examples/adc_dac/mcp4725/complete.js +19 -17
- package/examples/adc_dac/mcp4725/demo.js +5 -5
- package/examples/adc_dac/mcp4725/minimal.js +8 -6
- package/examples/adc_dac/mcp4728/complete.js +24 -22
- package/examples/adc_dac/mcp4728/demo.js +22 -22
- package/examples/adc_dac/mcp4728/minimal.js +8 -6
- package/examples/adc_dac/pcf8591/complete.js +41 -0
- package/examples/adc_dac/pcf8591/demo.js +39 -0
- package/examples/adc_dac/pcf8591/minimal.js +19 -0
- package/examples/comms/mcp2515/complete.js +75 -0
- package/examples/comms/mcp2515/demo.js +66 -0
- package/examples/comms/mcp2515/minimal.js +27 -0
- package/examples/comms/rda5807m/complete.js +55 -0
- package/examples/comms/rda5807m/demo.js +68 -0
- package/examples/comms/rda5807m/minimal.js +15 -0
- package/examples/comms/rfm9x/complete.js +50 -0
- package/examples/comms/rfm9x/demo.js +55 -0
- package/examples/comms/rfm9x/minimal.js +20 -0
- package/examples/display/pcf8576/complete.js +18 -15
- package/examples/display/pcf8576/demo.js +6 -6
- package/examples/display/pcf8576/minimal.js +12 -10
- package/examples/environmental/aht21/complete.js +15 -13
- package/examples/environmental/aht21/demo.js +8 -6
- package/examples/environmental/aht21/minimal.js +5 -5
- package/examples/environmental/bme280/complete.js +23 -20
- package/examples/environmental/bme280/demo.js +14 -14
- package/examples/environmental/bme280/minimal.js +13 -11
- package/examples/environmental/bme680/complete.js +25 -22
- package/examples/environmental/bme680/demo.js +38 -36
- package/examples/environmental/bme680/minimal.js +14 -12
- package/examples/gas/ens160/complete.js +29 -27
- package/examples/gas/ens160/demo.js +39 -37
- package/examples/gas/ens160/minimal.js +17 -15
- package/examples/gnss/neo6/complete.js +49 -0
- package/examples/gnss/neo6/demo.js +54 -0
- package/examples/gnss/neo6/minimal.js +30 -0
- package/examples/gyroscope/l3g4200d/complete.js +56 -0
- package/examples/gyroscope/l3g4200d/demo.js +49 -0
- package/examples/gyroscope/l3g4200d/minimal.js +19 -0
- package/examples/gyroscope/l3gd20h/complete.js +42 -0
- package/examples/gyroscope/l3gd20h/demo.js +29 -0
- package/examples/gyroscope/l3gd20h/minimal.js +13 -0
- package/examples/humidity/dht11/complete.js +22 -0
- package/examples/humidity/dht11/demo.js +38 -0
- package/examples/humidity/dht11/minimal.js +18 -0
- package/examples/imu/mpu6050/complete.js +27 -25
- package/examples/imu/mpu6050/demo.js +29 -26
- package/examples/imu/mpu6050/minimal.js +6 -6
- package/examples/imu/mpu9250/complete.js +65 -0
- package/examples/imu/mpu9250/demo.js +53 -0
- package/examples/imu/mpu9250/minimal.js +21 -0
- package/examples/imu/mpu9255/complete.js +73 -0
- package/examples/imu/mpu9255/demo.js +73 -0
- package/examples/imu/mpu9255/minimal.js +21 -0
- package/examples/io_expander/mcp23017/complete.js +70 -77
- package/examples/io_expander/mcp23017/demo.js +37 -33
- package/examples/io_expander/mcp23017/minimal.js +15 -11
- package/examples/io_expander/pcf8574/complete.js +60 -65
- package/examples/io_expander/pcf8574/demo.js +30 -25
- package/examples/io_expander/pcf8574/minimal.js +15 -11
- package/examples/io_expander/pcf8575/complete.js +24 -20
- package/examples/io_expander/pcf8575/demo.js +27 -23
- package/examples/io_expander/pcf8575/minimal.js +16 -12
- package/examples/io_expander/tpic6b595/complete.js +57 -0
- package/examples/io_expander/tpic6b595/demo.js +75 -0
- package/examples/io_expander/tpic6b595/minimal.js +26 -0
- package/examples/led/apa102/complete.js +72 -0
- package/examples/led/apa102/demo.js +92 -0
- package/examples/led/apa102/minimal.js +21 -0
- package/examples/led/sk6812rgbw/complete.js +42 -40
- package/examples/led/sk6812rgbw/demo.js +16 -16
- package/examples/led/sk6812rgbw/minimal.js +15 -17
- package/examples/led/ws2812b/complete.js +40 -38
- package/examples/led/ws2812b/demo.js +16 -16
- package/examples/led/ws2812b/minimal.js +13 -14
- package/examples/led/ws2814/complete.js +71 -0
- package/examples/led/ws2814/demo.js +82 -0
- package/examples/led/ws2814/minimal.js +23 -0
- package/examples/light/apds-9930/complete.js +46 -0
- package/examples/light/apds-9930/demo.js +31 -0
- package/examples/light/apds-9930/minimal.js +20 -0
- package/examples/light/apds9960/complete.js +45 -43
- package/examples/light/apds9960/demo.js +11 -9
- package/examples/light/apds9960/minimal.js +5 -5
- package/examples/magnetometer/as5600/complete.js +31 -29
- package/examples/magnetometer/as5600/demo.js +35 -33
- package/examples/magnetometer/as5600/minimal.js +7 -7
- package/examples/magnetometer/hmc5883l/complete.js +47 -0
- package/examples/magnetometer/hmc5883l/demo.js +50 -0
- package/examples/magnetometer/hmc5883l/minimal.js +15 -0
- package/examples/memory/24aa02uid/complete.js +23 -21
- package/examples/memory/24aa02uid/demo.js +32 -30
- package/examples/memory/24aa02uid/minimal.js +5 -5
- package/examples/motor/drv8830/complete.js +50 -0
- package/examples/motor/drv8830/demo.js +57 -0
- package/examples/motor/drv8830/minimal.js +23 -0
- package/examples/other/mpr121/complete.js +50 -0
- package/examples/other/mpr121/demo.js +30 -0
- package/examples/other/mpr121/minimal.js +17 -0
- package/examples/power/ade7953/complete.js +44 -0
- package/examples/power/ade7953/demo.js +28 -0
- package/examples/power/ade7953/minimal.js +15 -0
- package/examples/power/ina219/complete.js +20 -18
- package/examples/power/ina219/demo.js +15 -13
- package/examples/power/ina219/minimal.js +8 -8
- package/examples/power/ina226/complete.js +24 -22
- package/examples/power/ina226/demo.js +22 -20
- package/examples/power/ina226/minimal.js +5 -5
- package/examples/power/ina3221/complete.js +51 -49
- package/examples/power/ina3221/demo.js +13 -13
- package/examples/power/ina3221/minimal.js +8 -8
- package/examples/pressure/bmp085/complete.js +29 -0
- package/examples/pressure/bmp085/demo.js +34 -0
- package/examples/pressure/bmp085/minimal.js +19 -0
- package/examples/pressure/bmp180/complete.js +20 -17
- package/examples/pressure/bmp180/demo.js +24 -22
- package/examples/pressure/bmp180/minimal.js +13 -11
- package/examples/pressure/bmp280/complete.js +23 -20
- package/examples/pressure/bmp280/demo.js +44 -41
- package/examples/pressure/bmp280/minimal.js +13 -11
- package/examples/pressure/bmp384/complete.js +29 -0
- package/examples/pressure/bmp384/demo.js +40 -0
- package/examples/pressure/bmp384/minimal.js +18 -0
- package/examples/pressure/bmp581/complete.js +34 -0
- package/examples/pressure/bmp581/demo.js +56 -0
- package/examples/pressure/bmp581/minimal.js +19 -0
- package/examples/pressure/lps22df/complete.js +50 -0
- package/examples/pressure/lps22df/demo.js +41 -0
- package/examples/pressure/lps22df/minimal.js +19 -0
- package/examples/pressure/lps28dfw/complete.js +37 -0
- package/examples/pressure/lps28dfw/demo.js +33 -0
- package/examples/pressure/lps28dfw/minimal.js +19 -0
- package/examples/pressure/lps33hw/complete.js +43 -0
- package/examples/pressure/lps33hw/demo.js +43 -0
- package/examples/pressure/lps33hw/minimal.js +19 -0
- package/examples/rfid/mfrc522/complete.js +44 -0
- package/examples/rfid/mfrc522/demo.js +70 -0
- package/examples/rfid/mfrc522/minimal.js +17 -0
- package/examples/rtc/ds3231/complete.js +77 -0
- package/examples/rtc/ds3231/demo.js +60 -0
- package/examples/rtc/ds3231/minimal.js +23 -0
- package/examples/rtc/pcf8523/complete.js +66 -0
- package/examples/rtc/pcf8523/demo.js +65 -0
- package/examples/rtc/pcf8523/minimal.js +20 -0
- package/examples/temperature/mcp9808/complete.js +89 -0
- package/examples/temperature/mcp9808/demo.js +62 -0
- package/examples/temperature/mcp9808/minimal.js +21 -0
- package/examples/temperature/tmp117/complete.js +90 -0
- package/examples/temperature/tmp117/demo.js +73 -0
- package/examples/temperature/tmp117/minimal.js +21 -0
- package/examples/tof/vl53l0x/complete.js +118 -0
- package/examples/tof/vl53l0x/demo.js +83 -0
- package/examples/tof/vl53l0x/minimal.js +25 -0
- package/examples/tof/vl53l1x/complete.js +151 -0
- package/examples/tof/vl53l1x/demo.js +100 -0
- package/examples/tof/vl53l1x/minimal.js +25 -0
- package/package.json +5 -1
- package/src/chips/accelerometer/adxl345.js +482 -0
- package/src/chips/accelerometer/adxl362.js +594 -0
- package/src/chips/adc_dac/ad7705.js +345 -0
- package/src/chips/adc_dac/ad7706.js +331 -0
- package/src/chips/adc_dac/hx710a.js +184 -0
- package/src/chips/adc_dac/hx710b.js +186 -0
- package/src/chips/adc_dac/hx711.js +15 -15
- package/src/chips/adc_dac/mcp4725.js +48 -40
- package/src/chips/adc_dac/mcp4728.js +57 -44
- package/src/chips/adc_dac/pcf8591.js +196 -0
- package/src/chips/comms/mcp2515.js +659 -0
- package/src/chips/comms/rda5807m.js +393 -0
- package/src/chips/comms/rfm9x.js +590 -0
- package/src/chips/display/pcf8576.js +42 -33
- package/src/chips/environmental/aht21.js +52 -37
- package/src/chips/environmental/bme280.js +85 -66
- package/src/chips/environmental/bme680.js +110 -87
- package/src/chips/gas/ens160.js +82 -64
- package/src/chips/gnss/neo6.js +438 -0
- package/src/chips/gyroscope/l3g4200d.js +366 -0
- package/src/chips/gyroscope/l3gd20h.js +314 -0
- package/src/chips/humidity/dht11.js +135 -0
- package/src/chips/imu/mpu6050.js +89 -66
- package/src/chips/imu/mpu9250.js +394 -0
- package/src/chips/imu/mpu9255.js +447 -0
- package/src/chips/io_expander/mcp23017.js +240 -157
- package/src/chips/io_expander/pcf8574.js +149 -124
- package/src/chips/io_expander/pcf8575.js +164 -135
- package/src/chips/io_expander/tpic6b595.js +242 -0
- package/src/chips/led/_NeoPixelRGBBase.js +204 -0
- package/src/chips/led/_NeoPixelRGBWBase.js +218 -0
- package/src/chips/led/apa102.js +236 -0
- package/src/chips/led/sk6812rgbw.js +15 -149
- package/src/chips/led/ws2812b.js +14 -139
- package/src/chips/led/ws2814.js +49 -0
- package/src/chips/light/apds-9930.js +342 -0
- package/src/chips/light/apds9960.js +158 -123
- package/src/chips/magnetometer/as5600.js +102 -82
- package/src/chips/magnetometer/hmc5883l.js +222 -0
- package/src/chips/memory/_24aa02uid.js +32 -29
- package/src/chips/motor/drv8830.js +239 -0
- package/src/chips/other/mpr121.js +375 -0
- package/src/chips/power/ade7953.js +427 -0
- package/src/chips/power/ina219.js +45 -40
- package/src/chips/power/ina226.js +50 -45
- package/src/chips/power/ina3221.js +95 -76
- package/src/chips/pressure/bmp085.js +251 -0
- package/src/chips/pressure/bmp180.js +54 -37
- package/src/chips/pressure/bmp280.js +72 -53
- package/src/chips/pressure/bmp384.js +410 -0
- package/src/chips/pressure/bmp581.js +489 -0
- package/src/chips/pressure/lps22df.js +341 -0
- package/src/chips/pressure/lps28dfw.js +314 -0
- package/src/chips/pressure/lps33hw.js +255 -0
- package/src/chips/rfid/mfrc522.js +674 -0
- package/src/chips/rtc/ds3231.js +504 -0
- package/src/chips/rtc/pcf8523.js +539 -0
- package/src/chips/temperature/mcp9808.js +488 -0
- package/src/chips/temperature/tmp117.js +471 -0
- package/src/chips/tof/_vl53_base.js +160 -0
- package/src/chips/tof/vl53l0x.js +816 -0
- package/src/chips/tof/vl53l1x.js +816 -0
- package/src/connection/connection.js +111 -0
- package/src/connection/dhtxx.js +138 -0
- package/src/connection/dhtxx_mock.js +39 -0
- package/src/{transport → connection}/hx711.js +49 -22
- package/src/connection/hx711_mock.js +52 -0
- package/src/{transport → connection}/i2c.js +13 -9
- package/src/connection/i2c_mock.js +91 -0
- package/src/connection/input_pin.js +156 -0
- package/src/connection/neo6_mock.js +45 -0
- package/src/{transport → connection}/neopixel.js +23 -4
- package/src/connection/output_pin.js +41 -0
- package/src/connection/sipo.js +159 -0
- package/src/{transport → connection}/smbus.js +14 -10
- package/src/{transport → connection}/spi.js +12 -8
- package/src/connection/spi_mock.js +151 -0
- package/src/{transport → connection}/uart.js +33 -26
- package/examples/gnss/.gitkeep +0 -0
- package/examples/humidity/.gitkeep +0 -0
- package/examples/motor/.gitkeep +0 -0
- package/examples/temperature/.gitkeep +0 -0
- package/examples/tof/.gitkeep +0 -0
- package/src/chips/gnss/.gitkeep +0 -0
- package/src/chips/motor/.gitkeep +0 -0
- package/src/chips/temperature/.gitkeep +0 -0
- package/src/chips/tof/.gitkeep +0 -0
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { AHT21Full } = require('../../../src/chips/environmental/aht21');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const aht = new AHT21Full(
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const aht = new AHT21Full(connection); // Create AHT21 driver, (connection, addr=0x38) → void
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
(async () => {
|
|
10
|
+
console.log(await aht.isCalibrated()); // Check calibration status, () → boolean
|
|
10
11
|
// reads CAL bit from status byte
|
|
11
|
-
console.log(aht.isBusy());
|
|
12
|
+
console.log(await aht.isBusy()); // Check busy status, () → boolean
|
|
12
13
|
// reads BUSY bit from status byte
|
|
13
14
|
|
|
14
|
-
const r = aht.read();
|
|
15
|
+
const r = await aht.read(); // Trigger measurement, () → { temperature_c, humidity_pct }
|
|
15
16
|
// sends 0xAC trigger, waits 80 ms, decodes 6 bytes
|
|
16
|
-
console.log(r.temperature_c, r.humidity_pct);
|
|
17
|
+
console.log(r.temperature_c, r.humidity_pct);
|
|
17
18
|
|
|
18
|
-
console.log(aht.readTemperature());
|
|
19
|
+
console.log(await aht.readTemperature()); // Read temperature only, () → number °C
|
|
19
20
|
// triggers full measurement, returns temperature_c
|
|
20
|
-
console.log(aht.readHumidity());
|
|
21
|
+
console.log(await aht.readHumidity()); // Read humidity only, () → number %RH
|
|
21
22
|
// triggers full measurement, returns humidity_pct
|
|
22
23
|
|
|
23
|
-
const rc = aht.readWithCrc();
|
|
24
|
+
const rc = await aht.readWithCrc(); // Read with CRC verification, () → { temperature_c, humidity_pct, crc_ok }
|
|
24
25
|
// reads 7 bytes, verifies CRC-8 (poly 0x31, init 0xFF)
|
|
25
|
-
console.log(rc.temperature_c, rc.humidity_pct, rc.crc_ok);
|
|
26
|
+
console.log(rc.temperature_c, rc.humidity_pct, rc.crc_ok);
|
|
26
27
|
|
|
27
|
-
aht.softReset();
|
|
28
|
+
await aht.softReset(); // Send soft reset command, () → void
|
|
28
29
|
// sends 0xBA, waits 20 ms for recovery
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
await connection.close();
|
|
32
|
+
})();
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { AHT21Full } = require('../../../src/chips/environmental/aht21');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const aht = new AHT21Full(
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const aht = new AHT21Full(connection); // Create AHT21 driver, (connection, addr=0x38) → void
|
|
8
8
|
|
|
9
9
|
// --- Verify calibration before starting the logging session ---
|
|
10
10
|
// Most AHT21 modules ship pre-calibrated; if the CAL bit is not set
|
|
11
11
|
// the driver already sent the calibration init sequence during construction.
|
|
12
|
-
|
|
12
|
+
(async () => {
|
|
13
|
+
console.log('Calibrated:', await aht.isCalibrated()); // Check calibration status, () → boolean
|
|
14
|
+
})();
|
|
13
15
|
|
|
14
16
|
console.log('Time T (C) RH (%) Dew (C)');
|
|
15
17
|
|
|
16
18
|
let n = 0;
|
|
17
|
-
setInterval(() => {
|
|
19
|
+
setInterval(async () => {
|
|
18
20
|
// --- Each reading requires an 80 ms measurement cycle ---
|
|
19
21
|
// The sensor cannot output data faster than this; the driver
|
|
20
22
|
// handles the trigger + wait internally.
|
|
21
|
-
const rc = aht.readWithCrc();
|
|
23
|
+
const rc = await aht.readWithCrc(); // Read with CRC verification, () → { temperature_c, humidity_pct, crc_ok }
|
|
22
24
|
if (!rc.crc_ok) {
|
|
23
25
|
console.log('CRC error at sample', n);
|
|
24
26
|
return;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { AHT21Minimal } = require('../../../src/chips/environmental/aht21');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const aht = new AHT21Minimal(
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const aht = new AHT21Minimal(connection); // Create AHT21 driver, (connection, addr=0x38) → void
|
|
8
8
|
|
|
9
|
-
setInterval(() => {
|
|
10
|
-
const r = aht.read();
|
|
9
|
+
setInterval(async () => {
|
|
10
|
+
const r = await aht.read(); // Trigger measurement, () → { temperature_c, humidity_pct }
|
|
11
11
|
console.log(r.temperature_c, r.humidity_pct);
|
|
12
12
|
}, 1000);
|
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
3
|
const { BME280Full } = require('../../../src/chips/environmental/bme280');
|
|
4
4
|
|
|
5
5
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const bme = new BME280Full(
|
|
10
|
-
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const bme = new BME280Full(connection); // Create BME280 driver, (connection, busType='i2c')
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const cid = await bme.chipId(); // Read chip ID, () → number
|
|
11
13
|
// returns 0x60 for BME280
|
|
12
|
-
bme.configure(1, 1, 1, 0, 0, 0);
|
|
14
|
+
await bme.configure(1, 1, 1, 0, 0, 0); // Configure chip, (osrsT 0–5, osrsP 0–5, osrsH 0–5, mode 0/1/3, filter 0–4, tSb 0–7) → void
|
|
13
15
|
// writes ctrl_hum, config, ctrl_meas in correct order
|
|
14
|
-
bme.setOversampling(BME280Full.OSRS_X4, BME280Full.OSRS_X2, BME280Full.OSRS_X1); // Set oversampling, (osrsT 0–5, osrsP 0–5, osrsH 0–5) → void
|
|
16
|
+
await bme.setOversampling(BME280Full.OSRS_X4, BME280Full.OSRS_X2, BME280Full.OSRS_X1); // Set oversampling, (osrsT 0–5, osrsP 0–5, osrsH 0–5) → void
|
|
15
17
|
// humidity update requires ctrl_meas write to latch
|
|
16
|
-
bme.setMode(BME280Full.MODE_FORCED);
|
|
17
|
-
bme.setFilter(BME280Full.FILTER_4);
|
|
18
|
+
await bme.setMode(BME280Full.MODE_FORCED); // Set power mode, (mode 0/1/3) → void
|
|
19
|
+
await bme.setFilter(BME280Full.FILTER_4); // Set IIR filter, (coeff 0–4) → void
|
|
18
20
|
// suppresses short-term pressure disturbances
|
|
19
|
-
bme.setStandby(BME280Full.T_SB_125_MS);
|
|
21
|
+
await bme.setStandby(BME280Full.T_SB_125_MS); // Set standby time, (tSb 0–7) → void
|
|
20
22
|
// only relevant in normal mode; codes 6/7 mean 10/20 ms on BME280
|
|
21
|
-
const st = bme.status();
|
|
22
|
-
const t = bme.temperature();
|
|
23
|
-
const p = bme.pressure();
|
|
24
|
-
const h = bme.humidity();
|
|
25
|
-
const alt = bme.altitude();
|
|
23
|
+
const st = await bme.status(); // Read status register, () → number
|
|
24
|
+
const t = await bme.temperature(); // Read temperature, () → number °C
|
|
25
|
+
const p = await bme.pressure(); // Read pressure, () → number hPa
|
|
26
|
+
const h = await bme.humidity(); // Read humidity, () → number %RH
|
|
27
|
+
const alt = await bme.altitude(); // Compute altitude, (seaLevelHpa=1013.25) → number m
|
|
26
28
|
// uses barometric formula to convert pressure to metres
|
|
27
|
-
const slp = bme.seaLevelPressure(alt);
|
|
28
|
-
const dp = bme.dewPoint();
|
|
29
|
+
const slp = await bme.seaLevelPressure(alt); // Compute sea-level pressure, (altitudeM) → number hPa
|
|
30
|
+
const dp = await bme.dewPoint(); // Compute dew point, () → number °C
|
|
29
31
|
// Magnus-Tetens approximation from current T and RH
|
|
30
|
-
bme.reset();
|
|
32
|
+
await bme.reset(); // Soft reset chip, () → void
|
|
31
33
|
// re-reads calibration and re-applies configuration
|
|
32
|
-
console.log(`T=${t.toFixed(1)} C, P=${p.toFixed(1)} hPa, RH=${h.toFixed(1)} %RH, alt=${alt.toFixed(1)} m, dp=${dp.toFixed(1)} C`);
|
|
33
|
-
|
|
34
|
-
console.log('===DONE: 0 passed, 0 failed===');
|
|
34
|
+
console.log(`T=${t.toFixed(1)} C, P=${p.toFixed(1)} hPa, RH=${h.toFixed(1)} %RH, alt=${alt.toFixed(1)} m, dp=${dp.toFixed(1)} C`);
|
|
35
|
+
await connection.close();
|
|
36
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
37
|
+
})();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
3
|
const { BME280Full } = require('../../../src/chips/environmental/bme280');
|
|
4
4
|
|
|
5
5
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
9
|
|
|
10
10
|
function stats(arr) {
|
|
11
11
|
if (!arr.length) return [0, 0, 0];
|
|
@@ -22,16 +22,16 @@ async function sleep(ms) {
|
|
|
22
22
|
// BME280 datasheet "weather monitoring" preset: minimum power,
|
|
23
23
|
// single-shot, 8 ms typ / 9.3 ms max per cycle. Sleep between samples
|
|
24
24
|
// to demonstrate battery-friendly indoor monitoring.
|
|
25
|
-
const bme = new BME280Full(
|
|
26
|
-
bme.configure(BME280Full.OSRS_X1, BME280Full.OSRS_X1, BME280Full.OSRS_X1, BME280Full.MODE_FORCED, BME280Full.FILTER_OFF, BME280Full.T_SB_0_5_MS); // Configure chip, (osrsT=×1, osrsP=×1, osrsH=×1, mode=forced, filter=off, tSb=0) → void
|
|
25
|
+
const bme = new BME280Full(connection); // Create BME280 driver, (connection, busType='i2c')
|
|
26
|
+
await bme.configure(BME280Full.OSRS_X1, BME280Full.OSRS_X1, BME280Full.OSRS_X1, BME280Full.MODE_FORCED, BME280Full.FILTER_OFF, BME280Full.T_SB_0_5_MS); // Configure chip, (osrsT=×1, osrsP=×1, osrsH=×1, mode=forced, filter=off, tSb=0) → void
|
|
27
27
|
|
|
28
28
|
const temps = [], hums = [], pressures = [], alts = [], dews = [];
|
|
29
29
|
for (let n = 0; n < 10; n++) {
|
|
30
|
-
const t = bme.temperature();
|
|
31
|
-
const p = bme.pressure();
|
|
32
|
-
const h = bme.humidity();
|
|
33
|
-
const a = bme.altitude();
|
|
34
|
-
const d = bme.dewPoint();
|
|
30
|
+
const t = await bme.temperature(); // Read temperature, () → number °C
|
|
31
|
+
const p = await bme.pressure(); // Read pressure, () → number hPa
|
|
32
|
+
const h = await bme.humidity(); // Read humidity, () → number %RH
|
|
33
|
+
const a = await bme.altitude(); // Compute altitude, (seaLevelHpa=1013.25) → number m
|
|
34
|
+
const d = await bme.dewPoint(); // Compute dew point, () → number °C
|
|
35
35
|
temps.push(t); hums.push(h); pressures.push(p); alts.push(a); dews.push(d);
|
|
36
36
|
console.log(`${n}: ${t.toFixed(1)} C, ${h.toFixed(1)} %RH, ${p.toFixed(1)} hPa, dew=${d.toFixed(1)} C, alt=${a.toFixed(1)} m`);
|
|
37
37
|
await sleep(1000);
|
|
@@ -45,10 +45,10 @@ async function sleep(ms) {
|
|
|
45
45
|
console.log('--- Breathe gently on the sensor for 3 seconds ---');
|
|
46
46
|
await sleep(3000);
|
|
47
47
|
{
|
|
48
|
-
const t = bme.temperature();
|
|
49
|
-
const p = bme.pressure();
|
|
50
|
-
const h = bme.humidity();
|
|
51
|
-
const d = bme.dewPoint();
|
|
48
|
+
const t = await bme.temperature(); // Read temperature, () → number °C
|
|
49
|
+
const p = await bme.pressure(); // Read pressure, () → number hPa
|
|
50
|
+
const h = await bme.humidity(); // Read humidity, () → number %RH
|
|
51
|
+
const d = await bme.dewPoint(); // Compute dew point, () → number °C
|
|
52
52
|
temps.push(t); hums.push(h); pressures.push(p); dews.push(d);
|
|
53
53
|
console.log(`after breath: ${t.toFixed(1)} C, ${h.toFixed(1)} %RH, ${p.toFixed(1)} hPa, dew=${d.toFixed(1)} C`);
|
|
54
54
|
}
|
|
@@ -62,6 +62,6 @@ async function sleep(ms) {
|
|
|
62
62
|
console.log(`P: ${pMin.toFixed(1)}/${pAvg.toFixed(1)}/${pMax.toFixed(1)} hPa`);
|
|
63
63
|
console.log(`dew: ${dMin.toFixed(1)}/${dAvg.toFixed(1)}/${dMax.toFixed(1)} C`);
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
connection.close();
|
|
66
66
|
console.log('===DONE: 0 passed, 0 failed===');
|
|
67
67
|
})();
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
3
|
const { BME280Minimal } = require('../../../src/chips/environmental/bme280');
|
|
4
4
|
|
|
5
5
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const bme = new BME280Minimal(
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const bme = new BME280Minimal(connection); // Create BME280 driver, (connection, busType='i2c')
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
console.log(`${t.toFixed(1)} C, ${p.toFixed(1)} hPa, ${h.toFixed(1)} %RH`);
|
|
17
|
+
}
|
|
18
|
+
await connection.close();
|
|
19
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
20
|
+
})();
|
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
3
|
const { BME680Full } = require('../../../src/chips/environmental/bme680');
|
|
4
4
|
|
|
5
5
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const bme = new BME680Full(
|
|
10
|
-
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const bme = new BME680Full(connection); // Create BME680 driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const cid = await bme.chipId(); // Read chip ID, () → number
|
|
11
13
|
// returns 0x61 for BME680
|
|
12
|
-
console.log('chip_id=' + cid.toString(16));
|
|
13
|
-
bme.configure(BME680Full.OSRS_X1, BME680Full.OSRS_X1, BME680Full.OSRS_X1, BME680Full.MODE_SLEEP, BME680Full.FILTER_0); // Configure chip, (osrsT 0–5, osrsP 0–5, osrsH 0–5, mode 0/1, filter 0–7) → undefined
|
|
14
|
+
console.log('chip_id=' + cid.toString(16));
|
|
15
|
+
await bme.configure(BME680Full.OSRS_X1, BME680Full.OSRS_X1, BME680Full.OSRS_X1, BME680Full.MODE_SLEEP, BME680Full.FILTER_0); // Configure chip, (osrsT 0–5, osrsP 0–5, osrsH 0–5, mode 0/1, filter 0–7) → undefined
|
|
14
16
|
// writes ctrl_hum, config, ctrl_meas in correct order
|
|
15
|
-
bme.setOversampling(BME680Full.OSRS_X4, BME680Full.OSRS_X2, BME680Full.OSRS_X1); // Set oversampling, (osrsT 0–5, osrsP 0–5, osrsH 0–5) → undefined
|
|
17
|
+
await bme.setOversampling(BME680Full.OSRS_X4, BME680Full.OSRS_X2, BME680Full.OSRS_X1); // Set oversampling, (osrsT 0–5, osrsP 0–5, osrsH 0–5) → undefined
|
|
16
18
|
// changes conversion time vs resolution trade-off
|
|
17
|
-
bme.setFilter(BME680Full.FILTER_7);
|
|
19
|
+
await bme.setFilter(BME680Full.FILTER_7); // Set IIR filter, (coeff 0–7) → undefined
|
|
18
20
|
// applies to temperature and pressure only
|
|
19
|
-
bme.setHeater(320, 150);
|
|
21
|
+
await bme.setHeater(320, 150); // Configure heater profile 0, (tempC, durationMs) → undefined
|
|
20
22
|
// sets target temperature and on-time for gas measurement
|
|
21
|
-
bme.setHeaterProfile(1, 200, 100);
|
|
22
|
-
bme.selectHeaterProfile(0);
|
|
23
|
-
bme.setGasEnabled(true);
|
|
24
|
-
bme.setHeaterOff(false);
|
|
25
|
-
bme.setAmbientTemperature(25.0);
|
|
23
|
+
await bme.setHeaterProfile(1, 200, 100); // Configure heater profile 1, (index 0–9, tempC, durationMs) → undefined
|
|
24
|
+
await bme.selectHeaterProfile(0); // Select active profile, (index 0–9) → undefined
|
|
25
|
+
await bme.setGasEnabled(true); // Enable gas conversion, (enabled) → undefined
|
|
26
|
+
await bme.setHeaterOff(false); // Control heater override, (off) → undefined
|
|
27
|
+
await bme.setAmbientTemperature(25.0); // Override ambient for heater calc, (tempC) → undefined
|
|
26
28
|
// re-applies the active heater profile
|
|
27
|
-
const st = bme.status();
|
|
29
|
+
const st = await bme.status(); // Read status register, () → number
|
|
28
30
|
// bit 7 = new_data, bit 6 = gas_measuring, bit 5 = measuring
|
|
29
|
-
const r = bme.readAll();
|
|
31
|
+
const r = await bme.readAll(); // Read all sensors in one cycle, () → object
|
|
30
32
|
// returns {temperature, pressure, humidity, gasResistance}
|
|
31
|
-
const gv = bme.gasValid();
|
|
32
|
-
const hs = bme.heaterStable();
|
|
33
|
-
bme.reset();
|
|
33
|
+
const gv = await bme.gasValid(); // Check gas validity, () → boolean
|
|
34
|
+
const hs = await bme.heaterStable(); // Check heater stability, () → boolean
|
|
35
|
+
await bme.reset(); // Soft reset chip, () → undefined
|
|
34
36
|
// re-reads calibration and re-applies configuration
|
|
35
|
-
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`);
|
|
36
|
-
|
|
37
|
-
console.log('===DONE: 0 passed, 0 failed===');
|
|
37
|
+
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`);
|
|
38
|
+
await connection.close();
|
|
39
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
40
|
+
})();
|
|
@@ -1,34 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
3
|
const { BME680Full } = require('../../../src/chips/environmental/bme680');
|
|
4
4
|
|
|
5
5
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
// --- Room air quality probe: 4-in-1 sensor polling with VOC event ---
|
|
11
|
-
// Polls all four sensors once every 5 seconds for 5 minutes (60 ticks).
|
|
12
|
-
// At tick 30, the user is prompted to expose the sensor to a VOC source
|
|
13
|
-
// (isopropyl alcohol, marker pen). Gas resistance drops sharply on exposure
|
|
14
|
-
// and recovers over the remaining ticks, demonstrating raw VOC sensitivity
|
|
15
|
-
// without the closed-source BSEC library.
|
|
16
|
-
const bme = new BME680Full(transport); // Create BME680 driver, (transport)
|
|
17
|
-
bme.configure(BME680Full.OSRS_X2, BME680Full.OSRS_X16, BME680Full.OSRS_X1, BME680Full.MODE_FORCED, BME680Full.FILTER_15); // Configure chip, (osrsT=×2, osrsP=×16, osrsH=×1, mode=forced, filter=15) → undefined
|
|
18
|
-
bme.setHeater(320, 150); // Configure heater profile 0, (tempC=320, durationMs=150) → undefined
|
|
19
|
-
|
|
20
|
-
const temps = [], hums = [], pressures = [], gases = [];
|
|
21
|
-
for (let n = 0; n < 60; n++) {
|
|
22
|
-
if (n === 30) {
|
|
23
|
-
console.log('--- Expose sensor to VOC source now (alcohol/marker) ---');
|
|
24
|
-
}
|
|
25
|
-
const r = bme.readAll(); // Read all sensors in one cycle, () → object
|
|
26
|
-
temps.push(r.temperature);
|
|
27
|
-
pressures.push(r.pressure);
|
|
28
|
-
hums.push(r.humidity);
|
|
29
|
-
if (!isNaN(r.gasResistance)) gases.push(r.gasResistance);
|
|
30
|
-
console.log(`${n}: ${r.temperature.toFixed(1)} C, ${r.humidity.toFixed(1)} %RH, ${r.pressure.toFixed(1)} hPa, ${r.gasResistance.toFixed(0)} Ohm`);
|
|
31
|
-
}
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
32
9
|
|
|
33
10
|
function stats(arr) {
|
|
34
11
|
if (!arr.length) return { min: 0, avg: 0, max: 0 };
|
|
@@ -38,15 +15,40 @@ function stats(arr) {
|
|
|
38
15
|
return { min, avg, max };
|
|
39
16
|
}
|
|
40
17
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
18
|
+
(async () => {
|
|
19
|
+
// --- Room air quality probe: 4-in-1 sensor polling with VOC event ---
|
|
20
|
+
// Polls all four sensors once every 5 seconds for 5 minutes (60 ticks).
|
|
21
|
+
// At tick 30, the user is prompted to expose the sensor to a VOC source
|
|
22
|
+
// (isopropyl alcohol, marker pen). Gas resistance drops sharply on exposure
|
|
23
|
+
// and recovers over the remaining ticks, demonstrating raw VOC sensitivity
|
|
24
|
+
// without the closed-source BSEC library.
|
|
25
|
+
const bme = new BME680Full(connection); // Create BME680 driver, (connection)
|
|
26
|
+
await bme.configure(BME680Full.OSRS_X2, BME680Full.OSRS_X16, BME680Full.OSRS_X1, BME680Full.MODE_FORCED, BME680Full.FILTER_15); // Configure chip, (osrsT=×2, osrsP=×16, osrsH=×1, mode=forced, filter=15) → undefined
|
|
27
|
+
await bme.setHeater(320, 150); // Configure heater profile 0, (tempC=320, durationMs=150) → undefined
|
|
28
|
+
|
|
29
|
+
const temps = [], hums = [], pressures = [], gases = [];
|
|
30
|
+
for (let n = 0; n < 60; n++) {
|
|
31
|
+
if (n === 30) {
|
|
32
|
+
console.log('--- Expose sensor to VOC source now (alcohol/marker) ---');
|
|
33
|
+
}
|
|
34
|
+
const r = await bme.readAll(); // Read all sensors in one cycle, () → object
|
|
35
|
+
temps.push(r.temperature);
|
|
36
|
+
pressures.push(r.pressure);
|
|
37
|
+
hums.push(r.humidity);
|
|
38
|
+
if (!isNaN(r.gasResistance)) gases.push(r.gasResistance);
|
|
39
|
+
console.log(`${n}: ${r.temperature.toFixed(1)} C, ${r.humidity.toFixed(1)} %RH, ${r.pressure.toFixed(1)} hPa, ${r.gasResistance.toFixed(0)} Ohm`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ts = stats(temps);
|
|
43
|
+
const hs = stats(hums);
|
|
44
|
+
const ps = stats(pressures);
|
|
45
|
+
const gs = stats(gases);
|
|
46
|
+
console.log(`T: ${ts.min.toFixed(1)}/${ts.avg.toFixed(1)}/${ts.max.toFixed(1)} C`);
|
|
47
|
+
console.log(`RH: ${hs.min.toFixed(1)}/${hs.avg.toFixed(1)}/${hs.max.toFixed(1)} %`);
|
|
48
|
+
console.log(`P: ${ps.min.toFixed(1)}/${ps.avg.toFixed(1)}/${ps.max.toFixed(1)} hPa`);
|
|
49
|
+
console.log(`R_gas: ${gs.min.toFixed(0)}/${gs.avg.toFixed(0)}/${gs.max.toFixed(0)} Ohm`);
|
|
50
|
+
if (gs.min > 0) console.log(`VOC response ratio: ${(gs.max / gs.min).toFixed(1)}x`);
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
console.log('===DONE: 0 passed, 0 failed===');
|
|
52
|
+
await connection.close();
|
|
53
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
54
|
+
})();
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
3
|
const { BME680Minimal } = require('../../../src/chips/environmental/bme680');
|
|
4
4
|
|
|
5
5
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const bme = new BME680Minimal(
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const bme = new BME680Minimal(connection); // Create BME680 driver, (connection)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
})();
|
|
@@ -1,50 +1,52 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {
|
|
3
|
-
const { ENS160Full } = require('../../../
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { ENS160Full } = require('../../../src/chips/gas/ens160');
|
|
4
4
|
|
|
5
5
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
6
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x52', 16);
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const sensor = new ENS160Full(
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const sensor = new ENS160Full(connection); // Create ENS160 driver, (connection)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
(async () => {
|
|
12
|
+
const fw = await sensor.getFirmwareVersion(); // Get firmware version, () → object {major, minor, release}
|
|
12
13
|
// switches to IDLE, issues GET_APPVER, returns to STANDARD
|
|
13
|
-
console.log(`Firmware: ${fw.major}.${fw.minor}.${fw.release}`);
|
|
14
|
+
console.log(`Firmware: ${fw.major}.${fw.minor}.${fw.release}`);
|
|
14
15
|
|
|
15
|
-
sensor.setCompensation(25.0, 50.0);
|
|
16
|
+
await sensor.setCompensation(25.0, 50.0); // Set compensation, (tempCelsius, rhPercent) → undefined
|
|
16
17
|
// improves accuracy with external T/RH readings
|
|
17
18
|
|
|
18
|
-
sensor.configureInterrupt(true, false, false, true, false); // Configure interrupt, (enabled, activeHigh, pushPull, onData, onGpr) → undefined
|
|
19
|
+
await sensor.configureInterrupt(true, false, false, true, false); // Configure interrupt, (enabled, activeHigh, pushPull, onData, onGpr) → undefined
|
|
19
20
|
// sets INTn pin behavior for new data notification
|
|
20
21
|
|
|
21
|
-
console.log('Waiting for warm-up...');
|
|
22
|
-
while (true) {
|
|
23
|
-
|
|
24
|
-
}
|
|
22
|
+
console.log('Waiting for warm-up...');
|
|
23
|
+
while (true) { // Wait for valid data, () → blocks until warm
|
|
24
|
+
try { await sensor.readAirQuality(); break; } catch (e) { _delay(1000); }
|
|
25
|
+
}
|
|
25
26
|
|
|
26
|
-
const tvoc = sensor.readTvoc();
|
|
27
|
-
const eco2 = sensor.readEco2();
|
|
28
|
-
const aqi = sensor.readAqi();
|
|
29
|
-
const ethanol = sensor.readEthanol();
|
|
27
|
+
const tvoc = await sensor.readTvoc(); // Read TVOC, () → number ppb
|
|
28
|
+
const eco2 = await sensor.readEco2(); // Read eCO2, () → number ppm
|
|
29
|
+
const aqi = await sensor.readAqi(); // Read AQI, () → number 1–5
|
|
30
|
+
const ethanol = await sensor.readEthanol(); // Read ethanol, () → number ppb
|
|
30
31
|
// alias of DATA_TVOC at 0x22
|
|
31
|
-
const r1 = sensor.readRawResistance(1);
|
|
32
|
-
const r4 = sensor.readRawResistance(4);
|
|
33
|
-
const actuals = sensor.readCompensationActuals();
|
|
32
|
+
const r1 = await sensor.readRawResistance(1); // Read raw resistance, (sensor=1 or 4) → number Ohms
|
|
33
|
+
const r4 = await sensor.readRawResistance(4); // Read raw resistance, (sensor=1 or 4) → number Ohms
|
|
34
|
+
const actuals = await sensor.readCompensationActuals(); // Read compensation actuals, () → object {tempCelsius, rhPercent}
|
|
34
35
|
// returns T/RH values used by sensor
|
|
35
36
|
|
|
36
|
-
console.log(`TVOC=${tvoc} ppb, eCO2=${eco2} ppm, AQI=${aqi}`);
|
|
37
|
-
console.log(`Ethanol=${ethanol} ppb, R1=${r1.toFixed(0)} Ohm, R4=${r4.toFixed(0)} Ohm`);
|
|
38
|
-
console.log(`Actual T=${actuals.tempCelsius.toFixed(1)} C, RH=${actuals.rhPercent.toFixed(1)} %`);
|
|
37
|
+
console.log(`TVOC=${tvoc} ppb, eCO2=${eco2} ppm, AQI=${aqi}`);
|
|
38
|
+
console.log(`Ethanol=${ethanol} ppb, R1=${r1.toFixed(0)} Ohm, R4=${r4.toFixed(0)} Ohm`);
|
|
39
|
+
console.log(`Actual T=${actuals.tempCelsius.toFixed(1)} C, RH=${actuals.rhPercent.toFixed(1)} %`);
|
|
39
40
|
|
|
40
|
-
sensor.sleep();
|
|
41
|
+
await sensor.sleep(); // Enter deep sleep, () → undefined
|
|
41
42
|
// reduces current to ~10 uA
|
|
42
|
-
_delay(1000);
|
|
43
|
-
sensor.wake();
|
|
43
|
+
_delay(1000);
|
|
44
|
+
await sensor.wake(); // Wake and resume sensing, () → undefined
|
|
44
45
|
// transitions IDLE then STANDARD
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
console.log('===DONE: 0 passed, 0 failed===');
|
|
47
|
+
await connection.close();
|
|
48
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
49
|
+
})();
|
|
48
50
|
|
|
49
51
|
function _delay(ms) {
|
|
50
52
|
const start = Date.now();
|