periph 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -12
- package/examples/accelerometer/adxl345/complete.js +52 -0
- package/examples/accelerometer/adxl345/demo.js +34 -0
- package/examples/accelerometer/adxl345/minimal.js +18 -0
- package/examples/accelerometer/adxl362/complete.js +57 -0
- package/examples/accelerometer/adxl362/demo.js +51 -0
- package/examples/accelerometer/adxl362/minimal.js +21 -0
- package/examples/adc_dac/ad7705/complete.js +32 -0
- package/examples/adc_dac/ad7705/demo.js +42 -0
- package/examples/adc_dac/ad7705/minimal.js +16 -0
- package/examples/adc_dac/ad7706/complete.js +35 -0
- package/examples/adc_dac/ad7706/demo.js +44 -0
- package/examples/adc_dac/ad7706/minimal.js +16 -0
- package/examples/adc_dac/hx710a/complete.js +45 -0
- package/examples/adc_dac/hx710a/demo.js +52 -0
- package/examples/adc_dac/hx710a/minimal.js +16 -0
- package/examples/adc_dac/hx710b/complete.js +45 -0
- package/examples/adc_dac/hx710b/demo.js +64 -0
- package/examples/adc_dac/hx710b/minimal.js +16 -0
- package/examples/adc_dac/hx711/complete.js +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/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/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/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/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/src/chips/gnss/.gitkeep +0 -0
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { EEPROM24AA02UIDFull } = require('../../../src/chips/memory/_24aa02uid');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const eeprom = new EEPROM24AA02UIDFull(
|
|
6
|
+
const connection = new I2CConnection(1, 0x50);
|
|
7
|
+
const eeprom = new EEPROM24AA02UIDFull(connection); // Create 24AA02UID driver, (connection, addr=0x50) → void
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
|
|
9
|
+
(async () => {
|
|
10
|
+
// --- Read the chip's factory-programmed 32-bit serial number ---
|
|
11
|
+
// The UID at 0xFC-0xFF never changes and identifies the device
|
|
12
|
+
// across the entire 256-byte address space.
|
|
13
|
+
const uid = await eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
|
|
13
14
|
// reads 4 bytes at 0xFC-0xFF
|
|
14
|
-
console.log('Device UID: 0x' + uid.toString('hex').toUpperCase());
|
|
15
|
-
console.log('Device UID int:', uid.readUInt32BE(0));
|
|
15
|
+
console.log('Device UID: 0x' + uid.toString('hex').toUpperCase());
|
|
16
|
+
console.log('Device UID int:', uid.readUInt32BE(0));
|
|
16
17
|
|
|
17
|
-
// --- Maintain a 4-byte boot counter in user EEPROM at 0x00-0x03 ---
|
|
18
|
-
// Read the existing value (or zero on a fresh chip), increment,
|
|
19
|
-
// write back as 4 big-endian bytes. The user EEPROM is rewritable;
|
|
20
|
-
// the UID region above 0x80 is not, so the two stay independent.
|
|
21
|
-
const existing = eeprom.read(0x00, 4);
|
|
18
|
+
// --- Maintain a 4-byte boot counter in user EEPROM at 0x00-0x03 ---
|
|
19
|
+
// Read the existing value (or zero on a fresh chip), increment,
|
|
20
|
+
// write back as 4 big-endian bytes. The user EEPROM is rewritable;
|
|
21
|
+
// the UID region above 0x80 is not, so the two stay independent.
|
|
22
|
+
const existing = await eeprom.read(0x00, 4); // Sequential read, (address, length) → Buffer
|
|
22
23
|
// reads 4 bytes from user EEPROM
|
|
23
|
-
let counter = existing.readUInt32BE(0);
|
|
24
|
-
counter += 1;
|
|
25
|
-
const updated = Buffer.alloc(4);
|
|
26
|
-
updated.writeUInt32BE(counter, 0);
|
|
27
|
-
eeprom.write(0x00, updated);
|
|
24
|
+
let counter = existing.readUInt32BE(0);
|
|
25
|
+
counter += 1;
|
|
26
|
+
const updated = Buffer.alloc(4);
|
|
27
|
+
updated.writeUInt32BE(counter, 0);
|
|
28
|
+
await eeprom.write(0x00, updated); // Arbitrary-length write, (address, data) → void
|
|
28
29
|
// writes 4 bytes; ACK-polls when done
|
|
29
|
-
console.log('Boot count:', counter);
|
|
30
|
+
console.log('Boot count:', counter);
|
|
30
31
|
|
|
31
|
-
let n = 0;
|
|
32
|
-
setInterval(() => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}, 2000);
|
|
32
|
+
let n = 0;
|
|
33
|
+
setInterval(async () => {
|
|
34
|
+
// --- Loop reading the UID only, showing it never changes ---
|
|
35
|
+
// The two distinct areas of the chip (immutable identification
|
|
36
|
+
// above 0x80, rewritable storage below 0x80) are exercised
|
|
37
|
+
// independently.
|
|
38
|
+
const uid = await eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
|
|
39
|
+
console.log('[' + n + '] UID: 0x' + uid.toString('hex').toUpperCase() + ' (counter at user EEPROM 0x00-0x03)');
|
|
40
|
+
n++;
|
|
41
|
+
}, 2000);
|
|
42
|
+
})();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { EEPROM24AA02UIDMinimal } = require('../../../src/chips/memory/_24aa02uid');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const eeprom = new EEPROM24AA02UIDMinimal(
|
|
6
|
+
const connection = new I2CConnection(1, 0x50);
|
|
7
|
+
const eeprom = new EEPROM24AA02UIDMinimal(connection); // Create 24AA02UID driver, (connection, addr=0x50) → void
|
|
8
8
|
|
|
9
|
-
setInterval(() => {
|
|
10
|
-
const uid = eeprom.readUid();
|
|
9
|
+
setInterval(async () => {
|
|
10
|
+
const uid = await eeprom.readUid(); // Read 32-bit unique serial number, () → Buffer
|
|
11
11
|
console.log('UID:', uid.toString('hex').toUpperCase());
|
|
12
12
|
}, 2000);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Complete example for the MPR121 — exercises every Full-class method.
|
|
2
|
+
|
|
3
|
+
const { MPR121Full } = require('periph/src/chips/other/mpr121');
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c_auto');
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
const connection = new I2CConnection(0x5A); // Create I2C connection, (addr=0x5A, bus=undefined) → I2CConnection
|
|
8
|
+
const mpr = new MPR121Full(connection); // Construct MPR121 Full, (connection) → MPR121Full
|
|
9
|
+
// runs Minimal init then exposes Full configuration methods
|
|
10
|
+
|
|
11
|
+
await mpr.stop(); // Enter Stop Mode, () → Promise<void>
|
|
12
|
+
// required before writing most config registers
|
|
13
|
+
await mpr.configureThresholds(0, 15, 8); // Set thresholds, (electrode=0, touch=15, release=8) → Promise<void>
|
|
14
|
+
// ELE0: touch at 15 LSBs below baseline, release at 8 LSBs
|
|
15
|
+
await mpr.configureAllThresholds(12, 6); // Apply thresholds to all, (touch=12, release=6) → Promise<void>
|
|
16
|
+
// ELE1..ELE11: same touch/release values
|
|
17
|
+
await mpr.configureProximityThresholds(8, 4); // Set ELEPROX thresholds, (touch=8, release=4) → Promise<void>
|
|
18
|
+
// ELEPROX touch at 8 LSBs, release at 4
|
|
19
|
+
await mpr.configureBaselineFilter(1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0); // Set baseline filter, (mhdr, nhdr, nclr, fdlr, mhdf, nhdf, nclf, fdlf, nhdt, nclt, fdlt) → Promise<void>
|
|
20
|
+
// baseline filter defaults; tracks capacitance drift only
|
|
21
|
+
await mpr.configureSampling(16, 1, 0, 0, 4); // Set AFE config, (cdc=16, cdt=1, ffi=0, sfi=0, esi=4) → Promise<void>
|
|
22
|
+
// 16 µA global CDC, 0.5 µs charge time, 16 ms sample interval
|
|
23
|
+
await mpr.configureDebounce(1, 1); // Set debounce, (touch=1, release=1) → Promise<void>
|
|
24
|
+
// one consecutive measurement to detect touch/release
|
|
25
|
+
await mpr.configureAutoconfig(3300, 0, false, true, true); // Configure autoconfig, (vdd_mv=3300, retry=0, scts=false, are=true, ace=true) → Promise<void>
|
|
26
|
+
// recompute USL/TL/LSL for 3.3 V supply
|
|
27
|
+
await mpr.start(12, 2, 0); // Enter Run Mode, (n_electrodes=12, cl=2, eleprox_en=0) → Promise<void>
|
|
28
|
+
// all 12 electrodes, baseline init from first measurement, proximity off
|
|
29
|
+
|
|
30
|
+
const f0 = await mpr.filtered(0); // Read ELE0 filtered, (electrode=0) → Promise<number> 0..1023
|
|
31
|
+
// raw 10-bit value, inversely proportional to capacitance
|
|
32
|
+
const b0 = await mpr.baseline(0); // Read ELE0 baseline, (electrode=0) → Promise<number> 0..1023
|
|
33
|
+
// 8 MSBs from baseline register, shifted left 2
|
|
34
|
+
const oor = await mpr.oorStatus(); // Read OOR bitmask, () → Promise<number> bitmask
|
|
35
|
+
// bits 0..11 = ELE0..11 out-of-range
|
|
36
|
+
const pt = await mpr.proximityTouched(); // Read proximity touched, () → Promise<boolean>
|
|
37
|
+
// False: ELEPROX not enabled in this example
|
|
38
|
+
console.log(`ELE0 filtered=${f0} baseline=${b0} OOR=0x${oor.toString(16).padStart(4, '0')} prox_touched=${pt}`);
|
|
39
|
+
|
|
40
|
+
await mpr.enableInterrupt(MPR121Full.SOURCE_OOR); // Enable interrupt source, (source=SOURCE_OOR) → Promise<void>
|
|
41
|
+
// OOR will now assert INT as well as touch/release
|
|
42
|
+
await mpr.disableInterrupt(MPR121Full.SOURCE_OOR); // Disable interrupt source, (source=SOURCE_OOR) → Promise<void>
|
|
43
|
+
// OOR no longer asserts INT
|
|
44
|
+
await mpr.clearOvercurrent(); // Clear OVCF, () → Promise<void>
|
|
45
|
+
// safe no-op when overcurrent has not occurred
|
|
46
|
+
await mpr.reset(); // Soft reset, () → Promise<void>
|
|
47
|
+
// reapplies Minimal defaults; device ready for fresh use
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Demo for the MPR121 — 12-button musical keyboard with IRQ-driven detection.
|
|
2
|
+
|
|
3
|
+
const { MPR121Full } = require('periph/src/chips/other/mpr121');
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c_auto');
|
|
5
|
+
|
|
6
|
+
const NOTES = ['C4', 'C#4', 'D4', 'D#4', 'E4', 'F4', 'F#4', 'G4', 'G#4', 'A4', 'A#4', 'B4'];
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const connection = new I2CConnection(0x5A); // Create I2C connection, (addr=0x5A, bus=undefined) → I2CConnection
|
|
10
|
+
const mpr = new MPR121Full(connection); // Construct MPR121 Full, (connection) → MPR121Full
|
|
11
|
+
// defaults, all 12 electrodes enabled
|
|
12
|
+
|
|
13
|
+
let previous = 0;
|
|
14
|
+
setInterval(async () => {
|
|
15
|
+
const mask = await mpr.touched(); // Read 12-bit touch bitmask, () → Promise<number> bitmask
|
|
16
|
+
const newlyPressed = mask & ~previous;
|
|
17
|
+
const newlyReleased = (~mask) & previous;
|
|
18
|
+
for (let n = 0; n < 12; n++) {
|
|
19
|
+
if (newlyPressed & (1 << n)) {
|
|
20
|
+
console.log(`NOTE ON: ${NOTES[n]}`);
|
|
21
|
+
}
|
|
22
|
+
if (newlyReleased & (1 << n)) {
|
|
23
|
+
console.log(`NOTE OFF: ${NOTES[n]}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
previous = mask;
|
|
27
|
+
}, 50);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Minimal example for the MPR121 capacitive touch controller.
|
|
2
|
+
|
|
3
|
+
const { MPR121Minimal } = require('periph/src/chips/other/mpr121');
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c_auto');
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
const connection = new I2CConnection(0x5A); // Create I2C connection, (addr=0x5A, bus=undefined) → I2CConnection
|
|
8
|
+
const mpr = new MPR121Minimal(connection); // Construct MPR121 Minimal, (connection) → MPR121Minimal
|
|
9
|
+
// resets, applies default thresholds (T=12, R=6), enters Run Mode on all 12 electrodes
|
|
10
|
+
setInterval(async () => {
|
|
11
|
+
const t = await mpr.touched(); // Read 12-bit touch bitmask, () → Promise<number> bitmask
|
|
12
|
+
// bit n=1 means ELEn is currently touched
|
|
13
|
+
console.log(`touched=0x${t.toString(16).padStart(3, '0')}`);
|
|
14
|
+
}, 1000);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
main().catch(err => { console.error(err); process.exit(1); });
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { ADE7953Full } = require('../../../src/chips/power/ade7953');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const ade = new ADE7953Full(connection, 251.0, 30.0); // Create ADE7953 driver, (connection, voltage_gain=V/V, current_gain=A/V, bus_type='i2c')
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
console.log('version:', (await ade.version()).toString(16)); // Read silicon version, () → int
|
|
11
|
+
console.log('V=', await ade.voltage()); // Read bus voltage, () → float V
|
|
12
|
+
// converts raw VRMS to volts using voltage_gain
|
|
13
|
+
console.log('I_a=', await ade.current()); // Read load current, () → float A
|
|
14
|
+
// converts raw IRMSA to amperes using current_gain
|
|
15
|
+
console.log('P_a=', await ade.activePower()); // Read active power, () → float W
|
|
16
|
+
// converts raw AWATT (instantaneous, 6.99 kHz) to watts
|
|
17
|
+
console.log('E_a=', await ade.activeEnergy()); // Read active energy, () → float Wh
|
|
18
|
+
// converts raw AENERGYA accumulated LSBs to watt-hours
|
|
19
|
+
console.log('PF=', await ade.powerFactor()); // Read power factor, () → float
|
|
20
|
+
// converts raw PFA (1 LSB = 2^-15) to a −1.0..+1.0 ratio
|
|
21
|
+
console.log('f=', await ade.lineFrequency()); // Read line frequency, () → float Hz
|
|
22
|
+
|
|
23
|
+
await ade.configureChannelB(30.0); // Set Channel B calibration, (current_gain_b) → None
|
|
24
|
+
console.log('I_b=', await ade.currentB()); // Read Current Channel B, () → float A
|
|
25
|
+
|
|
26
|
+
await ade.setPga('a', 1); // Write PGA Channel A, (channel, gain) → None
|
|
27
|
+
// gain 1..16 (+22 valid for Channel A only)
|
|
28
|
+
await ade.setPhaseCalibration('a', 0.0); // Write phase calibration A, (channel, delay_s) → None
|
|
29
|
+
// negative delay_s advances; range ±383 × 1.117 µs
|
|
30
|
+
await ade.setGainCalibration(0x282, 0x400000); // Write active-power gain A, (register, value) → None
|
|
31
|
+
// 0x400000 = unity; valid range 0x200000..0x600000
|
|
32
|
+
await ade.setOffsetCalibration(0x289, 0); // Write active-power offset A, (register, value) → None
|
|
33
|
+
// signed 24-bit offset
|
|
34
|
+
console.log('checksum:', (await ade.checksum()).toString(16)); // Read CRC/checksum, () → int
|
|
35
|
+
await ade.enableChecksum(true); // Enable CRC/checksum, (enabled) → None
|
|
36
|
+
|
|
37
|
+
await ade.configureOvervoltage(260.0); // Configure overvoltage, (threshold) → None
|
|
38
|
+
// threshold in volts (same scale as voltage())
|
|
39
|
+
await ade.configureOvercurrent(40.0); // Configure overcurrent, (threshold) → None
|
|
40
|
+
// threshold in amperes; applies to BOTH current channels
|
|
41
|
+
|
|
42
|
+
await ade.reset(); // Software reset, () → None
|
|
43
|
+
// waits 110 ms then re-runs the mandatory power-up sequence
|
|
44
|
+
})();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { ADE7953Full } = require('../../../src/chips/power/ade7953');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const ade = new ADE7953Full(connection, 251.0, 30.0); // Create ADE7953 driver, (connection, voltage_gain=V/V, current_gain=A/V, bus_type='i2c')
|
|
8
|
+
|
|
9
|
+
// --- Prepare the chip: enable overcurrent interrupt and pin it to IRQ ---
|
|
10
|
+
// The ADE7953 exposes power-quality events via the IRQ pin. Driving
|
|
11
|
+
// OIA through the chip's own alert output lets the host react without
|
|
12
|
+
// polling every reading every cycle.
|
|
13
|
+
ade.configureOvercurrent(40.0); // Configure overcurrent, (threshold) → None
|
|
14
|
+
|
|
15
|
+
// --- Sample at 1 Hz and emit one structured line per cycle ---
|
|
16
|
+
// The energy accumulator resets on read by default (RSTREAD = 1), so
|
|
17
|
+
// activeEnergy() returns watt-hours accumulated since the previous
|
|
18
|
+
// call. Callers wanting a running total accumulate the returned deltas
|
|
19
|
+
// themselves (or call setReadWithReset(false) and track the 24-bit
|
|
20
|
+
// register's own rollovers instead).
|
|
21
|
+
console.log('%-10s %-10s %-10s %-12s'.replace(/%-?\d+s/g, (m) => m.padEnd(12)));
|
|
22
|
+
setInterval(async () => {
|
|
23
|
+
const v = await ade.voltage(); // Read bus voltage, () → float V
|
|
24
|
+
const i = await ade.current(); // Read load current, () → float A
|
|
25
|
+
const p = await ade.activePower(); // Read active power, () → float W
|
|
26
|
+
const e = await ade.activeEnergy(); // Read active energy, () → float Wh
|
|
27
|
+
console.log(`${v.toFixed(2).padEnd(10)} ${i.toFixed(3).padEnd(10)} ${p.toFixed(2).padEnd(10)} ${e.toFixed(5).padEnd(12)}`);
|
|
28
|
+
}, 1000);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
|
+
const { ADE7953Minimal } = require('../../../src/chips/power/ade7953');
|
|
5
|
+
|
|
6
|
+
const connection = new I2CConnection(1, 0x38);
|
|
7
|
+
const ade = new ADE7953Minimal(connection, 251.0, 30.0); // Create ADE7953 driver, (connection, voltage_gain=V/V, current_gain=A/V, bus_type='i2c')
|
|
8
|
+
|
|
9
|
+
setInterval(async () => {
|
|
10
|
+
const v = await ade.voltage(); // Read bus voltage, () → float V
|
|
11
|
+
const i = await ade.current(); // Read load current, () → float A
|
|
12
|
+
const p = await ade.activePower(); // Read active power, () → float W
|
|
13
|
+
const e = await ade.activeEnergy(); // Read active energy, () → float Wh
|
|
14
|
+
console.log(`V=${v.toFixed(2)} I=${i.toFixed(3)} P=${p.toFixed(2)} E=${e.toFixed(4)}`);
|
|
15
|
+
}, 1000);
|
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { INA219Full } = require('../../../src/chips/power/ina219');
|
|
5
5
|
|
|
6
6
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
7
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const ina = new INA219Full(
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
10
|
+
const ina = new INA219Full(connection);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
console.log(ina.
|
|
14
|
-
console.log(ina.
|
|
15
|
-
console.log(ina.
|
|
16
|
-
console.log(ina.
|
|
17
|
-
console.log(ina.
|
|
12
|
+
(async () => {
|
|
13
|
+
console.log(await ina.voltage()); // Read bus voltage, () → float V
|
|
14
|
+
console.log(await ina.shuntVoltage()); // Read shunt voltage, () → float V
|
|
15
|
+
console.log(await ina.current()); // Read load current, () → float A
|
|
16
|
+
console.log(await ina.power()); // Read power, () → float W
|
|
17
|
+
console.log(await ina.conversionReady()); // Check conversion done, () → bool
|
|
18
|
+
console.log(await ina.overflow()); // Check math overflow, () → bool
|
|
18
19
|
|
|
19
|
-
ina.configure(1, 3, 0x03, 0x03, 7);
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
await ina.configure(1, 3, 0x03, 0x03, 7);
|
|
21
|
+
// Configure ADC, (brng 0–1, pga 0–3, badc 0x0F, sadc 0x0F, mode 0–7) → None
|
|
22
|
+
// sets bus range, PGA gain, ADC resolution, and operating mode
|
|
22
23
|
|
|
23
|
-
ina.shutdown(); // Put chip into power-down mode, () → None
|
|
24
|
-
const end = Date.now() + 1;
|
|
25
|
-
while (Date.now() < end) {}
|
|
26
|
-
ina.wake(); // Restore previous operating mode, () → None
|
|
24
|
+
await ina.shutdown(); // Put chip into power-down mode, () → None
|
|
25
|
+
const end = Date.now() + 1;
|
|
26
|
+
while (Date.now() < end) {}
|
|
27
|
+
await ina.wake(); // Restore previous operating mode, () → None
|
|
27
28
|
|
|
28
|
-
ina.reset(); // Reset all registers and re-write calibration, () → None
|
|
29
|
+
await ina.reset(); // Reset all registers and re-write calibration, () → None
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
await connection.close();
|
|
32
|
+
})();
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { INA219Full } = require('../../../src/chips/power/ina219');
|
|
5
5
|
|
|
6
6
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
7
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const ina = new INA219Full(
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
10
|
+
const ina = new INA219Full(connection);
|
|
11
11
|
|
|
12
12
|
// --- Configure for noise-sensitive power rail monitoring ---
|
|
13
13
|
// 128-sample averaging suppresses switching noise on a noisy 5 V rail;
|
|
14
14
|
// continuous mode avoids re-triggering overhead between measurements.
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
(async () => {
|
|
16
|
+
await ina.configure(1, 3, 0x0F, 0x0F, 7);
|
|
17
|
+
// Configure ADC, (brng 0–1, pga 0–3, badc 0x0F, sadc 0x0F, mode 0–7) → None
|
|
17
18
|
|
|
18
|
-
console.log('V A W');
|
|
19
|
+
console.log('V A W');
|
|
19
20
|
|
|
20
|
-
setInterval(() => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}, 1000);
|
|
21
|
+
setInterval(async () => {
|
|
22
|
+
while (!(await ina.conversionReady())) {} // Check conversion done, () → bool
|
|
23
|
+
const v = await ina.voltage(); // Read bus voltage, () → float V
|
|
24
|
+
const i = await ina.current(); // Read load current, () → float A
|
|
25
|
+
const p = await ina.power(); // Read power, () → float W
|
|
26
|
+
console.log(`${v.toFixed(3)} V ${i.toFixed(4)} A ${p.toFixed(4)} W`);
|
|
27
|
+
}, 1000);
|
|
28
|
+
})();
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { INA219Minimal } = require('../../../src/chips/power/ina219');
|
|
5
5
|
|
|
6
6
|
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
7
7
|
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x40', 16);
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const ina = new INA219Minimal(
|
|
9
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
10
|
+
const ina = new INA219Minimal(connection);
|
|
11
11
|
|
|
12
|
-
setInterval(() => {
|
|
13
|
-
const v = ina.voltage(); // Read bus voltage, () → float V
|
|
14
|
-
const i = ina.current(); // Read load current, () → float A
|
|
15
|
-
const p = ina.power(); // Read power, () → float W
|
|
12
|
+
setInterval(async () => {
|
|
13
|
+
const v = await ina.voltage(); // Read bus voltage, () → float V
|
|
14
|
+
const i = await ina.current(); // Read load current, () → float A
|
|
15
|
+
const p = await ina.power(); // Read power, () → float W
|
|
16
16
|
console.log(`${v.toFixed(3)} V ${i.toFixed(4)} A ${p.toFixed(4)} W`);
|
|
17
|
-
}, 1000);
|
|
17
|
+
}, 1000);
|
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { INA226Full } = require('../../../src/chips/power/ina226');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const ina = new INA226Full(
|
|
6
|
+
const connection = new I2CConnection(1, 0x40);
|
|
7
|
+
const ina = new INA226Full(connection);
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
console.log('0x' + ina.
|
|
9
|
+
(async () => {
|
|
10
|
+
console.log('0x' + (await ina.manufacturerId()).toString(16));
|
|
11
|
+
console.log('0x' + (await ina.dieId()).toString(16));
|
|
11
12
|
|
|
12
|
-
console.log(ina.voltage());
|
|
13
|
-
console.log(ina.shuntVoltage());
|
|
14
|
-
console.log(ina.current());
|
|
15
|
-
console.log(ina.power());
|
|
16
|
-
console.log(ina.conversionReady());
|
|
17
|
-
console.log(ina.overflow());
|
|
13
|
+
console.log(await ina.voltage());
|
|
14
|
+
console.log(await ina.shuntVoltage());
|
|
15
|
+
console.log(await ina.current());
|
|
16
|
+
console.log(await ina.power());
|
|
17
|
+
console.log(await ina.conversionReady());
|
|
18
|
+
console.log(await ina.overflow());
|
|
18
19
|
|
|
19
|
-
ina.configure(3, 4, 4, 7);
|
|
20
|
+
await ina.configure(3, 4, 4, 7);
|
|
20
21
|
|
|
21
|
-
ina.setAlert(INA226Full.POL, 1.0, false, true);
|
|
22
|
-
console.log('0x' + ina.alertFlags().toString(16));
|
|
22
|
+
await ina.setAlert(INA226Full.POL, 1.0, false, true);
|
|
23
|
+
console.log('0x' + (await ina.alertFlags()).toString(16));
|
|
23
24
|
|
|
24
|
-
ina.setAlert(INA226Full.BOL, 5.5);
|
|
25
|
-
ina.setAlert(INA226Full.BUL, 4.5);
|
|
26
|
-
ina.setAlert(INA226Full.SOL, 0.05);
|
|
27
|
-
ina.setAlert(INA226Full.CNVR);
|
|
25
|
+
await ina.setAlert(INA226Full.BOL, 5.5);
|
|
26
|
+
await ina.setAlert(INA226Full.BUL, 4.5);
|
|
27
|
+
await ina.setAlert(INA226Full.SOL, 0.05);
|
|
28
|
+
await ina.setAlert(INA226Full.CNVR);
|
|
28
29
|
|
|
29
|
-
ina.shutdown();
|
|
30
|
-
ina.wake();
|
|
31
|
-
ina.reset();
|
|
30
|
+
await ina.shutdown();
|
|
31
|
+
await ina.wake();
|
|
32
|
+
await ina.reset();
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
await connection.close();
|
|
35
|
+
})();
|
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { INA226Full } = require('../../../src/chips/power/ina226');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const ina = new INA226Full(
|
|
6
|
+
const connection = new I2CConnection(1, 0x40);
|
|
7
|
+
const ina = new INA226Full(connection);
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
(async () => {
|
|
10
|
+
// 64-sample averaging smooths out switching noise from DC/DC converters
|
|
11
|
+
await ina.configure(3, 4, 4, 7);
|
|
11
12
|
|
|
12
|
-
// latch the alert so a brief spike is not missed between loop iterations
|
|
13
|
-
ina.setAlert(INA226Full.POL, 1.0, false, true);
|
|
13
|
+
// latch the alert so a brief spike is not missed between loop iterations
|
|
14
|
+
await ina.setAlert(INA226Full.POL, 1.0, false, true);
|
|
14
15
|
|
|
15
|
-
console.log('V A W');
|
|
16
|
+
console.log('V A W');
|
|
16
17
|
|
|
17
|
-
setInterval(() => {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
setInterval(async () => {
|
|
19
|
+
// wait for a fresh conversion to avoid reading stale register values
|
|
20
|
+
while (!(await ina.conversionReady())) {}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const v = await ina.voltage();
|
|
23
|
+
const i = await ina.current();
|
|
24
|
+
const p = await ina.power();
|
|
25
|
+
console.log(v.toFixed(3) + 'V ' + i.toFixed(4) + 'A ' + p.toFixed(4) + 'W');
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}, 1000);
|
|
27
|
+
// reading alertFlags clears the latch — do this after printing measurements
|
|
28
|
+
if ((await ina.alertFlags()) & INA226Full.AFF) {
|
|
29
|
+
console.log('ALERT: power limit exceeded');
|
|
30
|
+
}
|
|
31
|
+
}, 1000);
|
|
32
|
+
})();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { I2CConnection } = require('../../../src/connection/i2c');
|
|
4
4
|
const { INA226Minimal } = require('../../../src/chips/power/ina226');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const ina = new INA226Minimal(
|
|
6
|
+
const connection = new I2CConnection(1, 0x40);
|
|
7
|
+
const ina = new INA226Minimal(connection);
|
|
8
8
|
|
|
9
|
-
setInterval(() => {
|
|
10
|
-
console.log(ina.voltage(), ina.current(), ina.power());
|
|
9
|
+
setInterval(async () => {
|
|
10
|
+
console.log(await ina.voltage(), await ina.current(), await ina.power());
|
|
11
11
|
}, 1000);
|