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
package/README.md
CHANGED
|
@@ -14,10 +14,10 @@ Drivers are accessed by path — require the chip module directly:
|
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
16
|
const { INA226Minimal } = require('periph/src/chips/power/ina226');
|
|
17
|
-
const {
|
|
17
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
const sensor
|
|
19
|
+
const connection = new I2CConnection(1, 0x40); // I2C bus 1, address 0x40
|
|
20
|
+
const sensor = new INA226Minimal(connection);
|
|
21
21
|
console.log(await sensor.power()); // watts
|
|
22
22
|
```
|
|
23
23
|
|
|
@@ -30,18 +30,67 @@ Each chip exposes two classes:
|
|
|
30
30
|
|
|
31
31
|
| Chip | Category | Require path |
|
|
32
32
|
|------|----------|-------------|
|
|
33
|
+
| 24AA02UID | Memory | `periph/src/chips/memory/_24aa02uid` |
|
|
34
|
+
| AD7705 | ADC/DAC | `periph/src/chips/adc_dac/ad7705` |
|
|
35
|
+
| AD7706 | ADC/DAC | `periph/src/chips/adc_dac/ad7706` |
|
|
36
|
+
| ADE7953 | Power monitor | `periph/src/chips/power/ade7953` |
|
|
37
|
+
| ADXL345 | Accelerometer | `periph/src/chips/accelerometer/adxl345` |
|
|
38
|
+
| ADXL362 | Accelerometer | `periph/src/chips/accelerometer/adxl362` |
|
|
39
|
+
| AHT21 | Environmental sensor | `periph/src/chips/environmental/aht21` |
|
|
40
|
+
| APA102 | LED driver | `periph/src/chips/led/apa102` |
|
|
41
|
+
| APDS-9930 | Light sensor | `periph/src/chips/light/apds-9930` |
|
|
42
|
+
| APDS9960 | Light sensor | `periph/src/chips/light/apds9960` |
|
|
33
43
|
| AS5600 | Magnetometer | `periph/src/chips/magnetometer/as5600` |
|
|
34
|
-
|
|
|
35
|
-
|
|
|
44
|
+
| BME280 | Environmental sensor | `periph/src/chips/environmental/bme280` |
|
|
45
|
+
| BME680 | Environmental sensor | `periph/src/chips/environmental/bme680` |
|
|
46
|
+
| BMP085 | Pressure sensor | `periph/src/chips/pressure/bmp085` |
|
|
47
|
+
| BMP180 | Pressure sensor | `periph/src/chips/pressure/bmp180` |
|
|
48
|
+
| BMP280 | Pressure sensor | `periph/src/chips/pressure/bmp280` |
|
|
49
|
+
| BMP384 | Pressure sensor | `periph/src/chips/pressure/bmp384` |
|
|
50
|
+
| BMP581 | Pressure sensor | `periph/src/chips/pressure/bmp581` |
|
|
51
|
+
| DHT11 | Humidity sensor | `periph/src/chips/humidity/dht11` |
|
|
52
|
+
| DRV8830 | Motor driver | `periph/src/chips/motor/drv8830` |
|
|
53
|
+
| DS3231 | RTC | `periph/src/chips/rtc/ds3231` |
|
|
54
|
+
| ENS160 | Gas sensor | `periph/src/chips/gas/ens160` |
|
|
55
|
+
| HMC5883L | Magnetometer | `periph/src/chips/magnetometer/hmc5883l` |
|
|
56
|
+
| HX710A | ADC/DAC | `periph/src/chips/adc_dac/hx710a` |
|
|
57
|
+
| HX710B | ADC/DAC | `periph/src/chips/adc_dac/hx710b` |
|
|
58
|
+
| HX711 | ADC/DAC | `periph/src/chips/adc_dac/hx711` |
|
|
36
59
|
| INA219 | Power monitor | `periph/src/chips/power/ina219` |
|
|
37
60
|
| INA226 | Power monitor | `periph/src/chips/power/ina226` |
|
|
38
|
-
| INA3221 | Power monitor
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
61
|
+
| INA3221 | Power monitor | `periph/src/chips/power/ina3221` |
|
|
62
|
+
| L3G4200D | Gyroscope | `periph/src/chips/gyroscope/l3g4200d` |
|
|
63
|
+
| L3GD20H | Gyroscope | `periph/src/chips/gyroscope/l3gd20h` |
|
|
64
|
+
| LPS22DF | Pressure sensor | `periph/src/chips/pressure/lps22df` |
|
|
65
|
+
| LPS28DFW | Pressure sensor | `periph/src/chips/pressure/lps28dfw` |
|
|
66
|
+
| LPS33HW | Pressure sensor | `periph/src/chips/pressure/lps33hw` |
|
|
67
|
+
| MCP23017 | IO expander | `periph/src/chips/io_expander/mcp23017` |
|
|
68
|
+
| MCP2515 | Comms | `periph/src/chips/comms/mcp2515` |
|
|
69
|
+
| MCP4725 | ADC/DAC | `periph/src/chips/adc_dac/mcp4725` |
|
|
70
|
+
| MCP4728 | ADC/DAC | `periph/src/chips/adc_dac/mcp4728` |
|
|
71
|
+
| MCP9808 | Temperature sensor | `periph/src/chips/temperature/mcp9808` |
|
|
72
|
+
| MFRC522 | RFID/NFC | `periph/src/chips/rfid/mfrc522` |
|
|
73
|
+
| MPR121 | Other | `periph/src/chips/other/mpr121` |
|
|
74
|
+
| MPU6050 | IMU | `periph/src/chips/imu/mpu6050` |
|
|
75
|
+
| MPU9250 | IMU | `periph/src/chips/imu/mpu9250` |
|
|
76
|
+
| MPU9255 | IMU | `periph/src/chips/imu/mpu9255` |
|
|
77
|
+
| NEO6 | GNSS/GPS | `periph/src/chips/gnss/neo6` |
|
|
78
|
+
| NEOPIXELRGBBASE | LED driver | `periph/src/chips/led/_NeoPixelRGBBase` |
|
|
79
|
+
| NEOPIXELRGBWBASE | LED driver | `periph/src/chips/led/_NeoPixelRGBWBase` |
|
|
80
|
+
| PCF8523 | RTC | `periph/src/chips/rtc/pcf8523` |
|
|
81
|
+
| PCF8574 | IO expander | `periph/src/chips/io_expander/pcf8574` |
|
|
82
|
+
| PCF8575 | IO expander | `periph/src/chips/io_expander/pcf8575` |
|
|
83
|
+
| PCF8576 | Display driver | `periph/src/chips/display/pcf8576` |
|
|
84
|
+
| PCF8591 | ADC/DAC | `periph/src/chips/adc_dac/pcf8591` |
|
|
85
|
+
| RDA5807M | Comms | `periph/src/chips/comms/rda5807m` |
|
|
86
|
+
| RFM9X | Comms | `periph/src/chips/comms/rfm9x` |
|
|
87
|
+
| SK6812RGBW | LED driver | `periph/src/chips/led/sk6812rgbw` |
|
|
88
|
+
| TMP117 | Temperature sensor | `periph/src/chips/temperature/tmp117` |
|
|
89
|
+
| TPIC6B595 | IO expander | `periph/src/chips/io_expander/tpic6b595` |
|
|
90
|
+
| VL53L0X | Time-of-flight | `periph/src/chips/tof/vl53l0x` |
|
|
91
|
+
| VL53L1X | Time-of-flight | `periph/src/chips/tof/vl53l1x` |
|
|
92
|
+
| WS2812B | LED driver | `periph/src/chips/led/ws2812b` |
|
|
93
|
+
| WS2814 | LED driver | `periph/src/chips/led/ws2814` |
|
|
45
94
|
|
|
46
95
|
## Links
|
|
47
96
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { ADXL345Full } = require('periph/src/chips/accelerometer/adxl345');
|
|
5
|
+
|
|
6
|
+
(async () => {
|
|
7
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
8
|
+
const addr = parseInt(process.env.I2C_ADDR || '0x53', 16);
|
|
9
|
+
const connection = new I2CConnection(bus, addr);
|
|
10
|
+
const accel = new ADXL345Full(connection); // Create ADXL345 Full driver, (connection, bus_type='i2c')
|
|
11
|
+
|
|
12
|
+
await accel.setRange(4); // Set measurement range, (range_g) → g
|
|
13
|
+
// selects ±4 g; FULL_RES is preserved so scale stays 3.9 mg/LSB
|
|
14
|
+
await accel.setDataRate(200); // Set output data rate, (rate_hz) → Hz
|
|
15
|
+
// picks the nearest supported value (200 Hz)
|
|
16
|
+
await accel.setLowPower(false); // Set low-power mode, (enabled) → None
|
|
17
|
+
// normal-power mode; LOW_POWER bit in BW_RATE cleared
|
|
18
|
+
await accel.calibrateOffset(0, 0, 1, 64); // Calibrate offsets, (target_x=0 g, target_y=0 g, target_z=1 g, samples=64) → None g
|
|
19
|
+
// averages 64 samples with Z axis up and writes OFSX/OFSY/OFSZ
|
|
20
|
+
await accel.setTapDetection(0.5, 10); // Configure single-tap, (threshold_g, duration_ms, axes=0x07, suppress=false) → None g, ms
|
|
21
|
+
// 0.5 g threshold, 10 ms duration, all axes, no suppress
|
|
22
|
+
await accel.setDoubleTap(50, 200); // Configure double-tap, (latency_ms, window_ms) → None ms, ms
|
|
23
|
+
// 50 ms latency, 200 ms window between taps
|
|
24
|
+
await accel.setFifoMode(ADXL345Full.FIFO_STREAM, 16); // Configure FIFO, (mode, samples=16) → None
|
|
25
|
+
// stream mode, watermark 16 entries
|
|
26
|
+
await accel.setInterrupt(ADXL345Full.INT_WATERMARK, true, 1); // Configure interrupt, (source, enabled, pin=1) → None
|
|
27
|
+
// enable watermark interrupt on INT1
|
|
28
|
+
|
|
29
|
+
const [x, y, z] = await accel.read(); // Read 3-axis acceleration, () → [float, float, float] g
|
|
30
|
+
// single-shot burst read of all 6 data bytes
|
|
31
|
+
const samples = await accel.readFifo(); // Drain the FIFO, () → [[float, float, float]] g
|
|
32
|
+
// up to 32 (x, y, z) samples in *g*
|
|
33
|
+
const count = await accel.fifoCount(); // FIFO entries available, () → int
|
|
34
|
+
// from FIFO_STATUS register
|
|
35
|
+
const src = await accel.readInterruptSource(); // Read interrupt source, () → int
|
|
36
|
+
// bitmask of active INT_* sources; clears latches
|
|
37
|
+
|
|
38
|
+
await accel.selfTest(false); // Toggle self-test, (enabled) → None
|
|
39
|
+
// SELF_TEST bit in DATA_FORMAT cleared
|
|
40
|
+
await accel.setSleep(false); // Set sleep mode, (enabled, wakeup_hz=8) → None Hz
|
|
41
|
+
// wake up; no further state changes
|
|
42
|
+
await accel.setLinkMode(false); // Set activity/inactivity link, (enabled) → None
|
|
43
|
+
// Link bit in POWER_CTL cleared
|
|
44
|
+
await accel.setAutoSleep(false); // Set auto-sleep, (enabled) → None
|
|
45
|
+
// AUTO_SLEEP bit cleared
|
|
46
|
+
|
|
47
|
+
console.log(`x=${x.toFixed(3)} y=${y.toFixed(3)} z=${z.toFixed(3)} g`);
|
|
48
|
+
console.log(`fifo_count=${count} interrupts=0x${src.toString(16).padStart(2, '0')}`);
|
|
49
|
+
console.log(`samples=${samples.length}`);
|
|
50
|
+
|
|
51
|
+
await connection.close();
|
|
52
|
+
})();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { ADXL345Minimal } = require('periph/src/chips/accelerometer/adxl345');
|
|
5
|
+
|
|
6
|
+
(async () => {
|
|
7
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
8
|
+
const addr = parseInt(process.env.I2C_ADDR || '0x53', 16);
|
|
9
|
+
const connection = new I2CConnection(bus, addr);
|
|
10
|
+
const accel = new ADXL345Minimal(connection); // Create ADXL345 driver, (connection, bus_type='i2c')
|
|
11
|
+
|
|
12
|
+
// --- 50-sample stationary tilt characterization at 10 Hz ---
|
|
13
|
+
// With the sensor flat and the Z axis up, gravity should project entirely
|
|
14
|
+
// onto Z. Tilting the board visibly redistributes the 1 *g* magnitude
|
|
15
|
+
// across X and Y; the total vector magnitude stays near 1 *g*.
|
|
16
|
+
const SAMPLES = 50;
|
|
17
|
+
const PERIOD_MS = 100;
|
|
18
|
+
|
|
19
|
+
let magMin = Infinity;
|
|
20
|
+
let magMax = -Infinity;
|
|
21
|
+
|
|
22
|
+
for (let n = 0; n < SAMPLES; n++) {
|
|
23
|
+
const [x, y, z] = await accel.read(); // Read 3-axis acceleration, () → [float, float, float] g
|
|
24
|
+
const mag = Math.sqrt(x * x + y * y + z * z);
|
|
25
|
+
if (mag < magMin) magMin = mag;
|
|
26
|
+
if (mag > magMax) magMax = mag;
|
|
27
|
+
console.log(`${String(n).padStart(2, ' ')} x=${x >= 0 ? '+' : ''}${x.toFixed(3)} y=${y >= 0 ? '+' : ''}${y.toFixed(3)} z=${z >= 0 ? '+' : ''}${z.toFixed(3)} |a|=${mag.toFixed(3)} g`);
|
|
28
|
+
await new Promise(r => setTimeout(r, PERIOD_MS));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
console.log(`min |a|=${magMin.toFixed(3)} g max |a|=${magMax.toFixed(3)} g`);
|
|
32
|
+
|
|
33
|
+
await connection.close();
|
|
34
|
+
})();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { ADXL345Minimal } = require('periph/src/chips/accelerometer/adxl345');
|
|
5
|
+
|
|
6
|
+
(async () => {
|
|
7
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
8
|
+
const addr = parseInt(process.env.I2C_ADDR || '0x53', 16);
|
|
9
|
+
const connection = new I2CConnection(bus, addr);
|
|
10
|
+
const accel = new ADXL345Minimal(connection); // Create ADXL345 driver, (connection, bus_type='i2c')
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < 10; i++) {
|
|
13
|
+
const [x, y, z] = await accel.read(); // Read 3-axis acceleration, () → [float, float, float] g
|
|
14
|
+
console.log(`x=${x.toFixed(3)} y=${y.toFixed(3)} z=${z.toFixed(3)} g`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
await connection.close();
|
|
18
|
+
})();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { SPIConnection } = require('../../../src/connection/spi'); // SPIConnection class, (bus, dev, options) → SPIConnection
|
|
4
|
+
const { ADXL362Full } = require('../../../src/chips/accelerometer/adxl362'); // ADXL362Full class, (connection) → ADXL362Full
|
|
5
|
+
|
|
6
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: 0, maxSpeedHz: 8_000_000 }); // Open SPI bus, (busNumber, deviceNumber, mode=0, maxSpeedHz=8e6) → SPIConnection
|
|
11
|
+
const chip = new ADXL362Full(connection); // Create ADXL362 Full driver, (connection) → ADXL362Full
|
|
12
|
+
// init() runs asynchronously; identity errors surface on the first register access
|
|
13
|
+
|
|
14
|
+
// --- device_id triple ---
|
|
15
|
+
const { devidAd, devidMst, partid, revid } = await chip.deviceId(); // Read device IDs, () → Promise<{devidAd:int, devidMst:int, partid:int, revid:int}>
|
|
16
|
+
console.log(`DEVID_AD=0x${devidAd.toString(16)} DEVID_MST=0x${devidMst.toString(16)} PARTID=0x${partid.toString(16)} REVID=0x${revid.toString(16)}`);
|
|
17
|
+
|
|
18
|
+
await chip.setRange(4); // Set measurement range, (rangeG=4) → Promise<void>
|
|
19
|
+
await chip.setOdr(200.0); // Set output data rate, (odrHz=200.0) → Promise<void>
|
|
20
|
+
await chip.setHalfBandwidth(true); // Set antialiasing bandwidth, (enabled=true) → Promise<void>
|
|
21
|
+
await chip.setNoiseMode(ADXL362Full.NOISE_LOW); // Set noise mode, (mode=NOISE_LOW=1) → Promise<void>
|
|
22
|
+
|
|
23
|
+
const r12 = await chip.read(); // Read 12-bit acceleration, () → Promise<{x:float, y:float, z:float}> g
|
|
24
|
+
console.log(`12-bit: x=${r12.x.toFixed(3)} y=${r12.y.toFixed(3)} z=${r12.z.toFixed(3)}`);
|
|
25
|
+
|
|
26
|
+
const r8 = await chip.read8bit(); // Read 8-bit acceleration, () → Promise<{x:float, y:float, z:float}> g
|
|
27
|
+
console.log(` 8-bit: x=${r8.x.toFixed(3)} y=${r8.y.toFixed(3)} z=${r8.z.toFixed(3)}`);
|
|
28
|
+
|
|
29
|
+
const t = await chip.temperature(); // Read temperature, () → Promise<float> °C
|
|
30
|
+
console.log(`temperature: ${t.toFixed(2)} C`);
|
|
31
|
+
|
|
32
|
+
const rawStatus = await chip.status(); // Read STATUS register, () → Promise<byte>
|
|
33
|
+
console.log(`status: 0x${rawStatus.toString(16)}`);
|
|
34
|
+
console.log(`awake: ${await chip.awake() ? 1 : 0}`); // Check AWAKE bit, () → Promise<bool>
|
|
35
|
+
console.log(`data_ready: ${await chip.dataReady() ? 1 : 0}`); // Check DATA_READY, () → Promise<bool>
|
|
36
|
+
console.log(`fifo_entries: ${await chip.fifoEntries()}`); // Read FIFO entry count, () → Promise<int>
|
|
37
|
+
|
|
38
|
+
await chip.configureFifo(ADXL362Full.FIFO_STREAM, false, 128); // Configure FIFO, (mode=STREAM=2, storeTemp=false, watermark=128) → Promise<void>
|
|
39
|
+
await chip.setActivityThreshold(0.5, true); // Set activity threshold, (thresholdG=0.5, referenced=true) → Promise<void>
|
|
40
|
+
await chip.setActivityTime(5); // Set activity time, (samples=5) → Promise<void>
|
|
41
|
+
await chip.setInactivityThreshold(0.2, true); // Set inactivity threshold, (thresholdG=0.2, referenced=true) → Promise<void>
|
|
42
|
+
await chip.setInactivityTime(30); // Set inactivity time, (samples=30) → Promise<void>
|
|
43
|
+
await chip.enableActivityDetection(true); // Enable activity detection, (enabled=true) → Promise<void>
|
|
44
|
+
await chip.enableInactivityDetection(true); // Enable inactivity detection, (enabled=true) → Promise<void>
|
|
45
|
+
await chip.setLinkLoopMode(ADXL362Full.LINKLOOP_LOOP); // Set link/loop mode, (mode=LOOP=3) → Promise<void>
|
|
46
|
+
|
|
47
|
+
await chip.setInterrupt(1, ADXL362Full.SOURCE_DATA_READY, true); // Map DATA_READY to INT1, (pin=1, source=DATA_READY=0, enabled=true) → Promise<void>
|
|
48
|
+
await chip.setInterrupt(2, ADXL362Full.SOURCE_AWAKE, true); // Map AWAKE to INT2, (pin=2, source=AWAKE=6, enabled=true) → Promise<void>
|
|
49
|
+
await chip.setInterruptPolarity(1, true); // Set INT1 active-low, (pin=1, activeLow=true) → Promise<void>
|
|
50
|
+
|
|
51
|
+
await chip.selfTest(true); // Enable self-test, (enabled=true) → Promise<void>
|
|
52
|
+
await chip.selfTest(false); // Disable self-test, (enabled=false) → Promise<void>
|
|
53
|
+
|
|
54
|
+
await chip.softReset(); // Soft-reset the chip, () → Promise<void>
|
|
55
|
+
|
|
56
|
+
await connection.close();
|
|
57
|
+
})().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { SPIConnection } = require('../../../src/connection/spi'); // SPIConnection class, (bus, dev, options) → SPIConnection
|
|
4
|
+
const { ADXL362Full } = require('../../../src/chips/accelerometer/adxl362'); // ADXL362Full class, (connection) → ADXL362Full
|
|
5
|
+
|
|
6
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: 0, maxSpeedHz: 8_000_000 }); // Open SPI bus, (busNumber, deviceNumber, mode=0, maxSpeedHz=8e6) → SPIConnection
|
|
11
|
+
const chip = new ADXL362Full(connection); // Create ADXL362 Full driver, (connection) → ADXL362Full
|
|
12
|
+
|
|
13
|
+
// --- Configure referenced activity/inactivity thresholds ---
|
|
14
|
+
await chip.setActivityThreshold(0.25, true); // Set activity threshold, (thresholdG=0.25, referenced=true) → Promise<void>
|
|
15
|
+
await chip.setInactivityThreshold(0.15, true); // Set inactivity threshold, (thresholdG=0.15, referenced=true) → Promise<void>
|
|
16
|
+
await chip.setInactivityTime(30); // Set inactivity time, (samples=30) → Promise<void>
|
|
17
|
+
|
|
18
|
+
// --- Engage linked/loop mode and enable both detectors ---
|
|
19
|
+
await chip.enableActivityDetection(true); // Enable activity detection, (enabled=true) → Promise<void>
|
|
20
|
+
await chip.enableInactivityDetection(true); // Enable inactivity detection, (enabled=true) → Promise<void>
|
|
21
|
+
await chip.setLinkLoopMode(ADXL362Full.LINKLOOP_LOOP); // Set link/loop mode, (mode=LOOP=3) → Promise<void>
|
|
22
|
+
|
|
23
|
+
// --- Map AWAKE to INT2 and enter wake-up mode ---
|
|
24
|
+
await chip.setInterrupt(2, ADXL362Full.SOURCE_AWAKE, true); // Map AWAKE to INT2, (pin=2, source=AWAKE=6, enabled=true) → Promise<void>
|
|
25
|
+
await chip.setWakeupMode(true); // Enter wake-up mode, (enabled=true) → Promise<void>
|
|
26
|
+
|
|
27
|
+
// --- Poll AWAKE for 60 s and count asleep<->awake transitions ---
|
|
28
|
+
console.log('Watching for motion. Pick up or tap the board to wake; '
|
|
29
|
+
+ 'let it settle to sleep.');
|
|
30
|
+
let lastAwake = null;
|
|
31
|
+
let transitions = 0;
|
|
32
|
+
const start = Date.now();
|
|
33
|
+
while (Date.now() - start < 60_000) { // Loop until 60 s elapsed, () → bool
|
|
34
|
+
const nowAwake = await chip.awake(); // Read AWAKE bit, () → Promise<bool>
|
|
35
|
+
if (lastAwake === null || nowAwake !== lastAwake) {
|
|
36
|
+
const elapsed = ((Date.now() - start) / 1000).toFixed(2);
|
|
37
|
+
console.log(`${elapsed}s ${nowAwake ? 'AWAKE' : 'asleep'}`); // Print timestamped state, () → None
|
|
38
|
+
transitions++;
|
|
39
|
+
lastAwake = nowAwake;
|
|
40
|
+
}
|
|
41
|
+
await new Promise(r => setTimeout(r, 200)); // Sleep 200 ms between polls, () → None
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
console.log(`Total transitions observed: ${transitions}`); // Print final count, () → None
|
|
45
|
+
console.log('Note: during "asleep" periods the ADXL362 draws ~270 nA — '
|
|
46
|
+
+ 'roughly two orders of magnitude below the ~1.8 µA of the '
|
|
47
|
+
+ 'continuous 100 Hz measurement mode used by the Minimal '
|
|
48
|
+
+ 'read() example.');
|
|
49
|
+
|
|
50
|
+
await connection.close();
|
|
51
|
+
})().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { SPIConnection } = require('../../../src/connection/spi'); // SPIConnection class, (bus, dev, options) → SPIConnection
|
|
4
|
+
const { ADXL362Minimal } = require('../../../src/chips/accelerometer/adxl362'); // ADXL362Minimal class, (connection) → ADXL362Minimal
|
|
5
|
+
|
|
6
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: 0, maxSpeedHz: 8_000_000 }); // Open SPI bus, (busNumber, deviceNumber, mode=0, maxSpeedHz=8e6) → SPIConnection
|
|
11
|
+
const chip = new ADXL362Minimal(connection); // Create ADXL362 driver, (connection) → ADXL362Minimal
|
|
12
|
+
// (init() runs synchronously here — but this constructor returns the instance before init finishes; the read loop below awaits it implicitly via the first register access)
|
|
13
|
+
|
|
14
|
+
while (true) {
|
|
15
|
+
const { x, y, z } = await chip.read(); // Read 3-axis acceleration, () → Promise<{x:float, y:float, z:float}> g
|
|
16
|
+
console.log(`x=${x.toFixed(3)} y=${y.toFixed(3)} z=${z.toFixed(3)} g`);
|
|
17
|
+
await new Promise(r => setTimeout(r, 100));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await connection.close();
|
|
21
|
+
})();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const spi = require('spi-device');
|
|
4
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
5
|
+
const { AD7705Full } = require('../../../src/chips/adc_dac/ad7705');
|
|
6
|
+
|
|
7
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
8
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
9
|
+
|
|
10
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: spi.MODE3, maxSpeedHz: 5_000_000 }); // Create SPI connection, (bus=0, device=0, mode=3, maxSpeedHz=5_000_000) → SPIConnection
|
|
11
|
+
const adc = new AD7705Full(connection, 2.5, 2_457_600); // Create AD7705 driver, (connection, vref=2.5 V, mclk_hz=2_457_600 Hz) → AD7705Full
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
await adc.configure(2, 8, true, true, 60); // Configure channel 2, (channel=2, gain=8, bipolar=true, buffered=true, output_rate_hz=60) → None
|
|
15
|
+
// sets gain/bipolar/buffered/output_rate for the given channel; does not calibrate
|
|
16
|
+
await adc.selfCalibrate(2); // Self-calibrate channel, (channel=2) → None
|
|
17
|
+
// runs internal self-calibration, blocking until DRDY
|
|
18
|
+
|
|
19
|
+
const off2 = await adc.getOffsetCalibration(2); // Read offset calibration, (channel=2) → int 24-bit
|
|
20
|
+
const gain2 = await adc.getGainCalibration(2); // Read gain calibration, (channel=2) → int 24-bit
|
|
21
|
+
console.log('ch2 offset=' + off2 + ' gain=' + gain2);
|
|
22
|
+
|
|
23
|
+
const raw1 = await adc.readRawChannel(1); // Read raw 16-bit code, (channel=1) → int 16-bit
|
|
24
|
+
const v1 = await adc.readVoltageChannel(1); // Read voltage, (channel=1) → float V
|
|
25
|
+
const v2 = await adc.readVoltageChannel(2); // Read voltage, (channel=2) → float V
|
|
26
|
+
console.log('ch1 raw=' + raw1 + ' ch1 v=' + v1.toFixed(4) + ' ch2 v=' + v2.toFixed(4));
|
|
27
|
+
|
|
28
|
+
await adc.standby(); // Enter standby, () → None
|
|
29
|
+
// sets STBY=1 (~10 µA, registers retained)
|
|
30
|
+
await adc.wakeup(); // Exit standby, () → None
|
|
31
|
+
// clears STBY; blocks until a fresh conversion is available
|
|
32
|
+
})();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const spi = require('spi-device');
|
|
4
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
5
|
+
const { AD7705Full } = require('../../../src/chips/adc_dac/ad7705');
|
|
6
|
+
|
|
7
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
8
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
9
|
+
|
|
10
|
+
const TEMP_COEFF = 0.05;
|
|
11
|
+
const TEMP_REFERENCE = 1.25;
|
|
12
|
+
const CHANGE_THRESHOLD = 0.001;
|
|
13
|
+
|
|
14
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: spi.MODE3, maxSpeedHz: 5_000_000 }); // Create SPI connection, (bus=0, device=0, mode=3, maxSpeedHz=5_000_000) → SPIConnection
|
|
15
|
+
const adc = new AD7705Full(connection, 2.5, 2_457_600); // Create AD7705 driver, (connection, vref=2.5 V, mclk_hz=2_457_600 Hz) → AD7705Full
|
|
16
|
+
|
|
17
|
+
(async () => {
|
|
18
|
+
// --- Configure both channels for the bridge-pressure application ---
|
|
19
|
+
// Channel 1 reads the pressure bridge at gain 128 (small mV-level signal);
|
|
20
|
+
// Channel 2 reads an auxiliary temperature sensor at gain 2 for temperature
|
|
21
|
+
// compensation of the pressure reading.
|
|
22
|
+
await adc.configure(1, 128, true, true, 50); // Configure channel 1, (channel=1, gain=128, bipolar=true, buffered=true, output_rate_hz=50) → None
|
|
23
|
+
await adc.configure(2, 2, true, false, 50); // Configure channel 2, (channel=2, gain=2, bipolar=true, buffered=false, output_rate_hz=50) → None
|
|
24
|
+
|
|
25
|
+
// --- Self-calibrate both channels before the measurement loop ---
|
|
26
|
+
await adc.selfCalibrate(1); // Self-calibrate channel, (channel=1) → None
|
|
27
|
+
await adc.selfCalibrate(2); // Self-calibrate channel, (channel=2) → None
|
|
28
|
+
|
|
29
|
+
// --- Sample continuously and compensate the pressure reading for temperature ---
|
|
30
|
+
// pressure_compensated = pressure - TEMP_COEFF * (temp - TEMP_REFERENCE)
|
|
31
|
+
// Print whenever the compensated reading changes by more than 1 mV.
|
|
32
|
+
let lastPressure = null;
|
|
33
|
+
setInterval(async () => {
|
|
34
|
+
const pressureRaw = await adc.readVoltageChannel(1); // Read voltage, (channel=1) → float V
|
|
35
|
+
const temp = await adc.readVoltageChannel(2); // Read voltage, (channel=2) → float V
|
|
36
|
+
const pressure = pressureRaw - TEMP_COEFF * (temp - TEMP_REFERENCE);
|
|
37
|
+
if (lastPressure === null || Math.abs(pressure - lastPressure) > CHANGE_THRESHOLD) {
|
|
38
|
+
console.log(`→ pressure=${pressure.toFixed(4)} V (raw ${pressureRaw.toFixed(4)} V, temp ${temp.toFixed(4)} V)`);
|
|
39
|
+
lastPressure = pressure;
|
|
40
|
+
}
|
|
41
|
+
}, 200);
|
|
42
|
+
})();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const spi = require('spi-device');
|
|
4
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
5
|
+
const { AD7705Minimal } = require('../../../src/chips/adc_dac/ad7705');
|
|
6
|
+
|
|
7
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
8
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
9
|
+
|
|
10
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: spi.MODE3, maxSpeedHz: 5_000_000 }); // Create SPI connection, (bus=0, device=0, mode=3, maxSpeedHz=5_000_000) → SPIConnection
|
|
11
|
+
const adc = new AD7705Minimal(connection, 2.5, 2_457_600); // Create AD7705 driver, (connection, vref=2.5 V, mclk_hz=2_457_600 Hz) → AD7705Minimal
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
const v = await adc.readVoltage(); // Read Channel 1 voltage, () → float V
|
|
15
|
+
console.log(v.toFixed(4));
|
|
16
|
+
})();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const spi = require('spi-device');
|
|
4
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
5
|
+
const { AD7706Full } = require('../../../src/chips/adc_dac/ad7706');
|
|
6
|
+
|
|
7
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
8
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
9
|
+
|
|
10
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: spi.MODE3, maxSpeedHz: 5_000_000 }); // Create SPI connection, (bus=0, device=0, mode=3, maxSpeedHz=5_000_000) → SPIConnection
|
|
11
|
+
const adc = new AD7706Full(connection, 2.5, 2_457_600); // Create AD7706 driver, (connection, vref=2.5 V, mclk_hz=2_457_600 Hz) → AD7706Full
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
await adc.configure(2, 8, true, true, 60); // Configure channel 2, (channel=2, gain=8, bipolar=true, buffered=true, output_rate_hz=60) → None
|
|
15
|
+
// sets gain/bipolar/buffered/output_rate for the given channel; does not calibrate
|
|
16
|
+
await adc.selfCalibrate(2); // Self-calibrate channel, (channel=2) → None
|
|
17
|
+
// runs internal self-calibration, blocking until DRDY
|
|
18
|
+
await adc.configure(3, 8, true, true, 60); // Configure channel 3, (channel=3, gain=8, bipolar=true, buffered=true, output_rate_hz=60) → None
|
|
19
|
+
await adc.selfCalibrate(3); // Self-calibrate channel, (channel=3) → None
|
|
20
|
+
|
|
21
|
+
const off2 = await adc.getOffsetCalibration(2); // Read offset calibration, (channel=2) → int 24-bit
|
|
22
|
+
const gain2 = await adc.getGainCalibration(2); // Read gain calibration, (channel=2) → int 24-bit
|
|
23
|
+
console.log('ch2 offset=' + off2 + ' gain=' + gain2);
|
|
24
|
+
|
|
25
|
+
const raw1 = await adc.readRawChannel(1); // Read raw 16-bit code, (channel=1) → int 16-bit
|
|
26
|
+
const v1 = await adc.readVoltageChannel(1); // Read voltage, (channel=1) → float V
|
|
27
|
+
const v2 = await adc.readVoltageChannel(2); // Read voltage, (channel=2) → float V
|
|
28
|
+
const v3 = await adc.readVoltageChannel(3); // Read voltage, (channel=3) → float V
|
|
29
|
+
console.log('ch1 raw=' + raw1 + ' ch1 v=' + v1.toFixed(4) + ' ch2 v=' + v2.toFixed(4) + ' ch3 v=' + v3.toFixed(4));
|
|
30
|
+
|
|
31
|
+
await adc.standby(); // Enter standby, () → None
|
|
32
|
+
// sets STBY=1 (~10 µA, registers retained)
|
|
33
|
+
await adc.wakeup(); // Exit standby, () → None
|
|
34
|
+
// clears STBY; blocks until a fresh conversion is available
|
|
35
|
+
})();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const spi = require('spi-device');
|
|
4
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
5
|
+
const { AD7706Full } = require('../../../src/chips/adc_dac/ad7706');
|
|
6
|
+
|
|
7
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
8
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
9
|
+
|
|
10
|
+
const FILTER_DP_THRESHOLD = 0.001;
|
|
11
|
+
|
|
12
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: spi.MODE3, maxSpeedHz: 5_000_000 }); // Create SPI connection, (bus=0, device=0, mode=3, maxSpeedHz=5_000_000) → SPIConnection
|
|
13
|
+
const adc = new AD7706Full(connection, 2.5, 2_457_600); // Create AD7706 driver, (connection, vref=2.5 V, mclk_hz=2_457_600 Hz) → AD7706Full
|
|
14
|
+
|
|
15
|
+
(async () => {
|
|
16
|
+
// --- Configure all three channels for the HVAC manifold-pressure application ---
|
|
17
|
+
// All three pressure transducers are bridge-type with small mV-level output
|
|
18
|
+
// signals, so the AD7706's high-gain (128) pseudo-differential input is ideal.
|
|
19
|
+
// The shared-COMMON architecture lets all three bridges share a single return
|
|
20
|
+
// line instead of three fully-differential pairs.
|
|
21
|
+
await adc.configure(1, 128, true, true, 50); // Configure channel 1, (channel=1, gain=128, bipolar=true, buffered=true, output_rate_hz=50) → None
|
|
22
|
+
await adc.configure(2, 128, true, true, 50); // Configure channel 2, (channel=2, gain=128, bipolar=true, buffered=true, output_rate_hz=50) → None
|
|
23
|
+
await adc.configure(3, 128, true, true, 50); // Configure channel 3, (channel=3, gain=128, bipolar=true, buffered=true, output_rate_hz=50) → None
|
|
24
|
+
|
|
25
|
+
// --- Self-calibrate all three channels before the measurement loop ---
|
|
26
|
+
await adc.selfCalibrate(1); // Self-calibrate channel, (channel=1) → None
|
|
27
|
+
await adc.selfCalibrate(2); // Self-calibrate channel, (channel=2) → None
|
|
28
|
+
await adc.selfCalibrate(3); // Self-calibrate channel, (channel=3) → None
|
|
29
|
+
|
|
30
|
+
// --- Sample continuously and compute filter differential pressure ---
|
|
31
|
+
// Channel 1 = filter-inlet static, Channel 2 = filter-outlet static, Channel 3 = duct static.
|
|
32
|
+
// filter_dp = ch1 - ch2 is the filter differential pressure (clog indicator).
|
|
33
|
+
let lastFilterDp = null;
|
|
34
|
+
setInterval(async () => {
|
|
35
|
+
const inlet = await adc.readVoltageChannel(1); // Read voltage, (channel=1) → float V
|
|
36
|
+
const outlet = await adc.readVoltageChannel(2); // Read voltage, (channel=2) → float V
|
|
37
|
+
const duct = await adc.readVoltageChannel(3); // Read voltage, (channel=3) → float V
|
|
38
|
+
const filterDp = inlet - outlet;
|
|
39
|
+
if (lastFilterDp === null || Math.abs(filterDp - lastFilterDp) > FILTER_DP_THRESHOLD) {
|
|
40
|
+
console.log(`→ filter_dp=${filterDp.toFixed(4)} V, duct_pressure=${duct.toFixed(4)} V`);
|
|
41
|
+
lastFilterDp = filterDp;
|
|
42
|
+
}
|
|
43
|
+
}, 200);
|
|
44
|
+
})();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const spi = require('spi-device');
|
|
4
|
+
const { SPIConnection } = require('../../../src/connection/spi');
|
|
5
|
+
const { AD7706Minimal } = require('../../../src/chips/adc_dac/ad7706');
|
|
6
|
+
|
|
7
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
8
|
+
const SPI_DEV = parseInt(process.env.SPI_DEV || '0', 10);
|
|
9
|
+
|
|
10
|
+
const connection = new SPIConnection(SPI_BUS, SPI_DEV, { mode: spi.MODE3, maxSpeedHz: 5_000_000 }); // Create SPI connection, (bus=0, device=0, mode=3, maxSpeedHz=5_000_000) → SPIConnection
|
|
11
|
+
const adc = new AD7706Minimal(connection, 2.5, 2_457_600); // Create AD7706 driver, (connection, vref=2.5 V, mclk_hz=2_457_600 Hz) → AD7706Minimal
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
const v = await adc.readVoltage(); // Read Channel 1 voltage, () → float V
|
|
15
|
+
console.log(v.toFixed(4));
|
|
16
|
+
})();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Default } = require('opengpio');
|
|
4
|
+
const { HX711Connection } = require('../../../src/connection/hx711');
|
|
5
|
+
const { HX710AFull } = require('../../../src/chips/adc_dac/hx710a');
|
|
6
|
+
|
|
7
|
+
const dout = Default.input({ chip: 0, line: 5 }); // Configure DOUT as input, ({chip, line}) → Input
|
|
8
|
+
const pd_sck = Default.output({ chip: 0, line: 6 }); // Configure PD_SCK as output, ({chip, line}) → Output
|
|
9
|
+
const connection = new HX711Connection(dout, pd_sck); // Create HX711 transport connection, (dout, pd_sck)
|
|
10
|
+
const chip = new HX710AFull(connection); // Create HX710A driver — discards first conversion, (connection)
|
|
11
|
+
|
|
12
|
+
const ready = chip.isReady(); // Check if conversion is ready (non-blocking), () → boolean
|
|
13
|
+
// returns true when DOUT is LOW
|
|
14
|
+
const raw = chip.readRaw(); // Read signed 24-bit differential-input value, () → number
|
|
15
|
+
// blocks until DOUT goes LOW, then clocks out 24 bits
|
|
16
|
+
|
|
17
|
+
chip.setRate(40); // Select differential-input output rate, (rate: 10|40) → undefined
|
|
18
|
+
// takes effect after next read; issues dummy read to apply
|
|
19
|
+
chip.setRate(10); // (restores default 10 SPS)
|
|
20
|
+
|
|
21
|
+
const avg = chip.readAverage(10); // Average multiple raw readings, (times=10) → number
|
|
22
|
+
// blocks for `times` complete conversions
|
|
23
|
+
|
|
24
|
+
chip.tare(10); // Capture zero offset from 10-reading average, (times=10) → undefined
|
|
25
|
+
// stores result in internal _offset; call with nothing on the scale
|
|
26
|
+
const offset = chip.getOffset(); // Return stored tare offset, () → number
|
|
27
|
+
|
|
28
|
+
chip.setScale(420.0); // Set calibration scale factor, (factor: number) → undefined
|
|
29
|
+
// factor = (readAverage() - offset) / known_weight_in_target_unit
|
|
30
|
+
const scale = chip.getScale(); // Return current scale factor, () → number
|
|
31
|
+
|
|
32
|
+
const weight = chip.readWeight(5); // Return calibrated weight, (times=1) → number
|
|
33
|
+
// computes (readAverage(times) - offset) / scale
|
|
34
|
+
console.log('weight:', weight);
|
|
35
|
+
|
|
36
|
+
const tempRaw = chip.readTemperatureRaw(); // Read raw on-chip temperature code, () → number
|
|
37
|
+
// uncalibrated ADC code (~20.4 LSB/°C), not a °C value
|
|
38
|
+
console.log('temp raw:', tempRaw);
|
|
39
|
+
|
|
40
|
+
chip.powerDown(); // Enter power-down mode, () → undefined
|
|
41
|
+
// holds PD_SCK HIGH for >60 µs
|
|
42
|
+
chip.powerUp(); // Exit power-down, reset chip, discard settling conversion, () → undefined
|
|
43
|
+
// resets to differential input, gain 128, 10 SPS
|
|
44
|
+
|
|
45
|
+
connection.close();
|