2.0.0 • Published 3 years ago

ssd1351 v2.0.0

Weekly downloads
2
License
MIT
Repository
gitlab
Last release
3 years ago

ssd1351

Node.js module for controlling OLED SSD1351 devices.

pipeline status coverage report Quality Gate

Prerequisites

Wiring

SSD1351 pinRaspberry Pi pinRaspberry Pi GPIO
GND20
VCC (3,3 V)17
SCL (SPI_CLK)2311
SDA (SPI_MOSI)1910
RES2225
DC1824
CS (SPI_CEO_N)248

Installation

npm install ssd1351

Available Properties

RawData

Sets or gets the array of bits to be displayed on the OLED screen.

Remark : This method can be used to display an image directly on the oled screen. In the below example, the library jimp - MIT is used to resize the picture.

Usage:

const Jimp = require("jimp");
const height = 128, width = 128;
let i = 0;
const pixelsBuffer = Array.from({ length: height * width * 2 });
const myImage = await Jimp.read(path.join(__dirname, "testPicture.png"));
await myImage.rgba(false);
myImage.resize(height, width)
    .scan(0, 0, height, width, function (x, y, idx) {
        const bytes = Ssd1351.convertRgbColourToRgb565(this.bitmap.data[idx + 0], this.bitmap.data[idx + 1], this.bitmap.data[idx + 2], this.bitmap.data[idx + 3]);
        pixelsBuffer[idx / 2] = bytes[0];
        pixelsBuffer[idx / 2 + 1] = bytes[1];
        if (0 === idx) {
            console.info('convert rgb colour to rgb 565 bit colour');
        }
        else if (height * width === idx / 4) {
            resolve(pixelsBuffer);
        }
    });

console.info('draw image');
ssd1351.RawData = pixelsBuffer;

const pixelsBuffer = ssd1351.RawData;

await ssd1351.setCursor(0, 0);
await ssd1351.updateScreen();

Available Methods

convertHexColourToRgb

Converts hexadecimal colour code to a rgb colour code.

Usage:

Ssd1351.convertHexColourToRgb('#FF530D'); // Returns { r: 255, g: 83, b: 13 }

convertRgbColourToRgb565

Converts rgb colour code to the a 16 bits colour code compatible with the oled screen.

Usage:

Ssd1351.convertRgbColourToRgb565(128, 128, 128); // Returns [ 132, 16 ]

drawCanvas

Converts a canvas generated by Cairo to a bytes array and saves it in the application memory buffer.
Remark : This method only writes the string in the application buffer. Use updateScreen to update the oled display content.

Usage:

//Creates a canvas context using 'canvas'
const { createCanvas } = require('canvas');
const ssd1351 = new Ssd1351();
ssd1351.clearDisplay();

const canvas = createCanvas(128, 128);
const ctx = canvas.getContext('2d', { pixelFormat: 'RGB16_565' });

const textToDisplay = "myDisplayedText";
const textMeasures = ctx.measureText(textToDisplay);
ctx.fillText(textToDisplay, 0, textMeasures.actualBoundingBoxAscent);

//Copy the canvas image to the application memory buffer
ssd1351.drawCanvas(ctx)

drawLine

Draws a line with the specified colour and saves it in the application memory buffer.
Remark : This method only writes the string in the application buffer. Use updateScreen to update the oled display content.

Usage:

await ssd1351.drawLine(0, 0, 127, 127); // Draws a white line from the top left corner of the screen to the bottom right.
await ssd1351.drawLine(0, 0, 127, 127,Ssd1351.convertHexColourToRgb('#FF530D')); // Draws a red line from the top left corner of the screen to the bottom right.

drawCircle

Draws a circle with the specified colour and saves it in the application memory buffer.
Remark : This method only writes the string in the application buffer. Use updateScreen to update the oled display content.

Usage:

ssd1351.drawCircle(63, 63, 63); // Draws a white circle.
ssd1351.drawCircle(63, 63, 63, Ssd1351.convertHexColourToRgb('#FF530D')); // Draws a red circle.

fillCircle

Fills the interior of a circle with the specified colour and saves it in the application memory buffer.
Remark : This method only writes the string in the application buffer. Use updateScreen to update the oled display content.

Usage:

ssd1351.fillCircle(63, 63, 32); // Colours in white the interior of the circle.
ssd1351.fillCircle(63, 63, 32, Ssd1351.convertHexColourToRgb('#FF530D')); // Colours in red the interior of the circle.

drawRectangle

Draws a rectangle with the specified colour and saves it in the application memory buffer.
Remark : This method only writes the string in the application buffer. Use updateScreen to update the oled display content.

Usage:

ssd1351.drawRectangle(32, 32, 64, 64); // Draws the white borders of the rectangle.
ssd1351.drawRectangle(32, 32, 64, 64, Ssd1351.convertHexColourToRgb('#FF530D')); // Draws the red borders of the rectangle.

fillRectangle

Fills the interior of a rectangle with the specified colour and saves it in the application memory buffer.
Remark : This method only writes the string in the application buffer. Use updateScreen to update the oled display content.

Usage:

ssd1351.fillRectangle(48, 48, 32, 32); // Colours in white the interior of the rectangle.
ssd1351.fillRectangle(48, 48, 32, 32,Ssd1351.convertHexColourToRgb('#FF530D')); // Colours in red the interior of the rectangle.

getCursor

Gets current cursor position as an object {x,y}.

Usage:

ssd1351.getCursor(); // Returns for example{ x:64, y: 40}

setCursor

Sets the current cursor position.

Usage:

ssd1351.setCursor(0, 0); // Sets the cursor position : 1 row, 1 column

setVerticalScroll

Sets the row to be displayed at the top of the screen. This method can be used to scroll vertically the content of the screen.

Usage:

await ssd1351.setVerticalScroll(10);

turnOffDisplay

Turn off the display.

Usage:

await ssd1351.turnOffDisplay();

turnOnDisplay

Turns on the display. Per default the contrast is set to the maximum.

Usage:

const Ssd1351 = require('ssd1351').Ssd1351;
const ssd1351 = new Ssd1351();
await ssd1351.turnOnDisplay(); // Maximum brightness
await ssd1351.turnOnDisplay(0x10); // Reduced brightness

updateScreen

Writes the application buffer to the oled GDDRAM (Graphic Display Data RAM). Call this method to update the oled display content.

Usage:

await ssd1351.updateScreen(); // The display is refreshed

writeString

Writes the specified string given in parameter at the current cursor position. The parameters colour,wrap, padding and background colour are optional. Remark : This method only writes the string in the application buffer. Use updateScreen to update the oled display content.

Usage:

await ssd1351.writeString(oledFont5x7, 4, '12:12', { r: 255, g: 255, b: 255 }); // Writes in white the string 12:12 with the pixel font 'oledFont5x7', the character size '4'
await ssd1351.writeString(oledFont5x7, 4, '12:12', { r: 255, g: 255, b: 255 },undefined,undefined,{ r: 128, g: 128 , b: 128 }); // Writes in white the string 12:12 with the pixel font 'oledFont5x7', the character size '4'.

Credits

2.0.0

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.6-beta2

5 years ago

0.1.6-beta1

5 years ago

0.1.6-beta

5 years ago

0.1.6-alpha

5 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago