periph 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/examples/adc_dac/ad5251/complete.js +66 -0
- package/examples/adc_dac/ad5251/demo.js +69 -0
- package/examples/adc_dac/ad5251/minimal.js +23 -0
- package/examples/adc_dac/ad5252/complete.js +66 -0
- package/examples/adc_dac/ad5252/demo.js +69 -0
- package/examples/adc_dac/ad5252/minimal.js +23 -0
- package/examples/adc_dac/ads7828/complete.js +46 -0
- package/examples/adc_dac/ads7828/demo.js +45 -0
- package/examples/adc_dac/ads7828/minimal.js +17 -0
- package/examples/adc_dac/cat5171/complete.js +52 -0
- package/examples/adc_dac/cat5171/demo.js +59 -0
- package/examples/adc_dac/cat5171/minimal.js +23 -0
- package/examples/adc_dac/cs43l22/complete.js +88 -0
- package/examples/adc_dac/cs43l22/demo.js +56 -0
- package/examples/adc_dac/cs43l22/minimal.js +20 -0
- package/examples/adc_dac/ds1881/complete.js +62 -0
- package/examples/adc_dac/ds1881/demo.js +61 -0
- package/examples/adc_dac/ds1881/minimal.js +25 -0
- package/examples/adc_dac/ds3502/complete.js +46 -0
- package/examples/adc_dac/ds3502/demo.js +54 -0
- package/examples/adc_dac/ds3502/minimal.js +28 -0
- package/examples/adc_dac/mcp3422/complete.js +48 -0
- package/examples/adc_dac/mcp3422/demo.js +49 -0
- package/examples/adc_dac/mcp3422/minimal.js +25 -0
- package/examples/display/sh1106/complete.js +101 -0
- package/examples/display/sh1106/demo.js +68 -0
- package/examples/display/sh1106/minimal.js +25 -0
- package/examples/display/ssd1305/complete.js +129 -0
- package/examples/display/ssd1305/demo.js +71 -0
- package/examples/display/ssd1305/minimal.js +25 -0
- package/examples/display/ssd1306/complete.js +115 -0
- package/examples/display/ssd1306/demo.js +70 -0
- package/examples/display/ssd1306/minimal.js +25 -0
- package/examples/environmental/am2315/complete.js +34 -0
- package/examples/environmental/am2315/demo.js +46 -0
- package/examples/environmental/am2315/minimal.js +21 -0
- package/examples/humidity/htu21df/complete.js +49 -0
- package/examples/humidity/htu21df/demo.js +50 -0
- package/examples/humidity/htu21df/minimal.js +22 -0
- package/examples/humidity/sht31/complete.js +53 -0
- package/examples/humidity/sht31/demo.js +53 -0
- package/examples/humidity/sht31/minimal.js +21 -0
- package/examples/humidity/si7021/complete.js +55 -0
- package/examples/humidity/si7021/demo.js +58 -0
- package/examples/humidity/si7021/minimal.js +21 -0
- package/examples/imu/bno055/complete.js +85 -0
- package/examples/imu/bno055/demo.js +70 -0
- package/examples/imu/bno055/minimal.js +20 -0
- package/examples/io_expander/pca6408a/complete.js +63 -0
- package/examples/io_expander/pca6408a/demo.js +58 -0
- package/examples/io_expander/pca6408a/minimal.js +20 -0
- package/examples/io_expander/pca6416a/complete.js +68 -0
- package/examples/io_expander/pca6416a/demo.js +60 -0
- package/examples/io_expander/pca6416a/minimal.js +20 -0
- package/examples/io_expander/pca9536/complete.js +63 -0
- package/examples/io_expander/pca9536/demo.js +57 -0
- package/examples/io_expander/pca9536/minimal.js +20 -0
- package/examples/io_expander/pca9539/complete.js +68 -0
- package/examples/io_expander/pca9539/demo.js +60 -0
- package/examples/io_expander/pca9539/minimal.js +20 -0
- package/examples/light/max44009/complete.js +56 -0
- package/examples/light/max44009/demo.js +49 -0
- package/examples/light/max44009/minimal.js +22 -0
- package/examples/memory/at24c02n/complete.js +39 -0
- package/examples/memory/at24c02n/demo.js +39 -0
- package/examples/memory/at24c02n/minimal.js +15 -0
- package/examples/memory/at24c64/complete.js +39 -0
- package/examples/memory/at24c64/demo.js +39 -0
- package/examples/memory/at24c64/minimal.js +15 -0
- package/examples/memory/cat24c512/complete.js +39 -0
- package/examples/memory/cat24c512/demo.js +39 -0
- package/examples/memory/cat24c512/minimal.js +15 -0
- package/examples/other/pca9541/complete.js +52 -0
- package/examples/other/pca9541/demo.js +61 -0
- package/examples/other/pca9541/minimal.js +23 -0
- package/examples/temperature/tmp102/complete.js +74 -0
- package/examples/temperature/tmp102/demo.js +71 -0
- package/examples/temperature/tmp102/minimal.js +20 -0
- package/examples/tof/vl6180x/complete.js +62 -0
- package/examples/tof/vl6180x/demo.js +77 -0
- package/examples/tof/vl6180x/minimal.js +23 -0
- package/package.json +1 -1
- package/src/chips/adc_dac/ad5251.js +345 -0
- package/src/chips/adc_dac/ad5252.js +345 -0
- package/src/chips/adc_dac/ads7828.js +225 -0
- package/src/chips/adc_dac/cat5171.js +213 -0
- package/src/chips/adc_dac/cs43l22.js +645 -0
- package/src/chips/adc_dac/ds1881.js +357 -0
- package/src/chips/adc_dac/ds3502.js +241 -0
- package/src/chips/adc_dac/mcp3422.js +312 -0
- package/src/chips/display/mono_oled.js +182 -0
- package/src/chips/display/sh1106.js +496 -0
- package/src/chips/display/ssd1305.js +655 -0
- package/src/chips/display/ssd1306.js +458 -0
- package/src/chips/environmental/am2315.js +237 -0
- package/src/chips/humidity/htu21df.js +222 -0
- package/src/chips/humidity/sht31.js +284 -0
- package/src/chips/humidity/si7021.js +282 -0
- package/src/chips/imu/bno055.js +496 -0
- package/src/chips/io_expander/pca6408a.js +407 -0
- package/src/chips/io_expander/pca6416a.js +455 -0
- package/src/chips/io_expander/pca9536.js +398 -0
- package/src/chips/io_expander/pca9539.js +457 -0
- package/src/chips/light/max44009.js +336 -0
- package/src/chips/memory/at24c02n.js +220 -0
- package/src/chips/memory/at24c64.js +220 -0
- package/src/chips/memory/cat24c512.js +221 -0
- package/src/chips/other/pca9541.js +315 -0
- package/src/chips/temperature/tmp102.js +361 -0
- package/src/chips/tof/vl6180x.js +580 -0
- package/src/discovery/registry.js +65 -13
|
@@ -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,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); });
|
|
@@ -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); });
|