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
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
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Suz Hinton

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
88 changes: 82 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ OLED JS Pi

## 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)).
A NodeJS driver for I2C/SPI compatible monochrome OLED screens. Only I2C is supported at this time.
Compatible with Raspberry Pi, Works with 128 x 32, 128 x 64, 96 x 16 and 64x48 sized screens, of the SSD1306 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/)!

Expand All @@ -17,30 +18,67 @@ OLED screens are really cool - now you can control them with JavaScript!

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

`npm install oled-js-pi`
`npm install oled-ssd1306-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: SDL and SCL.

### I2C example

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

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

var oled = new oled(opts);

// do cool oled things here
```

The above code uses the default I2C address of 0x3C and the I2C device /dev/i2c-1 (default on newer Raspberry Pi boards).

Additional options that can be passed, with default values shown:

```javascript
var opts = {
width: 128, // screen width
height; 32, // screen height
address: 0x3C, // Pass I2C address of screen if it is not the default of 0x3C
device: '/dev/i2c-1', // Pass your i2c device here if it is not /dev/i2c-1
microview: true, // set to true if you have a microview display
};
```

Allowable combinations for screen width and height are:
128x32, 128x64, 96x16 and 64x48.

### Wait, how do I find out the I2C address of my OLED screen?
Check your screen's documentation...

You can use the i2c npm library for this. Make sure the display is connected to the I2C bus with pull-ups and run the
following:

```
npm install i2c
```

Then run the following script:

```javascript
var i2c = require('i2c');
var address = 0x3C;
var wire = new i2c(address, {device: '/dev/i2c-1'});

wire.scan(function(err, data) {
// result contains an array of addresses
});
```

This will return the I2C addresses of any I2C devices connected to the bus at /dev/i2c-1. If you have other devices
than the screen attached, you will need to manually filter those out.

## Available methods

Expand Down Expand Up @@ -136,6 +174,40 @@ Usage:
oled.fillRect(1, 1, 10, 20, 1);
```

### drawRect
Draws an empty rectangle.

Arguments:
+ int **x0, y0** - top left corner of rectangle
+ int **x1, y1** - bottom right corner 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.

Usage:
```javascript
// args: (x0, y0, x1, y1, color)
oled.drawRect(1, 1, 10, 20, 1);
```

### drawCircle
Draws an empty circle.

Arguments:
+ int **x** - x of circle's center
+ int **y** - y of circle's center
+ int **r** - radius of circle
+ 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.

Usage:
```javascript
// args: (x, y, r, color)
oled.drawCircle(30, 10, 5, 1);
```


### drawBitmap
Draws a bitmap using raw pixel data returned from an image parser. The image sourced must be monochrome, and indexed to only 2 colors. Resize the bitmap to your screen dimensions first. Using an image editor or ImageMagick might be required.

Expand Down Expand Up @@ -214,6 +286,7 @@ Arguments:
+ string **text** - the actual text you want to show on the display.
+ int **color** - color of text. Can be specified as either 0 for 'off' or black, and 1 or 255 for 'on' or white.
+ bool **wrapping** - true applies word wrapping at the screen limit, false for no wrapping. If a long string without spaces is supplied as the text, just letter wrapping will apply instead.
+ int **linespacing** - amount of spacing between lines of text on the screen. Negative numbers are also ok.

Optional bool as last argument specifies whether screen updates immediately with result. Default is true.

Expand All @@ -239,3 +312,6 @@ Usage:
```javascript
oled.update();
```

Forked from https://github.com/kd7yva/oled-js-pi

Loading