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,68 @@
1
+ // SH1106 demo 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). Demo: a bouncing ball inside a border, a contrast fade, inverse flashes, hardware scroll and 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
+ // --- Draw the border once ---
13
+ // A one-pixel border around the 128 x 64 panel; the ball bounces inside it.
14
+ lcd.clear(); // Clear framebuffer, ()
15
+ lcd.drawRect(0, 0, 128, 64); // Draw rectangle, (x, y, w, h, on=true, fill=false)
16
+ await lcd.show(); // Send framebuffer to the display, () → Promise<void>
17
+
18
+ // --- Bounce a 6 x 6 ball at about 20 frames per second ---
19
+ // The ball is erased and redrawn in the framebuffer, then the frame is sent with show().
20
+ let bx = 20, by = 12, dx = 3, dy = 2;
21
+ for (let frame = 0; frame < 200; frame++) {
22
+ lcd.drawRect(bx, by, 6, 6, false, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
23
+ bx += dx;
24
+ by += dy;
25
+ if (bx < 2 || bx > 120) { dx = -dx; bx += 2 * dx; }
26
+ if (by < 2 || by > 56) { dy = -dy; by += 2 * dy; }
27
+ lcd.drawRect(bx, by, 6, 6, true, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
28
+ await lcd.show(); // Send framebuffer to the display, () → Promise<void>
29
+ await new Promise((r) => setTimeout(r, 50));
30
+ }
31
+
32
+ // --- Fade the contrast down and back up ---
33
+ // 255 -> 0 -> 255 in steps of 5 shows the full range of the segment drive current.
34
+ for (let v = 255; v >= 0; v -= 5) {
35
+ await lcd.setContrast(v); // Set contrast, (value 0..255) → Promise<void>
36
+ await new Promise((r) => setTimeout(r, 20));
37
+ }
38
+ for (let v = 0; v <= 255; v += 5) {
39
+ await lcd.setContrast(v); // Set contrast, (value 0..255) → Promise<void>
40
+ await new Promise((r) => setTimeout(r, 20));
41
+ }
42
+
43
+ // --- Flash the inverse display twice ---
44
+ for (let i = 0; i < 2; i++) {
45
+ await lcd.setInvert(true); // Invert display, (on) → Promise<void>
46
+ await new Promise((r) => setTimeout(r, 400));
47
+ await lcd.setInvert(false); // Invert display, (on) → Promise<void>
48
+ await new Promise((r) => setTimeout(r, 400));
49
+ }
50
+
51
+ // --- Hardware scroll ---
52
+ // Stepping the display start line moves the image up inside the controller, no data is re-sent;
53
+ // the picture wraps around after 64 lines.
54
+ for (let line = 0; line < 64; line++) {
55
+ await lcd.setStartLine(line); // Scroll the image up, (line 0..63) → Promise<void>
56
+ await new Promise((r) => setTimeout(r, 30));
57
+ }
58
+ for (let line = 63; line >= 0; line--) {
59
+ await lcd.setStartLine(line); // Scroll the image up, (line 0..63) → Promise<void>
60
+ await new Promise((r) => setTimeout(r, 30));
61
+ }
62
+
63
+ // --- Power down ---
64
+ // Sleep turns the display and the charge pump off; RAM and registers are kept.
65
+ await lcd.sleep(); // Enter sleep, () → Promise<void>
66
+ connection.close();
67
+ process.exit(0);
68
+ })().catch((e) => { console.error(e); process.exit(1); });
@@ -0,0 +1,25 @@
1
+ // SH1106 minimal 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). Minimal use: a border and a diagonal on the 128 x 64 panel.
3
+ 'use strict';
4
+ const { I2CConnection } = require('../../../src/connection/i2c');
5
+ const { SH1106Minimal } = require('../../../src/chips/display/sh1106');
6
+
7
+ const connection = new I2CConnection(1, 0x3C); // Create I2C connection, (busNumber=1, addr=0x3C)
8
+ const lcd = new SH1106Minimal(connection); // Create SH1106 driver, (connection, width=128, height=64, columnOffset=2, internalDcdc=true)
9
+
10
+ (async () => {
11
+ await lcd.ready();
12
+ lcd.clear(); // Clear framebuffer, ()
13
+ for (let x = 0; x < 128; x++) {
14
+ lcd.setPixel(x, 0); // Set pixel, (x 0..127, y 0..63, on=true)
15
+ lcd.setPixel(x, 63); // Set pixel, (x 0..127, y 0..63, on=true)
16
+ lcd.setPixel(x, Math.floor(x / 2)); // Set pixel, (x 0..127, y 0..63, on=true)
17
+ }
18
+ for (let y = 0; y < 64; y++) {
19
+ lcd.setPixel(0, y); // Set pixel, (x 0..127, y 0..63, on=true)
20
+ lcd.setPixel(127, y); // Set pixel, (x 0..127, y 0..63, on=true)
21
+ }
22
+ await lcd.show(); // Send framebuffer to the display, () → Promise<void>
23
+ connection.close();
24
+ process.exit(0);
25
+ })().catch((e) => { console.error(e); process.exit(1); });
@@ -0,0 +1,129 @@
1
+ // SSD1305 complete example: 1.3" 128 x 64 OLED module (SSD1305, RAM columns 4..131) over I2C on a Raspberry Pi (Node.js).
2
+ // Wiring: SDA=GPIO2, SCL=GPIO3 (/dev/i2c-1), VCC = 3V3 (OLED supply VCC 7..15 V from the module, no charge pump); address 0x3C (SA0 = low) or 0x3D (SA0 = high). 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 { SSD1305Full } = require('../../../src/chips/display/ssd1305');
6
+
7
+ const connection = new I2CConnection(1, 0x3C); // Create I2C connection, (busNumber=1, addr=0x3C)
8
+ const lcd = new SSD1305Full(connection); // Create SSD1305 driver, (connection, width=128, height=64, columnOffset=4)
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 16..64) → Promise<void>
67
+ // number of driven rows
68
+ await lcd.setClock(1, 7); // Set clock, (divide 1..16, osc 0..15) → Promise<void>
69
+ // divide ratio 1 at the reset oscillator setting
70
+ await lcd.setPrecharge(2, 2); // Set pre-charge, (phase1 1..15, phase2 1..15) → Promise<void>
71
+ // pre-charge and discharge periods in display clocks
72
+ await lcd.setComConfig(true); // Set COM pin configuration, (alternative, remap=false) → Promise<void>
73
+ // alternative is the reset value and right for 128 x 64 modules
74
+ await lcd.setVcomh(0x34); // Set VCOMH deselect level, (value 0x00..0x3C) → Promise<void>
75
+ // 0x34 (about 0.77 x VCC) is the reset value
76
+ await lcd.setDimMode(0x40, 0x40); // Configure dim levels, (contrast 0..255, brightness 0..255) → Promise<void>
77
+ // used while dim mode is on
78
+ await lcd.setDim(true); // Dim mode, (on) → Promise<void>
79
+ // 0xAC display on in dim mode
80
+ await new Promise((r) => setTimeout(r, 1000));
81
+ await lcd.setDim(false); // Dim mode, (on) → Promise<void>
82
+ await lcd.setBrightness(0x80); // Set colour-bank brightness, (value 0..255) → Promise<void>
83
+ // no visible effect in monochrome mode
84
+ await lcd.setAreaColor(false); // Set area-colour mode, (enable, lowPower=false) → Promise<void>
85
+ // keep disabled on monochrome panels
86
+ await lcd.setLut(49, 63, 63, 63); // Set pulse widths, (bank0, a, b, c each 31..63) → Promise<void>
87
+ // reset values
88
+ await lcd.setBankColors([0, 0, 0, 0], [0, 0, 0, 0]); // Assign bank colours, (banks1to16, banks17to32=null) → Promise<void>
89
+ // all banks colour A
90
+ await lcd.setAddressingMode('horizontal'); // Select addressing mode, (mode "page"|"horizontal"|"vertical") → Promise<void>
91
+ // show() then streams the frame in one transfer
92
+ await lcd.show(); // Update display, () → Promise<void>
93
+ await lcd.setAddressingMode('page'); // Select addressing mode, (mode "page"|"horizontal"|"vertical") → Promise<void>
94
+
95
+ // Hardware scrolling.
96
+ await lcd.setScrollHorizontal(true, 0, 7, 0, 1); // Set horizontal scroll, (right, startPage, endPage, interval 0..6, columns=1) → Promise<void>
97
+ // interval index 0 = 6 frames per step
98
+ await lcd.scrollStart(); // Start scrolling, () → Promise<void>
99
+ await new Promise((r) => setTimeout(r, 2000));
100
+ await lcd.scrollStop(); // Stop scrolling, () → Promise<void>
101
+ // deactivates and rewrites the RAM from the framebuffer
102
+ await lcd.setScrollArea(0, 64); // Set vertical scroll area, (topFixed 0..63, scrollRows 1..64) → Promise<void>
103
+ await lcd.setScrollVertical(true, 0, 7, 0, 1, 1); // Set vertical+horizontal scroll, (right, startPage, endPage, interval, columns, rows 1..63) → Promise<void>
104
+ await lcd.scrollStart(); // Start scrolling, () → Promise<void>
105
+ await new Promise((r) => setTimeout(r, 2000));
106
+ await lcd.scrollStop(); // Stop scrolling, () → Promise<void>
107
+
108
+ // Reads (I2C only) and raw commands.
109
+ const status = await lcd.readStatus(); // Read status, () → Promise<number>
110
+ // bit 6 = 1 when the display is off
111
+ const ram = await lcd.readPage(0, 2, 8); // Read display RAM, (page 0..7, column, n) → Promise<Buffer>
112
+ // sets the address and discards the dummy byte
113
+ await lcd.sendCommand(0xE3); // Send raw command stream, (...bytes) → Promise<void>
114
+ // NOP
115
+
116
+ // Power.
117
+ await lcd.setDisplay(false); // Display on/off, (on) → Promise<void>
118
+ // RAM and settings are kept
119
+ await new Promise((r) => setTimeout(r, 1000));
120
+ await lcd.setDisplay(true); // Display on/off, (on) → Promise<void>
121
+ await lcd.sleep(); // Enter sleep, () → Promise<void>
122
+ // display off; switch VCC off afterwards
123
+ await new Promise((r) => setTimeout(r, 1000));
124
+ await lcd.wake(); // Leave sleep, () → Promise<void>
125
+ // display on and a 100 ms wait (tAF)
126
+ console.log(`status 0x${status.toString(16)}, lit ${lit}, ram ${ram.toString("hex")}`);
127
+ connection.close();
128
+ process.exit(0);
129
+ })().catch((e) => { console.error(e); process.exit(1); });
@@ -0,0 +1,71 @@
1
+ // SSD1305 demo example: 1.3" 128 x 64 OLED module (SSD1305, RAM columns 4..131) over I2C on a Raspberry Pi (Node.js).
2
+ // Wiring: SDA=GPIO2, SCL=GPIO3 (/dev/i2c-1), VCC = 3V3 (OLED supply VCC 7..15 V from the module, no charge pump); address 0x3C (SA0 = low) or 0x3D (SA0 = high). Demo: a bouncing ball inside a border, a contrast fade, inverse flashes, hardware scroll and sleep.
3
+ 'use strict';
4
+ const { I2CConnection } = require('../../../src/connection/i2c');
5
+ const { SSD1305Full } = require('../../../src/chips/display/ssd1305');
6
+
7
+ const connection = new I2CConnection(1, 0x3C); // Create I2C connection, (busNumber=1, addr=0x3C)
8
+ const lcd = new SSD1305Full(connection); // Create SSD1305 driver, (connection, width=128, height=64, columnOffset=4)
9
+
10
+ (async () => {
11
+ await lcd.ready();
12
+ // --- Draw the border once ---
13
+ // A one-pixel border around the 128 x 64 panel; the ball bounces inside it.
14
+ lcd.clear(); // Clear framebuffer, ()
15
+ lcd.drawRect(0, 0, 128, 64); // Draw rectangle, (x, y, w, h, on=true, fill=false)
16
+ await lcd.show(); // Send framebuffer to the display, () → Promise<void>
17
+
18
+ // --- Bounce a 6 x 6 ball at about 20 frames per second ---
19
+ // The ball is erased and redrawn in the framebuffer, then the frame is sent with show().
20
+ let bx = 20, by = 12, dx = 3, dy = 2;
21
+ for (let frame = 0; frame < 200; frame++) {
22
+ lcd.drawRect(bx, by, 6, 6, false, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
23
+ bx += dx;
24
+ by += dy;
25
+ if (bx < 2 || bx > 120) { dx = -dx; bx += 2 * dx; }
26
+ if (by < 2 || by > 56) { dy = -dy; by += 2 * dy; }
27
+ lcd.drawRect(bx, by, 6, 6, true, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
28
+ await lcd.show(); // Send framebuffer to the display, () → Promise<void>
29
+ await new Promise((r) => setTimeout(r, 50));
30
+ }
31
+
32
+ // --- Fade the contrast down and back up ---
33
+ // 255 -> 0 -> 255 in steps of 5 shows the full range of the segment drive current.
34
+ for (let v = 255; v >= 0; v -= 5) {
35
+ await lcd.setContrast(v); // Set contrast, (value 0..255) → Promise<void>
36
+ await new Promise((r) => setTimeout(r, 20));
37
+ }
38
+ for (let v = 0; v <= 255; v += 5) {
39
+ await lcd.setContrast(v); // Set contrast, (value 0..255) → Promise<void>
40
+ await new Promise((r) => setTimeout(r, 20));
41
+ }
42
+
43
+ // --- Flash the inverse display twice ---
44
+ for (let i = 0; i < 2; i++) {
45
+ await lcd.setInvert(true); // Invert display, (on) → Promise<void>
46
+ await new Promise((r) => setTimeout(r, 400));
47
+ await lcd.setInvert(false); // Invert display, (on) → Promise<void>
48
+ await new Promise((r) => setTimeout(r, 400));
49
+ }
50
+
51
+ // --- Dim mode ---
52
+ // Dim mode lowers contrast and colour-bank brightness to the levels stored with setDimMode.
53
+ await lcd.setDimMode(0x10, 0x10); // Configure dim levels, (contrast 0..255, brightness 0..255) → Promise<void>
54
+ await lcd.setDim(true); // Dim mode, (on) → Promise<void>
55
+ await new Promise((r) => setTimeout(r, 2000));
56
+ await lcd.setDim(false); // Dim mode, (on) → Promise<void>
57
+
58
+ // --- Hardware scroll ---
59
+ // The scroll engine moves all eight pages right in the controller without re-sending any data;
60
+ // stopping rewrites the RAM from the framebuffer as the datasheet requires.
61
+ await lcd.setScrollHorizontal(true, 0, 7, 0); // Set horizontal scroll, (right, startPage, endPage, interval 0..6, columns=1) → Promise<void>
62
+ await lcd.scrollStart(); // Start scrolling, () → Promise<void>
63
+ await new Promise((r) => setTimeout(r, 5000));
64
+ await lcd.scrollStop(); // Stop scrolling, () → Promise<void>
65
+
66
+ // --- Power down ---
67
+ // Sleep turns the display off (switch VCC off afterwards); RAM and registers are kept.
68
+ await lcd.sleep(); // Enter sleep, () → Promise<void>
69
+ connection.close();
70
+ process.exit(0);
71
+ })().catch((e) => { console.error(e); process.exit(1); });
@@ -0,0 +1,25 @@
1
+ // SSD1305 minimal example: 1.3" 128 x 64 OLED module (SSD1305, RAM columns 4..131) over I2C on a Raspberry Pi (Node.js).
2
+ // Wiring: SDA=GPIO2, SCL=GPIO3 (/dev/i2c-1), VCC = 3V3 (OLED supply VCC 7..15 V from the module, no charge pump); address 0x3C (SA0 = low) or 0x3D (SA0 = high). Minimal use: a border and a diagonal on the 128 x 64 panel.
3
+ 'use strict';
4
+ const { I2CConnection } = require('../../../src/connection/i2c');
5
+ const { SSD1305Minimal } = require('../../../src/chips/display/ssd1305');
6
+
7
+ const connection = new I2CConnection(1, 0x3C); // Create I2C connection, (busNumber=1, addr=0x3C)
8
+ const lcd = new SSD1305Minimal(connection); // Create SSD1305 driver, (connection, width=128, height=64, columnOffset=4)
9
+
10
+ (async () => {
11
+ await lcd.ready();
12
+ lcd.clear(); // Clear framebuffer, ()
13
+ for (let x = 0; x < 128; x++) {
14
+ lcd.setPixel(x, 0); // Set pixel, (x 0..127, y 0..63, on=true)
15
+ lcd.setPixel(x, 63); // Set pixel, (x 0..127, y 0..63, on=true)
16
+ lcd.setPixel(x, Math.floor(x / 2)); // Set pixel, (x 0..127, y 0..63, on=true)
17
+ }
18
+ for (let y = 0; y < 64; y++) {
19
+ lcd.setPixel(0, y); // Set pixel, (x 0..127, y 0..63, on=true)
20
+ lcd.setPixel(127, y); // Set pixel, (x 0..127, y 0..63, on=true)
21
+ }
22
+ await lcd.show(); // Send framebuffer to the display, () → Promise<void>
23
+ connection.close();
24
+ process.exit(0);
25
+ })().catch((e) => { console.error(e); process.exit(1); });
@@ -0,0 +1,115 @@
1
+ // SSD1306 complete example: 0.96" 128 x 64 OLED module (SSD1306) over I2C on a Raspberry Pi (Node.js).
2
+ // Wiring: SDA=GPIO2, SCL=GPIO3 (/dev/i2c-1), VCC = 3V3 (the module generates the OLED supply with the SSD1306 charge pump); address 0x3C (SA0 = low) or 0x3D (SA0 = high). 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 { SSD1306Full } = require('../../../src/chips/display/ssd1306');
6
+
7
+ const connection = new I2CConnection(1, 0x3C); // Create I2C connection, (busNumber=1, addr=0x3C)
8
+ const lcd = new SSD1306Full(connection); // Create SSD1306 driver, (connection, width=128, height=64, externalVcc=false)
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 0x7F
42
+ await new Promise((r) => setTimeout(r, 800));
43
+ await lcd.setContrast(0x7F); // 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 16..64) → Promise<void>
67
+ // number of driven rows
68
+ await lcd.setClock(1, 8); // Set clock, (divide 1..16, osc 0..15) → Promise<void>
69
+ // divide ratio 1 at the reset oscillator setting
70
+ await lcd.setPrecharge(2, 2); // Set pre-charge, (phase1 1..15, phase2 1..15) → Promise<void>
71
+ // pre-charge and discharge periods in display clocks
72
+ await lcd.setComConfig(true); // Set COM pin configuration, (alternative, remap=false) → Promise<void>
73
+ // alternative is the reset value and right for 128 x 64 modules
74
+ await lcd.setVcomh(0x20); // Set VCOMH deselect level, (value 0x00..0x70) → Promise<void>
75
+ // 0x20 (about 0.77 x VCC) is the reset value
76
+ await lcd.setChargePump(true); // Enable the charge pump, (enabled) → Promise<void>
77
+ // 0x8D 0x14; takes effect with the display on
78
+
79
+ // Addressing modes.
80
+ await lcd.setAddressingMode('horizontal'); // Select addressing mode, (mode "page"|"horizontal"|"vertical") → Promise<void>
81
+ // show() then streams the frame in one transfer
82
+ await lcd.show(); // Update display, () → Promise<void>
83
+ await lcd.setAddressingMode('page'); // Select addressing mode, (mode "page"|"horizontal"|"vertical") → Promise<void>
84
+
85
+ // Hardware scrolling (RAM access is refused while a scroll is active).
86
+ await lcd.setScrollHorizontal(true, 0, 7, 7); // Set horizontal scroll, (right, startPage, endPage, interval 0..7) → Promise<void>
87
+ // interval index 7 = 2 frames per step
88
+ await lcd.scrollStart(); // Start scrolling, () → Promise<void>
89
+ await new Promise((r) => setTimeout(r, 2000));
90
+ await lcd.scrollStop(); // Stop scrolling, () → Promise<void>
91
+ // deactivates and rewrites the RAM from the framebuffer
92
+ await lcd.setScrollArea(0, 64); // Set vertical scroll area, (topFixed 0..63, scrollRows 1..64) → Promise<void>
93
+ await lcd.setScrollVertical(true, 0, 7, 7, 1); // Set diagonal scroll, (right, startPage, endPage, interval 0..7, rows 1..63) → Promise<void>
94
+ await lcd.scrollStart(); // Start scrolling, () → Promise<void>
95
+ await new Promise((r) => setTimeout(r, 2000));
96
+ await lcd.scrollStop(); // Stop scrolling, () → Promise<void>
97
+
98
+ // Raw commands.
99
+ await lcd.sendCommand(0xE3); // Send raw command stream, (...bytes) → Promise<void>
100
+ // NOP
101
+
102
+ // Power.
103
+ await lcd.setDisplay(false); // Display on/off, (on) → Promise<void>
104
+ // RAM and settings are kept
105
+ await new Promise((r) => setTimeout(r, 1000));
106
+ await lcd.setDisplay(true); // Display on/off, (on) → Promise<void>
107
+ await lcd.sleep(); // Enter sleep, () → Promise<void>
108
+ // display off; switch VCC off afterwards
109
+ await new Promise((r) => setTimeout(r, 1000));
110
+ await lcd.wake(); // Leave sleep, () → Promise<void>
111
+ // display on and a 100 ms wait (tAF)
112
+ console.log(`lit ${lit}`);
113
+ connection.close();
114
+ process.exit(0);
115
+ })().catch((e) => { console.error(e); process.exit(1); });
@@ -0,0 +1,70 @@
1
+ // SSD1306 demo example: 0.96" 128 x 64 OLED module (SSD1306) over I2C on a Raspberry Pi (Node.js).
2
+ // Wiring: SDA=GPIO2, SCL=GPIO3 (/dev/i2c-1), VCC = 3V3 (the module generates the OLED supply with the SSD1306 charge pump); address 0x3C (SA0 = low) or 0x3D (SA0 = high). Demo: a bouncing ball inside a border, a contrast fade, inverse flashes, hardware scroll and sleep.
3
+ 'use strict';
4
+ const { I2CConnection } = require('../../../src/connection/i2c');
5
+ const { SSD1306Full } = require('../../../src/chips/display/ssd1306');
6
+
7
+ const connection = new I2CConnection(1, 0x3C); // Create I2C connection, (busNumber=1, addr=0x3C)
8
+ const lcd = new SSD1306Full(connection); // Create SSD1306 driver, (connection, width=128, height=64, externalVcc=false)
9
+
10
+ (async () => {
11
+ await lcd.ready();
12
+ // --- Draw the border once ---
13
+ // A one-pixel border around the 128 x 64 panel; the ball bounces inside it.
14
+ lcd.clear(); // Clear framebuffer, ()
15
+ lcd.drawRect(0, 0, 128, 64); // Draw rectangle, (x, y, w, h, on=true, fill=false)
16
+ await lcd.show(); // Send framebuffer to the display, () → Promise<void>
17
+
18
+ // --- Bounce a 6 x 6 ball at about 20 frames per second ---
19
+ // The ball is erased and redrawn in the framebuffer, then the frame is sent with show().
20
+ let bx = 20, by = 12, dx = 3, dy = 2;
21
+ for (let frame = 0; frame < 200; frame++) {
22
+ lcd.drawRect(bx, by, 6, 6, false, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
23
+ bx += dx;
24
+ by += dy;
25
+ if (bx < 2 || bx > 120) { dx = -dx; bx += 2 * dx; }
26
+ if (by < 2 || by > 56) { dy = -dy; by += 2 * dy; }
27
+ lcd.drawRect(bx, by, 6, 6, true, true); // Draw rectangle, (x, y, w, h, on=true, fill=false)
28
+ await lcd.show(); // Send framebuffer to the display, () → Promise<void>
29
+ await new Promise((r) => setTimeout(r, 50));
30
+ }
31
+
32
+ // --- Fade the contrast down and back up ---
33
+ // 255 -> 0 -> 255 in steps of 5 shows the full range of the segment drive current.
34
+ for (let v = 255; v >= 0; v -= 5) {
35
+ await lcd.setContrast(v); // Set contrast, (value 0..255) → Promise<void>
36
+ await new Promise((r) => setTimeout(r, 20));
37
+ }
38
+ for (let v = 0; v <= 255; v += 5) {
39
+ await lcd.setContrast(v); // Set contrast, (value 0..255) → Promise<void>
40
+ await new Promise((r) => setTimeout(r, 20));
41
+ }
42
+
43
+ // --- Flash the inverse display twice ---
44
+ for (let i = 0; i < 2; i++) {
45
+ await lcd.setInvert(true); // Invert display, (on) → Promise<void>
46
+ await new Promise((r) => setTimeout(r, 400));
47
+ await lcd.setInvert(false); // Invert display, (on) → Promise<void>
48
+ await new Promise((r) => setTimeout(r, 400));
49
+ }
50
+
51
+ // --- Hardware scroll ---
52
+ // The scroll engine moves all eight pages right in the controller without re-sending any data;
53
+ // RAM access is prohibited while it runs, so it is stopped before the next show().
54
+ await lcd.setScrollHorizontal(true, 0, 7, 7); // Set horizontal scroll, (right, startPage, endPage, interval 0..7) → Promise<void>
55
+ await lcd.scrollStart(); // Start scrolling, () → Promise<void>
56
+ await new Promise((r) => setTimeout(r, 5000));
57
+ await lcd.scrollStop(); // Stop scrolling, () → Promise<void>
58
+
59
+ // A diagonal scroll moves one row vertically per step in addition.
60
+ await lcd.setScrollVertical(true, 0, 7, 7, 1); // Set diagonal scroll, (right, startPage, endPage, interval 0..7, rows 1..63) → Promise<void>
61
+ await lcd.scrollStart(); // Start scrolling, () → Promise<void>
62
+ await new Promise((r) => setTimeout(r, 5000));
63
+ await lcd.scrollStop(); // Stop scrolling, () → Promise<void>
64
+
65
+ // --- Power down ---
66
+ // Sleep turns the display off; RAM and registers are kept.
67
+ await lcd.sleep(); // Enter sleep, () → Promise<void>
68
+ connection.close();
69
+ process.exit(0);
70
+ })().catch((e) => { console.error(e); process.exit(1); });
@@ -0,0 +1,25 @@
1
+ // SSD1306 minimal example: 0.96" 128 x 64 OLED module (SSD1306) over I2C on a Raspberry Pi (Node.js).
2
+ // Wiring: SDA=GPIO2, SCL=GPIO3 (/dev/i2c-1), VCC = 3V3 (the module generates the OLED supply with the SSD1306 charge pump); address 0x3C (SA0 = low) or 0x3D (SA0 = high). Minimal use: a border and a diagonal on the 128 x 64 panel.
3
+ 'use strict';
4
+ const { I2CConnection } = require('../../../src/connection/i2c');
5
+ const { SSD1306Minimal } = require('../../../src/chips/display/ssd1306');
6
+
7
+ const connection = new I2CConnection(1, 0x3C); // Create I2C connection, (busNumber=1, addr=0x3C)
8
+ const lcd = new SSD1306Minimal(connection); // Create SSD1306 driver, (connection, width=128, height=64, externalVcc=false)
9
+
10
+ (async () => {
11
+ await lcd.ready();
12
+ lcd.clear(); // Clear framebuffer, ()
13
+ for (let x = 0; x < 128; x++) {
14
+ lcd.setPixel(x, 0); // Set pixel, (x 0..127, y 0..63, on=true)
15
+ lcd.setPixel(x, 63); // Set pixel, (x 0..127, y 0..63, on=true)
16
+ lcd.setPixel(x, Math.floor(x / 2)); // Set pixel, (x 0..127, y 0..63, on=true)
17
+ }
18
+ for (let y = 0; y < 64; y++) {
19
+ lcd.setPixel(0, y); // Set pixel, (x 0..127, y 0..63, on=true)
20
+ lcd.setPixel(127, y); // Set pixel, (x 0..127, y 0..63, on=true)
21
+ }
22
+ await lcd.show(); // Send framebuffer to the display, () → Promise<void>
23
+ connection.close();
24
+ process.exit(0);
25
+ })().catch((e) => { console.error(e); process.exit(1); });
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { AM2315Full } = require('../../../src/chips/environmental/am2315');
5
+
6
+ const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
7
+ const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x5C', 16);
8
+
9
+ const connection = new I2CConnection(I2C_BUS, I2C_ADDR); // Create I²C connection, (bus=1, addr=0x5C) → Connection
10
+ const sensor = new AM2315Full(connection); // Create AM2315 driver, (connection) → void
11
+
12
+ async function main() {
13
+ const r = await sensor.read(); // Read temperature and humidity, () → {temperature_c, humidity_pct}
14
+ // previous measurement; reads are kept >= 2 s apart, CRC-16 checked
15
+ console.log(r.temperature_c, r.humidity_pct);
16
+ console.log(await sensor.readTemperature()); // Read temperature only, () → number °C
17
+ console.log(await sensor.readHumidity()); // Read humidity only, () → number %RH
18
+ console.log(await sensor.readRaw()); // Read raw words, () → [number, number]
19
+ // [humidity x10, temperature x10 as sign + magnitude]
20
+ console.log(await sensor.readFresh()); // Real-time value, () → {temperature_c, humidity_pct}
21
+ // two reads >= 2 s apart; returns the second
22
+ console.log(await sensor.readRegisters(0x08, 7)); // Read registers, (start, count) → Buffer
23
+ // function 0x03, 1-10 registers, CRC verified
24
+ console.log(await sensor.readDeviceInfo()); // Read device information, () → {model, version, device_id}
25
+ console.log(await sensor.readUserRegisters()); // Read user registers, () → [number, number]
26
+ await sensor.writeUserRegisters(0x1234, 0xABCD); // Write user registers, (user1, user2) → void
27
+ await sensor.writeRegisters(0x10, [0x00, 0x01]); // Write registers, (start, data) → void
28
+ // only the user registers 0x10-0x13 are allowed
29
+ await sensor.wake(); // Wake the sensor, () → void
30
+ // dummy write, the NACK is ignored
31
+ connection.close();
32
+ }
33
+
34
+ main().catch(err => { console.error(err); process.exit(1); });