periph 1.3.3 → 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.
Files changed (150) hide show
  1. package/README.md +36 -0
  2. package/examples/adc_dac/ad5251/complete.js +66 -0
  3. package/examples/adc_dac/ad5251/demo.js +69 -0
  4. package/examples/adc_dac/ad5251/minimal.js +23 -0
  5. package/examples/adc_dac/ad5252/complete.js +66 -0
  6. package/examples/adc_dac/ad5252/demo.js +69 -0
  7. package/examples/adc_dac/ad5252/minimal.js +23 -0
  8. package/examples/adc_dac/ads7828/complete.js +46 -0
  9. package/examples/adc_dac/ads7828/demo.js +45 -0
  10. package/examples/adc_dac/ads7828/minimal.js +17 -0
  11. package/examples/adc_dac/cat5171/complete.js +52 -0
  12. package/examples/adc_dac/cat5171/demo.js +59 -0
  13. package/examples/adc_dac/cat5171/minimal.js +23 -0
  14. package/examples/adc_dac/cs43l22/complete.js +88 -0
  15. package/examples/adc_dac/cs43l22/demo.js +56 -0
  16. package/examples/adc_dac/cs43l22/minimal.js +20 -0
  17. package/examples/adc_dac/ds1881/complete.js +62 -0
  18. package/examples/adc_dac/ds1881/demo.js +61 -0
  19. package/examples/adc_dac/ds1881/minimal.js +25 -0
  20. package/examples/adc_dac/ds3502/complete.js +46 -0
  21. package/examples/adc_dac/ds3502/demo.js +54 -0
  22. package/examples/adc_dac/ds3502/minimal.js +28 -0
  23. package/examples/adc_dac/es8311/complete.js +80 -0
  24. package/examples/adc_dac/es8311/demo.js +59 -0
  25. package/examples/adc_dac/es8311/minimal.js +18 -0
  26. package/examples/adc_dac/mcp3422/complete.js +48 -0
  27. package/examples/adc_dac/mcp3422/demo.js +49 -0
  28. package/examples/adc_dac/mcp3422/minimal.js +25 -0
  29. package/examples/adc_dac/mcp4xxx/complete.js +97 -0
  30. package/examples/adc_dac/mcp4xxx/demo.js +76 -0
  31. package/examples/adc_dac/mcp4xxx/minimal.js +22 -0
  32. package/examples/display/sh1106/complete.js +101 -0
  33. package/examples/display/sh1106/demo.js +68 -0
  34. package/examples/display/sh1106/minimal.js +25 -0
  35. package/examples/display/ssd1305/complete.js +129 -0
  36. package/examples/display/ssd1305/demo.js +71 -0
  37. package/examples/display/ssd1305/minimal.js +25 -0
  38. package/examples/display/ssd1306/complete.js +115 -0
  39. package/examples/display/ssd1306/demo.js +70 -0
  40. package/examples/display/ssd1306/minimal.js +25 -0
  41. package/examples/environmental/am2315/complete.js +34 -0
  42. package/examples/environmental/am2315/demo.js +46 -0
  43. package/examples/environmental/am2315/minimal.js +21 -0
  44. package/examples/humidity/htu21df/complete.js +49 -0
  45. package/examples/humidity/htu21df/demo.js +50 -0
  46. package/examples/humidity/htu21df/minimal.js +22 -0
  47. package/examples/humidity/sht31/complete.js +53 -0
  48. package/examples/humidity/sht31/demo.js +53 -0
  49. package/examples/humidity/sht31/minimal.js +21 -0
  50. package/examples/humidity/si7021/complete.js +55 -0
  51. package/examples/humidity/si7021/demo.js +58 -0
  52. package/examples/humidity/si7021/minimal.js +21 -0
  53. package/examples/imu/bno055/complete.js +85 -0
  54. package/examples/imu/bno055/demo.js +70 -0
  55. package/examples/imu/bno055/minimal.js +20 -0
  56. package/examples/imu/qmi8658a/complete.js +134 -0
  57. package/examples/imu/qmi8658a/demo.js +81 -0
  58. package/examples/imu/qmi8658a/minimal.js +22 -0
  59. package/examples/io_expander/pca6408a/complete.js +63 -0
  60. package/examples/io_expander/pca6408a/demo.js +58 -0
  61. package/examples/io_expander/pca6408a/minimal.js +20 -0
  62. package/examples/io_expander/pca6416a/complete.js +68 -0
  63. package/examples/io_expander/pca6416a/demo.js +60 -0
  64. package/examples/io_expander/pca6416a/minimal.js +20 -0
  65. package/examples/io_expander/pca9536/complete.js +63 -0
  66. package/examples/io_expander/pca9536/demo.js +57 -0
  67. package/examples/io_expander/pca9536/minimal.js +20 -0
  68. package/examples/io_expander/pca9539/complete.js +68 -0
  69. package/examples/io_expander/pca9539/demo.js +60 -0
  70. package/examples/io_expander/pca9539/minimal.js +20 -0
  71. package/examples/light/max44009/complete.js +56 -0
  72. package/examples/light/max44009/demo.js +49 -0
  73. package/examples/light/max44009/minimal.js +22 -0
  74. package/examples/memory/at24c02n/complete.js +39 -0
  75. package/examples/memory/at24c02n/demo.js +39 -0
  76. package/examples/memory/at24c02n/minimal.js +15 -0
  77. package/examples/memory/at24c64/complete.js +39 -0
  78. package/examples/memory/at24c64/demo.js +39 -0
  79. package/examples/memory/at24c64/minimal.js +15 -0
  80. package/examples/memory/cat24c512/complete.js +39 -0
  81. package/examples/memory/cat24c512/demo.js +39 -0
  82. package/examples/memory/cat24c512/minimal.js +15 -0
  83. package/examples/motor/tmc2130/complete.js +138 -0
  84. package/examples/motor/tmc2130/demo.js +96 -0
  85. package/examples/motor/tmc2130/minimal.js +30 -0
  86. package/examples/motor/tmc2208/complete.js +92 -0
  87. package/examples/motor/tmc2208/demo.js +85 -0
  88. package/examples/motor/tmc2208/minimal.js +25 -0
  89. package/examples/motor/tmc2209/complete.js +106 -0
  90. package/examples/motor/tmc2209/demo.js +97 -0
  91. package/examples/motor/tmc2209/minimal.js +25 -0
  92. package/examples/motor/tmc5160/complete.js +205 -0
  93. package/examples/motor/tmc5160/demo.js +104 -0
  94. package/examples/motor/tmc5160/minimal.js +35 -0
  95. package/examples/other/pca9541/complete.js +52 -0
  96. package/examples/other/pca9541/demo.js +61 -0
  97. package/examples/other/pca9541/minimal.js +23 -0
  98. package/examples/power/axp2101/complete.js +135 -0
  99. package/examples/power/axp2101/demo.js +68 -0
  100. package/examples/power/axp2101/minimal.js +24 -0
  101. package/examples/rtc/pcf85063a/complete.js +68 -0
  102. package/examples/rtc/pcf85063a/demo.js +76 -0
  103. package/examples/rtc/pcf85063a/minimal.js +20 -0
  104. package/examples/temperature/tmp102/complete.js +74 -0
  105. package/examples/temperature/tmp102/demo.js +71 -0
  106. package/examples/temperature/tmp102/minimal.js +20 -0
  107. package/examples/tof/vl6180x/complete.js +62 -0
  108. package/examples/tof/vl6180x/demo.js +77 -0
  109. package/examples/tof/vl6180x/minimal.js +23 -0
  110. package/package.json +1 -1
  111. package/src/chips/adc_dac/ad5251.js +345 -0
  112. package/src/chips/adc_dac/ad5252.js +345 -0
  113. package/src/chips/adc_dac/ads7828.js +225 -0
  114. package/src/chips/adc_dac/cat5171.js +213 -0
  115. package/src/chips/adc_dac/cs43l22.js +645 -0
  116. package/src/chips/adc_dac/ds1881.js +357 -0
  117. package/src/chips/adc_dac/ds3502.js +241 -0
  118. package/src/chips/adc_dac/es8311.js +621 -0
  119. package/src/chips/adc_dac/mcp3422.js +312 -0
  120. package/src/chips/adc_dac/mcp4xxx.js +982 -0
  121. package/src/chips/display/mono_oled.js +182 -0
  122. package/src/chips/display/sh1106.js +496 -0
  123. package/src/chips/display/ssd1305.js +655 -0
  124. package/src/chips/display/ssd1306.js +458 -0
  125. package/src/chips/environmental/am2315.js +237 -0
  126. package/src/chips/humidity/htu21df.js +222 -0
  127. package/src/chips/humidity/sht31.js +284 -0
  128. package/src/chips/humidity/si7021.js +282 -0
  129. package/src/chips/imu/bno055.js +496 -0
  130. package/src/chips/imu/qmi8658a.js +1011 -0
  131. package/src/chips/io_expander/pca6408a.js +407 -0
  132. package/src/chips/io_expander/pca6416a.js +455 -0
  133. package/src/chips/io_expander/pca9536.js +398 -0
  134. package/src/chips/io_expander/pca9539.js +457 -0
  135. package/src/chips/light/max44009.js +336 -0
  136. package/src/chips/memory/at24c02n.js +220 -0
  137. package/src/chips/memory/at24c64.js +220 -0
  138. package/src/chips/memory/cat24c512.js +221 -0
  139. package/src/chips/motor/tmc2130.js +537 -0
  140. package/src/chips/motor/tmc2208.js +490 -0
  141. package/src/chips/motor/tmc2209.js +565 -0
  142. package/src/chips/motor/tmc5160.js +900 -0
  143. package/src/chips/other/pca9541.js +315 -0
  144. package/src/chips/power/axp2101.js +968 -0
  145. package/src/chips/rtc/pcf85063a.js +482 -0
  146. package/src/chips/temperature/tmp102.js +361 -0
  147. package/src/chips/tof/vl6180x.js +580 -0
  148. package/src/connection/uart.js +9 -0
  149. package/src/connection/uart_mock.js +65 -0
  150. package/src/discovery/registry.js +85 -8
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ES8311Full } = require('../../../src/chips/adc_dac/es8311');
5
+
6
+ async function main() {
7
+ const connection = new I2CConnection(1, 0x18); // Create I2C connection, (bus=1, addr=0x18)
8
+ const codec = new ES8311Full(connection, 12288000, 48000); // Create ES8311 driver and run the init sequence, (connection, mclkHz=12288000 Hz, sampleRateHz=48000 Hz)
9
+ // reset, clock dividers, I2S 16-bit slave, analog path, mic 24 dB, DAC silent
10
+
11
+ await codec.setVolume(-30.0); // Set DAC volume, (db −95.5–32 dB) → Promise<void>
12
+ // writes 0x32 = round(db / 0.5) + 191
13
+ console.log(await codec.getVolume()); // Read back DAC volume, () → Promise<float dB>
14
+ // (0x32 − 191) × 0.5
15
+ await codec.setMute(false); // Unmute the DAC, (muted=false) → Promise<void>
16
+ // clears DSM and DEM mute bits of 0x31
17
+ await codec.setMicGain(27); // Set microphone PGA gain, (db 0–30 dB) → Promise<void>
18
+ // 0x14 bits 3:0 = round(db / 3)
19
+ console.log(await codec.getMicGain()); // Read back PGA gain, () → Promise<float dB>
20
+ // 3 dB per register step
21
+ await codec.configureClock(12288000, 16000); // Program the clock tree, (mclkHz Hz, sampleRateHz Hz, mclkFromBclk=false, mclkInvert=false) → Promise<void>
22
+ // preset table first, then computed pre-divider / multiplier / OSR
23
+ await codec.configureSerial({ format: 'i2s', wordLength: 16 }); // Configure the digital audio port, ({format='i2s', wordLength=16, master=false, bclkInvert=false, lrckInvert=false, dacChannel='left', bclkDiv, lrckDiv, continuousBclk=true}) → Promise<void>
24
+ // 0x09 / 0x0A format and word length, slave mode
25
+ await codec.setTristate(false, false); // Tri-state BCLK/LRCK and ADCDAT, (bclkLrck=false, adcdat=false) → Promise<void>
26
+ // 0x07 bits 5:4
27
+ await codec.setInput('analog'); // Select microphone input, (source='analog'|'digital'|'none') → Promise<void>
28
+ // MIC1P / MIC1N differential, PGA powered
29
+ await codec.configureDmic(false); // Select PDM latch edge, (latchFallingEdge=false) → Promise<void>
30
+ // 0x15 bit 0
31
+ await codec.setAdcVolume(0); // Set ADC digital volume, (db −95.5–32 dB) → Promise<void>
32
+ // 0x17; ALC maximum gain when the ALC is on
33
+ await codec.configureAdc({ scaleDb: 24, osr: 64, hpf: true }); // Configure ADC path, ({scaleDb=24 dB, osr=64, doubleSpeed=false, hpf=true, hpfCoeffs=[0x0C, 0x0C]}) → Promise<void>
34
+ // 0x16 scale, 0x03 speed / OSR, 0x1B / 0x1C high-pass filter
35
+ await codec.setAdcRamp(0); // Set ADC soft-ramp rate, (rate 0–15) → Promise<void>
36
+ // 0 = off; n = 0.25 dB per 2^(n+1) LRCK
37
+ await codec.configureAlc(true, { maxLevelDb: -12.0, minLevelDb: -18.1, automute: true, noiseGateDb: -60 }); // Configure ALC, (enabled, {maxLevelDb, minLevelDb, window, automute, automuteWindow, noiseGateDb}) → Promise<void>
38
+ // 0x18–0x1A, levels rounded to the nearest listed value
39
+ await codec.configureAlc(false); // Disable ALC, (enabled=false) → Promise<void>
40
+ // restores defaults
41
+ await codec.setAdcEq(null); // Bypass ADC equalizer, (coefficients=null) → Promise<void>
42
+ // 0x1C bit 6; an array of five 30-bit values loads b0,a1,a2,b1,b2
43
+ await codec.setDacRamp(8); // Set DAC soft-ramp rate, (rate 0–15) → Promise<void>
44
+ // 0x37 bits 7:4
45
+ await codec.configureDrc(true, { maxLevelDb: -12.0, minLevelDb: -24.1 }); // Configure DRC, (enabled, {maxLevelDb, minLevelDb, window}) → Promise<void>
46
+ // 0x34 / 0x35; DAC volume becomes the maximum gain
47
+ await codec.configureDrc(false); // Disable DRC, (enabled=false) → Promise<void>
48
+ // clears the DRC enable bit
49
+ await codec.setDacEq(null); // Bypass DAC equalizer, (coefficients=null) → Promise<void>
50
+ // 0x37 bit 3; an array of three 30-bit values loads b0,b1,a1
51
+ await codec.setDacMuteOptions(true, true, false); // Set DAC mute bits, (dsm=true, dem=true, dsmTarget=false) → Promise<void>
52
+ // 0x31 bits 7:5 individually
53
+ await codec.setLoopback(true); // Route ADC output into the DAC, (enabled) → Promise<void>
54
+ // 0x44 bit 7
55
+ await codec.setLoopback(false); // Disable loopback, (enabled=false) → Promise<void>
56
+ // 0x44 bit 7 cleared
57
+ await codec.setAdcdatMode('dac_adc'); // Select ADCDAT content, (mode='adc_adc'|'adc_zero'|'zero_adc'|'dac_adc'|'adc_dac'|'dac_dac') → Promise<void>
58
+ // DAC + ADC: digital feedback for echo cancellation
59
+ await codec.setAdcdatMode('adc_adc'); // Restore ADCDAT content, (mode='adc_adc') → Promise<void>
60
+ // ADC data on both slots
61
+ await codec.setSdpMute(false, false); // Mute serial input / output, (input=false, output=false) → Promise<void>
62
+ // 0x09 / 0x0A bit 6
63
+ await codec.setLowPower({}); // Clear all low-power bits, ({dac, pga, pgaOut, adc, adcRef, dacRef, flash, integrator}) → Promise<void>
64
+ // 0x0F; all off = best THD+N
65
+ console.log(await codec.readRegister(0x32)); // Read raw register, (register 0x00–0xFF) → Promise<int>
66
+ // returns the byte as stored in the chip
67
+ await codec.writeRegister(0x32, 0xBF); // Write raw register, (register, value) → Promise<void>
68
+ // 0xBF = 0 dB DAC volume
69
+ await new Promise((resolve) => setTimeout(resolve, 1000));
70
+ await codec.setMute(true); // Mute the DAC, (muted=true) → Promise<void>
71
+ // sets DSM and DEM mute
72
+ await codec.powerDown(); // Enter standby, () → Promise<void>
73
+ // powers down analog blocks, resets digital, clears CSM_ON
74
+ await codec.powerUp(); // Leave standby, () → Promise<void>
75
+ // re-enables analog blocks, clocks and CSM_ON
76
+ await codec.reset(); // Software reset, () → Promise<void>
77
+ // registers return to reset values; reconfigure afterwards
78
+ }
79
+
80
+ main();
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ES8311Full } = require('../../../src/chips/adc_dac/es8311');
5
+
6
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7
+
8
+ async function main() {
9
+ // --- Bring up the codec for a voice assistant ---
10
+ // The control port only configures the codec; the I2S stream (MCLK, BCLK,
11
+ // LRCK, DSDIN, ASDOUT) is produced elsewhere. 16 kHz is the usual rate for
12
+ // speech recognition.
13
+ const connection = new I2CConnection(1, 0x18); // Create I2C connection, (bus=1, addr=0x18)
14
+ const codec = new ES8311Full(connection, 12288000, 48000); // Create ES8311 driver, (connection, mclkHz=12288000 Hz, sampleRateHz=48000 Hz)
15
+ await codec.configureClock(12288000, 16000); // Program the clock tree, (mclkHz Hz, sampleRateHz Hz) → Promise<void>
16
+ await codec.configureSerial({ format: 'i2s', wordLength: 16 }); // Configure the digital audio port, ({format='i2s', wordLength=16}) → Promise<void>
17
+
18
+ // --- Configure the microphone path ---
19
+ // 24 dB analog gain plus the ALC keeps quiet and loud talkers at a similar
20
+ // level; the noise gate and automute silence the line between utterances.
21
+ await codec.setMicGain(24); // Set microphone PGA gain, (db 0–30 dB) → Promise<void>
22
+ console.log('mic gain', await codec.getMicGain()); // Read back PGA gain, () → Promise<float dB>
23
+ await codec.setAdcVolume(0); // Set ADC digital volume, (db −95.5–32 dB) → Promise<void>
24
+ await codec.configureAlc(true, { maxLevelDb: -12.0, minLevelDb: -18.1, automute: true, noiseGateDb: -60 }); // Configure ALC, (enabled, {maxLevelDb, minLevelDb, automute, noiseGateDb}) → Promise<void>
25
+ await codec.configureAdc({ hpf: true }); // Configure ADC path, ({scaleDb=24 dB, osr=64, hpf=true}) → Promise<void>
26
+
27
+ // --- Configure playback ---
28
+ // The DRC compresses loud peaks so a small speaker does not clip; the soft
29
+ // ramp avoids clicks while the volume changes.
30
+ await codec.configureDrc(true, { maxLevelDb: -12.0, minLevelDb: -24.1 }); // Configure DRC, (enabled, {maxLevelDb, minLevelDb}) → Promise<void>
31
+ await codec.setDacRamp(8); // Set DAC soft-ramp rate, (rate 0–15) → Promise<void>
32
+ await codec.setMute(false); // Unmute the DAC, (muted=false) → Promise<void>
33
+
34
+ // --- Ramp the playback volume ---
35
+ // Step from -60 dB to -10 dB, reading the value back each time.
36
+ for (let vol = -60; vol <= -10; vol += 10) {
37
+ await codec.setVolume(vol); // Set DAC volume, (db −95.5–32 dB) → Promise<void>
38
+ console.log('volume', await codec.getVolume(), 'dB'); // Read back DAC volume, () → Promise<float dB>
39
+ await sleep(500);
40
+ }
41
+
42
+ // --- Echo-cancellation feedback and loopback ---
43
+ // "dac_adc" puts the DAC data next to the microphone on ADCDAT so the host
44
+ // can cancel the speaker echo; the loopback routes the microphone to the
45
+ // speaker for a quick acoustic check.
46
+ await codec.setAdcdatMode('dac_adc'); // Select ADCDAT content, (mode) → Promise<void>
47
+ await sleep(2000);
48
+ await codec.setAdcdatMode('adc_adc'); // Restore ADCDAT content, (mode) → Promise<void>
49
+ await codec.setLoopback(true); // Route ADC output into the DAC, (enabled) → Promise<void>
50
+ await sleep(2000);
51
+ await codec.setLoopback(false); // Disable loopback, (enabled) → Promise<void>
52
+
53
+ // --- Shut down ---
54
+ // Mute first so power-down does not pop, then enter standby.
55
+ await codec.setMute(true); // Mute the DAC, (muted=true) → Promise<void>
56
+ await codec.powerDown(); // Enter standby, () → Promise<void>
57
+ }
58
+
59
+ main();
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ES8311Minimal } = require('../../../src/chips/adc_dac/es8311');
5
+
6
+ async function main() {
7
+ const connection = new I2CConnection(1, 0x18); // Create I2C connection, (bus=1, addr=0x18)
8
+ const codec = new ES8311Minimal(connection, 12288000, 48000); // Create ES8311 driver and run the init sequence, (connection, mclkHz=12288000 Hz, sampleRateHz=48000 Hz)
9
+
10
+ await codec.setMicGain(24); // Set microphone PGA gain, (db 0–30 dB, 3 dB steps) → Promise<void>
11
+ await codec.setMute(false); // Unmute the DAC, (muted=false) → Promise<void>
12
+ await codec.setVolume(-20.0); // Set DAC volume, (db −95.5–32 dB, 0.5 dB steps) → Promise<void>
13
+
14
+ await new Promise((resolve) => setTimeout(resolve, 5000));
15
+ await codec.setMute(true); // Mute the DAC, (muted=true) → Promise<void>
16
+ }
17
+
18
+ main();
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ // Complete example: exercise every method in the public API.
4
+
5
+ const { I2CConnection } = require('periph/src/connection/i2c');
6
+ const { MCP3422Full } = require('periph/src/chips/adc_dac/mcp3422');
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, MCP3422Full.I2C_ADDRESS);
13
+ const adc = new MCP3422Full(connection); // Create MCP3422 Full driver, (connection)
14
+ await adc.init(); // Write the default configuration, () → void (one-shot, 16 bit, x1, RDY = 0)
15
+
16
+ console.log(await adc.readRaw(0)); // One-shot code, (channel 0–1) → int
17
+ // writes RDY = 1, O/C = 0, waits, polls RDY
18
+ console.log(await adc.readVoltage(1)); // One-shot voltage, (channel 0–1) → float V
19
+ console.log(await adc.readAll()); // Both channels, () → [float V, float V]
20
+ console.log(await adc.readScan([0, 1, 0])); // Scan a list of channels, (channels) → [float V, ...]
21
+
22
+ await adc.setResolution(18); // Select 18 bit / 3.75 SPS, (bits 12|14|16|18) → void
23
+ // throws RangeError for other values
24
+ await adc.setGain(8); // Select PGA x8, (gain 1|2|4|8) → void
25
+ console.log(adc.getResolution(), adc.getGain()); // Read back the selection, () → int, int
26
+ console.log(adc.lsb(), adc.fullScale()); // LSB and full scale, () → float V, float V
27
+ // 2·2.048/2^bits and 2.048/gain
28
+
29
+ await adc.setResolution(12); // Back to 12 bit / 240 SPS, (bits) → void
30
+ await adc.setGain(1); // Back to x1, (gain) → void
31
+ await adc.setChannel(0); // Channel for continuous conversion, (channel 0–1) → void
32
+ await adc.startContinuous(); // Start continuous conversion, (channel) → void
33
+ // O/C = 1; the first sample after a change is discarded
34
+ console.log(adc.isContinuous()); // Report the mode, () → bool
35
+ console.log(await adc.readContinuousRaw()); // Next fresh code, () → int
36
+ console.log(await adc.readContinuous()); // Next fresh voltage, () → float V
37
+ console.log(await adc.readConfig(), await adc.isReady()); // Config byte and RDY, () → int, bool
38
+ await adc.stopContinuous(); // Back to one-shot / standby, () → void
39
+
40
+ await adc.generalCallConvert(); // Start a conversion on every device, () → void
41
+ // sends 0x00 0x08
42
+ await sleep(100);
43
+ console.log(await adc.readPendingRaw()); // Result of that conversion, () → int
44
+ await adc.generalCallReset(); // Reset to power-on defaults, () → void
45
+ // sends 0x00 0x06; the driver state follows
46
+
47
+ await connection.close();
48
+ })();
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ // Demo: a two-channel bridge / thermocouple monitor. Reads CH1 (a thermistor
4
+ // divider) at 16 bit / x1, then 18 bit / x8 on CH2 (a bridge sensor), then runs
5
+ // continuous conversion on CH1 at 12 bit / 240 SPS and finishes with a general
6
+ // call reset.
7
+
8
+ const { I2CConnection } = require('periph/src/connection/i2c');
9
+ const { MCP3422Full } = require('periph/src/chips/adc_dac/mcp3422');
10
+
11
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
12
+
13
+ (async () => {
14
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
15
+ const connection = new I2CConnection(bus, MCP3422Full.I2C_ADDRESS);
16
+ const adc = new MCP3422Full(connection); // Create MCP3422 Full driver, (connection)
17
+ await adc.init(); // Write the default configuration, () → void (one-shot, 16 bit, x1, RDY = 0)
18
+
19
+ // --- CH1: thermistor divider at 16 bit / x1 ---
20
+ for (let i = 0; i < 3; i++) {
21
+ const raw = await adc.readRaw(0); // One-shot code, (channel 0–1) → int
22
+ console.log('CH1 raw', raw, '=', (await adc.readVoltage(0)).toFixed(5), 'V');// One-shot voltage, (channel 0–1) → float V
23
+ await sleep(1000);
24
+ }
25
+
26
+ // --- CH2: bridge sensor at 18 bit / x8 ---
27
+ await adc.setResolution(18); // Select 18 bit / 3.75 SPS, (bits) → void
28
+ await adc.setGain(8); // Select PGA x8, (gain) → void
29
+ const [bridge] = await adc.readScan([1]); // Scan channels, (channels) → [float V]
30
+ console.log('CH2', (bridge * 1e6).toFixed(1), 'uV, LSB', (adc.lsb() / adc.getGain() * 1e6).toFixed(3), 'uV');// LSB, () → float V
31
+
32
+ // --- Continuous conversion on CH1 at 12 bit / 240 SPS ---
33
+ await adc.setResolution(12);
34
+ await adc.setGain(1);
35
+ await adc.startContinuous(0); // Start continuous conversion, (channel) → void
36
+ const samples = [];
37
+ const t0 = Date.now();
38
+ for (let i = 0; i < 20; i++) {
39
+ samples.push(await adc.readContinuous()); // Next fresh voltage, () → float V
40
+ }
41
+ const elapsed = (Date.now() - t0) / 1000;
42
+ await adc.stopContinuous(); // Back to one-shot / standby, () → void
43
+ console.log('min', Math.min(...samples).toFixed(5), 'max', Math.max(...samples).toFixed(5),
44
+ 'mean', (samples.reduce((a, b) => a + b, 0) / samples.length).toFixed(5), 'V,', (samples.length / elapsed).toFixed(0), 'samples/s');
45
+
46
+ await adc.generalCallReset(); // Reset to power-on defaults, () → void
47
+
48
+ await connection.close();
49
+ })();
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ // Minimal example: read both differential inputs.
4
+
5
+ const { I2CConnection } = require('periph/src/connection/i2c');
6
+ const { MCP3422Minimal } = require('periph/src/chips/adc_dac/mcp3422');
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, MCP3422Minimal.I2C_ADDRESS);
13
+ const adc = new MCP3422Minimal(connection); // Create MCP3422 driver, (connection)
14
+ await adc.init(); // Write the default configuration, () → void (one-shot, 16 bit, x1, RDY = 0)
15
+
16
+ for (let i = 0; i < 10; i++) {
17
+ const raw = await adc.readRaw(0); // Read a signed code, (channel 0–1) → int
18
+ const volts = await adc.readVoltage(1); // Read the differential voltage, (channel 0–1) → float V
19
+ console.log('CH1 raw', raw, 'CH2', volts.toFixed(6), 'V');
20
+ console.log(await adc.readAll()); // Read both channels, () → [float V, float V]
21
+ await sleep(1000);
22
+ }
23
+
24
+ await connection.close();
25
+ })();
@@ -0,0 +1,97 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { Mcp4xxxFull } = require('../../../src/chips/adc_dac/mcp4xxx');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x2C', 16);
8
+
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ // MCP4651: dual 8-bit potentiometer (volatile); the non-volatile calls at the end need e.g. an MCP4661.
11
+ const pot = new Mcp4xxxFull(connection, 'MCP4651', 10000.0, 75.0); // Create MCP4XXX driver, (connection, part='MCP4532', rAb=10000 Ω, rWiper=75 Ω, hvc=null, hvcSettleMs=1) → Mcp4xxxFull
12
+
13
+ (async () => {
14
+ await pot.init(); // Bus check, () → void
15
+ // reads wipers and TCON, no writes
16
+
17
+ // --- Part properties ---
18
+ console.log(pot.channels()); // Number of networks, () → int 1-2
19
+ // property of the selected part
20
+ console.log(pot.steps()); // Number of wiper positions, () → int 129 or 257
21
+ // max code + 1
22
+ console.log(pot.isPotentiometer()); // Terminal A on a pin, () → bool
23
+ // true for the X1 parts
24
+ console.log(pot.isNonvolatile()); // Has EEPROM, () → bool
25
+ // true for 454X / 456X / 464X / 466X
26
+
27
+ // --- Wiper position and resistance ---
28
+ await pot.setWiper(100, 0); // Set wiper, (code 0-256, channel=0) → void
29
+ // writes [(0 << 4) | D8, code & 0xFF]; code clamped
30
+ console.log(await pot.getWiper(0)); // Read wiper, (channel=0) → int 0-256
31
+ // two-byte read of the wiper register
32
+ await pot.setBoth(10, 20); // Set both wipers, (code0, code1) → void
33
+ // dual parts only; two transactions
34
+ await pot.setResistance(2200.0, 1); // Set W-B resistance, (ohms, channel=0) → void
35
+ // nearest code of R = N/max*RAB + RW, clamped
36
+ console.log(await pot.getResistance(1)); // Read W-B resistance, (channel=0) → float Ω
37
+ // N/max*RAB + RW
38
+ console.log(pot.getResistanceStep()); // Resistance of one step, () → float Ω
39
+ // RAB / max code
40
+
41
+ // --- Ratio and W-A resistance ---
42
+ await pot.setRatio(0.5, 0); // Set wiper ratio, (ratio 0.0-1.0, channel=0) → void
43
+ // code = round(ratio * max code)
44
+ console.log(await pot.getRatio(0)); // Read wiper ratio, (channel=0) → float 0.0-1.0
45
+ // code / max code
46
+ await pot.setResistanceWa(3300.0, 0); // Set W-A resistance, (ohms, channel=0) → void
47
+ // potentiometer parts only
48
+ console.log(await pot.getResistanceWa(0)); // Read W-A resistance, (channel=0) → float Ω
49
+ // (max code - N)/max*RAB + RW
50
+
51
+ // --- Increment / decrement ---
52
+ console.log(await pot.increment(8, 0)); // Step wiper up, (steps=1, channel=0) → int
53
+ // one continuous transaction of increment commands, saturating
54
+ console.log(await pot.decrement(4, 0)); // Step wiper down, (steps=1, channel=0) → int
55
+ // same with decrement commands, saturating at 0
56
+
57
+ // --- Shutdown and terminals ---
58
+ await pot.shutdown(1); // Shut network down, (channel=0) → void
59
+ // TCON.RxHW = 0: A open, W tied to B; wiper kept
60
+ console.log(await pot.isShutdown(1)); // Read shutdown state, (channel=0) → bool
61
+ // from TCON
62
+ await pot.resume(1); // Leave shutdown, (channel=0) → void
63
+ // TCON.RxHW = 1
64
+ await pot.setTerminals(true, false, true, 0); // Connect terminals, (a=true, w=true, b=true, channel=0) → void
65
+ // TCON.RxA / RxW / RxB, other bits preserved
66
+ console.log(await pot.getTerminals(0)); // Read terminals, (channel=0) → {a, w, b}
67
+ // from TCON
68
+ await pot.setTerminals(true, true, true, 0); // Reconnect all terminals, (a=true, w=true, b=true, channel=0) → void
69
+ // restores the wiper terminal
70
+ console.log(await pot.getTcon()); // Read TCON, () → int 0-0x1FF
71
+ // raw terminal control register
72
+ await pot.setGeneralCall(true); // Set General Call, (enabled) → void
73
+ // TCON.GCEN; chip answers address 0x00 commands
74
+
75
+ // --- Raw access, model, reset ---
76
+ console.log(await pot.readRegister(0x04)); // Raw read, (address 0-15) → int 0-0x1FF
77
+ // nine-bit value of any address the part has
78
+ await pot.writeRegister(0x04, 0x1FF); // Raw write, (address, value) → void
79
+ // volatile wipers, TCON (and EEPROM addresses on NV parts)
80
+ pot.setRab(10000.0, 75.0); // Set resistance model, (rAb Ω, rWiper Ω) → void
81
+ // no I²C traffic; affects conversions only
82
+ await pot.reset(); // Emulate power-on reset, () → void
83
+ // mid-scale (or EEPROM wiper) in every wiper, TCON 0x1FF
84
+
85
+ // --- Non-volatile parts only (MCP454X / 456X / 464X / 466X) ---
86
+ // console.log(await pot.readStatus()); // Read STATUS, () → {eepromBusy, wiperLock, writeProtect}
87
+ // await pot.waitReady(20); // Wait for the EEPROM write cycle, (timeoutMs=20 ms) → void
88
+ // console.log(await pot.getNvWiper(0)); // Read EEPROM wiper, (channel=0) → int
89
+ // await pot.setNvWiper(64, 0); // Write EEPROM wiper, (code, channel=0) → void
90
+ // console.log(await pot.storeWiper(0)); // Store current wiper, (channel=0) → int
91
+ // console.log(await pot.readData(0)); // Read EEPROM register, (index 0-9) → int 0-0x1FF
92
+ // await pot.writeData(0, 0x155); // Write EEPROM register, (index 0-9, value 0-0x1FF) → void
93
+ // console.log(await pot.isWiperLocked(0)); // Read WiperLock, (channel=0) → bool
94
+ // console.log(await pot.isWriteProtected()); // Read write protect, () → bool
95
+ // await pot.setWiperLock(true, 0); // High-voltage command, (locked, channel=0) → void (needs hvc pin)
96
+ // await pot.setWriteProtect(true); // High-voltage command, (enabled) → void (needs hvc pin)
97
+ })();
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { Mcp4xxxFull } = require('../../../src/chips/adc_dac/mcp4xxx');
5
+
6
+ const PART = process.env.MCP4XXX_PART || 'MCP4532'; // any of MCP4531 ... MCP4662
7
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
8
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x58', 16);
9
+
10
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
11
+ const pot = new Mcp4xxxFull(connection, PART, 10000.0, 75.0); // Create MCP4XXX driver, (connection, part='MCP4532', rAb=10000 Ω, rWiper=75 Ω, hvc=null, hvcSettleMs=1) → Mcp4xxxFull
12
+
13
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
14
+
15
+ (async () => {
16
+ await pot.init(); // Bus check, () → void
17
+
18
+ // --- Identify the family member ---
19
+ // One driver covers sixteen parts; the descriptor tells resolution, networks and memory type.
20
+ console.log(PART, pot.channels(), 'network(s)', pot.steps(), 'steps', // Part properties, () → int
21
+ pot.isPotentiometer() ? 'pot' : 'rheostat', pot.isNonvolatile() ? 'EEPROM' : 'RAM');
22
+ console.log('power-up wiper', await pot.getWiper(), await pot.getResistance(), 'ohm'); // Read wiper, (channel=0) → int
23
+
24
+ // --- Set 2.2 kΩ and report the quantisation error ---
25
+ // The wiper snaps to the nearest step of RAB / max code.
26
+ await pot.setResistance(2200.0); // Set W-B resistance, (ohms, channel=0) → void
27
+ const actual = await pot.getResistance(); // Read W-B resistance, (channel=0) → float Ω
28
+ console.log('target=2200 ohm code=%d actual=%s ohm error=%s ohm', await pot.getWiper(), actual.toFixed(1), (actual - 2200).toFixed(1));
29
+
30
+ // --- Step the wiper up and down ---
31
+ // increment / decrement send one command byte per step in a single transaction and
32
+ // saturate at full scale and zero scale.
33
+ for (const [steps, up] of [[8, true], [8, true], [4, false], [10, true]]) {
34
+ const code = up ? await pot.increment(steps) : await pot.decrement(steps); // Step wiper, (steps=1, channel=0) → int
35
+ console.log('%s%d -> code=%d R_WB=%s ohm', up ? '+' : '-', steps, code, (await pot.getResistance()).toFixed(1));
36
+ }
37
+
38
+ // --- Ratios ---
39
+ // The ratio is the fraction of RAB between W and B (the unloaded divider ratio of a potentiometer).
40
+ for (const ratio of [0.0, 0.25, 0.5, 0.75, 1.0]) {
41
+ await pot.setRatio(ratio); // Set wiper ratio, (ratio 0.0-1.0, channel=0) → void
42
+ let line = `ratio=${ratio.toFixed(2)} code=${await pot.getWiper()} R_WB=${(await pot.getResistance()).toFixed(1)}`;
43
+ if (pot.isPotentiometer()) line += ` R_WA=${(await pot.getResistanceWa()).toFixed(1)}`; // Read W-A resistance, (channel=0) → float Ω
44
+ console.log(line);
45
+ }
46
+
47
+ // --- Dual parts: drive both networks ---
48
+ if (pot.channels() === 2) {
49
+ await pot.setBoth(32, 96); // Set both wipers, (code0, code1) → void
50
+ console.log('both:', await pot.getWiper(0), await pot.getWiper(1), '->', await pot.increment(5, 1), await pot.decrement(2, 1));
51
+ }
52
+
53
+ // --- Shutdown and terminal disconnect ---
54
+ // Shutdown ties W to B and opens A without losing the wiper; setTerminals(true, false, true) floats W.
55
+ await pot.shutdown(); // Shut network down, (channel=0) → void
56
+ console.log('shutdown=%s code=%d', await pot.isShutdown(), await pot.getWiper()); // Read state, (channel=0) → bool
57
+ await sleep(1000);
58
+ await pot.resume(); // Leave shutdown, (channel=0) → void
59
+ await pot.setTerminals(true, false, true); // Disconnect the wiper, (a=true, w=true, b=true, channel=0) → void
60
+ console.log('terminals', await pot.getTerminals()); // Read terminals, (channel=0) → {a, w, b}
61
+ await pot.setTerminals(true, true, true); // Reconnect all terminals, (a=true, w=true, b=true, channel=0) → void
62
+
63
+ // --- Non-volatile parts: EEPROM wiper and data ---
64
+ // storeWiper makes the setting survive power cycles; every EEPROM write uses one of the
65
+ // 1 000 000 write cycles, so do not do this in a loop.
66
+ if (pot.isNonvolatile()) {
67
+ console.log(await pot.readStatus()); // Read STATUS, () → {eepromBusy, wiperLock, writeProtect}
68
+ console.log('stored', await pot.storeWiper()); // Store the wiper in EEPROM, (channel=0) → int
69
+ await pot.writeData(0, 0x155); // Write calibration marker, (index 0-9, value 0-0x1FF) → void
70
+ console.log('data0', (await pot.readData(0)).toString(16), 'nv wiper', await pot.getNvWiper()); // Read back, (index) → int
71
+ }
72
+
73
+ // --- Back to the power-up state ---
74
+ await pot.reset(); // Emulate power-on reset, () → void
75
+ console.log('after reset:', await pot.getWiper());
76
+ })();
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { Mcp4xxxMinimal } = require('../../../src/chips/adc_dac/mcp4xxx');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x58', 16);
8
+
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
10
+ const pot = new Mcp4xxxMinimal(connection, 'MCP4532', 10000.0, 75.0); // Create MCP4XXX driver, (connection, part='MCP4532', rAb=10000 Ω, rWiper=75 Ω) → Mcp4xxxMinimal
11
+
12
+ (async () => {
13
+ await pot.init(); // Bus check, () → void
14
+ await pot.setWiper(32); // Set wiper, (code 0-128, channel=0) → void
15
+ await pot.setResistance(2200.0); // Set W-B resistance, (ohms, channel=0) → void
16
+
17
+ setInterval(async () => {
18
+ const code = await pot.getWiper(); // Read wiper, (channel=0) → int 0-128
19
+ const ohms = await pot.getResistance(); // Read W-B resistance, (channel=0) → float Ω
20
+ console.log('code=%d R_WB=%s ohm', code, ohms.toFixed(0));
21
+ }, 1000);
22
+ })();
@@ -0,0 +1,101 @@
1
+ // SH1106 complete example: 1.3" 128 x 64 OLED module (SH1106, RAM columns 2..129) over I2C on a Raspberry Pi (Node.js).
2
+ // Wiring: SDA=GPIO2, SCL=GPIO3 (/dev/i2c-1), VCC = 3V3; address 0x3C (SA0 = VSS) or 0x3D (SA0 = VDD1). Complete: every Full method - drawing, contrast, invert, flip, scroll, drive tuning, reads, sleep.
3
+ 'use strict';
4
+ const { I2CConnection } = require('../../../src/connection/i2c');
5
+ const { SH1106Full } = require('../../../src/chips/display/sh1106');
6
+
7
+ const connection = new I2CConnection(1, 0x3C); // Create I2C connection, (busNumber=1, addr=0x3C)
8
+ const lcd = new SH1106Full(connection); // Create SH1106 driver, (connection, width=128, height=64, columnOffset=2, internalDcdc=true)
9
+
10
+ (async () => {
11
+ await lcd.ready();
12
+ // Framebuffer drawing: everything is composed in RAM and sent with show().
13
+ lcd.clear(); // Clear framebuffer, ()
14
+ // zeroes every pixel of the framebuffer; the panel is unchanged until show()
15
+ lcd.fill(true); // Fill framebuffer, (on=true)
16
+ // sets (or clears) every pixel
17
+ lcd.fill(false); // Fill framebuffer, (on=true)
18
+ lcd.drawRect(0, 0, 128, 64); // Draw rectangle, (x, y, w, h, on=true, fill=false)
19
+ // one-pixel outline around the whole panel
20
+ lcd.drawLine(0, 0, 127, 63); // Draw line, (x0, y0, x1, y1, on=true)
21
+ // Bresenham line into the framebuffer
22
+ lcd.drawLine(0, 63, 127, 0); // Draw line, (x0, y0, x1, y1, on=true)
23
+ lcd.drawRect(10, 10, 30, 20, true, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
24
+ // filled rectangle
25
+ lcd.drawRect(18, 16, 14, 8, false, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
26
+ // on=false clears pixels: a hole in the filled rectangle
27
+ lcd.setPixel(64, 32, true); // Set pixel, (x, y, on=true)
28
+ const lit = lcd.getPixel(64, 32); // Read framebuffer pixel, (x, y) → boolean
29
+ // reads the framebuffer, not the panel
30
+ const icon = Buffer.from([0x3C, 0x42, 0x81, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C, 0x00, 0x7E, 0x81, 0x81, 0x81, 0x7E, 0x00]);
31
+ lcd.blit(100, 16, icon, 2); // Copy bitmap, (x, y multiple of 8, columns, heightPages=1)
32
+ // two page rows of 8 columns, bit 0 = top pixel
33
+ await lcd.show(); // Send framebuffer to the display, () → Promise<void>
34
+ // per page: page + column command, then 128 data bytes in 31-byte chunks
35
+ await new Promise((r) => setTimeout(r, 2000));
36
+ await lcd.showPage(2); // Send one framebuffer page, (page 0..7) → Promise<void>
37
+ // cheaper partial update of 8 rows
38
+
39
+ // Contrast and display modes.
40
+ await lcd.setContrast(0x20); // Set contrast, (value 0..255) → Promise<void>
41
+ // segment drive current; reset value is 0x80
42
+ await new Promise((r) => setTimeout(r, 800));
43
+ await lcd.setContrast(0x80); // Set contrast, (value 0..255) → Promise<void>
44
+ await lcd.setInvert(true); // Invert display, (on) → Promise<void>
45
+ // RAM 0 = pixel on; RAM is unchanged
46
+ await new Promise((r) => setTimeout(r, 800));
47
+ await lcd.setInvert(false); // Invert display, (on) → Promise<void>
48
+ await lcd.setAllOn(true); // Force all pixels on, (on) → Promise<void>
49
+ // test mode, RAM is kept
50
+ await new Promise((r) => setTimeout(r, 800));
51
+ await lcd.setAllOn(false); // Force all pixels on, (on) → Promise<void>
52
+ await lcd.setFlip(true, true); // Mirror display, (horizontal, vertical) → Promise<void>
53
+ // segment re-map and COM scan direction; framebuffer unchanged
54
+ await new Promise((r) => setTimeout(r, 1500));
55
+ await lcd.setFlip(false, false); // Mirror display, (horizontal, vertical) → Promise<void>
56
+
57
+ // Hardware vertical scroll and drive tuning.
58
+ for (let line = 0; line < 64; line += 2) {
59
+ await lcd.setStartLine(line); // Scroll the image up, (line 0..63) → Promise<void>
60
+ // RAM line shown at COM0; the image wraps around
61
+ await new Promise((r) => setTimeout(r, 30));
62
+ }
63
+ await lcd.setStartLine(0); // Scroll the image up, (line 0..63) → Promise<void>
64
+ await lcd.setDisplayOffset(0); // Set COM offset, (offset 0..63) → Promise<void>
65
+ // shifts the COM mapping
66
+ await lcd.setMultiplex(64); // Set multiplex ratio, (ratio 1..64) → Promise<void>
67
+ // number of driven rows
68
+ await lcd.setClock(1, 5); // Set clock, (divide 1..16, osc 0..15) → Promise<void>
69
+ // divide ratio 1 at the nominal oscillator frequency
70
+ await lcd.setPrecharge(2, 2); // Set pre-charge, (precharge 1..15, discharge 1..15) → Promise<void>
71
+ // pre-charge and discharge periods in display clocks
72
+ await lcd.setComConfig(true); // Set COM pin configuration, (alternative) → Promise<void>
73
+ // alternative (0x12) is the reset value and right for 128 x 64 modules
74
+ await lcd.setVcomDeselect(0x35); // Set VCOM deselect level, (value 0..255) → Promise<void>
75
+ await lcd.setPumpVoltage(0); // Set pump voltage, (level 0..3) → Promise<void>
76
+ // 0 = 7.4 V, 1 = 8.0 V, 2 = 8.4 V, 3 = 9.0 V
77
+
78
+ // Reads (I2C only) and raw commands.
79
+ const status = await lcd.readStatus(); // Read status, () → Promise<number>
80
+ // bit 7 BUSY, bit 6 = 1 when the display is off
81
+ const ram = await lcd.readPage(0, 2, 8); // Read display RAM, (page 0..7, column, n) → Promise<Buffer>
82
+ // sets the address and discards the dummy byte
83
+ await lcd.sendCommand(0xE3); // Send raw command stream, (...bytes) → Promise<void>
84
+ // NOP
85
+
86
+ // Power.
87
+ await lcd.setDisplay(false); // Display on/off, (on) → Promise<void>
88
+ // RAM and settings are kept
89
+ await new Promise((r) => setTimeout(r, 1000));
90
+ await lcd.setDisplay(true); // Display on/off, (on) → Promise<void>
91
+ await lcd.sleep(); // Enter sleep, () → Promise<void>
92
+ // display off; the DC-DC stops
93
+ await new Promise((r) => setTimeout(r, 1000));
94
+ await lcd.wake(); // Leave sleep, () → Promise<void>
95
+ // display on and a 100 ms wait for VPP
96
+ await lcd.setDcdc(true); // Switch the internal DC-DC, (on) → Promise<void>
97
+ // issue while the display is off; true = 0x8B, false = 0x8A for an external VPP
98
+ console.log(`status 0x${status.toString(16)}, lit ${lit}, ram ${ram.toString("hex")}`);
99
+ connection.close();
100
+ process.exit(0);
101
+ })().catch((e) => { console.error(e); process.exit(1); });