periph 1.5.0 → 1.5.2
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 +19 -0
- package/examples/color/as7262/complete.js +60 -0
- package/examples/color/as7262/demo.js +65 -0
- package/examples/color/as7262/minimal.js +23 -0
- package/examples/environmental/aht10/complete.js +37 -0
- package/examples/environmental/aht10/demo.js +43 -0
- package/examples/environmental/aht10/minimal.js +12 -0
- package/examples/environmental/aht20/complete.js +41 -0
- package/examples/environmental/aht20/demo.js +49 -0
- package/examples/environmental/aht20/minimal.js +12 -0
- package/examples/environmental/am2320/complete.js +34 -0
- package/examples/environmental/am2320/demo.js +46 -0
- package/examples/environmental/am2320/minimal.js +21 -0
- package/examples/humidity/hdc1008/complete.js +39 -0
- package/examples/humidity/hdc1008/demo.js +46 -0
- package/examples/humidity/hdc1008/minimal.js +22 -0
- package/examples/humidity/hdc1080/complete.js +34 -0
- package/examples/humidity/hdc1080/demo.js +46 -0
- package/examples/humidity/hdc1080/minimal.js +22 -0
- package/examples/humidity/hs30xx/complete.js +43 -0
- package/examples/humidity/hs30xx/demo.js +40 -0
- package/examples/humidity/hs30xx/minimal.js +21 -0
- package/examples/humidity/hs40xx/complete.js +54 -0
- package/examples/humidity/hs40xx/demo.js +38 -0
- package/examples/humidity/hs40xx/minimal.js +21 -0
- package/examples/io_expander/tca9554/complete.js +63 -0
- package/examples/io_expander/tca9554/demo.js +58 -0
- package/examples/io_expander/tca9554/minimal.js +20 -0
- package/examples/led/ht16k33/complete.js +45 -0
- package/examples/led/ht16k33/demo.js +54 -0
- package/examples/led/ht16k33/minimal.js +24 -0
- package/examples/led/is31fl3731/complete.js +60 -0
- package/examples/led/is31fl3731/demo.js +72 -0
- package/examples/led/is31fl3731/minimal.js +26 -0
- package/examples/led/pca9685/complete.js +43 -0
- package/examples/led/pca9685/demo.js +77 -0
- package/examples/led/pca9685/minimal.js +24 -0
- package/examples/power/ina260/complete.js +38 -0
- package/examples/power/ina260/demo.js +32 -0
- package/examples/power/ina260/minimal.js +11 -0
- package/examples/power/lc709203f/complete.js +57 -0
- package/examples/power/lc709203f/demo.js +34 -0
- package/examples/power/lc709203f/minimal.js +11 -0
- package/examples/power/lm25066/complete.js +54 -0
- package/examples/power/lm25066/demo.js +41 -0
- package/examples/power/lm25066/minimal.js +12 -0
- package/examples/power/ltc4151/complete.js +40 -0
- package/examples/power/ltc4151/demo.js +49 -0
- package/examples/power/ltc4151/minimal.js +11 -0
- package/examples/power/max17048/complete.js +68 -0
- package/examples/power/max17048/demo.js +56 -0
- package/examples/power/max17048/minimal.js +19 -0
- package/examples/pressure/lps22hb/complete.js +43 -0
- package/examples/pressure/lps22hb/demo.js +43 -0
- package/examples/pressure/lps22hb/minimal.js +19 -0
- package/examples/pressure/mpl115a2/complete.js +25 -0
- package/examples/pressure/mpl115a2/demo.js +30 -0
- package/examples/pressure/mpl115a2/minimal.js +20 -0
- package/package.json +1 -1
- package/src/chips/color/as7262.js +419 -0
- package/src/chips/environmental/aht10.js +186 -0
- package/src/chips/environmental/aht20.js +226 -0
- package/src/chips/environmental/am2320.js +237 -0
- package/src/chips/humidity/hdc1008.js +262 -0
- package/src/chips/humidity/hdc1080.js +208 -0
- package/src/chips/humidity/hs30xx.js +254 -0
- package/src/chips/humidity/hs40xx.js +382 -0
- package/src/chips/io_expander/tca9554.js +407 -0
- package/src/chips/led/ht16k33.js +273 -0
- package/src/chips/led/is31fl3731.js +501 -0
- package/src/chips/led/pca9685.js +350 -0
- package/src/chips/power/ina260.js +229 -0
- package/src/chips/power/lc709203f.js +376 -0
- package/src/chips/power/lm25066.js +370 -0
- package/src/chips/power/ltc4151.js +297 -0
- package/src/chips/power/max17048.js +302 -0
- package/src/chips/pressure/lps22hb.js +257 -0
- package/src/chips/pressure/mpl115a2.js +171 -0
- package/src/discovery/registry.js +56 -14
package/README.md
CHANGED
|
@@ -47,12 +47,16 @@ Each chip exposes two classes:
|
|
|
47
47
|
| ADS7828 | ADC/DAC | `periph/src/chips/adc_dac/ads7828` |
|
|
48
48
|
| ADXL345 | Accelerometer | `periph/src/chips/accelerometer/adxl345` |
|
|
49
49
|
| ADXL362 | Accelerometer | `periph/src/chips/accelerometer/adxl362` |
|
|
50
|
+
| AHT10 | Environmental sensor | `periph/src/chips/environmental/aht10` |
|
|
51
|
+
| AHT20 | Environmental sensor | `periph/src/chips/environmental/aht20` |
|
|
50
52
|
| AHT21 | Environmental sensor | `periph/src/chips/environmental/aht21` |
|
|
51
53
|
| AM2315 | Environmental sensor | `periph/src/chips/environmental/am2315` |
|
|
54
|
+
| AM2320 | Environmental sensor | `periph/src/chips/environmental/am2320` |
|
|
52
55
|
| APA102 | LED driver | `periph/src/chips/led/apa102` |
|
|
53
56
|
| APDS-9930 | Light sensor | `periph/src/chips/light/apds-9930` |
|
|
54
57
|
| APDS9960 | Light sensor | `periph/src/chips/light/apds9960` |
|
|
55
58
|
| AS5600 | Magnetometer | `periph/src/chips/magnetometer/as5600` |
|
|
59
|
+
| AS7262 | Color sensor | `periph/src/chips/color/as7262` |
|
|
56
60
|
| AT24C02N | Memory | `periph/src/chips/memory/at24c02n` |
|
|
57
61
|
| AT24C64 | Memory | `periph/src/chips/memory/at24c64` |
|
|
58
62
|
| AXP2101 | Power monitor | `periph/src/chips/power/axp2101` |
|
|
@@ -78,7 +82,12 @@ Each chip exposes two classes:
|
|
|
78
82
|
| ENS160 | Gas sensor | `periph/src/chips/gas/ens160` |
|
|
79
83
|
| ES8311 | ADC/DAC | `periph/src/chips/adc_dac/es8311` |
|
|
80
84
|
| FXOS8700 | Accelerometer | `periph/src/chips/accelerometer/fxos8700` |
|
|
85
|
+
| HDC1008 | Humidity sensor | `periph/src/chips/humidity/hdc1008` |
|
|
86
|
+
| HDC1080 | Humidity sensor | `periph/src/chips/humidity/hdc1080` |
|
|
81
87
|
| HMC5883L | Magnetometer | `periph/src/chips/magnetometer/hmc5883l` |
|
|
88
|
+
| HS30XX | Humidity sensor | `periph/src/chips/humidity/hs30xx` |
|
|
89
|
+
| HS40XX | Humidity sensor | `periph/src/chips/humidity/hs40xx` |
|
|
90
|
+
| HT16K33 | LED driver | `periph/src/chips/led/ht16k33` |
|
|
82
91
|
| HTU21DF | Humidity sensor | `periph/src/chips/humidity/htu21df` |
|
|
83
92
|
| HX710A | ADC/DAC | `periph/src/chips/adc_dac/hx710a` |
|
|
84
93
|
| HX710B | ADC/DAC | `periph/src/chips/adc_dac/hx710b` |
|
|
@@ -88,14 +97,21 @@ Each chip exposes two classes:
|
|
|
88
97
|
| IL0373 | Display driver | `periph/src/chips/display/il0373` |
|
|
89
98
|
| INA219 | Power monitor | `periph/src/chips/power/ina219` |
|
|
90
99
|
| INA226 | Power monitor | `periph/src/chips/power/ina226` |
|
|
100
|
+
| INA260 | Power monitor | `periph/src/chips/power/ina260` |
|
|
91
101
|
| INA3221 | Power monitor | `periph/src/chips/power/ina3221` |
|
|
102
|
+
| IS31FL3731 | LED driver | `periph/src/chips/led/is31fl3731` |
|
|
92
103
|
| L3G4200D | Gyroscope | `periph/src/chips/gyroscope/l3g4200d` |
|
|
93
104
|
| L3GD20H | Gyroscope | `periph/src/chips/gyroscope/l3gd20h` |
|
|
105
|
+
| LC709203F | Power monitor | `periph/src/chips/power/lc709203f` |
|
|
94
106
|
| LIS3DH | Accelerometer | `periph/src/chips/accelerometer/lis3dh` |
|
|
107
|
+
| LM25066 | Power monitor | `periph/src/chips/power/lm25066` |
|
|
95
108
|
| LPS22DF | Pressure sensor | `periph/src/chips/pressure/lps22df` |
|
|
109
|
+
| LPS22HB | Pressure sensor | `periph/src/chips/pressure/lps22hb` |
|
|
96
110
|
| LPS28DFW | Pressure sensor | `periph/src/chips/pressure/lps28dfw` |
|
|
97
111
|
| LPS33HW | Pressure sensor | `periph/src/chips/pressure/lps33hw` |
|
|
98
112
|
| LSM303 | Accelerometer | `periph/src/chips/accelerometer/lsm303` |
|
|
113
|
+
| LTC4151 | Power monitor | `periph/src/chips/power/ltc4151` |
|
|
114
|
+
| MAX17048 | Power monitor | `periph/src/chips/power/max17048` |
|
|
99
115
|
| MAX44009 | Light sensor | `periph/src/chips/light/max44009` |
|
|
100
116
|
| MB85RC | Memory | `periph/src/chips/memory/mb85rc` |
|
|
101
117
|
| MCP23008 | IO expander | `periph/src/chips/io_expander/mcp23008` |
|
|
@@ -108,6 +124,7 @@ Each chip exposes two classes:
|
|
|
108
124
|
| MCP9808 | Temperature sensor | `periph/src/chips/temperature/mcp9808` |
|
|
109
125
|
| MFRC522 | RFID/NFC | `periph/src/chips/rfid/mfrc522` |
|
|
110
126
|
| MMA8451Q | Accelerometer | `periph/src/chips/accelerometer/mma8451q` |
|
|
127
|
+
| MPL115A2 | Pressure sensor | `periph/src/chips/pressure/mpl115a2` |
|
|
111
128
|
| MPR121 | Other | `periph/src/chips/other/mpr121` |
|
|
112
129
|
| MPU6050 | IMU | `periph/src/chips/imu/mpu6050` |
|
|
113
130
|
| MPU9250 | IMU | `periph/src/chips/imu/mpu9250` |
|
|
@@ -121,6 +138,7 @@ Each chip exposes two classes:
|
|
|
121
138
|
| PCA9536 | IO expander | `periph/src/chips/io_expander/pca9536` |
|
|
122
139
|
| PCA9539 | IO expander | `periph/src/chips/io_expander/pca9539` |
|
|
123
140
|
| PCA9541 | Other | `periph/src/chips/other/pca9541` |
|
|
141
|
+
| PCA9685 | LED driver | `periph/src/chips/led/pca9685` |
|
|
124
142
|
| PCF85063A | RTC | `periph/src/chips/rtc/pcf85063a` |
|
|
125
143
|
| PCF8523 | RTC | `periph/src/chips/rtc/pcf8523` |
|
|
126
144
|
| PCF8574 | IO expander | `periph/src/chips/io_expander/pcf8574` |
|
|
@@ -141,6 +159,7 @@ Each chip exposes two classes:
|
|
|
141
159
|
| SSD1306 | Display driver | `periph/src/chips/display/ssd1306` |
|
|
142
160
|
| SSD1331 | Display driver | `periph/src/chips/display/ssd1331` |
|
|
143
161
|
| ST7036 | Display driver | `periph/src/chips/display/st7036` |
|
|
162
|
+
| TCA9554 | IO expander | `periph/src/chips/io_expander/tca9554` |
|
|
144
163
|
| TMC2130 | Motor driver | `periph/src/chips/motor/tmc2130` |
|
|
145
164
|
| TMC2208 | Motor driver | `periph/src/chips/motor/tmc2208` |
|
|
146
165
|
| TMC2209 | Motor driver | `periph/src/chips/motor/tmc2209` |
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AS7262Full } = require('../../../src/chips/color/as7262');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x49', 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=0x49) → Connection
|
|
11
|
+
const sensor = new AS7262Full(connection); // Create AS7262 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Reset and configure defaults, () → Promise<void>
|
|
15
|
+
console.log(await sensor.read()); // Read calibrated channels, () → Promise<{violet, ..., red}>
|
|
16
|
+
// one one-shot conversion
|
|
17
|
+
console.log(await sensor.readRaw()); // Read raw counts, () → Promise<{violet, ..., red}>
|
|
18
|
+
console.log(await sensor.temperature()); // Read device temperature, () → Promise<number> °C
|
|
19
|
+
await sensor.measure(); // Start a one-shot conversion, () → Promise<void>
|
|
20
|
+
// does not wait
|
|
21
|
+
while (!(await sensor.dataReady())) await sleep(50); // Check data ready, () → Promise<boolean>
|
|
22
|
+
console.log(await sensor.readCalibrated()); // Read last calibrated results, () → Promise<object>
|
|
23
|
+
console.log(await sensor.readRawLast()); // Read last raw counts, () → Promise<object>
|
|
24
|
+
console.log(await sensor.readChannel(5, true)); // Read one channel, (index, calibrated=true) → Promise<number>
|
|
25
|
+
// 0..5 = V, B, G, Y, O, R
|
|
26
|
+
await sensor.setGain(16); // Set gain, (gain) → Promise<void>
|
|
27
|
+
// 0-3 index or 1, 3.7, 16, 64
|
|
28
|
+
console.log(await sensor.getGain()); // Get gain, () → Promise<number>
|
|
29
|
+
await sensor.setIntegrationTime(165.2); // Set integration time, (ms) → Promise<void>
|
|
30
|
+
// 2.8 - 714 ms
|
|
31
|
+
console.log(await sensor.getIntegrationTime()); // Get integration time, () → Promise<number> ms
|
|
32
|
+
await sensor.setMode(3); // Set bank mode, (mode) → Promise<void>
|
|
33
|
+
// 0, 1, 2 continuous; 3 one-shot
|
|
34
|
+
console.log(await sensor.getMode()); // Get bank mode, () → Promise<number>
|
|
35
|
+
await sensor.setContinuous(2); // Continuous conversions, (mode=2) → Promise<void>
|
|
36
|
+
await sensor.setContinuous(0);
|
|
37
|
+
await sensor.setMode(3);
|
|
38
|
+
await sensor.setInterrupt(false); // Enable/disable INT pin, (enabled) → Promise<void>
|
|
39
|
+
await sensor.setLed(true, 25); // Driver LED, (on, currentMa=12.5) → Promise<void>
|
|
40
|
+
// 12.5, 25, 50 or 100 mA
|
|
41
|
+
await sensor.setLed(false);
|
|
42
|
+
await sensor.setIndicatorLed(true, 4); // Indicator LED, (on, currentMa=1) → Promise<void>
|
|
43
|
+
// 1, 2, 4 or 8 mA
|
|
44
|
+
await sensor.setIndicatorLed(false);
|
|
45
|
+
console.log(await sensor.hardwareVersion()); // Hardware version, () → Promise<[type, version]>
|
|
46
|
+
console.log(await sensor.firmwareVersion()); // Firmware version, () → Promise<[major, minor, sub]>
|
|
47
|
+
console.log((await sensor.deviceType()).toString(16)); // Device type, () → Promise<number> (0x40)
|
|
48
|
+
console.log(await sensor.readVirtual(0x05)); // Read a virtual register, (reg) → Promise<number>
|
|
49
|
+
await sensor.writeVirtual(0x05, 0x3B); // Write a virtual register, (reg, value) → Promise<void>
|
|
50
|
+
await sensor.setContinuous(2);
|
|
51
|
+
await sensor.onInterrupt(async () => console.log('data ready', await sensor.readCalibrated())); // Subscribe to INT, (callback, intPin=null) → Promise<void>
|
|
52
|
+
await sleep(3000);
|
|
53
|
+
console.log(await sensor.pollInterrupt()); // Poll DATA_RDY, () → Promise<number>
|
|
54
|
+
await sensor.offInterrupt(); // Unsubscribe, () → Promise<void>
|
|
55
|
+
await sensor.softReset(); // Soft reset, () → Promise<void>
|
|
56
|
+
// restores defaults
|
|
57
|
+
connection.close();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AS7262Full } = require('../../../src/chips/color/as7262');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x49', 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=0x49) → Connection
|
|
11
|
+
const sensor = new AS7262Full(connection); // Create AS7262 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
// --- Spectrometer ---
|
|
15
|
+
// Versions, gain sweep, integration time comparison, LED reflectance difference, continuous mode.
|
|
16
|
+
await sensor.init(); // Reset and configure defaults, () → Promise<void>
|
|
17
|
+
console.log((await sensor.deviceType()).toString(16), await sensor.hardwareVersion(), await sensor.firmwareVersion()); // Identity
|
|
18
|
+
console.log('chip ' + (await sensor.temperature()) + ' C'); // Read device temperature, () → Promise<number> °C
|
|
19
|
+
|
|
20
|
+
for (const gain of [1, 3.7, 16, 64]) {
|
|
21
|
+
await sensor.setGain(gain); // Set gain, (gain) → Promise<void>
|
|
22
|
+
console.log('gain', await sensor.getGain()); // Get gain, () → Promise<number>
|
|
23
|
+
console.log(' cal', await sensor.read()); // Read calibrated, () → Promise<object>
|
|
24
|
+
console.log(' raw', await sensor.readRaw()); // Read raw, () → Promise<object>
|
|
25
|
+
}
|
|
26
|
+
await sensor.setGain(16);
|
|
27
|
+
|
|
28
|
+
for (const ms of [50, 500]) {
|
|
29
|
+
await sensor.setIntegrationTime(ms); // Set integration time, (ms) → Promise<void>
|
|
30
|
+
const t0 = Date.now();
|
|
31
|
+
await sensor.read();
|
|
32
|
+
console.log('integration', await sensor.getIntegrationTime(), 'ms ->', (Date.now() - t0) / 1000, 's');
|
|
33
|
+
}
|
|
34
|
+
await sensor.setIntegrationTime(165.2);
|
|
35
|
+
|
|
36
|
+
await sensor.setMode(3); // Set bank mode, (mode) → Promise<void>
|
|
37
|
+
const base = await sensor.read();
|
|
38
|
+
await sensor.setIndicatorLed(true, 4); // Indicator LED, (on, currentMa) → Promise<void>
|
|
39
|
+
await sensor.setLed(true, 25); // Driver LED, (on, currentMa) → Promise<void>
|
|
40
|
+
const lit = await sensor.read();
|
|
41
|
+
await sensor.setLed(false);
|
|
42
|
+
await sensor.setIndicatorLed(false);
|
|
43
|
+
const diff = {};
|
|
44
|
+
for (const k of Object.keys(lit)) diff[k] = lit[k] - base[k];
|
|
45
|
+
const dominant = Object.keys(diff).reduce((a, b) => (diff[a] >= diff[b] ? a : b));
|
|
46
|
+
console.log('reflectance', diff, 'dominant', dominant);
|
|
47
|
+
|
|
48
|
+
await sensor.measure(); // Start one-shot, () → Promise<void>
|
|
49
|
+
while (!(await sensor.dataReady())) await sleep(50); // Data ready, () → Promise<boolean>
|
|
50
|
+
console.log(await sensor.readCalibrated(), await sensor.readRawLast(), await sensor.readChannel(0)); // Last results / one channel
|
|
51
|
+
|
|
52
|
+
await sensor.setContinuous(2); // Continuous mode, (mode=2) → Promise<void>
|
|
53
|
+
await sensor.onInterrupt(async () => console.log(await sensor.readCalibrated())); // Subscribe to INT, (callback, intPin=null) → Promise<void>
|
|
54
|
+
await sleep(5000);
|
|
55
|
+
console.log(await sensor.pollInterrupt()); // Poll DATA_RDY, () → Promise<number>
|
|
56
|
+
await sensor.offInterrupt(); // Unsubscribe, () → Promise<void>
|
|
57
|
+
await sensor.setMode(3);
|
|
58
|
+
await sensor.setInterrupt(false); // Disable INT, (enabled) → Promise<void>
|
|
59
|
+
await sensor.writeVirtual(0x05, 0x3B); // Write virtual register, (reg, value) → Promise<void>
|
|
60
|
+
console.log(await sensor.readVirtual(0x05)); // Read virtual register, (reg) → Promise<number>
|
|
61
|
+
await sensor.softReset(); // Soft reset, () → Promise<void>
|
|
62
|
+
connection.close();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AS7262Minimal } = require('../../../src/chips/color/as7262');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x49', 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=0x49) → Connection
|
|
11
|
+
const sensor = new AS7262Minimal(connection); // Create AS7262 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Reset and configure defaults, () → Promise<void>
|
|
15
|
+
while (true) {
|
|
16
|
+
const d = await sensor.read(); // Read six calibrated channels, () → Promise<{violet, blue, green, yellow, orange, red}>
|
|
17
|
+
console.log(d);
|
|
18
|
+
console.log((await sensor.temperature()) + ' C'); // Read device temperature, () → Promise<number> °C
|
|
19
|
+
await sleep(2000);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AHT10Full } = require('../../../src/chips/environmental/aht10');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const aht = new AHT10Full(connection); // Create AHT10 driver, (connection, addr=0x38) → void
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
console.log(await aht.isCalibrated()); // Check calibration status, () → boolean
|
|
11
|
+
// reads CAL bit from status byte
|
|
12
|
+
console.log(await aht.isBusy()); // Check busy status, () → boolean
|
|
13
|
+
// reads BUSY bit from status byte
|
|
14
|
+
|
|
15
|
+
const r = await aht.read(); // Trigger measurement, () → { temperature_c, humidity_pct }
|
|
16
|
+
// sends 0xAC trigger, waits 80 ms, decodes 6 bytes
|
|
17
|
+
console.log(r.temperature_c, r.humidity_pct);
|
|
18
|
+
|
|
19
|
+
console.log(await aht.readTemperature()); // Read temperature only, () → number °C
|
|
20
|
+
// triggers full measurement, returns temperature_c
|
|
21
|
+
console.log(await aht.readHumidity()); // Read humidity only, () → number %RH
|
|
22
|
+
// triggers full measurement, returns humidity_pct
|
|
23
|
+
|
|
24
|
+
const raw = await aht.readRaw(); // Read raw 20-bit values, () → { raw_humidity, raw_temperature }
|
|
25
|
+
// same measurement as read(), undecoded
|
|
26
|
+
console.log(raw.raw_humidity, raw.raw_temperature);
|
|
27
|
+
|
|
28
|
+
console.log((await aht.readStatus()).toString(16)); // Read status byte, () → number
|
|
29
|
+
// bit 7 BUSY, bits 6:5 MODE, bit 3 CAL
|
|
30
|
+
console.log(await aht.dewPoint()); // Dew point, () → number °C
|
|
31
|
+
// one fresh measurement, Magnus formula
|
|
32
|
+
|
|
33
|
+
await aht.softReset(); // Send soft reset command, () → void
|
|
34
|
+
// sends 0xBA, waits 20 ms, re-runs the init command
|
|
35
|
+
|
|
36
|
+
await connection.close();
|
|
37
|
+
})();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AHT10Full } = require('../../../src/chips/environmental/aht10');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const aht = new AHT10Full(connection); // Create AHT10 driver, (connection, addr=0x38) → void
|
|
8
|
+
|
|
9
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
// --- Verify calibration before starting the logging session ---
|
|
13
|
+
// The driver already ran the init command (0xE1) and retried once via
|
|
14
|
+
// soft reset if CAL was not set, so this should print true.
|
|
15
|
+
console.log('Calibrated:', await aht.isCalibrated()); // Check calibration status, () → boolean
|
|
16
|
+
|
|
17
|
+
let tMin = Infinity, tMax = -Infinity, rhMin = Infinity, rhMax = -Infinity;
|
|
18
|
+
console.log('Sample T (C) RH (%) Dew (C)');
|
|
19
|
+
for (let n = 0; n < 12; n++) {
|
|
20
|
+
// --- One measurement takes > 75 ms ---
|
|
21
|
+
// The driver waits 80 ms after the trigger and polls BUSY, so the
|
|
22
|
+
// calls below simply block until the data is valid.
|
|
23
|
+
const r = await aht.read(); // Trigger measurement, () → { temperature_c, humidity_pct }
|
|
24
|
+
const dew = await aht.dewPoint(); // Dew point, () → number °C
|
|
25
|
+
tMin = Math.min(tMin, r.temperature_c); tMax = Math.max(tMax, r.temperature_c);
|
|
26
|
+
rhMin = Math.min(rhMin, r.humidity_pct); rhMax = Math.max(rhMax, r.humidity_pct);
|
|
27
|
+
console.log(
|
|
28
|
+
String(n).padEnd(9) +
|
|
29
|
+
r.temperature_c.toFixed(2).padEnd(11) +
|
|
30
|
+
r.humidity_pct.toFixed(2).padEnd(11) +
|
|
31
|
+
dew.toFixed(2)
|
|
32
|
+
);
|
|
33
|
+
// --- Keep the interval >= 1 s ---
|
|
34
|
+
// Measuring more often self-heats the sensor and biases the reading.
|
|
35
|
+
await sleep(5000);
|
|
36
|
+
}
|
|
37
|
+
console.log(`T min/max: ${tMin.toFixed(2)} / ${tMax.toFixed(2)} C RH min/max: ${rhMin.toFixed(2)} / ${rhMax.toFixed(2)} %`);
|
|
38
|
+
|
|
39
|
+
await aht.softReset(); // Send soft reset command, () → void
|
|
40
|
+
// sends 0xBA, waits 20 ms, re-runs the init command
|
|
41
|
+
console.log('Calibrated after reset:', await aht.isCalibrated()); // Check calibration status, () → boolean
|
|
42
|
+
await connection.close();
|
|
43
|
+
})();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AHT10Minimal } = require('../../../src/chips/environmental/aht10');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const aht = new AHT10Minimal(connection); // Create AHT10 driver, (connection, addr=0x38) → void
|
|
8
|
+
|
|
9
|
+
setInterval(async () => {
|
|
10
|
+
const r = await aht.read(); // Trigger measurement, () → { temperature_c, humidity_pct }
|
|
11
|
+
console.log(r.temperature_c, r.humidity_pct);
|
|
12
|
+
}, 1000);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AHT20Full } = require('../../../src/chips/environmental/aht20');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const aht = new AHT20Full(connection); // Create AHT20 driver, (connection, addr=0x38) → void
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
console.log(await aht.isCalibrated()); // Check calibration status, () → boolean
|
|
11
|
+
// reads CAL bit from status byte
|
|
12
|
+
console.log(await aht.isBusy()); // Check busy status, () → boolean
|
|
13
|
+
// reads BUSY bit from status byte
|
|
14
|
+
|
|
15
|
+
const r = await aht.read(); // Trigger measurement, () → { temperature_c, humidity_pct }
|
|
16
|
+
// sends 0xAC trigger, waits 80 ms, decodes 6 bytes
|
|
17
|
+
console.log(r.temperature_c, r.humidity_pct);
|
|
18
|
+
|
|
19
|
+
console.log(await aht.readTemperature()); // Read temperature only, () → number °C
|
|
20
|
+
// triggers full measurement, returns temperature_c
|
|
21
|
+
console.log(await aht.readHumidity()); // Read humidity only, () → number %RH
|
|
22
|
+
// triggers full measurement, returns humidity_pct
|
|
23
|
+
|
|
24
|
+
const raw = await aht.readRaw(); // Read raw 20-bit values, () → { raw_humidity, raw_temperature }
|
|
25
|
+
// same measurement as read(), undecoded
|
|
26
|
+
console.log(raw.raw_humidity, raw.raw_temperature);
|
|
27
|
+
|
|
28
|
+
const c = await aht.readWithCrc(); // Read with CRC check, () → { temperature_c, humidity_pct, crc_ok }
|
|
29
|
+
// reads 7 bytes, verifies CRC-8 (poly 0x31, init 0xFF)
|
|
30
|
+
console.log(c.crc_ok);
|
|
31
|
+
|
|
32
|
+
console.log((await aht.readStatus()).toString(16)); // Read status byte, () → number
|
|
33
|
+
// bit 7 BUSY, bit 3 CAL
|
|
34
|
+
console.log(await aht.dewPoint()); // Dew point, () → number °C
|
|
35
|
+
// one fresh measurement, Magnus formula
|
|
36
|
+
|
|
37
|
+
await aht.softReset(); // Send soft reset command, () → void
|
|
38
|
+
// sends 0xBA, waits 20 ms, re-runs the calibration check
|
|
39
|
+
|
|
40
|
+
await connection.close();
|
|
41
|
+
})();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AHT20Full } = require('../../../src/chips/environmental/aht20');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const aht = new AHT20Full(connection); // Create AHT20 driver, (connection, addr=0x38) → void
|
|
8
|
+
|
|
9
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
// --- Verify calibration before starting the logging session ---
|
|
13
|
+
// The driver already checked the status word against 0x18 and, if needed,
|
|
14
|
+
// soft-reset and wrote the calibration registers, so this should print true.
|
|
15
|
+
console.log('Calibrated:', await aht.isCalibrated()); // Check calibration status, () → boolean
|
|
16
|
+
|
|
17
|
+
let tMin = Infinity, tMax = -Infinity, rhMin = Infinity, rhMax = -Infinity;
|
|
18
|
+
console.log('Sample T (C) RH (%) Dew (C)');
|
|
19
|
+
for (let n = 0; n < 12; n++) {
|
|
20
|
+
// --- One measurement takes > 80 ms ---
|
|
21
|
+
// The driver waits 80 ms after the trigger and polls BUSY, so the
|
|
22
|
+
// calls below simply block until the data is valid.
|
|
23
|
+
const r = await aht.read(); // Trigger measurement, () → { temperature_c, humidity_pct }
|
|
24
|
+
const dew = await aht.dewPoint(); // Dew point, () → number °C
|
|
25
|
+
tMin = Math.min(tMin, r.temperature_c); tMax = Math.max(tMax, r.temperature_c);
|
|
26
|
+
rhMin = Math.min(rhMin, r.humidity_pct); rhMax = Math.max(rhMax, r.humidity_pct);
|
|
27
|
+
console.log(
|
|
28
|
+
String(n).padEnd(9) +
|
|
29
|
+
r.temperature_c.toFixed(2).padEnd(11) +
|
|
30
|
+
r.humidity_pct.toFixed(2).padEnd(11) +
|
|
31
|
+
dew.toFixed(2)
|
|
32
|
+
);
|
|
33
|
+
// --- Every 10th sample, verify the transfer with the CRC-8 ---
|
|
34
|
+
// The 7th byte protects bytes 0-5; a bad CRC means the I²C line is noisy.
|
|
35
|
+
if (n % 10 === 9) {
|
|
36
|
+
const c = await aht.readWithCrc(); // Read with CRC check, () → { temperature_c, humidity_pct, crc_ok }
|
|
37
|
+
console.log('CRC ok:', c.crc_ok);
|
|
38
|
+
}
|
|
39
|
+
// --- Keep the interval >= 1 s ---
|
|
40
|
+
// Measuring more often self-heats the sensor and biases the reading.
|
|
41
|
+
await sleep(5000);
|
|
42
|
+
}
|
|
43
|
+
console.log(`T min/max: ${tMin.toFixed(2)} / ${tMax.toFixed(2)} C RH min/max: ${rhMin.toFixed(2)} / ${rhMax.toFixed(2)} %`);
|
|
44
|
+
|
|
45
|
+
await aht.softReset(); // Send soft reset command, () → void
|
|
46
|
+
// sends 0xBA, waits 20 ms, re-runs the calibration check
|
|
47
|
+
console.log('Calibrated after reset:', await aht.isCalibrated()); // Check calibration status, () → boolean
|
|
48
|
+
await connection.close();
|
|
49
|
+
})();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AHT20Minimal } = require('../../../src/chips/environmental/aht20');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const aht = new AHT20Minimal(connection); // Create AHT20 driver, (connection, addr=0x38) → void
|
|
8
|
+
|
|
9
|
+
setInterval(async () => {
|
|
10
|
+
const r = await aht.read(); // Trigger measurement, () → { temperature_c, humidity_pct }
|
|
11
|
+
console.log(r.temperature_c, r.humidity_pct);
|
|
12
|
+
}, 1000);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AM2320Full } = require('../../../src/chips/environmental/am2320');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5C', 16);
|
|
8
|
+
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x5C) → Connection
|
|
10
|
+
const sensor = new AM2320Full(connection); // Create AM2320 driver, (connection) → void
|
|
11
|
+
|
|
12
|
+
async function main() {
|
|
13
|
+
const r = await sensor.read(); // Read temperature and humidity, () → {temperature_c, humidity_pct}
|
|
14
|
+
// previous measurement; reads are kept >= 2 s apart, CRC-16 checked
|
|
15
|
+
console.log(r.temperature_c, r.humidity_pct);
|
|
16
|
+
console.log(await sensor.readTemperature()); // Read temperature only, () → number °C
|
|
17
|
+
console.log(await sensor.readHumidity()); // Read humidity only, () → number %RH
|
|
18
|
+
console.log(await sensor.readRaw()); // Read raw words, () → [number, number]
|
|
19
|
+
// [humidity x10, temperature x10 as sign + magnitude]
|
|
20
|
+
console.log(await sensor.readFresh()); // Real-time value, () → {temperature_c, humidity_pct}
|
|
21
|
+
// two reads >= 2 s apart; returns the second
|
|
22
|
+
console.log(await sensor.readRegisters(0x08, 7)); // Read registers, (start, count) → Buffer
|
|
23
|
+
// function 0x03, 1-10 registers, CRC verified
|
|
24
|
+
console.log(await sensor.readDeviceInfo()); // Read device information, () → {model, version, device_id}
|
|
25
|
+
console.log(await sensor.readUserRegisters()); // Read user registers, () → [number, number]
|
|
26
|
+
await sensor.writeUserRegisters(0x1234, 0xABCD); // Write user registers, (user1, user2) → void
|
|
27
|
+
await sensor.writeRegisters(0x10, [0x00, 0x01]); // Write registers, (start, data) → void
|
|
28
|
+
// only the user registers 0x10-0x13 are allowed
|
|
29
|
+
await sensor.wake(); // Wake the sensor, () → void
|
|
30
|
+
// dummy write, the NACK is ignored
|
|
31
|
+
connection.close();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AM2320Full } = require('../../../src/chips/environmental/am2320');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5C', 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=0x5C) → Connection
|
|
11
|
+
const sensor = new AM2320Full(connection); // Create AM2320 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
// Magnus formula
|
|
14
|
+
function dewPoint(t, rh) {
|
|
15
|
+
const g = Math.log(Math.max(rh, 0.1) / 100.0) + 17.62 * t / (243.12 + t);
|
|
16
|
+
return 243.12 * g / (17.62 - g);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
const info = await sensor.readDeviceInfo(); // Read device information, () → {model, version, device_id}
|
|
21
|
+
console.log('model %d, version %d, device id 0x%s', info.model, info.version, info.device_id.toString(16).toUpperCase());
|
|
22
|
+
|
|
23
|
+
// --- Weather-station logger: a sample every 5 s, min/max tracking ---
|
|
24
|
+
let tMin = 1000, tMax = -1000, hMin = 1000, hMax = -1000;
|
|
25
|
+
for (let i = 1; i <= 30; i++) {
|
|
26
|
+
// The sensor measures after a communication and returns that result on the next
|
|
27
|
+
// one, so every sample is the previous measurement; the driver enforces the >= 2 s
|
|
28
|
+
// spacing and the CRC-16 check.
|
|
29
|
+
const r = (i % 10 === 0)
|
|
30
|
+
? await sensor.readFresh() // Real-time value, () → {temperature_c, humidity_pct}
|
|
31
|
+
: await sensor.read(); // Read temperature and humidity, () → {temperature_c, humidity_pct}
|
|
32
|
+
const t = r.temperature_c, rh = r.humidity_pct;
|
|
33
|
+
tMin = Math.min(tMin, t); tMax = Math.max(tMax, t);
|
|
34
|
+
hMin = Math.min(hMin, rh); hMax = Math.max(hMax, rh);
|
|
35
|
+
console.log('%s %s C %s %%RH dew point %s C (T %s..%s, RH %s..%s)', new Date().toISOString(),
|
|
36
|
+
t.toFixed(1), rh.toFixed(1), dewPoint(t, rh).toFixed(1), tMin.toFixed(1), tMax.toFixed(1), hMin.toFixed(1), hMax.toFixed(1));
|
|
37
|
+
await sleep(5000);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// --- User registers as a persistent counter ---
|
|
41
|
+
await sensor.writeUserRegisters(30, 0xBEEF); // Write user registers, (user1, user2) → void
|
|
42
|
+
console.log('user registers:', await sensor.readUserRegisters()); // Read user registers, () → [number, number]
|
|
43
|
+
connection.close();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
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 { AM2320Minimal } = require('../../../src/chips/environmental/am2320');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5C', 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=0x5C) → Connection
|
|
11
|
+
const sensor = new AM2320Minimal(connection); // Create AM2320 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
while (true) {
|
|
15
|
+
const r = await sensor.read(); // Read temperature and humidity, () → {temperature_c, humidity_pct}
|
|
16
|
+
console.log('%s C, %s %%RH', r.temperature_c.toFixed(1), r.humidity_pct.toFixed(1));
|
|
17
|
+
await sleep(2000);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { HDC1008Full } = require('../../../src/chips/humidity/hdc1008');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x40) → Connection
|
|
11
|
+
const sensor = new HDC1008Full(connection); // Create HDC1008 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Write default configuration, () → void
|
|
15
|
+
console.log('serial id 0x' + (await sensor.serialId()).toString(16)); // Read the 40-bit serial ID, () → number
|
|
16
|
+
console.log('config 0x' + (await sensor.readConfig()).toString(16)); // Read the configuration register, () → number
|
|
17
|
+
const [t, rh] = await sensor.read(); // Read temperature and humidity, () → [number °C, number %RH]
|
|
18
|
+
console.log('%s C, %s %%RH', t.toFixed(2), rh.toFixed(1));
|
|
19
|
+
console.log('temperature', (await sensor.readTemperature()).toFixed(2)); // () → number °C, single mode
|
|
20
|
+
console.log('humidity', (await sensor.readHumidity()).toFixed(1)); // () → number %RH, single mode
|
|
21
|
+
console.log('raw', await sensor.readRaw()); // Read raw words, () → [number, number]
|
|
22
|
+
await sensor.setResolution(11, 8); // Set resolution, (temperatureBits, humidityBits) → void
|
|
23
|
+
console.log('conversion time %s ms', (sensor.conversionTime() * 1000).toFixed(2)); // Typical conversion time, () → number s
|
|
24
|
+
await sensor.setResolution(14, 14);
|
|
25
|
+
await sensor.setHeater(true); // Switch the heater, (on) → void
|
|
26
|
+
console.log('heater on:', await sensor.isHeaterOn()); // Heater state, () → boolean
|
|
27
|
+
await sensor.setHeater(false);
|
|
28
|
+
console.log('battery low:', await sensor.batteryLow()); // VDD below 2.8 V, () → boolean
|
|
29
|
+
await sensor.softwareReset(); // Software reset, () → void
|
|
30
|
+
|
|
31
|
+
await sensor.onInterrupt((result) => console.log('data ready', result)); // Subscribe to data ready, (callback) → void
|
|
32
|
+
await connection.write(Buffer.from([0x00])); // trigger one measurement
|
|
33
|
+
await sleep(100);
|
|
34
|
+
console.log('ready:', await sensor.pollInterrupt()); // Data ready check, () → boolean
|
|
35
|
+
await sensor.offInterrupt(); // Unsubscribe, () → void
|
|
36
|
+
connection.close();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { HDC1008Full } = require('../../../src/chips/humidity/hdc1008');
|
|
5
|
+
|
|
6
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
8
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x40) → Connection
|
|
11
|
+
const sensor = new HDC1008Full(connection); // Create HDC1008 driver, (connection) → void
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await sensor.init(); // Write default configuration, () → void
|
|
15
|
+
console.log('serial id 0x' + (await sensor.serialId()).toString(16)); // Read the 40-bit serial ID, () → number
|
|
16
|
+
|
|
17
|
+
// --- Condensation-aware hygrometer: 15 readings, 2 s apart ---
|
|
18
|
+
for (let i = 0; i < 15; i++) {
|
|
19
|
+
const [t, rh] = await sensor.read(); // Read temperature and humidity, () → [number, number]
|
|
20
|
+
const g = Math.log(Math.max(rh, 0.01) / 100.0) + 17.62 * t / (243.12 + t);
|
|
21
|
+
const dew = 243.12 * g / (17.62 - g); // Magnus dew point, °C
|
|
22
|
+
console.log('%s C %s %%RH dew point %s C', t.toFixed(2), rh.toFixed(1), dew.toFixed(2));
|
|
23
|
+
await sleep(2000);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// --- Heater test: 10 s ---
|
|
27
|
+
const rh0 = await sensor.readHumidity(); // () → number %RH
|
|
28
|
+
const t0 = await sensor.readTemperature(); // () → number °C
|
|
29
|
+
await sensor.setHeater(true); // Switch the heater, (on) → void
|
|
30
|
+
await sleep(10000);
|
|
31
|
+
const rh1 = await sensor.readHumidity();
|
|
32
|
+
const t1 = await sensor.readTemperature();
|
|
33
|
+
console.log('RH drop %s %%RH, temperature rise %s K', (rh0 - rh1).toFixed(1), (t1 - t0).toFixed(2));
|
|
34
|
+
await sensor.setHeater(false);
|
|
35
|
+
|
|
36
|
+
// --- Resolution comparison ---
|
|
37
|
+
await sensor.setResolution(11, 8); // Set resolution, (temperatureBits, humidityBits) → void
|
|
38
|
+
const start = Date.now();
|
|
39
|
+
const [t, rh] = await sensor.read();
|
|
40
|
+
console.log('11/8 bit: %s C %s %%RH in %d ms', t.toFixed(2), rh.toFixed(1), Date.now() - start);
|
|
41
|
+
await sensor.setResolution(14, 14);
|
|
42
|
+
console.log('battery low:', await sensor.batteryLow()); // VDD below 2.8 V, () → boolean
|
|
43
|
+
connection.close();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
main().catch(err => { console.error(err); process.exit(1); });
|