Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c423fb7
Update oled.js
baltazorr Aug 31, 2016
4d529d7
Update README.md
baltazorr Aug 31, 2016
7ea6fc3
Update package.json
baltazorr Aug 31, 2016
984c642
Update README.md
baltazorr Sep 1, 2016
0899562
Update oled.js
baltazorr Sep 1, 2016
de01770
Update README.md
baltazorr Sep 1, 2016
e424ad9
Error fix
Nov 15, 2016
606fa05
Update oled.js
Nov 15, 2016
74f19fb
Merge pull request #1 from FeelTheLemon/patch-1
baltazorr Nov 15, 2016
33ebbd1
Made it work with NodeJS 6.9.1 on arm7l (Orange Pi)
haraldkubota Nov 26, 2016
e9cacb6
Adding sample: clock
haraldkubota Nov 26, 2016
b0ee271
Adding README.md and cleaned up example clock program
haraldkubota Nov 28, 2016
18aa18a
Merge pull request #2 from haraldkubota/master
baltazorr Nov 29, 2016
21fd9ad
Compatibility with older version as Node.js 6.0.0
Nov 29, 2016
52fda01
Compatibility with older version as Node.js 6.0.0
baltazorr Nov 29, 2016
4da48ce
Update version
baltazorr Nov 29, 2016
3ed12ab
Fix setTimeout bug in busy check. Fix bug in writeString that adds ex…
bnielsen1965 Jul 4, 2017
53d938a
Added linespacing and letterspacing as options and fixed bugs in offs…
bnielsen1965 Jul 6, 2017
dea312d
Fix bug where writes to display could start before asynchronous initi…
bnielsen1965 Aug 13, 2017
6720d51
Merge pull request #3 from bnielsen1965/master
baltazorr Aug 19, 2017
d5b9686
Speed up page update on display and page clear
laurbadescu Feb 18, 2018
5ab0550
Merge pull request #5 from laurbadescu/patch-1
baltazorr Feb 19, 2018
6d74778
Added drawRGBAImage() method with examples and documentation.
bnielsen1965 Aug 20, 2018
03e239f
Merge pull request #6 from bnielsen1965/master
baltazorr Dec 10, 2018
a7e2ada
readme update
tjgionet Jan 22, 2019
caa339b
Merge pull request #7 from tjgionet/master
baltazorr Jan 23, 2019
63e57be
examples/clock.js: Failsafe checks for I2C bus
leon-anavi Oct 13, 2019
4f32bc0
Merge pull request #8 from leon-anavi/fix-ENOENT
baltazorr Oct 17, 2019
ed1c32a
center vertically the clock
gasp Mar 23, 2020
92534bc
Merge pull request #9 from gasp/patch-2
baltazorr Aug 3, 2020
6736960
Enhancement to add support for larger fonts.
lynniemagoo Dec 6, 2020
bf36c87
Merge pull request #10 from lynniemagoo/master
baltazorr Dec 7, 2020
f06dbdd
feature: add support for sh1106
hadifikri May 4, 2023
dea27bc
Merge pull request #13 from hadifikri/master
baltazorr May 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 137 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
![‘npm version’](http://img.shields.io/npm/v/oled-js.svg?style=flat) ![‘downloads over month’](http://img.shields.io/npm/dm/oled-js.svg?style=flat)

OLED JS Pi
OLED JS Pi over i2c-bus
========================

![oled-cat](http://f.cl.ly/items/2G041X2C1o2A1n2D3S18/cat-oled.png)

## What is this?

A NodeJS driver for I2C/SPI compatible monochrome OLED screens; to be used on the Raspberry Pi! Works with 128 x 32, 128 x 64 and 96 x 16 sized screens, of the SSD1306 OLED/PLED Controller (read the [datasheet here](http://www.adafruit.com/datasheets/SSD1306.pdf)).
This is fork of package [`oled-js-pi`](https://github.com/kd7yva/oled-js-pi) that works thru `i2c-bus` package and not use package `i2c`.

A NodeJS driver for I2C/SPI compatible monochrome OLED screens; to be used on the Raspberry Pi! Works with 128 x 32, 128 x 64 and 96 x 16 sized screens, of the SSD1306/SH1106 OLED/PLED Controller (read the [datasheet here](http://www.adafruit.com/datasheets/SSD1306.pdf)).

This based on the Blog Post and code by Suz Hinton - [Read her blog post about how OLED screens work](http://meow.noopkat.com/oled-js/)!

OLED screens are really cool - now you can control them with JavaScript!

## Install

Raspberry Pi allows for software I2C. To enable software I2C, add `dtoverlay=i2c-gpio,bus=3` to `/boot.config.txt`. The software I2C would be available on `bus` no `3`
where the `SDA` is on pin `GPIO23`/`BCM 16` and `SCK` is on pun `GPIO24`/`BCM 18`.

If you haven't already, install [NodeJS](http://nodejs.org/).

`npm install oled-js-pi`
`npm install oled-i2c-bus`

For `SH1106`, if you get an error:
```
"Error: , Remote I/O error"
```

You might have to lower the baudrate by adding the following line to `/boot/config.txt` and rebooting the Pi
```
dtparam=i2c_baudrate=10000
```

This is a known issue with Raspberry Pi as noted in [Raspberry Pi I2C hardware bug](https://github.com/fivdi/i2c-bus/issues/36). Alternatively, use software I2C.

## I2C screens
Hook up I2C compatible oled to the Raspberry Pi. Pins: SDL and SCL
Hook up I2C compatible oled to the Raspberry Pi. Pins: SDA and SCL

### I2C example

```javascript
var oled = require('oled-js-pi');
var i2c = require('i2c-bus');
var oled = require('oled-i2c-bus');

var opts = {
width: 128,
height: 64,
address: 0x3D
address: 0x3D,
bus: 1,
driver:"SSD1306"
};

var oled = new oled(opts);
var i2cbus = i2c.openSync(opts.bus)
var oled = new oled(i2cBus, opts);

// do cool oled things here

Expand Down Expand Up @@ -125,7 +144,7 @@ Draws a filled rectangle.

Arguments:
+ int **x0, y0** - top left corner of rectangle
+ int **x1, y1** - bottom right corner of rectangle
+ int **w, h** - width and height of rectangle
+ int **color** - can be specified as either 0 for 'off' or black, and 1 or 255 for 'on' or white.

Optional bool as last argument specifies whether screen updates immediately with result. Default is true.
Expand Down Expand Up @@ -172,6 +191,48 @@ pngtolcd('nyan-cat.png', true, function(err, bitmap) {
});
```

### drawRGBAImage
Draw an RGBA coded image at specific coordinates. This only supports a monochrome
OLED so transparent pixels must be 100% transparent, off pixels should have an
RGB value of (0, 0, 0), and pixels with any color value will be considered on.

Use a library such as [pngjs](https://www.npmjs.com/package/pngjs) to read a png
file into the required rgba data structure.

Example:
```JavaScript
const fs = require('fs');
const PNG = require('pngjs').PNG;
const i2c = require('i2c-bus');
const oled = require('oled-i2c-bus');

var i2cBus = i2c.openSync(0);

var opts = {
width: 128,
height: 64,
address: 0x3C
};

var display = new oled(i2cBus, opts);

display.clearDisplay();
display.turnOnDisplay();

fs.createReadStream('./test.png')
.pipe(new PNG({ filterType: 4 }))
.on('parsed', function () {
setInterval(() => { drawImage(this) }, 1000);
});

function drawImage(image) {
let x = Math.floor(Math.random() * (display.WIDTH) - image.width / 2);
let y = Math.floor(Math.random() * (display.HEIGHT) - image.height / 2);
display.drawRGBAImage(image, x, y);
}
```


### startScroll
Scrolls the current display either left or right.
Arguments:
Expand Down Expand Up @@ -232,10 +293,76 @@ oled.setCursor(1, 1);
oled.writeString(font, 1, 'Cats and dogs are really cool animals, you know.', 1, true);
```

Checkout https://www.npmjs.com/package/oled-font-pack for all-in-one font package.

### update
Sends the entire buffer in its current state to the oled display, effectively syncing the two. This method generally does not need to be called, unless you're messing around with the framebuffer manually before you're ready to sync with the display. It's also needed if you're choosing not to draw on the screen immediately with the built in methods.

Usage:
```javascript
oled.update();
```

### battery
Draw a battery level in percentage indicator. This method allows for up to 4 different states of the battery:
- 0 bar : battery < 10%
- 1 bar : 10% >= battery < 40%
- 2 bar : 40% >= battery < 70%
- 3 bar : battery >= 70%

Arguments:
* int **x** - start column
* int **y** - start row
* int **percentage** - battery level percentage

usage:
```javascript
// args: (x,y,percentage)
oled.battery(1,1,20);
```

### bluetooth
Draw a bluetooth icon

usage:
```javascript
//args: (x,y)
oled.bluetooth(1,1);
```

### wifi
Draw a WiFi signal strength in percentage indicator. This method allows for up to 4 different signal strength of the WiFi signal:
- 0 bar : signal < 10%
- 1 bar : 10% >= signal < 40%
- 2 bar : 40% >= signal < 70%
- 3 bar : signal >= 70%

Arguments:
* int **x** - start column
* int **y** - start row
* int **percentage** - signal strength in percentage

usage:
```javascript
// args: (x,y,percentage)
oled.wifi(1,1,20);
```

### image
A wrapper for `drawRGBAImage` that supports a fix animation. The animation always start from `x=1` and `y=1`.

Arguments:
* int **x** - start column (ignored on `animation = true`)
* int **y** - start row (ignored on `animation=true`)
* string **image** - full path to the image or the filename of the image in the `resources` folder
* object **font** - font to draw "error" message
* boolean **clear** - clear the display before the draw
* boolean **reset** - stop all animations
* boolean **animated** - enable/disable animation
* boolean **wrapping** - enable/disable of the error message wrapping

usage:
```javascript
var font = require('oled-font-pack')
oled.image(1,1,'rpi-frambuesa.png',font.oled_5x7,true,false,false,true);
```
Loading