periph 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -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 +42 -0
- package/examples/adc_dac/hx711/demo.js +35 -0
- package/examples/adc_dac/hx711/minimal.js +16 -0
- 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 +43 -0
- package/examples/adc_dac/mcp4728/demo.js +41 -0
- package/examples/adc_dac/mcp4728/minimal.js +13 -0
- 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 +35 -0
- package/examples/display/pcf8576/demo.js +48 -0
- package/examples/display/pcf8576/minimal.js +20 -0
- package/examples/environmental/aht21/complete.js +32 -0
- package/examples/environmental/aht21/demo.js +46 -0
- package/examples/environmental/aht21/minimal.js +12 -0
- package/examples/environmental/bme280/complete.js +37 -0
- package/examples/environmental/bme280/demo.js +67 -0
- package/examples/environmental/bme280/minimal.js +20 -0
- package/examples/environmental/bme680/complete.js +40 -0
- package/examples/environmental/bme680/demo.js +54 -0
- package/examples/environmental/bme680/minimal.js +21 -0
- package/examples/gas/ens160/complete.js +54 -0
- package/examples/gas/ens160/demo.js +54 -0
- package/examples/gas/ens160/minimal.js +29 -0
- 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 +58 -0
- package/examples/imu/mpu6050/demo.js +37 -0
- package/examples/imu/mpu6050/minimal.js +14 -0
- 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 +64 -0
- package/examples/light/apds9960/demo.js +34 -0
- package/examples/light/apds9960/minimal.js +12 -0
- 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 +42 -0
- package/examples/memory/24aa02uid/demo.js +42 -0
- package/examples/memory/24aa02uid/minimal.js +12 -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 +29 -22
- package/examples/pressure/bmp280/demo.js +42 -23
- 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/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 +165 -0
- package/src/chips/adc_dac/mcp4725.js +48 -40
- package/src/chips/adc_dac/mcp4728.js +297 -0
- 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 +232 -0
- package/src/chips/environmental/aht21.js +185 -0
- package/src/chips/environmental/bme280.js +385 -0
- package/src/chips/environmental/bme680.js +512 -0
- package/src/chips/gas/ens160.js +298 -0
- 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 +289 -0
- 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 +499 -0
- package/src/chips/magnetometer/as5600.js +102 -82
- package/src/chips/magnetometer/hmc5883l.js +222 -0
- package/src/chips/memory/_24aa02uid.js +182 -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 +188 -206
- 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/connection/connection.js +111 -0
- package/src/connection/dhtxx.js +138 -0
- package/src/connection/dhtxx_mock.js +39 -0
- package/src/connection/hx711.js +132 -0
- 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/display/.gitkeep +0 -0
- package/examples/environmental/.gitkeep +0 -0
- package/examples/gnss/.gitkeep +0 -0
- package/examples/humidity/.gitkeep +0 -0
- package/examples/imu/.gitkeep +0 -0
- package/examples/light/.gitkeep +0 -0
- package/examples/pressure/.gitkeep +0 -0
- package/src/chips/display/.gitkeep +0 -0
- package/src/chips/environmental/.gitkeep +0 -0
- package/src/chips/gnss/.gitkeep +0 -0
- package/src/chips/imu/.gitkeep +0 -0
- package/src/chips/light/.gitkeep +0 -0
- package/src/chips/pressure/.gitkeep +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { AHT21Minimal } = require('../../../src/chips/environmental/aht21');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const aht = new AHT21Minimal(connection); // Create AHT21 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,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { BME280Full } = require('../../../src/chips/environmental/bme280');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const bme = new BME280Full(connection); // Create BME280 driver, (connection, busType='i2c')
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const cid = await bme.chipId(); // Read chip ID, () → number
|
|
13
|
+
// returns 0x60 for BME280
|
|
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
|
|
15
|
+
// writes ctrl_hum, config, ctrl_meas in correct order
|
|
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
|
|
17
|
+
// humidity update requires ctrl_meas write to latch
|
|
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
|
|
20
|
+
// suppresses short-term pressure disturbances
|
|
21
|
+
await bme.setStandby(BME280Full.T_SB_125_MS); // Set standby time, (tSb 0–7) → void
|
|
22
|
+
// only relevant in normal mode; codes 6/7 mean 10/20 ms on BME280
|
|
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
|
|
28
|
+
// uses barometric formula to convert pressure to metres
|
|
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
|
|
31
|
+
// Magnus-Tetens approximation from current T and RH
|
|
32
|
+
await bme.reset(); // Soft reset chip, () → void
|
|
33
|
+
// re-reads calibration and re-applies configuration
|
|
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
|
+
})();
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { BME280Full } = require('../../../src/chips/environmental/bme280');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
|
|
10
|
+
function stats(arr) {
|
|
11
|
+
if (!arr.length) return [0, 0, 0];
|
|
12
|
+
const sum = arr.reduce((a, b) => a + b, 0);
|
|
13
|
+
return [Math.min(...arr), sum / arr.length, Math.max(...arr)];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function sleep(ms) {
|
|
17
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
(async () => {
|
|
21
|
+
// --- Weather monitoring preset: forced mode, ×1/×1/×1, filter off ---
|
|
22
|
+
// BME280 datasheet "weather monitoring" preset: minimum power,
|
|
23
|
+
// single-shot, 8 ms typ / 9.3 ms max per cycle. Sleep between samples
|
|
24
|
+
// to demonstrate battery-friendly indoor monitoring.
|
|
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
|
+
|
|
28
|
+
const temps = [], hums = [], pressures = [], alts = [], dews = [];
|
|
29
|
+
for (let n = 0; n < 10; n++) {
|
|
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
|
+
temps.push(t); hums.push(h); pressures.push(p); alts.push(a); dews.push(d);
|
|
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
|
+
await sleep(1000);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// --- Half-way: breathe gently on the sensor for 3 seconds ---
|
|
41
|
+
// User exposes the sensor to humid exhaled air; humidity climbs from
|
|
42
|
+
// ~40 %RH toward ~80 %RH, dew point spikes toward ambient temperature,
|
|
43
|
+
// pressure stays flat, temperature rises only slightly. Demonstrates
|
|
44
|
+
// the humidity channel's response and the dew-point alarm use case.
|
|
45
|
+
console.log('--- Breathe gently on the sensor for 3 seconds ---');
|
|
46
|
+
await sleep(3000);
|
|
47
|
+
{
|
|
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
|
+
temps.push(t); hums.push(h); pressures.push(p); dews.push(d);
|
|
53
|
+
console.log(`after breath: ${t.toFixed(1)} C, ${h.toFixed(1)} %RH, ${p.toFixed(1)} hPa, dew=${d.toFixed(1)} C`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const [tMin, tAvg, tMax] = stats(temps);
|
|
57
|
+
const [hMin, hAvg, hMax] = stats(hums);
|
|
58
|
+
const [pMin, pAvg, pMax] = stats(pressures);
|
|
59
|
+
const [dMin, dAvg, dMax] = stats(dews);
|
|
60
|
+
console.log(`T: ${tMin.toFixed(1)}/${tAvg.toFixed(1)}/${tMax.toFixed(1)} C`);
|
|
61
|
+
console.log(`RH: ${hMin.toFixed(1)}/${hAvg.toFixed(1)}/${hMax.toFixed(1)} %`);
|
|
62
|
+
console.log(`P: ${pMin.toFixed(1)}/${pAvg.toFixed(1)}/${pMax.toFixed(1)} hPa`);
|
|
63
|
+
console.log(`dew: ${dMin.toFixed(1)}/${dAvg.toFixed(1)}/${dMax.toFixed(1)} C`);
|
|
64
|
+
|
|
65
|
+
connection.close();
|
|
66
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
67
|
+
})();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { BME280Minimal } = require('../../../src/chips/environmental/bme280');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const bme = new BME280Minimal(connection); // Create BME280 driver, (connection, busType='i2c')
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
for (let i = 0; i < 5; i++) {
|
|
13
|
+
const t = await bme.temperature(); // Read temperature, () → number °C
|
|
14
|
+
const p = await bme.pressure(); // Read pressure, () → number hPa
|
|
15
|
+
const h = await bme.humidity(); // Read humidity, () → number %RH
|
|
16
|
+
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
|
+
})();
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { BME680Full } = require('../../../src/chips/environmental/bme680');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const bme = new BME680Full(connection); // Create BME680 driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const cid = await bme.chipId(); // Read chip ID, () → number
|
|
13
|
+
// returns 0x61 for BME680
|
|
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
|
|
16
|
+
// writes ctrl_hum, config, ctrl_meas in correct order
|
|
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
|
|
18
|
+
// changes conversion time vs resolution trade-off
|
|
19
|
+
await bme.setFilter(BME680Full.FILTER_7); // Set IIR filter, (coeff 0–7) → undefined
|
|
20
|
+
// applies to temperature and pressure only
|
|
21
|
+
await bme.setHeater(320, 150); // Configure heater profile 0, (tempC, durationMs) → undefined
|
|
22
|
+
// sets target temperature and on-time for gas measurement
|
|
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
|
|
28
|
+
// re-applies the active heater profile
|
|
29
|
+
const st = await bme.status(); // Read status register, () → number
|
|
30
|
+
// bit 7 = new_data, bit 6 = gas_measuring, bit 5 = measuring
|
|
31
|
+
const r = await bme.readAll(); // Read all sensors in one cycle, () → object
|
|
32
|
+
// returns {temperature, pressure, humidity, gasResistance}
|
|
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
|
|
36
|
+
// re-reads calibration and re-applies configuration
|
|
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
|
+
})();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { BME680Full } = require('../../../src/chips/environmental/bme680');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
|
|
10
|
+
function stats(arr) {
|
|
11
|
+
if (!arr.length) return { min: 0, avg: 0, max: 0 };
|
|
12
|
+
const min = Math.min(...arr);
|
|
13
|
+
const max = Math.max(...arr);
|
|
14
|
+
const avg = arr.reduce((s, v) => s + v, 0) / arr.length;
|
|
15
|
+
return { min, avg, max };
|
|
16
|
+
}
|
|
17
|
+
|
|
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`);
|
|
51
|
+
|
|
52
|
+
await connection.close();
|
|
53
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
54
|
+
})();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { BME680Minimal } = require('../../../src/chips/environmental/bme680');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x76', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const bme = new BME680Minimal(connection); // Create BME680 driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
for (let i = 0; i < 5; i++) {
|
|
13
|
+
const t = await bme.temperature(); // Read temperature, () → number °C
|
|
14
|
+
const p = await bme.pressure(); // Read pressure, () → number hPa
|
|
15
|
+
const h = await bme.humidity(); // Read humidity, () → number %RH
|
|
16
|
+
const g = await bme.gasResistance(); // Read gas resistance, () → number Ω
|
|
17
|
+
console.log(`${t.toFixed(1)} C, ${p.toFixed(1)} hPa, ${h.toFixed(1)} %RH, ${g.toFixed(0)} Ohm`);
|
|
18
|
+
}
|
|
19
|
+
await connection.close();
|
|
20
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
21
|
+
})();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { ENS160Full } = require('../../../src/chips/gas/ens160');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x52', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const sensor = new ENS160Full(connection); // Create ENS160 driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const fw = await sensor.getFirmwareVersion(); // Get firmware version, () → object {major, minor, release}
|
|
13
|
+
// switches to IDLE, issues GET_APPVER, returns to STANDARD
|
|
14
|
+
console.log(`Firmware: ${fw.major}.${fw.minor}.${fw.release}`);
|
|
15
|
+
|
|
16
|
+
await sensor.setCompensation(25.0, 50.0); // Set compensation, (tempCelsius, rhPercent) → undefined
|
|
17
|
+
// improves accuracy with external T/RH readings
|
|
18
|
+
|
|
19
|
+
await sensor.configureInterrupt(true, false, false, true, false); // Configure interrupt, (enabled, activeHigh, pushPull, onData, onGpr) → undefined
|
|
20
|
+
// sets INTn pin behavior for new data notification
|
|
21
|
+
|
|
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
|
+
}
|
|
26
|
+
|
|
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
|
|
31
|
+
// alias of DATA_TVOC at 0x22
|
|
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}
|
|
35
|
+
// returns T/RH values used by sensor
|
|
36
|
+
|
|
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)} %`);
|
|
40
|
+
|
|
41
|
+
await sensor.sleep(); // Enter deep sleep, () → undefined
|
|
42
|
+
// reduces current to ~10 uA
|
|
43
|
+
_delay(1000);
|
|
44
|
+
await sensor.wake(); // Wake and resume sensing, () → undefined
|
|
45
|
+
// transitions IDLE then STANDARD
|
|
46
|
+
|
|
47
|
+
await connection.close();
|
|
48
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
49
|
+
})();
|
|
50
|
+
|
|
51
|
+
function _delay(ms) {
|
|
52
|
+
const start = Date.now();
|
|
53
|
+
while (Date.now() - start < ms) { /* spin */ }
|
|
54
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { ENS160Full } = require('../../../src/chips/gas/ens160');
|
|
4
|
+
|
|
5
|
+
const AQI_LABELS = {1: 'Excellent', 2: 'Good', 3: 'Moderate', 4: 'Poor', 5: 'Unhealthy'};
|
|
6
|
+
|
|
7
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
8
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x52', 16);
|
|
9
|
+
|
|
10
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
11
|
+
const sensor = new ENS160Full(connection); // Create ENS160 driver, (connection)
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
// --- Wait for sensor warm-up ---
|
|
15
|
+
// The ENS160 requires ~3 minutes after power-on or idle before VALIDITY_FLAG
|
|
16
|
+
// reaches 0. During warm-up, readings are unreliable. The driver surfaces the
|
|
17
|
+
// status so the application can display progress to the user.
|
|
18
|
+
console.log('Waiting for sensor warm-up...');
|
|
19
|
+
while (true) { // Wait for valid data, () → blocks until warm
|
|
20
|
+
try { await sensor.readAirQuality(); break; } catch (e) {
|
|
21
|
+
const s = await sensor.status();
|
|
22
|
+
if (s === 1) console.log('Warm-up in progress...');
|
|
23
|
+
else if (s === 2) console.log('Initial start-up (first power-on, up to 1 hour)...');
|
|
24
|
+
else console.log('No valid output');
|
|
25
|
+
_delay(1000);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
console.log('Sensor ready!');
|
|
29
|
+
|
|
30
|
+
// --- Set compensation from external sensor ---
|
|
31
|
+
// If an external temperature/humidity sensor is available, feeding its readings
|
|
32
|
+
// to the ENS160 improves accuracy outside the 20-80%RH range. Here we use a
|
|
33
|
+
// fixed 22C/45%RH as an example.
|
|
34
|
+
await sensor.setCompensation(22.0, 45.0); // Set compensation, (tempCelsius=22.0, rhPercent=45.0) → undefined
|
|
35
|
+
|
|
36
|
+
// --- Indoor air quality monitoring loop ---
|
|
37
|
+
// Reads AQI, TVOC, and eCO2 every second and prints a human-readable label.
|
|
38
|
+
// AQI 1-2 is acceptable for occupied spaces; AQI 3+ suggests ventilation.
|
|
39
|
+
for (let n = 0; n < 60; n++) {
|
|
40
|
+
const data = await sensor.readAirQuality(); // Read air quality, () → object {aqi, tvocPpb, eco2Ppm}
|
|
41
|
+
const aqi = data.aqi;
|
|
42
|
+
const label = AQI_LABELS[aqi] || 'Unknown';
|
|
43
|
+
console.log(`${n}s: AQI=${aqi} (${label}) TVOC=${data.tvocPpb} ppb eCO2=${data.eco2Ppm} ppm`);
|
|
44
|
+
_delay(1000);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await connection.close();
|
|
48
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
49
|
+
})();
|
|
50
|
+
|
|
51
|
+
function _delay(ms) {
|
|
52
|
+
const start = Date.now();
|
|
53
|
+
while (Date.now() - start < ms) { /* spin */ }
|
|
54
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { ENS160Minimal } = require('../../../src/chips/gas/ens160');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x52', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
const sensor = new ENS160Minimal(connection); // Create ENS160 driver, (connection)
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
console.log('Waiting for sensor warm-up...');
|
|
13
|
+
while (true) { // Wait for valid data, () → blocks until warm
|
|
14
|
+
try { await sensor.readAirQuality(); break; } catch (e) { _delay(1000); }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < 10; i++) {
|
|
18
|
+
const data = await sensor.readAirQuality(); // Read air quality, () → object {aqi, tvocPpb, eco2Ppm}
|
|
19
|
+
console.log(`AQI=${data.aqi} TVOC=${data.tvocPpb} ppb eCO2=${data.eco2Ppm} ppm`);
|
|
20
|
+
_delay(1000);
|
|
21
|
+
}
|
|
22
|
+
await connection.close();
|
|
23
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
24
|
+
})();
|
|
25
|
+
|
|
26
|
+
function _delay(ms) {
|
|
27
|
+
const start = Date.now();
|
|
28
|
+
while (Date.now() - start < ms) { /* spin */ }
|
|
29
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { UARTConnection } = require('../../../src/connection/uart');
|
|
3
|
+
const { NEO6Full } = require('../../../src/chips/gnss/neo6');
|
|
4
|
+
|
|
5
|
+
// To use I2C (DDC) instead of UART:
|
|
6
|
+
// const { I2CConnection } = require('../../../src/connection/i2c');
|
|
7
|
+
// const connection = new I2CConnection(1, 0x42);
|
|
8
|
+
// const gps = new NEO6Full(connection, 'i2c');
|
|
9
|
+
// To use SPI instead of UART:
|
|
10
|
+
// const { SPIConnection } = require('../../../src/connection/spi');
|
|
11
|
+
// const connection = new SPIConnection(0, 0, { mode: 0, maxSpeedHz: 200_000 });
|
|
12
|
+
// const gps = new NEO6Full(connection, 'spi');
|
|
13
|
+
|
|
14
|
+
const UART_PORT = process.env.UART_PORT || '/dev/ttyS0';
|
|
15
|
+
|
|
16
|
+
async function main() {
|
|
17
|
+
const connection = new UARTConnection(UART_PORT, { baudRate: 9600 });
|
|
18
|
+
await connection.open();
|
|
19
|
+
const gps = new NEO6Full(connection); // Create NEO-6 driver, (connection, busType='uart')
|
|
20
|
+
|
|
21
|
+
await gps.setRate(1); // Set navigation update rate, (hz) → Promise<void>
|
|
22
|
+
// writes CFG-RATE with measRate = 1000/hz ms
|
|
23
|
+
await gps.setPlatform(0); // Set dynamic platform model, (model 0-8) → Promise<void>
|
|
24
|
+
// writes CFG-NAV5 with mask=dynModel only
|
|
25
|
+
await gps.saveConfig(); // Persist current configuration, () → Promise<void>
|
|
26
|
+
// writes CFG-CFG with saveMask=all, deviceMask=BBR|Flash|EEPROM
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < 20; i++) {
|
|
29
|
+
if (await gps.update()) { // Read + parse one NMEA sentence, () → Promise<boolean>
|
|
30
|
+
console.log(gps.latitude(), gps.longitude(), gps.altitude());
|
|
31
|
+
// decimal degrees / decimal degrees / meters MSL
|
|
32
|
+
console.log(gps.speed(), gps.course()); // Speed over ground, () → number|null m/s
|
|
33
|
+
// Course over ground, () → number|null deg
|
|
34
|
+
console.log(gps.utcTime(), gps.utcDate()); // UTC time of last fix sentence, () → string|null hhmmss.ss
|
|
35
|
+
// UTC date of last RMC sentence, () → string|null ddmmyy
|
|
36
|
+
console.log(gps.hdop()); // Horizontal dilution of precision, () → number|null
|
|
37
|
+
}
|
|
38
|
+
await new Promise(r => setTimeout(r, 50));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const navStatus = await gps.pollUbx(0x01, 0x03); // Poll a UBX message and return its payload, (msgClass, msgId) → Promise<Buffer>
|
|
42
|
+
console.log('NAV-STATUS payload:', navStatus);
|
|
43
|
+
|
|
44
|
+
await gps.coldStart(); // Force a cold start via CFG-RST, () → Promise<void>
|
|
45
|
+
|
|
46
|
+
await connection.close();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { UARTConnection } = require('../../../src/connection/uart');
|
|
3
|
+
const { NEO6Full } = require('../../../src/chips/gnss/neo6');
|
|
4
|
+
|
|
5
|
+
// To use I2C (DDC) instead of UART:
|
|
6
|
+
// const { I2CConnection } = require('../../../src/connection/i2c');
|
|
7
|
+
// const connection = new I2CConnection(1, 0x42);
|
|
8
|
+
// const gps = new NEO6Full(connection, 'i2c');
|
|
9
|
+
// To use SPI instead of UART:
|
|
10
|
+
// const { SPIConnection } = require('../../../src/connection/spi');
|
|
11
|
+
// const connection = new SPIConnection(0, 0, { mode: 0, maxSpeedHz: 200_000 });
|
|
12
|
+
// const gps = new NEO6Full(connection, 'spi');
|
|
13
|
+
|
|
14
|
+
const UART_PORT = process.env.UART_PORT || '/dev/ttyS0';
|
|
15
|
+
|
|
16
|
+
// --- Portable GPS logger ---
|
|
17
|
+
// The module self-configures at factory defaults (9600 baud NMEA, 1 Hz); no
|
|
18
|
+
// CFG messages are needed for a basic position log. Runs for 60 seconds,
|
|
19
|
+
// polling update() far faster than the 1 Hz sentence rate so no sentence is
|
|
20
|
+
// missed, and prints one line per second once a fresh GGA has been parsed.
|
|
21
|
+
async function main() {
|
|
22
|
+
const connection = new UARTConnection(UART_PORT, { baudRate: 9600 });
|
|
23
|
+
await connection.open();
|
|
24
|
+
const gps = new NEO6Full(connection); // Create NEO-6 driver, (connection, busType='uart')
|
|
25
|
+
|
|
26
|
+
const start = Date.now();
|
|
27
|
+
while (Date.now() - start < 60_000) {
|
|
28
|
+
const gotFix = await gps.update(); // Read + parse one NMEA sentence, () → Promise<boolean>
|
|
29
|
+
|
|
30
|
+
// --- No fix yet: show the wait state ---
|
|
31
|
+
// gpsFix alone would not be trustworthy here; update() already only
|
|
32
|
+
// resolves true once the GGA fix-status field confirms a real fix,
|
|
33
|
+
// so a plain fix() === 0 check is enough to detect the waiting state.
|
|
34
|
+
if (gps.fix() === 0) {
|
|
35
|
+
console.log(`waiting for fix... satellites in use: ${gps.satellites()}`);
|
|
36
|
+
|
|
37
|
+
// --- Fix acquired: log the full position record ---
|
|
38
|
+
// Cold-start TTFF is ~26 s typical outdoors; once gotFix flips true
|
|
39
|
+
// the position, altitude, and HDOP fields below are all populated
|
|
40
|
+
// together.
|
|
41
|
+
} else if (gotFix) {
|
|
42
|
+
console.log(
|
|
43
|
+
`${gps.utcTime()} lat=${gps.latitude().toFixed(6)} lon=${gps.longitude().toFixed(6)} ` +
|
|
44
|
+
`alt=${gps.altitude().toFixed(1)} m sats=${gps.satellites()} hdop=${gps.hdop()}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await new Promise(r => setTimeout(r, 200));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
await connection.close();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { UARTConnection } = require('../../../src/connection/uart');
|
|
3
|
+
const { NEO6Minimal } = require('../../../src/chips/gnss/neo6');
|
|
4
|
+
|
|
5
|
+
// To use I2C (DDC) instead of UART:
|
|
6
|
+
// const { I2CConnection } = require('../../../src/connection/i2c');
|
|
7
|
+
// const connection = new I2CConnection(1, 0x42);
|
|
8
|
+
// const gps = new NEO6Minimal(connection, 'i2c');
|
|
9
|
+
// To use SPI instead of UART:
|
|
10
|
+
// const { SPIConnection } = require('../../../src/connection/spi');
|
|
11
|
+
// const connection = new SPIConnection(0, 0, { mode: 0, maxSpeedHz: 200_000 });
|
|
12
|
+
// const gps = new NEO6Minimal(connection, 'spi');
|
|
13
|
+
|
|
14
|
+
const UART_PORT = process.env.UART_PORT || '/dev/ttyS0';
|
|
15
|
+
|
|
16
|
+
async function main() {
|
|
17
|
+
const connection = new UARTConnection(UART_PORT, { baudRate: 9600 });
|
|
18
|
+
await connection.open();
|
|
19
|
+
const gps = new NEO6Minimal(connection); // Create NEO-6 driver, (connection, busType='uart')
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < 20; i++) {
|
|
22
|
+
if (await gps.update()) { // Read + parse one NMEA sentence, () → Promise<boolean>
|
|
23
|
+
console.log(gps.latitude(), gps.longitude(), gps.altitude());
|
|
24
|
+
}
|
|
25
|
+
await new Promise(r => setTimeout(r, 50));
|
|
26
|
+
}
|
|
27
|
+
await connection.close();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
3
|
+
const { L3G4200DFull } = require('../../../src/chips/gyroscope/l3g4200d');
|
|
4
|
+
|
|
5
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
6
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x68', 16);
|
|
7
|
+
|
|
8
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const gyro = new L3G4200DFull(connection); // Create L3G4200D driver, (connection, busType='i2c')
|
|
12
|
+
const cid = await gyro.whoAmI(); // Read WHO_AM_I, () → number
|
|
13
|
+
// returns 0xD3 for L3G4200D
|
|
14
|
+
await gyro.configure(1, 0, 500); // Configure chip, (odr 0–3, bandwidth 0–3, full_scale 250/500/2000) → undefined
|
|
15
|
+
// sets CTRL_REG1 DR/BW and CTRL_REG4 FS
|
|
16
|
+
await gyro.enableAxes(true, true, true); // Enable axes, (x, y, z) → undefined
|
|
17
|
+
// sets Xen/Yen/Zen bits in CTRL_REG1
|
|
18
|
+
await gyro.setFullScale(2000); // Set full scale, (full_scale 250/500/2000) → undefined
|
|
19
|
+
// updates FS[1:0] in CTRL_REG4
|
|
20
|
+
const ready = await gyro.dataReady(); // Check data ready, () → boolean
|
|
21
|
+
// returns STATUS_REG.ZYXDA
|
|
22
|
+
const status = await gyro.status(); // Read STATUS, () → number
|
|
23
|
+
// raw status byte (ZYXOR, ZOR, YOR, XOR, ZYXDA, ZDA, YDA, XDA)
|
|
24
|
+
const temp = await gyro.temperature(); // Read temperature, () → number
|
|
25
|
+
// 8-bit signed relative count (−1 °C/digit)
|
|
26
|
+
await gyro.enableHighpass(0, 4); // Enable high-pass, (mode 0–3, cutoff 0–9) → undefined
|
|
27
|
+
// sets HPen and HPM/HPCF; cutoff depends on ODR
|
|
28
|
+
await gyro.disableHighpass(); // Disable high-pass, () → undefined
|
|
29
|
+
// clears HPen in CTRL_REG5
|
|
30
|
+
await gyro.setInterrupt(true, false, true, false, true, false, false, true); // Configure INT1, (x_high, x_low, y_high, y_low, z_high, z_low, and_mode, latch) → undefined
|
|
31
|
+
// enable high events on x/y/z; latch until INT1_SRC read
|
|
32
|
+
await gyro.setThreshold('x', 87.5); // Set X threshold, (axis 'x'/'y'/'z', threshold_dps) → undefined
|
|
33
|
+
// converts dps to raw 15-bit value via sensitivity
|
|
34
|
+
await gyro.setDuration(4, false); // Set INT1 duration, (samples 0–127, wait=false) → undefined
|
|
35
|
+
// INT1 must be true for `samples` ODR cycles before firing
|
|
36
|
+
await gyro.setDataReadyPin(true); // Route DRDY to INT2, (enable=true) → undefined
|
|
37
|
+
// sets I2_DRDY in CTRL_REG3
|
|
38
|
+
await gyro.enableFifo(2, 10); // Enable FIFO, (mode 0–4, watermark=0) → undefined
|
|
39
|
+
// mode 2 = stream mode; watermark=10 frames
|
|
40
|
+
await gyro.disableFifo(); // Disable FIFO, () → undefined
|
|
41
|
+
// bypass mode and clear FIFO_EN
|
|
42
|
+
const samples = await gyro.fifoSamples(); // Read FIFO count, () → number
|
|
43
|
+
// FSS[4:0] from FIFO_SRC_REG
|
|
44
|
+
await gyro.powerDown(); // Enter power-down, () → undefined
|
|
45
|
+
// clears PD in CTRL_REG1
|
|
46
|
+
await gyro.wakeUp(); // Wake from power-down, () → undefined
|
|
47
|
+
// sets PD; previously enabled axes restored
|
|
48
|
+
await gyro.sleep(); // Enter sleep mode, () → undefined
|
|
49
|
+
// PD=1, all axes off
|
|
50
|
+
const intSrc = await gyro.readIntSource(); // Read & clear INT1_SRC, () → number
|
|
51
|
+
// reading clears the interrupt-active bit
|
|
52
|
+
const [x, y, z] = await gyro.angularRate(); // Read X/Y/Z angular rate, () → [number, number, number] rad/s
|
|
53
|
+
console.log(`X=${x.toFixed(2)} Y=${y.toFixed(2)} Z=${z.toFixed(2)} rad/s, T=${temp}, ready=${ready}, status=0x${status.toString(16)}, fifo=${samples}, src=0x${intSrc.toString(16)}, cid=0x${cid.toString(16)}`);
|
|
54
|
+
await connection.close();
|
|
55
|
+
console.log('===DONE: 0 passed, 0 failed===');
|
|
56
|
+
})();
|