XIAO ESP32C6+SSD1306で全面表示して遊ぶ。実装編(ガジェットメイドカフェ)


いろいろ、注意
----

- かこログをみろ
- ssd1306を直接操作　ssd1306を理解する?
- カフェでなにを、展示したか。？おぼえて、いないが、まあ~~~いいか?

目的
----

OLEDのテスト



結果(ガジェットメイドカフェ)
----

![image_original(23).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/ed4ffda9-ef38-4355-b2d5-01bd49887c40.jpeg)

プログラム
----

```c++

//有機ELのSSD1306で豆腐を召喚
//秋月のOLEDとアイテンドウのOLEDのアドレスは3c
//SSD1306_all_v_1_XIAO_ESP32C6_1


//ヘッダー
#include <Arduino.h>
#include <Wire.h>
#include "kao_1.h"


//定義
#define MAX_PAGE                   (7)
#define MAX_COL                    (127)

#define COMMAND_MODE               0x80 // continuation bit is set!
#define DATA_MODE                  0x40

#define SET_COLUMN_ADDRESS         0x21 // takes two bytes, start address and end address of display data RAM
#define SET_PAGE_ADDRESS           0x22 // takes two bytes, start address and end address of display data RAM

#define SET_MEMORY_ADDRESSING_MODE 0x20 // takes one byte as given above
#define HORIZONTAL_ADDRESSING_MODE 0x00


//I2Cに配列を転送する
void write_s(uint8_t *str1, uint8_t len1) {

  Wire.beginTransmission(  0x3c  );

  for (int icount = 0; icount < len1; icount++) {

    //一文字出力
    Wire.write(*str1 ++);

  }//for

  Wire.endTransmission();

}//write_s


//セットページアドレス
void setPageAddress(uint8_t start, uint8_t end)
{
  uint8_t databytes[6] = {COMMAND_MODE, SET_PAGE_ADDRESS, COMMAND_MODE, start, COMMAND_MODE, end};
  write_s(databytes, 6);
}//setPageAddress


//セットカラムアクセス
void setColumnAddress(uint8_t start, uint8_t end)
{
  uint8_t databytes[6] = {COMMAND_MODE, SET_COLUMN_ADDRESS, COMMAND_MODE, start, COMMAND_MODE, end};
  write_s(databytes, 6);
}//setColumnAddress


//セットメモリーアドレシングモード
void setMemoryAddressingMode()
{
  uint8_t databytes[4] = {COMMAND_MODE, SET_MEMORY_ADDRESSING_MODE, COMMAND_MODE, HORIZONTAL_ADDRESSING_MODE};
  write_s(databytes, 4);
}//setMemoryAddressingMode


//初期化
void setup() {

  //I2Cの初期化
  Wire.begin(D9,D10); //XIAO ESP32C6+SSD1306
  //Wire.begin(D10,D9); //XIAO ESP32C6+GROVE
  delay(200);

  //SSD1306の初期化スペル(魔法)
  //0x80,0x8D,0x80,0x14,0x80,0xAF
  write_s( (uint8_t*) "\200\215\200\024\200\257", 6);
  delay(100);

  //セットメモリーアドレシングモード (画面の終端に来たら画面の先頭に)
  setMemoryAddressingMode();

  //範囲の設定 (OLED内部のx,yカウンターを初期化してホームポジション0,0に)
  setPageAddress(0, MAX_PAGE);  // all pages
  setColumnAddress(0, MAX_COL); // all columns


  //データの配列の定義
  uint8_t databytes[2] = {DATA_MODE,0x00};

  //画面
  for (int icount = 0; icount < ((128/8)*64); icount++) {
    databytes[1] = kao_1[icount];
    write_s(databytes, 2);
  }//for


}//setup


//メインループ
void loop() {
  delay(3); //dummy
}//loop


```

kao_1.h


```


// 'kao1', 128x512px
const unsigned char kao_1 [] PROGMEM = {

	0x00, 0x00, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xfc, 0xe0, 0xe6, 0xe6, 0xe0, 0xe6, 0xe6, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x70, 0x70, 0x70, 0x00, 0x00, 0x00, 0x00, 0x18, 0x10, 0x00, 0x08, 0x18, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xfc, 0x80, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 
	0xc0, 0xf8, 0xf0, 0xe0, 0xc0, 0xc0, 0xe0, 0x78, 0xfc, 0xfe, 0x7c, 0x38, 0x30, 0x30, 0x78, 0x6c, 
	0x3e, 0x6f, 0x7f, 0x7c, 0x78, 0x70, 0xf8, 0xfc, 0xfe, 0xfe, 0xfc, 0xf8, 0xe0, 0xe0, 0xe0, 0xe0, 
	0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0xc0, 0xf8, 0xfe, 0x1f, 0x07, 0x00, 0x00, 0xc0, 0xf8, 0xff, 0x1f, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x0e, 0x0e, 0x0e, 0x00, 0x00, 0xc0, 0xe0, 0x70, 0x38, 0x18, 0x08, 0x00, 
	0x00, 0x00, 0x00, 0x30, 0xf0, 0xf0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x78, 
	0x00, 0xf8, 0xf8, 0xc0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0x07, 0x06, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0x80, 0xfe, 0xfe, 0x7c, 0x3f, 0x1f, 
	0x0f, 0x8f, 0x47, 0x21, 0x11, 0x08, 0x04, 0x04, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 
	0x02, 0x02, 0x02, 0x02, 0x84, 0xc4, 0xc8, 0xc8, 0x91, 0xa3, 0x47, 0x87, 0x0f, 0x1f, 0x3f, 0xff, 
	0xff, 0xfc, 0xf8, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x01, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x06, 0x06, 0x07, 0x07, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 
	0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x81, 0x00, 0x00, 0x80, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0xf0, 0xef, 0xff, 0x0f, 0xc0, 0x30, 0x0c, 0xc2, 
	0xc1, 0xc0, 0x00, 0xff, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf8, 0xfc, 0xfc, 0x7c, 0x7c, 0x3e, 0x3f, 
	0x1f, 0xcf, 0x8f, 0x1e, 0x1f, 0x1f, 0x07, 0x0f, 0x07, 0x07, 0x03, 0x00, 0x01, 0x06, 0xfc, 0xe8, 
	0x81, 0x07, 0x0f, 0x77, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x70, 0xe0, 0xc0, 0xc0, 0xf0, 0x78, 0x3e, 0x1e, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x70, 0x70, 0x70, 0xf0, 0xf0, 
	0xf8, 0x7c, 0x1c, 0x1e, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0xff, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0x80, 0x00, 0x03, 0x07, 0x00, 0x00, 0x07, 0x07, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0xfc, 0x7f, 0x80, 0x00, 0x01, 
	0x01, 0x01, 0x00, 0xff, 0xfe, 0xe0, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 
	0x80, 0x80, 0x81, 0x83, 0x8c, 0x98, 0x90, 0xe0, 0xc0, 0xc0, 0x80, 0x08, 0x10, 0x20, 0xe0, 0x18, 
	0x07, 0x02, 0x82, 0x82, 0x83, 0x86, 0x08, 0x10, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x40, 0xe0, 0x70, 0x38, 0x1e, 0x0f, 0x07, 0x03, 0x07, 0x07, 0x06, 0x06, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 
	0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x7f, 0x7f, 0x7f, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x1f, 0xf0, 0x00, 
	0xfe, 0xe0, 0x60, 0xa3, 0x3f, 0xbf, 0x7e, 0xbc, 0x3c, 0xfc, 0xfe, 0x7e, 0x7e, 0x7e, 0x3f, 0xef, 
	0xf7, 0xfb, 0xe3, 0x99, 0x7d, 0x46, 0x7c, 0x80, 0xfd, 0x0f, 0x06, 0xf1, 0x55, 0x23, 0x1e, 0xe0, 
	0x80, 0x00, 0x03, 0x7c, 0x40, 0x41, 0x8e, 0xb0, 0xc0, 0xe7, 0x3c, 0xe0, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8, 0xf8, 0x98, 0x80, 0x80, 
	0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x38, 0x38, 0x38, 
	0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xb8, 0xf8, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x19, 0xee, 
	0x37, 0xe6, 0xc6, 0x9f, 0x3c, 0xbb, 0xb0, 0x97, 0x98, 0xdf, 0xc4, 0xe0, 0xff, 0xff, 0xfe, 0xf8, 
	0xf3, 0xf7, 0xf3, 0xfb, 0xfb, 0xf9, 0xfd, 0xfd, 0xfd, 0xfe, 0xff, 0x10, 0x00, 0x00, 0x00, 0x7f, 
	0xc9, 0x97, 0xac, 0x08, 0x18, 0x90, 0xb0, 0xe0, 0x60, 0x37, 0x79, 0x8f, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x83, 0xff, 0xff, 0x1f, 0x07, 0x07, 0x07, 
	0x7f, 0xff, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe0, 0xf0, 0x3c, 0x1e, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0xf0, 0xf0, 0x70, 0x70, 0x70, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 
	0x00, 0x00, 0x00, 0xff, 0x08, 0x17, 0x2f, 0xdf, 0xbf, 0xbf, 0x7f, 0x7f, 0xff, 0xf7, 0xf7, 0xf7, 
	0xf7, 0xf7, 0xf7, 0xfb, 0xfd, 0x7f, 0xbf, 0x5f, 0xaf, 0x57, 0x0b, 0x30, 0xc8, 0x00, 0x00, 0x00, 
	0xff, 0x89, 0x91, 0x03, 0x1f, 0x31, 0xe3, 0x0e, 0x38, 0x60, 0xc0, 0x83, 0x8e, 0x10, 0x20, 0xc0, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0e, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x01, 0x03, 0x07, 0x1f, 0x1e, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 
	0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe0, 0xc0, 0x3f, 
	0xc0, 0x00, 0x00, 0x03, 0x7e, 0xb8, 0x30, 0x1f, 0x1f, 0x18, 0x08, 0x0e, 0xc0, 0xe0, 0xf6, 0xfc, 
	0xc6, 0x3e, 0x1e, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x61, 0x40, 0x60, 0x20, 
	0x1f, 0x01, 0xdf, 0xc3, 0xee, 0x70, 0x31, 0x13, 0x16, 0x98, 0xd8, 0xd0, 0xd1, 0xe2, 0xe2, 0x02

};



```