↑SSD1306を点灯させた所
小 型の有機EL、品番SSD1306を動かしてみました。
液晶ディスプレイと似ていますが、発光する性質があるので、暗闇でもバックライトなしで使う事が出来ます。
今回点灯させたのは、アマゾンで安価で出回っている、SSD1306です。
横128ピクセル×縦64ピクセルと、ブレッドボードにささる小さい有機ELです。
こ の有機EL、アマゾンの写真は同じですが、「SPI通信で動くタイプ、I2C通信で動くタイプ」があります。
さらに、表示色が「青色のみ、白色のみ、青黄の2色」の3種類ががあります。
写真だと分からないので、購入する際は注意する必要があります。
今回購入したのは、 「SPI通信で動くタイプ」「青黄の2色」 を購入しました。
HiLetgo 0.96" SPI シリアル 128×64 OLED LCDディスプレイSSD1306液晶 STM32/51/MSP430/Arduinoに対応 ブルーイエロー [並行輸入品]
購 入してから分かったのですが、「SPI通信で動くタイプ」は、裏の抵抗を取り替えれば、I2Cタイプとしても動くようです。
SPI通信用としていますが、もとはI2Cでも使え、配線でどちらか一方を選べるようになっています。
表示色の青黄は、上が黄色、下が青色と、色の部分が決まっているため、ドット画を表示させると、上の写真のようにツートンカラーになってしまいました。
ドット絵を表示させるなら、青色のみ又は白色のみを購入する事を、お勧めします。
点 灯させる電子回路はモジュールなので、写真のとおり簡単です。
配線は、SPI通信です。
↑SIP通信の配線
プログラムも、Arduinoのライブラリーを使っているので、ライブラリーをダウンロードし、サンプルスケッチを書き込めば、すんなりサンプルプログラムが表示されます。
ライブラリーは、次の3つが必要でした。
古いArduinoの開発環境のため、@ABの3つのライブラリーが必要でしたが、新しい開発環境では@Aの2つですむようです。
■必要なライブラリー
(GitHubからZipをダウンロードし、Arduinoでインクルードします。)
@Adafruit SSD1306 by Adafruit
AAdafruit GFX Library by Adafruit
BAdafruit_BusIO by Adafruit
■プログラム
サンプルプログラムでいらないものを、ごっそり削除し、ドット絵のデータを「ほのか(当店のマスコットキャラクタ)」にしただけです。
長いですが、ほとんどドットデータです。
SSD1306は、ドットマトリクスLEDと違い、ドット以外にも、文字も表示できる ので、取り扱いが簡単です。
■ドットデータ
ほのかのドットデータは、依然に液晶ディスプレイで作ったデータ(WD-G2406B グラフィック液晶ディスプレイの点灯実験) を利用しました。
サイズが違うので、一部修正しています。
エクセルでドット絵を描き、0と1のデータに変換し、Arduinoへ貼り付けています。
■動画(Youtube)
電子キットの文字と、ほのかの画像が交互に表示されます。
ほのかのドット画のセンスは、これが限界です。
VIDEO
有機EL SSD1306の、サンプルプログラムです。
流石センスがあります。
VIDEO
【I2Cバージョンを使った、ビットマップ画像を表示】
I 2Cバージョンを使ってみました。
I2CはSPIよりも描画速度が遅い事になっていますが、今回の場合は問題ありません。
配線が少なく入手性も良いので、I2Cバージョンも作ってみました。
■電子回路
写真のとおり、非常にシンプルです。
■プログラム
ほ とんどSPIと同じです。
気をつける点は、スレーブ番号と端子です。
今回使ったモジュールのスレーブ番号は、0x3cでした。
/**************************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x64 pixel display using I2C to communicate
3 pins are required to interface (two I2C and one reset).
Adafruit invests time and resources providing this open
source code, please support Adafruit and open-source
hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries,
with contributions from the open source community.
BSD license, check license.txt for more information
All text above, and the splash screen below must be
included in any redistribution.
**************************************************************************/
#include
#include
#include
#include
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3c ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 64
#define LOGO_WIDTH 128
void setup() {
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
// Draw a single pixel in white
display.drawPixel(10, 10, SSD1306_WHITE);
display.display();
delay(2000);
}
void testdrawstyles(void) {
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.println(F(" "));
display.println(F("FOR BEGINNERS"));
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.println(F("DENSHIKIT"));
display.display();
delay(1000);
}
static const unsigned char PROGMEM logo_bmp[] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xde, 0xde, 0xdb, 0x7d, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0x65, 0x6b, 0x6e, 0xc6, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xdf, 0xdd, 0xb5, 0xbb, 0x57, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0x65, 0x66, 0xde, 0xdb, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfb, 0x77, 0xb6, 0xcb, 0x69, 0x75, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xad, 0x5b, 0x7a, 0xde, 0xb6, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x56, 0xea, 0xed, 0xad, 0xeb, 0xeb, 0x7f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x5b, 0x5b, 0xb6, 0xd6, 0x7a, 0xbb, 0x7f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x6a, 0xdb, 0xbb, 0x7b, 0x5b, 0x5b, 0xbf, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xb7, 0x55, 0x55, 0xd5, 0xad, 0xbd, 0x5f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfa, 0xd5, 0xae, 0xef, 0xae, 0xfa, 0xc6, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf7, 0x7e, 0xeb, 0x34, 0xf5, 0x2e, 0xeb, 0x4f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfb, 0x4a, 0x6d, 0xae, 0x9f, 0xb6, 0xba, 0xf7, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xed, 0xb6, 0xee, 0xd7, 0x72, 0xdb, 0x6f, 0x1f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfb, 0x5d, 0xeb, 0xd9, 0xdd, 0x55, 0xd9, 0xeb, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xcd, 0xad, 0xed, 0x55, 0x6e, 0xde, 0xad, 0x6f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xee, 0xab, 0xeb, 0x5b, 0xb6, 0xcb, 0x56, 0xa7, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xb5, 0x5b, 0xed, 0xec, 0x93, 0x6a, 0xeb, 0xb5, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xdb, 0x77, 0xf5, 0x66, 0xde, 0xb7, 0x5d, 0x5b, 0xef, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x56, 0xb7, 0xf6, 0xbb, 0x65, 0x93, 0x65, 0xed, 0xbf, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf6, 0xaf, 0xf5, 0x45, 0x34, 0xdb, 0x5d, 0x75, 0xdf, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x5a, 0xdf, 0xfa, 0xf7, 0xdb, 0xd1, 0x67, 0xae, 0x6f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x76, 0x4f, 0xfa, 0x99, 0xaa, 0x6d, 0x98, 0xfa, 0xb7, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x9d, 0xdf, 0xfd, 0x6c, 0xa7, 0x3c, 0xee, 0xa8, 0x5f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0xc8, 0xdf, 0xfd, 0x56, 0xf1, 0x96, 0xa6, 0xeb, 0x4f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x7e, 0xbf, 0xfe, 0xaf, 0x3c, 0xaa, 0x53, 0x65, 0x27, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xa4, 0xbf, 0xff, 0x91, 0x97, 0x4b, 0xdd, 0x95, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0xbb, 0x3f, 0xff, 0xca, 0xd3, 0x00, 0x45, 0xc6, 0xbf, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xd9, 0xbf, 0xff, 0xea, 0xfa, 0x40, 0x31, 0x76, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfc, 0x6a, 0x7c, 0x0f, 0xf2, 0x14, 0xc4, 0x8e, 0xdb, 0x3f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x9d, 0xf8, 0x03, 0xff, 0xef, 0x92, 0x45, 0x6a, 0xdf, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0xd4, 0xf2, 0x00, 0xff, 0xff, 0x80, 0x67, 0x5a, 0xdf, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0xd4, 0xe6, 0x00, 0xff, 0xff, 0xaa, 0x33, 0xde, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x7a, 0xc4, 0x53, 0xff, 0xff, 0x51, 0x30, 0xb5, 0x5f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfd, 0x25, 0x8e, 0x89, 0xff, 0xff, 0x04, 0xba, 0xbb, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xb5, 0x9c, 0x44, 0xff, 0xff, 0xea, 0x3a, 0xdc, 0x5f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0xdb, 0x1c, 0x52, 0xff, 0xff, 0xf1, 0x7e, 0xd7, 0x6f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0xa9, 0x3f, 0xa4, 0xff, 0xff, 0xf5, 0xbe, 0xba, 0xbf, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0x5b, 0x3f, 0xe9, 0xff, 0xff, 0xea, 0xbf, 0x7d, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x6d, 0xbf, 0xc6, 0xff, 0xff, 0xea, 0xfe, 0xce, 0xbf, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x57, 0xff, 0xd3, 0xff, 0xff, 0xdf, 0xfe, 0x66, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x55, 0xff, 0xcc, 0xfe, 0xff, 0xfe, 0xfb, 0xaa, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x6c, 0xff, 0x7b, 0xfd, 0xff, 0xff, 0xff, 0x55, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x57, 0x7f, 0xbf, 0xff, 0xff, 0xff, 0xfa, 0xd6, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x52, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xd5, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x5a, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xf9, 0x54, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xa3, 0x1f, 0xff, 0xfb, 0xbf, 0xff, 0xfd, 0x67, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xa9, 0xcf, 0xff, 0xfc, 0xff, 0xff, 0xfc, 0x95, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xea, 0x5f, 0xff, 0xff, 0xff, 0xff, 0xe6, 0xd5, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xa5, 0x4f, 0xff, 0xff, 0xff, 0xff, 0xd9, 0x56, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xd4, 0x9f, 0xff, 0xff, 0xff, 0xff, 0x94, 0x93, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xd2, 0xcf, 0xff, 0xff, 0xff, 0xfc, 0x4b, 0x4a, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe8, 0x47, 0xff, 0xff, 0xff, 0xd3, 0x51, 0x6b, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xef, 0x69, 0xff, 0xff, 0xfe, 0xa5, 0x2d, 0x94, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf1, 0x16, 0x05, 0xff, 0xf0, 0x19, 0x52, 0x6a, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf4, 0xc1, 0x74, 0x0a, 0xa0, 0xa5, 0x53, 0x2b, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfa, 0x5a, 0x13, 0x0f, 0xb4, 0x32, 0x22, 0x91, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xeb, 0x21, 0xa4, 0x2f, 0xe5, 0x95, 0xa8, 0xd6, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xed, 0x4e, 0x55, 0x9a, 0xf1, 0x4a, 0x4b, 0x2a, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe7, 0xa2, 0x90, 0x9d, 0x6c, 0xa1, 0x29, 0xb2, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf7, 0xe8, 0x5d, 0x4f, 0xd5, 0x2a, 0x94, 0x9a, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xeb, 0xdb, 0x42, 0x47, 0xc2, 0xb5, 0x42, 0xa4, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf1, 0xe1, 0x15, 0x5e, 0xd4, 0x12, 0x5d, 0x15, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xec, 0xec, 0xc4, 0x47, 0xd3, 0x89, 0x44, 0xe4, 0xff, 0xff, 0xff, 0xff
};
void testdrawbitmap(void) {
display.clearDisplay();
display.drawBitmap(
(display.width() - LOGO_WIDTH ) / 2,
(display.height() - LOGO_HEIGHT) / 2,
logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
display.display();
delay(1000);
}
void loop() {
testdrawstyles(); // Draw 'stylized' characters
testdrawbitmap(); // Draw a small bitmap image
}}
■ドットデータ
自力で書くのは辛いので、イメージコンバーターを使いました。
カラーのイメージ画像を、ペイントソフトでモノクロ画像にし、形を修正します。
イメージコンバーター のオプション(Conversion)で、「PresetをColor ,モノトーン」「PrepareをType:Color,Main Scan Direction:Top to Bottom」「ImageをBlock type:16Bit」に、書き出します。
書き出した配列だけコピーし、プログラムの配列に書き込みました。
(2021年6月26日(土)作成、2021年7月4日(日)加筆)