○OLEDディスプレイ制御端子
Arduino A4(SDA)、A5(SCL)
Raspberry Pi SDA0、SCL0
○配線
・Arduino
・Raspberry Pi
※OLEDディスプレイの形状は異なります。
○Node.jsモジュールのインストール
次のように操作して、「oled-js」と関連モジュールをインストールします。
①コマンドプロンプト、またはターミナルを起動し、作業用フォルダに移動します。
②「npm install oled-js」と入力します。
③「npm install pngparse png-to-lcd oled-font-5x7」と入力します。
「oled-js」の詳細は、こちらを参照してください。
○プログラム
◇Arduino
・テキスト表示
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var five = require('johnny-five'), | |
board = new five.Board(), | |
Oled = require('oled-js'), | |
font = require('oled-font-5x7'); | |
board.on('ready', function() { | |
console.log('Connected to Arduino, ready.'); | |
var opts = { | |
width: 128, | |
height: 64, | |
address: 0x3C | |
}; | |
var oled = new Oled(board, five, opts); | |
// sets cursor to x = 1, y = 1 | |
oled.setCursor(1, 1); | |
oled.writeString(font, 1, 'Cats and dogs are really cool animals, you know.', 1, true, 2); | |
oled.update(); | |
}); |
・グラフィックス(PNG画像を変換)表示
※上半分が影があるように暗くなっていますが、目視では見えません。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var five = require('johnny-five'), | |
board = new five.Board(), | |
Oled = require('oled-js'), | |
pngtolcd = require('png-to-lcd'); | |
board.on('ready', function() { | |
console.log('Connected to Arduino, ready.'); | |
var opts = { | |
width: 128, | |
height: 64, | |
address: 0x3C | |
}; | |
var oled = new Oled(board, five, opts); | |
pngtolcd('cat.png', true, function(err, bitmap) { | |
oled.buffer = bitmap; | |
oled.update(); | |
}); | |
}); |
◇Raspberry Pi
・テキスト表示
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var raspi = require('raspi-io'); | |
var five = require('johnny-five'); | |
var board = new five.Board({ | |
io: new raspi() | |
}); | |
var Oled = require('oled-js'), | |
font = require('oled-font-5x7'); | |
board.on('ready', function() { | |
console.log('Connected to Arduino, ready.'); | |
var opts = { | |
width: 128, | |
height: 64, | |
address: 0x3C | |
}; | |
var oled = new Oled(board, five, opts); | |
// sets cursor to x = 1, y = 1 | |
oled.setCursor(1, 1); | |
oled.writeString(font, 1, 'Cats and dogs are really cool animals, you know.', 1, true, 2); | |
oled.update(); | |
}); |
・グラフィックス(PNG画像を変換)表示
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var raspi = require('raspi-io'); | |
var five = require('johnny-five'); | |
var board = new five.Board({ | |
io: new raspi() | |
}); | |
var Oled = require('oled-js'), | |
pngtolcd = require('png-to-lcd'); | |
board.on('ready', function() { | |
console.log('Connected to Arduino, ready.'); | |
var opts = { | |
width: 128, | |
height: 64, | |
address: 0x3C | |
}; | |
var oled = new Oled(board, five, opts); | |
pngtolcd('cat.png', true, function(err, bitmap) { | |
oled.buffer = bitmap; | |
oled.update(); | |
}); | |
}); |
0 件のコメント:
コメントを投稿