ひらがな表示だけで、結構メモリ使用してしまったので、漢字表示は無理だろうなーと思っていたのですが、8×8の美咲フォントを用いて字数を絞ることで、Arduino Uno(Atmega328)での表示を実現されている方が!
猫にコ・ン・バ・ン・ワ:Arduino用美咲フォントライブラリを作成しました
http://nuneno.cocolog-nifty.com/blog/2016/03/arduino-e818.html
これはすごい!ライブラリも公開されていましたので、watchX で動かしてみます。
案内されている通り、zipファイルと解凍してarduinoのlibrariesフォルダに入れて、Arduino IDE を起動すると「スケッチ」の「ライブラリのインクルード」の一覧に「misakiUTF-16」が追加されます。
表示サンプルの banner.ino を参考にしつつ(というか描画以外ほぼそのまま)日本語表示プログラムを書いてみました。
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
#include <oled.h> | |
#include <misakiUTF16.h> | |
#include <SoftwareSerial.h> | |
#include <SPI.h> | |
unsigned char animation_offsetY=0; | |
// ビットパターン表示 | |
// d: 8ビットパターンデータ | |
// | |
void bitdisp(byte x, byte y, uint8_t d ) { | |
for (byte i=0; i<8;i++) { | |
if (d & 0x80>>i) { | |
if(x + i < 128 && y < 64){ | |
drawPixel(x + i ,y , 1); | |
} | |
} | |
} | |
} | |
// フォントパターンを画面に表示する | |
// 引数 | |
// x,y 表示位置 | |
// pUTF8 表示する文字列 | |
// ※半角文字は全角文字に置き換えを行う | |
// | |
void drawJPChar(byte x, byte y, char * pUTF8) { | |
int n; | |
uint16_t pUTF16[40]; | |
byte buf[20][8]; //160x8ドットのバナー表示パターン | |
n = Utf8ToUtf16(pUTF16, pUTF8); // UTF8からUTF16に変換する | |
// バナー用パターン作成 | |
for (byte i=0; i < n; i++) { | |
getFontDataByUTF16(&buf[i][0], utf16_HantoZen(pUTF16[i])); // フォントデータの取得 | |
} | |
// ドット表示 | |
for (byte i=0; i < 8; i++) { | |
for (byte j=0; j < n; j++){ | |
bitdisp(x + (j * 8) ,y + i , buf[j][i]); | |
} | |
} | |
} | |
void setup() { | |
while (!Serial); | |
delay(500); | |
Serial.begin(115200); | |
SPI.begin(); | |
ssd1306_configure(); | |
clearAll(); | |
drawJPChar(0,0,"教育漢字1006文字"); | |
drawJPChar(0,8,"小学校で習う漢字が"); | |
drawJPChar(0,16,"8x8ドットで表示可能です!"); | |
drawJPChar(0,24,"みさきフォントすごい!"); | |
drawJPChar(0,32,"あいうえおかきくけこさしすせそ"); | |
ssd1306_drawBuffer(0, 0, 128,64, mbuf); | |
} | |
void loop() { | |
} |
やったー!表示できたー!さすがに 8×8 だと単体での判読が厳しい文字もあるけど、文章になればぜんぜん大丈夫ですね。すごい!