periph 1.4.0 → 1.5.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 +27 -0
- package/examples/adc_dac/ad5251/complete.js +66 -0
- package/examples/adc_dac/ad5251/demo.js +69 -0
- package/examples/adc_dac/ad5251/minimal.js +23 -0
- package/examples/adc_dac/ad5252/complete.js +66 -0
- package/examples/adc_dac/ad5252/demo.js +69 -0
- package/examples/adc_dac/ad5252/minimal.js +23 -0
- package/examples/adc_dac/ads7828/complete.js +46 -0
- package/examples/adc_dac/ads7828/demo.js +45 -0
- package/examples/adc_dac/ads7828/minimal.js +17 -0
- package/examples/adc_dac/cat5171/complete.js +52 -0
- package/examples/adc_dac/cat5171/demo.js +59 -0
- package/examples/adc_dac/cat5171/minimal.js +23 -0
- package/examples/adc_dac/cs43l22/complete.js +88 -0
- package/examples/adc_dac/cs43l22/demo.js +56 -0
- package/examples/adc_dac/cs43l22/minimal.js +20 -0
- package/examples/adc_dac/ds1881/complete.js +62 -0
- package/examples/adc_dac/ds1881/demo.js +61 -0
- package/examples/adc_dac/ds1881/minimal.js +25 -0
- package/examples/adc_dac/ds3502/complete.js +46 -0
- package/examples/adc_dac/ds3502/demo.js +54 -0
- package/examples/adc_dac/ds3502/minimal.js +28 -0
- package/examples/adc_dac/mcp3422/complete.js +48 -0
- package/examples/adc_dac/mcp3422/demo.js +49 -0
- package/examples/adc_dac/mcp3422/minimal.js +25 -0
- package/examples/display/sh1106/complete.js +101 -0
- package/examples/display/sh1106/demo.js +68 -0
- package/examples/display/sh1106/minimal.js +25 -0
- package/examples/display/ssd1305/complete.js +129 -0
- package/examples/display/ssd1305/demo.js +71 -0
- package/examples/display/ssd1305/minimal.js +25 -0
- package/examples/display/ssd1306/complete.js +115 -0
- package/examples/display/ssd1306/demo.js +70 -0
- package/examples/display/ssd1306/minimal.js +25 -0
- package/examples/environmental/am2315/complete.js +34 -0
- package/examples/environmental/am2315/demo.js +46 -0
- package/examples/environmental/am2315/minimal.js +21 -0
- package/examples/humidity/htu21df/complete.js +49 -0
- package/examples/humidity/htu21df/demo.js +50 -0
- package/examples/humidity/htu21df/minimal.js +22 -0
- package/examples/humidity/sht31/complete.js +53 -0
- package/examples/humidity/sht31/demo.js +53 -0
- package/examples/humidity/sht31/minimal.js +21 -0
- package/examples/humidity/si7021/complete.js +55 -0
- package/examples/humidity/si7021/demo.js +58 -0
- package/examples/humidity/si7021/minimal.js +21 -0
- package/examples/imu/bno055/complete.js +85 -0
- package/examples/imu/bno055/demo.js +70 -0
- package/examples/imu/bno055/minimal.js +20 -0
- package/examples/io_expander/pca6408a/complete.js +63 -0
- package/examples/io_expander/pca6408a/demo.js +58 -0
- package/examples/io_expander/pca6408a/minimal.js +20 -0
- package/examples/io_expander/pca6416a/complete.js +68 -0
- package/examples/io_expander/pca6416a/demo.js +60 -0
- package/examples/io_expander/pca6416a/minimal.js +20 -0
- package/examples/io_expander/pca9536/complete.js +63 -0
- package/examples/io_expander/pca9536/demo.js +57 -0
- package/examples/io_expander/pca9536/minimal.js +20 -0
- package/examples/io_expander/pca9539/complete.js +68 -0
- package/examples/io_expander/pca9539/demo.js +60 -0
- package/examples/io_expander/pca9539/minimal.js +20 -0
- package/examples/light/max44009/complete.js +56 -0
- package/examples/light/max44009/demo.js +49 -0
- package/examples/light/max44009/minimal.js +22 -0
- package/examples/memory/at24c02n/complete.js +39 -0
- package/examples/memory/at24c02n/demo.js +39 -0
- package/examples/memory/at24c02n/minimal.js +15 -0
- package/examples/memory/at24c64/complete.js +39 -0
- package/examples/memory/at24c64/demo.js +39 -0
- package/examples/memory/at24c64/minimal.js +15 -0
- package/examples/memory/cat24c512/complete.js +39 -0
- package/examples/memory/cat24c512/demo.js +39 -0
- package/examples/memory/cat24c512/minimal.js +15 -0
- package/examples/other/pca9541/complete.js +52 -0
- package/examples/other/pca9541/demo.js +61 -0
- package/examples/other/pca9541/minimal.js +23 -0
- package/examples/temperature/tmp102/complete.js +74 -0
- package/examples/temperature/tmp102/demo.js +71 -0
- package/examples/temperature/tmp102/minimal.js +20 -0
- package/examples/tof/vl6180x/complete.js +62 -0
- package/examples/tof/vl6180x/demo.js +77 -0
- package/examples/tof/vl6180x/minimal.js +23 -0
- package/package.json +1 -1
- package/src/chips/adc_dac/ad5251.js +345 -0
- package/src/chips/adc_dac/ad5252.js +345 -0
- package/src/chips/adc_dac/ads7828.js +225 -0
- package/src/chips/adc_dac/cat5171.js +213 -0
- package/src/chips/adc_dac/cs43l22.js +645 -0
- package/src/chips/adc_dac/ds1881.js +357 -0
- package/src/chips/adc_dac/ds3502.js +241 -0
- package/src/chips/adc_dac/mcp3422.js +312 -0
- package/src/chips/display/mono_oled.js +182 -0
- package/src/chips/display/sh1106.js +496 -0
- package/src/chips/display/ssd1305.js +655 -0
- package/src/chips/display/ssd1306.js +458 -0
- package/src/chips/environmental/am2315.js +237 -0
- package/src/chips/humidity/htu21df.js +222 -0
- package/src/chips/humidity/sht31.js +284 -0
- package/src/chips/humidity/si7021.js +282 -0
- package/src/chips/imu/bno055.js +496 -0
- package/src/chips/io_expander/pca6408a.js +407 -0
- package/src/chips/io_expander/pca6416a.js +455 -0
- package/src/chips/io_expander/pca9536.js +398 -0
- package/src/chips/io_expander/pca9539.js +457 -0
- package/src/chips/light/max44009.js +336 -0
- package/src/chips/memory/at24c02n.js +220 -0
- package/src/chips/memory/at24c64.js +220 -0
- package/src/chips/memory/cat24c512.js +221 -0
- package/src/chips/other/pca9541.js +315 -0
- package/src/chips/temperature/tmp102.js +361 -0
- package/src/chips/tof/vl6180x.js +580 -0
- package/src/discovery/registry.js +65 -13
package/README.md
CHANGED
|
@@ -34,6 +34,8 @@ Each chip exposes two classes:
|
|
|
34
34
|
| 24AA02UID | Memory | `periph/src/chips/memory/_24aa02uid` |
|
|
35
35
|
| AD5243 | ADC/DAC | `periph/src/chips/adc_dac/ad5243` |
|
|
36
36
|
| AD5248 | ADC/DAC | `periph/src/chips/adc_dac/ad5248` |
|
|
37
|
+
| AD5251 | ADC/DAC | `periph/src/chips/adc_dac/ad5251` |
|
|
38
|
+
| AD5252 | ADC/DAC | `periph/src/chips/adc_dac/ad5252` |
|
|
37
39
|
| AD7705 | ADC/DAC | `periph/src/chips/adc_dac/ad7705` |
|
|
38
40
|
| AD7706 | ADC/DAC | `periph/src/chips/adc_dac/ad7706` |
|
|
39
41
|
| ADE7953 | Power monitor | `periph/src/chips/power/ade7953` |
|
|
@@ -42,13 +44,17 @@ Each chip exposes two classes:
|
|
|
42
44
|
| ADS1113 | ADC/DAC | `periph/src/chips/adc_dac/ads1113` |
|
|
43
45
|
| ADS1114 | ADC/DAC | `periph/src/chips/adc_dac/ads1114` |
|
|
44
46
|
| ADS1115 | ADC/DAC | `periph/src/chips/adc_dac/ads1115` |
|
|
47
|
+
| ADS7828 | ADC/DAC | `periph/src/chips/adc_dac/ads7828` |
|
|
45
48
|
| ADXL345 | Accelerometer | `periph/src/chips/accelerometer/adxl345` |
|
|
46
49
|
| ADXL362 | Accelerometer | `periph/src/chips/accelerometer/adxl362` |
|
|
47
50
|
| AHT21 | Environmental sensor | `periph/src/chips/environmental/aht21` |
|
|
51
|
+
| AM2315 | Environmental sensor | `periph/src/chips/environmental/am2315` |
|
|
48
52
|
| APA102 | LED driver | `periph/src/chips/led/apa102` |
|
|
49
53
|
| APDS-9930 | Light sensor | `periph/src/chips/light/apds-9930` |
|
|
50
54
|
| APDS9960 | Light sensor | `periph/src/chips/light/apds9960` |
|
|
51
55
|
| AS5600 | Magnetometer | `periph/src/chips/magnetometer/as5600` |
|
|
56
|
+
| AT24C02N | Memory | `periph/src/chips/memory/at24c02n` |
|
|
57
|
+
| AT24C64 | Memory | `periph/src/chips/memory/at24c64` |
|
|
52
58
|
| AXP2101 | Power monitor | `periph/src/chips/power/axp2101` |
|
|
53
59
|
| BMA150 | Accelerometer | `periph/src/chips/accelerometer/bma150` |
|
|
54
60
|
| BMA180 | Accelerometer | `periph/src/chips/accelerometer/bma180` |
|
|
@@ -59,14 +65,21 @@ Each chip exposes two classes:
|
|
|
59
65
|
| BMP280 | Pressure sensor | `periph/src/chips/pressure/bmp280` |
|
|
60
66
|
| BMP384 | Pressure sensor | `periph/src/chips/pressure/bmp384` |
|
|
61
67
|
| BMP581 | Pressure sensor | `periph/src/chips/pressure/bmp581` |
|
|
68
|
+
| BNO055 | IMU | `periph/src/chips/imu/bno055` |
|
|
69
|
+
| CAT24C512 | Memory | `periph/src/chips/memory/cat24c512` |
|
|
70
|
+
| CAT5171 | ADC/DAC | `periph/src/chips/adc_dac/cat5171` |
|
|
71
|
+
| CS43L22 | ADC/DAC | `periph/src/chips/adc_dac/cs43l22` |
|
|
62
72
|
| DHT11 | Humidity sensor | `periph/src/chips/humidity/dht11` |
|
|
63
73
|
| DRV2605 | Motor driver | `periph/src/chips/motor/drv2605` |
|
|
64
74
|
| DRV8830 | Motor driver | `periph/src/chips/motor/drv8830` |
|
|
75
|
+
| DS1881 | ADC/DAC | `periph/src/chips/adc_dac/ds1881` |
|
|
65
76
|
| DS3231 | RTC | `periph/src/chips/rtc/ds3231` |
|
|
77
|
+
| DS3502 | ADC/DAC | `periph/src/chips/adc_dac/ds3502` |
|
|
66
78
|
| ENS160 | Gas sensor | `periph/src/chips/gas/ens160` |
|
|
67
79
|
| ES8311 | ADC/DAC | `periph/src/chips/adc_dac/es8311` |
|
|
68
80
|
| FXOS8700 | Accelerometer | `periph/src/chips/accelerometer/fxos8700` |
|
|
69
81
|
| HMC5883L | Magnetometer | `periph/src/chips/magnetometer/hmc5883l` |
|
|
82
|
+
| HTU21DF | Humidity sensor | `periph/src/chips/humidity/htu21df` |
|
|
70
83
|
| HX710A | ADC/DAC | `periph/src/chips/adc_dac/hx710a` |
|
|
71
84
|
| HX710B | ADC/DAC | `periph/src/chips/adc_dac/hx710b` |
|
|
72
85
|
| HX711 | ADC/DAC | `periph/src/chips/adc_dac/hx711` |
|
|
@@ -83,10 +96,12 @@ Each chip exposes two classes:
|
|
|
83
96
|
| LPS28DFW | Pressure sensor | `periph/src/chips/pressure/lps28dfw` |
|
|
84
97
|
| LPS33HW | Pressure sensor | `periph/src/chips/pressure/lps33hw` |
|
|
85
98
|
| LSM303 | Accelerometer | `periph/src/chips/accelerometer/lsm303` |
|
|
99
|
+
| MAX44009 | Light sensor | `periph/src/chips/light/max44009` |
|
|
86
100
|
| MB85RC | Memory | `periph/src/chips/memory/mb85rc` |
|
|
87
101
|
| MCP23008 | IO expander | `periph/src/chips/io_expander/mcp23008` |
|
|
88
102
|
| MCP23017 | IO expander | `periph/src/chips/io_expander/mcp23017` |
|
|
89
103
|
| MCP2515 | Comms | `periph/src/chips/comms/mcp2515` |
|
|
104
|
+
| MCP3422 | ADC/DAC | `periph/src/chips/adc_dac/mcp3422` |
|
|
90
105
|
| MCP4725 | ADC/DAC | `periph/src/chips/adc_dac/mcp4725` |
|
|
91
106
|
| MCP4728 | ADC/DAC | `periph/src/chips/adc_dac/mcp4728` |
|
|
92
107
|
| MCP4XXX | ADC/DAC | `periph/src/chips/adc_dac/mcp4xxx` |
|
|
@@ -101,6 +116,11 @@ Each chip exposes two classes:
|
|
|
101
116
|
| NEO6 | GNSS/GPS | `periph/src/chips/gnss/neo6` |
|
|
102
117
|
| NEOPIXELRGBBASE | LED driver | `periph/src/chips/led/_NeoPixelRGBBase` |
|
|
103
118
|
| NEOPIXELRGBWBASE | LED driver | `periph/src/chips/led/_NeoPixelRGBWBase` |
|
|
119
|
+
| PCA6408A | IO expander | `periph/src/chips/io_expander/pca6408a` |
|
|
120
|
+
| PCA6416A | IO expander | `periph/src/chips/io_expander/pca6416a` |
|
|
121
|
+
| PCA9536 | IO expander | `periph/src/chips/io_expander/pca9536` |
|
|
122
|
+
| PCA9539 | IO expander | `periph/src/chips/io_expander/pca9539` |
|
|
123
|
+
| PCA9541 | Other | `periph/src/chips/other/pca9541` |
|
|
104
124
|
| PCF85063A | RTC | `periph/src/chips/rtc/pcf85063a` |
|
|
105
125
|
| PCF8523 | RTC | `periph/src/chips/rtc/pcf8523` |
|
|
106
126
|
| PCF8574 | IO expander | `periph/src/chips/io_expander/pcf8574` |
|
|
@@ -113,13 +133,19 @@ Each chip exposes two classes:
|
|
|
113
133
|
| RDA5807M | Comms | `periph/src/chips/comms/rda5807m` |
|
|
114
134
|
| RFM9X | Comms | `periph/src/chips/comms/rfm9x` |
|
|
115
135
|
| SD_SPI | Memory | `periph/src/chips/memory/sd_spi` |
|
|
136
|
+
| SH1106 | Display driver | `periph/src/chips/display/sh1106` |
|
|
137
|
+
| SHT31 | Humidity sensor | `periph/src/chips/humidity/sht31` |
|
|
138
|
+
| SI7021 | Humidity sensor | `periph/src/chips/humidity/si7021` |
|
|
116
139
|
| SK6812RGBW | LED driver | `periph/src/chips/led/sk6812rgbw` |
|
|
140
|
+
| SSD1305 | Display driver | `periph/src/chips/display/ssd1305` |
|
|
141
|
+
| SSD1306 | Display driver | `periph/src/chips/display/ssd1306` |
|
|
117
142
|
| SSD1331 | Display driver | `periph/src/chips/display/ssd1331` |
|
|
118
143
|
| ST7036 | Display driver | `periph/src/chips/display/st7036` |
|
|
119
144
|
| TMC2130 | Motor driver | `periph/src/chips/motor/tmc2130` |
|
|
120
145
|
| TMC2208 | Motor driver | `periph/src/chips/motor/tmc2208` |
|
|
121
146
|
| TMC2209 | Motor driver | `periph/src/chips/motor/tmc2209` |
|
|
122
147
|
| TMC5160 | Motor driver | `periph/src/chips/motor/tmc5160` |
|
|
148
|
+
| TMP102 | Temperature sensor | `periph/src/chips/temperature/tmp102` |
|
|
123
149
|
| TMP117 | Temperature sensor | `periph/src/chips/temperature/tmp117` |
|
|
124
150
|
| TPIC6B595 | IO expander | `periph/src/chips/io_expander/tpic6b595` |
|
|
125
151
|
| UC1611S | Display driver | `periph/src/chips/display/uc1611s` |
|
|
@@ -127,6 +153,7 @@ Each chip exposes two classes:
|
|
|
127
153
|
| UC8276C | Display driver | `periph/src/chips/display/uc8276c` |
|
|
128
154
|
| VL53L0X | Time-of-flight | `periph/src/chips/tof/vl53l0x` |
|
|
129
155
|
| VL53L1X | Time-of-flight | `periph/src/chips/tof/vl53l1x` |
|
|
156
|
+
| VL6180X | Time-of-flight | `periph/src/chips/tof/vl6180x` |
|
|
130
157
|
| WS2812B | LED driver | `periph/src/chips/led/ws2812b` |
|
|
131
158
|
| WS2814 | LED driver | `periph/src/chips/led/ws2814` |
|
|
132
159
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Complete example: exercises every method of AD5251Full.
|
|
4
|
+
|
|
5
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
6
|
+
const { AD5251Full } = require('periph/src/chips/adc_dac/ad5251');
|
|
7
|
+
|
|
8
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
12
|
+
const connection = new I2CConnection(bus, AD5251Full.I2C_ADDRESS);
|
|
13
|
+
const pot = new AD5251Full(connection); // Create AD5251 Full driver, (connection, rAb=50000 Ω, rWiper=75 Ω)
|
|
14
|
+
await pot.init(); // Prepare driver, () → None
|
|
15
|
+
// no I²C traffic; the chip needs no initialisation
|
|
16
|
+
|
|
17
|
+
await pot.setWiper(0, 40); // Set wiper position, (channel 0–1, code 0–63) → None
|
|
18
|
+
// writes [instruction, code]; the instruction byte selects the channel
|
|
19
|
+
console.log(await pot.getWiper(0)); // Read wiper position, (channel 0–1) → int 0–63
|
|
20
|
+
// sends the instruction alone, then reads one byte
|
|
21
|
+
await pot.setResistance(0, 25000.0); // Set W–B resistance, (channel 0–1, ohms Ω) → None
|
|
22
|
+
// inverts R = D/64·RAB + RW to the nearest code
|
|
23
|
+
console.log(await pot.getResistance(0)); // Read W–B resistance, (channel 0–1) → float Ω
|
|
24
|
+
// evaluates D/64·RAB + RW for the current code
|
|
25
|
+
|
|
26
|
+
await pot.setBoth(8, 56); // Write both wipers, (code0 0–63, code1 0–63) → None
|
|
27
|
+
// two transactions, channel 0 then channel 1
|
|
28
|
+
await pot.setRatio(0, 0.25); // Set divider ratio, (channel 0–1, ratio 0.0–1.0) → None
|
|
29
|
+
// code = round(ratio × 64), clamped to 63
|
|
30
|
+
console.log(await pot.getRatio(0)); // Read divider ratio, (channel 0–1) → float
|
|
31
|
+
// code / 64
|
|
32
|
+
await pot.setResistanceWa(1, 15000.0); // Set W–A resistance, (channel 0–1, ohms Ω) → None
|
|
33
|
+
// rheostat between W and A with B open
|
|
34
|
+
console.log(await pot.getResistanceWa(1)); // Read W–A resistance, (channel 0–1) → float Ω
|
|
35
|
+
// (64 − D)/64·RAB + RW
|
|
36
|
+
await pot.increment(0); // Step up one code, (channel=all 0–1) → None
|
|
37
|
+
// quick command; omit the channel to address both
|
|
38
|
+
await pot.decrement(0); // Step down one code, (channel=all 0–1) → None
|
|
39
|
+
// quick command; saturates at 0
|
|
40
|
+
await pot.double(0); // Raise by 6 dB, (channel=all 0–1) → None
|
|
41
|
+
// quick command; the code doubles, saturating at 63
|
|
42
|
+
await pot.halve(0); // Lower by 6 dB, (channel=all 0–1) → None
|
|
43
|
+
// quick command; the code is halved
|
|
44
|
+
await pot.store(); // Store wipers in EEMEM, (channel=all 0–1) → None
|
|
45
|
+
// quick command, then ACK polling (≈ 26 ms)
|
|
46
|
+
await pot.setBoth(1, 2);
|
|
47
|
+
await pot.restore(); // Restore wipers from EEMEM, (channel=all 0–1) → None
|
|
48
|
+
// quick command followed by NOP
|
|
49
|
+
console.log(await pot.getWiper(0), await pot.getWiper(1));
|
|
50
|
+
await pot.writeEemem(4, 0x5A); // Write user EEMEM byte, (index 4–15, value 0–63) → None
|
|
51
|
+
// followed by ACK polling (≈ 26 ms)
|
|
52
|
+
console.log(await pot.readEemem(4)); // Read user EEMEM byte, (index 4–15) → int 0–63
|
|
53
|
+
// pointer write, then a one-byte read
|
|
54
|
+
console.log(await pot.readTolerance(0)); // Read stored RAB tolerance, (channel 0–1) → float %
|
|
55
|
+
// sign-magnitude integer byte + decimal byte / 256
|
|
56
|
+
console.log(await pot.rabActual(0)); // Actual RAB of a channel, (channel 0–1) → float Ω
|
|
57
|
+
// rAb × (1 + tolerance / 100)
|
|
58
|
+
await pot.nop(); // Send NOP, () → None
|
|
59
|
+
// quick command 0x80; the chip returns to idle
|
|
60
|
+
pot.setRab(50000.0, 120.0); // Change resistance model, (rAb Ω, rWiper=unchanged Ω) → None
|
|
61
|
+
// affects conversions only; no I²C traffic
|
|
62
|
+
await sleep(1000);
|
|
63
|
+
await pot.reset(); // Reset from EEMEM, () → None
|
|
64
|
+
// quick command 0xB8, then ACK polling
|
|
65
|
+
await connection.close();
|
|
66
|
+
})();
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Voltage-divider level setter: steps channel 0 as a divider (A at VDD, B at
|
|
4
|
+
// GND) through several ratios and prints the expected output voltage at
|
|
5
|
+
// VDD = 3.3 V; sets channel 1 as a 20 kΩ rheostat and reports the
|
|
6
|
+
// quantisation error; steps the wiper with the quick commands, stores and restores it, reads and
|
|
7
|
+
// writes the user EEMEM, prints the stored RAB tolerance and resets from EEMEM.
|
|
8
|
+
|
|
9
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
10
|
+
const { AD5251Full } = require('periph/src/chips/adc_dac/ad5251');
|
|
11
|
+
|
|
12
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
13
|
+
const VDD = 3.3;
|
|
14
|
+
|
|
15
|
+
(async () => {
|
|
16
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
17
|
+
const connection = new I2CConnection(bus, AD5251Full.I2C_ADDRESS);
|
|
18
|
+
const pot = new AD5251Full(connection); // Create AD5251 Full driver, (connection, rAb=50000 Ω, rWiper=75 Ω)
|
|
19
|
+
await pot.init(); // Prepare driver, () → None
|
|
20
|
+
|
|
21
|
+
// --- Step channel 0 through divider ratios ---
|
|
22
|
+
// With A at VDD and B at GND the wiper voltage is ratio × VDD; the code is
|
|
23
|
+
// round(ratio × 64), so 0.999 lands on the top code 63.
|
|
24
|
+
for (const ratio of [0.0, 0.25, 0.5, 0.75, 0.999]) {
|
|
25
|
+
await pot.setRatio(0, ratio); // Set divider ratio, (channel 0–1, ratio 0.0–1.0) → None
|
|
26
|
+
const code = await pot.getWiper(0); // Read wiper position, (channel 0–1) → int 0–63
|
|
27
|
+
const actual = await pot.getRatio(0); // Read divider ratio, (channel 0–1) → float
|
|
28
|
+
console.log(`ratio ${ratio.toFixed(3)} -> code ${code} (${actual.toFixed(4)}) -> ${(actual * VDD).toFixed(3)} V`);
|
|
29
|
+
await sleep(500);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// --- Use channel 1 as a 20 kΩ rheostat ---
|
|
33
|
+
// The 64 steps quantise the resistance (~781 Ω per code on a 50 kΩ part), so
|
|
34
|
+
// the readback differs slightly from the request.
|
|
35
|
+
await pot.setResistance(1, 20000.0); // Set W–B resistance, (channel 0–1, ohms Ω) → None
|
|
36
|
+
const r = await pot.getResistance(1); // Read W–B resistance, (channel 0–1) → float Ω
|
|
37
|
+
console.log(`rheostat ${r.toFixed(1)} Ω, error ${(r - 20000.0).toFixed(1)} Ω`);
|
|
38
|
+
|
|
39
|
+
// --- Step and scale the wiper with the quick commands ---
|
|
40
|
+
// increment/decrement move one code, double/halve change the level by 6 dB.
|
|
41
|
+
await pot.setWiper(0, 16); // Set wiper position, (channel 0–1, code 0–63) → None
|
|
42
|
+
await pot.increment(0); // Quick command, (channel=all 0–1) → None
|
|
43
|
+
console.log('increment ->', await pot.getWiper(0));
|
|
44
|
+
await pot.decrement(0); // Quick command, (channel=all 0–1) → None
|
|
45
|
+
console.log('decrement ->', await pot.getWiper(0));
|
|
46
|
+
await pot.double(0); // Quick command, (channel=all 0–1) → None
|
|
47
|
+
console.log('double ->', await pot.getWiper(0));
|
|
48
|
+
await pot.halve(0); // Quick command, (channel=all 0–1) → None
|
|
49
|
+
console.log('halve ->', await pot.getWiper(0));
|
|
50
|
+
|
|
51
|
+
// --- Make the settings persistent ---
|
|
52
|
+
// store() writes the wipers to EEMEM (≈ 26 ms, ACK polling); after a change,
|
|
53
|
+
// restore() brings the stored values back.
|
|
54
|
+
await pot.store(); // Store wipers in EEMEM, (channel=all 0–1) → None
|
|
55
|
+
await pot.setBoth(1, 2); // Write both wipers, (code0 0–63, code1 0–63) → None
|
|
56
|
+
await pot.restore(); // Restore wipers from EEMEM, (channel=all 0–1) → None
|
|
57
|
+
console.log('restored:', await pot.getWiper(0), await pot.getWiper(1));
|
|
58
|
+
|
|
59
|
+
// --- User EEMEM bytes and the factory tolerance ---
|
|
60
|
+
await pot.writeEemem(4, 0x40); // Write user EEMEM byte, (index 4–15, value 0–63) → None
|
|
61
|
+
console.log('eemem 4', await pot.readEemem(4)); // Read user EEMEM byte, (index 4–15) → int 0–63
|
|
62
|
+
console.log('tolerance', (await pot.readTolerance(0)).toFixed(3), '%'); // Read stored RAB tolerance, (channel 0–1) → float %
|
|
63
|
+
console.log('RAB', (await pot.rabActual(0)).toFixed(1), 'Ω'); // Actual RAB of a channel, (channel 0–1) → float Ω
|
|
64
|
+
|
|
65
|
+
// --- Restore the stored state ---
|
|
66
|
+
// reset() restores both wipers from EEMEM and waits for the write cycle.
|
|
67
|
+
await pot.reset(); // Reset from EEMEM, () → None
|
|
68
|
+
await connection.close();
|
|
69
|
+
})();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { AD5251Minimal } = require('periph/src/chips/adc_dac/ad5251');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
10
|
+
const connection = new I2CConnection(bus, AD5251Minimal.I2C_ADDRESS);
|
|
11
|
+
const pot = new AD5251Minimal(connection); // Create AD5251 driver, (connection, rAb=50000 Ω, rWiper=75 Ω)
|
|
12
|
+
await pot.init(); // Prepare driver, () → None
|
|
13
|
+
|
|
14
|
+
for (const code of [0, 16, 32, 48, 63]) {
|
|
15
|
+
await pot.setWiper(0, code); // Set wiper position, (channel 0–1, code 0–63) → None
|
|
16
|
+
console.log(code, await pot.getWiper(0)); // Read wiper position, (channel 0–1) → int 0–63
|
|
17
|
+
console.log(await pot.getResistance(0)); // Read W–B resistance, (channel 0–1) → float Ω
|
|
18
|
+
await sleep(500);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
await pot.setResistance(1, 20000.0); // Set W–B resistance, (channel 0–1, ohms Ω) → None
|
|
22
|
+
await connection.close();
|
|
23
|
+
})();
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Complete example: exercises every method of AD5252Full.
|
|
4
|
+
|
|
5
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
6
|
+
const { AD5252Full } = require('periph/src/chips/adc_dac/ad5252');
|
|
7
|
+
|
|
8
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
12
|
+
const connection = new I2CConnection(bus, AD5252Full.I2C_ADDRESS);
|
|
13
|
+
const pot = new AD5252Full(connection); // Create AD5252 Full driver, (connection, rAb=10000 Ω, rWiper=75 Ω)
|
|
14
|
+
await pot.init(); // Prepare driver, () → None
|
|
15
|
+
// no I²C traffic; the chip needs no initialisation
|
|
16
|
+
|
|
17
|
+
await pot.setWiper(0, 100); // Set wiper position, (channel 0–1, code 0–255) → None
|
|
18
|
+
// writes [instruction, code]; the instruction byte selects the channel
|
|
19
|
+
console.log(await pot.getWiper(0)); // Read wiper position, (channel 0–1) → int 0–255
|
|
20
|
+
// sends the instruction alone, then reads one byte
|
|
21
|
+
await pot.setResistance(0, 5000.0); // Set W–B resistance, (channel 0–1, ohms Ω) → None
|
|
22
|
+
// inverts R = D/256·RAB + RW to the nearest code
|
|
23
|
+
console.log(await pot.getResistance(0)); // Read W–B resistance, (channel 0–1) → float Ω
|
|
24
|
+
// evaluates D/256·RAB + RW for the current code
|
|
25
|
+
|
|
26
|
+
await pot.setBoth(32, 224); // Write both wipers, (code0 0–255, code1 0–255) → None
|
|
27
|
+
// two transactions, channel 0 then channel 1
|
|
28
|
+
await pot.setRatio(0, 0.25); // Set divider ratio, (channel 0–1, ratio 0.0–1.0) → None
|
|
29
|
+
// code = round(ratio × 256), clamped to 255
|
|
30
|
+
console.log(await pot.getRatio(0)); // Read divider ratio, (channel 0–1) → float
|
|
31
|
+
// code / 256
|
|
32
|
+
await pot.setResistanceWa(1, 3000.0); // Set W–A resistance, (channel 0–1, ohms Ω) → None
|
|
33
|
+
// rheostat between W and A with B open
|
|
34
|
+
console.log(await pot.getResistanceWa(1)); // Read W–A resistance, (channel 0–1) → float Ω
|
|
35
|
+
// (256 − D)/256·RAB + RW
|
|
36
|
+
await pot.increment(0); // Step up one code, (channel=all 0–1) → None
|
|
37
|
+
// quick command; omit the channel to address both
|
|
38
|
+
await pot.decrement(0); // Step down one code, (channel=all 0–1) → None
|
|
39
|
+
// quick command; saturates at 0
|
|
40
|
+
await pot.double(0); // Raise by 6 dB, (channel=all 0–1) → None
|
|
41
|
+
// quick command; the code doubles, saturating at 255
|
|
42
|
+
await pot.halve(0); // Lower by 6 dB, (channel=all 0–1) → None
|
|
43
|
+
// quick command; the code is halved
|
|
44
|
+
await pot.store(); // Store wipers in EEMEM, (channel=all 0–1) → None
|
|
45
|
+
// quick command, then ACK polling (≈ 26 ms)
|
|
46
|
+
await pot.setBoth(1, 2);
|
|
47
|
+
await pot.restore(); // Restore wipers from EEMEM, (channel=all 0–1) → None
|
|
48
|
+
// quick command followed by NOP
|
|
49
|
+
console.log(await pot.getWiper(0), await pot.getWiper(1));
|
|
50
|
+
await pot.writeEemem(4, 0x5A); // Write user EEMEM byte, (index 4–15, value 0–255) → None
|
|
51
|
+
// followed by ACK polling (≈ 26 ms)
|
|
52
|
+
console.log(await pot.readEemem(4)); // Read user EEMEM byte, (index 4–15) → int 0–255
|
|
53
|
+
// pointer write, then a one-byte read
|
|
54
|
+
console.log(await pot.readTolerance(0)); // Read stored RAB tolerance, (channel 0–1) → float %
|
|
55
|
+
// sign-magnitude integer byte + decimal byte / 256
|
|
56
|
+
console.log(await pot.rabActual(0)); // Actual RAB of a channel, (channel 0–1) → float Ω
|
|
57
|
+
// rAb × (1 + tolerance / 100)
|
|
58
|
+
await pot.nop(); // Send NOP, () → None
|
|
59
|
+
// quick command 0x80; the chip returns to idle
|
|
60
|
+
pot.setRab(50000.0, 120.0); // Change resistance model, (rAb Ω, rWiper=unchanged Ω) → None
|
|
61
|
+
// affects conversions only; no I²C traffic
|
|
62
|
+
await sleep(1000);
|
|
63
|
+
await pot.reset(); // Reset from EEMEM, () → None
|
|
64
|
+
// quick command 0xB8, then ACK polling
|
|
65
|
+
await connection.close();
|
|
66
|
+
})();
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Voltage-divider level setter: steps channel 0 as a divider (A at VDD, B at
|
|
4
|
+
// GND) through several ratios and prints the expected output voltage at
|
|
5
|
+
// VDD = 3.3 V; sets channel 1 as a 2.2 kΩ rheostat and reports the
|
|
6
|
+
// quantisation error; steps the wiper with the quick commands, stores and restores it, reads and
|
|
7
|
+
// writes the user EEMEM, prints the stored RAB tolerance and resets from EEMEM.
|
|
8
|
+
|
|
9
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
10
|
+
const { AD5252Full } = require('periph/src/chips/adc_dac/ad5252');
|
|
11
|
+
|
|
12
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
13
|
+
const VDD = 3.3;
|
|
14
|
+
|
|
15
|
+
(async () => {
|
|
16
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
17
|
+
const connection = new I2CConnection(bus, AD5252Full.I2C_ADDRESS);
|
|
18
|
+
const pot = new AD5252Full(connection); // Create AD5252 Full driver, (connection, rAb=10000 Ω, rWiper=75 Ω)
|
|
19
|
+
await pot.init(); // Prepare driver, () → None
|
|
20
|
+
|
|
21
|
+
// --- Step channel 0 through divider ratios ---
|
|
22
|
+
// With A at VDD and B at GND the wiper voltage is ratio × VDD; the code is
|
|
23
|
+
// round(ratio × 256), so 0.999 lands on the top code 255.
|
|
24
|
+
for (const ratio of [0.0, 0.25, 0.5, 0.75, 0.999]) {
|
|
25
|
+
await pot.setRatio(0, ratio); // Set divider ratio, (channel 0–1, ratio 0.0–1.0) → None
|
|
26
|
+
const code = await pot.getWiper(0); // Read wiper position, (channel 0–1) → int 0–255
|
|
27
|
+
const actual = await pot.getRatio(0); // Read divider ratio, (channel 0–1) → float
|
|
28
|
+
console.log(`ratio ${ratio.toFixed(3)} -> code ${code} (${actual.toFixed(4)}) -> ${(actual * VDD).toFixed(3)} V`);
|
|
29
|
+
await sleep(500);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// --- Use channel 1 as a 2.2 kΩ rheostat ---
|
|
33
|
+
// The 256 steps quantise the resistance (~39 Ω per code on a 10 kΩ part), so
|
|
34
|
+
// the readback differs slightly from the request.
|
|
35
|
+
await pot.setResistance(1, 2200.0); // Set W–B resistance, (channel 0–1, ohms Ω) → None
|
|
36
|
+
const r = await pot.getResistance(1); // Read W–B resistance, (channel 0–1) → float Ω
|
|
37
|
+
console.log(`rheostat ${r.toFixed(1)} Ω, error ${(r - 2200.0).toFixed(1)} Ω`);
|
|
38
|
+
|
|
39
|
+
// --- Step and scale the wiper with the quick commands ---
|
|
40
|
+
// increment/decrement move one code, double/halve change the level by 6 dB.
|
|
41
|
+
await pot.setWiper(0, 64); // Set wiper position, (channel 0–1, code 0–255) → None
|
|
42
|
+
await pot.increment(0); // Quick command, (channel=all 0–1) → None
|
|
43
|
+
console.log('increment ->', await pot.getWiper(0));
|
|
44
|
+
await pot.decrement(0); // Quick command, (channel=all 0–1) → None
|
|
45
|
+
console.log('decrement ->', await pot.getWiper(0));
|
|
46
|
+
await pot.double(0); // Quick command, (channel=all 0–1) → None
|
|
47
|
+
console.log('double ->', await pot.getWiper(0));
|
|
48
|
+
await pot.halve(0); // Quick command, (channel=all 0–1) → None
|
|
49
|
+
console.log('halve ->', await pot.getWiper(0));
|
|
50
|
+
|
|
51
|
+
// --- Make the settings persistent ---
|
|
52
|
+
// store() writes the wipers to EEMEM (≈ 26 ms, ACK polling); after a change,
|
|
53
|
+
// restore() brings the stored values back.
|
|
54
|
+
await pot.store(); // Store wipers in EEMEM, (channel=all 0–1) → None
|
|
55
|
+
await pot.setBoth(1, 2); // Write both wipers, (code0 0–255, code1 0–255) → None
|
|
56
|
+
await pot.restore(); // Restore wipers from EEMEM, (channel=all 0–1) → None
|
|
57
|
+
console.log('restored:', await pot.getWiper(0), await pot.getWiper(1));
|
|
58
|
+
|
|
59
|
+
// --- User EEMEM bytes and the factory tolerance ---
|
|
60
|
+
await pot.writeEemem(4, 0x40); // Write user EEMEM byte, (index 4–15, value 0–255) → None
|
|
61
|
+
console.log('eemem 4', await pot.readEemem(4)); // Read user EEMEM byte, (index 4–15) → int 0–255
|
|
62
|
+
console.log('tolerance', (await pot.readTolerance(0)).toFixed(3), '%'); // Read stored RAB tolerance, (channel 0–1) → float %
|
|
63
|
+
console.log('RAB', (await pot.rabActual(0)).toFixed(1), 'Ω'); // Actual RAB of a channel, (channel 0–1) → float Ω
|
|
64
|
+
|
|
65
|
+
// --- Restore the stored state ---
|
|
66
|
+
// reset() restores both wipers from EEMEM and waits for the write cycle.
|
|
67
|
+
await pot.reset(); // Reset from EEMEM, () → None
|
|
68
|
+
await connection.close();
|
|
69
|
+
})();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { AD5252Minimal } = require('periph/src/chips/adc_dac/ad5252');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
10
|
+
const connection = new I2CConnection(bus, AD5252Minimal.I2C_ADDRESS);
|
|
11
|
+
const pot = new AD5252Minimal(connection); // Create AD5252 driver, (connection, rAb=10000 Ω, rWiper=75 Ω)
|
|
12
|
+
await pot.init(); // Prepare driver, () → None
|
|
13
|
+
|
|
14
|
+
for (const code of [0, 64, 128, 192, 255]) {
|
|
15
|
+
await pot.setWiper(0, code); // Set wiper position, (channel 0–1, code 0–255) → None
|
|
16
|
+
console.log(code, await pot.getWiper(0)); // Read wiper position, (channel 0–1) → int 0–255
|
|
17
|
+
console.log(await pot.getResistance(0)); // Read W–B resistance, (channel 0–1) → float Ω
|
|
18
|
+
await sleep(500);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
await pot.setResistance(1, 2200.0); // Set W–B resistance, (channel 0–1, ohms Ω) → None
|
|
22
|
+
await connection.close();
|
|
23
|
+
})();
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Complete example: exercises every method of ADS7828Full.
|
|
4
|
+
|
|
5
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
6
|
+
const { ADS7828Full } = require('periph/src/chips/adc_dac/ads7828');
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
10
|
+
const connection = new I2CConnection(bus, ADS7828Full.I2C_ADDRESS); // Create I2C connection, (bus, address)
|
|
11
|
+
const adc = new ADS7828Full(connection); // Create ADS7828 Full driver, (connection, vref=null → internal 2.5 V)
|
|
12
|
+
await adc.init(); // Enable internal reference, () → None
|
|
13
|
+
// sends command 0x08 and waits 1 ms for the reference to settle
|
|
14
|
+
|
|
15
|
+
console.log(await adc.readRaw(3)); // Read CH3 raw code, (channel 0–7) → int
|
|
16
|
+
// single-ended, interleaved channel encoding; returns 0–4095
|
|
17
|
+
console.log(await adc.readVoltage(3)); // Read CH3 voltage, (channel 0–7) → float V
|
|
18
|
+
// raw / 4096 × vref
|
|
19
|
+
console.log(await adc.readAll()); // Read all eight channels, () → float[8] V
|
|
20
|
+
// one conversion per channel, CH0…CH7
|
|
21
|
+
|
|
22
|
+
console.log(await adc.readDifferentialRaw(0)); // Read pair 0 raw code, (pair 0–3, inverted=false) → int
|
|
23
|
+
// CH0 (+) / CH1 (−); a negative difference reads 0
|
|
24
|
+
console.log(await adc.readDifferential(1, true)); // Read pair 1 inverted, (pair 0–3, inverted=false) → float V
|
|
25
|
+
// CH3 (+) / CH2 (−)
|
|
26
|
+
console.log(await adc.readSignedDifferential(0)); // Read pair 0 signed, (pair 0–3) → float V
|
|
27
|
+
// two conversions (normal and inverted), range −vref … +vref
|
|
28
|
+
|
|
29
|
+
console.log(adc.lsb()); // Get code step, () → float V
|
|
30
|
+
// vref / 4096 (610 µV at 2.5 V)
|
|
31
|
+
console.log(await adc.readScan([0, 2, 4, 6])); // Scan channels, (channels int[]) → int[]
|
|
32
|
+
// one raw conversion per channel in the given order
|
|
33
|
+
|
|
34
|
+
await adc.setReference(5.0); // Use external reference, (vref null|float V) → None
|
|
35
|
+
// PD1 = 0 from now on; the reference must already be stable
|
|
36
|
+
console.log(adc.getReference()); // Get reference voltage, () → float V
|
|
37
|
+
console.log(adc.usesInternalReference()); // Internal reference selected?, () → bool
|
|
38
|
+
await adc.setReference(null); // Use internal reference, (vref null|float V) → None
|
|
39
|
+
// re-runs the reference turn-on and 1 ms settle wait
|
|
40
|
+
|
|
41
|
+
adc.setPowerMode(ADS7828Full.REF_ON_ADC_ON); // Set PD bits, (pd 0–3) → None
|
|
42
|
+
// internal reference requires PD1 = 1 (values 2 or 3)
|
|
43
|
+
await adc.powerDown(); // Power down completely, () → None
|
|
44
|
+
// lone command with PD=00; next read re-enables the reference
|
|
45
|
+
await connection.close();
|
|
46
|
+
})();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { ADS7828Full } = require('periph/src/chips/adc_dac/ads7828');
|
|
5
|
+
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
const DIVIDER = 2.0; // inputs sit behind 2:1 dividers (rails up to 5 V)
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
11
|
+
const connection = new I2CConnection(bus, ADS7828Full.I2C_ADDRESS); // Create I2C connection, (bus, address)
|
|
12
|
+
const adc = new ADS7828Full(connection); // Create ADS7828 driver, (connection, vref=null → internal 2.5 V)
|
|
13
|
+
await adc.init(); // Enable internal reference, () → None
|
|
14
|
+
|
|
15
|
+
// --- Eight-channel supply monitor ---
|
|
16
|
+
// Scan CH0–CH7 once per second with the internal 2.5 V reference, print raw
|
|
17
|
+
// codes and rail voltages (after the divider ratio) and keep a running
|
|
18
|
+
// minimum/maximum per channel.
|
|
19
|
+
const vmin = new Array(8).fill(99);
|
|
20
|
+
const vmax = new Array(8).fill(0);
|
|
21
|
+
for (let n = 0; n < 5; n++) {
|
|
22
|
+
const raws = await adc.readScan([0, 1, 2, 3, 4, 5, 6, 7]); // Scan channels, (channels int[]) → int[]
|
|
23
|
+
const volts = raws.map((r) => r * adc.lsb() * DIVIDER);
|
|
24
|
+
volts.forEach((v, ch) => { vmin[ch] = Math.min(vmin[ch], v); vmax[ch] = Math.max(vmax[ch], v); });
|
|
25
|
+
console.log('scan', n, raws.map((r, i) => `${r}=${volts[i].toFixed(3)}V`).join(' '));
|
|
26
|
+
await sleep(1000);
|
|
27
|
+
}
|
|
28
|
+
console.log('min', vmin.map((v) => v.toFixed(3)).join(' '));
|
|
29
|
+
console.log('max', vmax.map((v) => v.toFixed(3)).join(' '));
|
|
30
|
+
|
|
31
|
+
// --- Read a bridge sensor on CH0/CH1 ---
|
|
32
|
+
// The signed differential read does two conversions (normal and inverted
|
|
33
|
+
// polarity) so the sign of the bridge output is preserved.
|
|
34
|
+
const mv = (await adc.readSignedDifferential(0)) * 1000; // Read pair 0 signed, (pair 0–3) → float V
|
|
35
|
+
console.log(`bridge ${mv.toFixed(2)} mV`);
|
|
36
|
+
|
|
37
|
+
// --- Second scan against an external 5.0 V reference ---
|
|
38
|
+
// Switching to a 5 V external reference gives full-scale range up to VDD.
|
|
39
|
+
await adc.setReference(5.0); // Use external reference, (vref null|float V) → None
|
|
40
|
+
console.log('ext 5 V scan', await adc.readScan([0, 1, 2, 3, 4, 5, 6, 7])); // Scan channels, (channels int[]) → int[]
|
|
41
|
+
|
|
42
|
+
// --- Finish in full power-down ---
|
|
43
|
+
await adc.powerDown(); // Power down completely, () → None
|
|
44
|
+
await connection.close();
|
|
45
|
+
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { ADS7828Minimal } = require('periph/src/chips/adc_dac/ads7828');
|
|
5
|
+
|
|
6
|
+
(async () => {
|
|
7
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
8
|
+
const connection = new I2CConnection(bus, ADS7828Minimal.I2C_ADDRESS); // Create I2C connection, (bus, address)
|
|
9
|
+
const adc = new ADS7828Minimal(connection); // Create ADS7828 driver, (connection, vref=null → internal 2.5 V)
|
|
10
|
+
await adc.init(); // Enable internal reference, () → None
|
|
11
|
+
|
|
12
|
+
const raw = await adc.readRaw(0); // Read CH0 raw code, (channel 0–7) → int
|
|
13
|
+
const volts = await adc.readVoltage(0); // Read CH0 voltage, (channel 0–7) → float V
|
|
14
|
+
const all = await adc.readAll(); // Read all eight channels, () → float[8] V
|
|
15
|
+
console.log(raw, volts, all);
|
|
16
|
+
await connection.close();
|
|
17
|
+
})();
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Complete example: exercises every method of CAT5171Full.
|
|
4
|
+
|
|
5
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
6
|
+
const { CAT5171Full } = require('periph/src/chips/adc_dac/cat5171');
|
|
7
|
+
|
|
8
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
12
|
+
const connection = new I2CConnection(bus, CAT5171Full.I2C_ADDRESS);
|
|
13
|
+
const pot = new CAT5171Full(connection); // Create CAT5171 Full driver, (connection, rAb=100000 Ω, rWiper=50 Ω)
|
|
14
|
+
await pot.init(); // Prepare driver, () → None
|
|
15
|
+
// no I²C traffic; the chip needs no initialisation
|
|
16
|
+
|
|
17
|
+
await pot.setWiper(100); // Set wiper position, (code 0–255) → None
|
|
18
|
+
// writes [instruction, code] with RS = 0, SD = 0
|
|
19
|
+
console.log(await pot.getWiper()); // Read wiper position, () → int 0–255
|
|
20
|
+
// bare one-byte read; no instruction byte is sent
|
|
21
|
+
await pot.setResistance(50000.0); // Set W–B resistance, (ohms Ω) → None
|
|
22
|
+
// inverts R = D/256·RAB + RW to the nearest code
|
|
23
|
+
console.log(await pot.getResistance()); // Read W–B resistance, () → float Ω
|
|
24
|
+
// evaluates D/256·RAB + RW for the current code
|
|
25
|
+
|
|
26
|
+
await pot.setRatio(0.25); // Set divider ratio, (ratio 0.0–1.0) → None
|
|
27
|
+
// code = round(ratio × 256), clamped to 255
|
|
28
|
+
console.log(await pot.getRatio()); // Read divider ratio, () → float
|
|
29
|
+
// code / 256
|
|
30
|
+
await pot.setResistanceWa(30000.0); // Set W–A resistance, (ohms Ω) → None
|
|
31
|
+
// rheostat between W and A with B open
|
|
32
|
+
console.log(await pot.getResistanceWa()); // Read W–A resistance, () → float Ω
|
|
33
|
+
// (256 − D)/256·RAB + RW
|
|
34
|
+
console.log(await pot.increment(5)); // Step the wiper, (steps=1) → int 0–255
|
|
35
|
+
// read, add, clamp, write; returns the new code
|
|
36
|
+
|
|
37
|
+
await pot.midscale(); // Move wiper to midscale, () → None
|
|
38
|
+
// RS = 1 instruction; wiper goes to 0x80
|
|
39
|
+
await pot.shutdown(); // Shut down, () → None
|
|
40
|
+
// SD = 1: A opens, wiper shorts to B, WCR kept
|
|
41
|
+
console.log(pot.isShutdown()); // Query shutdown state, () → bool
|
|
42
|
+
// driver-tracked; the chip cannot report it
|
|
43
|
+
await sleep(1000);
|
|
44
|
+
await pot.resume(); // Leave shutdown, () → None
|
|
45
|
+
// rewrites the kept code with SD = 0
|
|
46
|
+
|
|
47
|
+
pot.setRab(50000.0, 120.0); // Change resistance model, (rAb Ω, rWiper Ω) → None
|
|
48
|
+
// affects conversions only; no I²C traffic
|
|
49
|
+
await pot.reset(); // Midscale reset, () → None
|
|
50
|
+
// RS = 1, SD = 0; wiper returns to 0x80
|
|
51
|
+
await connection.close();
|
|
52
|
+
})();
|