npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ssd1351

v2.0.0

Published

Node.js module for controlling [OLED SSD1351](https://www.newhavendisplay.com/app_notes/SSD1351.pdf) devices.

Downloads

8

Readme

ssd1351

Node.js module for controlling OLED SSD1351 devices.

pipeline status coverage report Quality Gate

Prerequisites

Wiring

| SSD1351 pin |Raspberry Pi pin|Raspberry Pi GPIO| |----------------|:---------------|:----------------| | GND | 20 | | | VCC (3,3 V) | 17 | | | SCL (SPI_CLK) | 23 | 11 | | SDA (SPI_MOSI) | 19 | 10 | | RES | 22 | 25 | | DC | 18 | 24 | | CS (SPI_CEO_N) | 24 | 8 |

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