SSD1306 128x64 OLED 【三】

在不使用Adafruit的Library來試著點SSD1306



一.產生圖形資料

把上圖logo(128x64 bits)轉換成Array data

使用這個網站來轉換 https://javl.github.io/image2cpp/


1. Select Image,匯入圖形檔


2. Image Settings,圖形設定 (沒有要修改的設定)


3. 確認圖形有正常顯示

4. Code output format,選擇 Arduino code, single bitmap

5. Draw mode,選擇 Vertical - 1 bit per pixel

6. 點擊 Generate code產生出陣列資料,然後按 Copy output複製array data



二.Arduino IDE

把下列程式直接複製貼上你的Arduino IDE (上面的logo陣列已經在 NaN[] 裡面)


#include "Wire.h"

const unsigned char NaN [] PROGMEM = {
// 'arduino_logo', 128x64px
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 
0x3f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x3f, 0x0f, 0x07, 
0x07, 0x03, 0x01, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 
0xe0, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x01, 0x01, 0x03, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 
0xff, 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x01, 0x01, 0x03, 
0x07, 0x07, 0x0f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 
0x80, 0xf0, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 
0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 
0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0xf0, 0xfc, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0x7f, 0x7f, 
0x7f, 0x7f, 0x07, 0x07, 0x07, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xf0, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x03, 0x1f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 
0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x0f, 0x07, 0x01, 0x00, 0x00, 0x00, 
0x80, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xf8, 
0xf8, 0xf8, 0xc0, 0xc0, 0xc0, 0xf8, 0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0xe0, 0xc0, 
0x80, 0x80, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 
0x0f, 0x0f, 0x07, 0x07, 0x03, 0x01, 0x01, 0x00, 0x80, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 
0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x80, 0x00, 0x01, 0x01, 0x03, 0x07, 0x07, 0x0f, 
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x80, 
0x80, 0xc0, 0xe0, 0xf8, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 
0xf8, 0xfc, 0xfc, 0xfc, 0xfc, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xf8, 
0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xfc, 0xfe, 0xfe, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x03, 0x00, 
0x70, 0x00, 0x01, 0x0f, 0x7f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x01, 0x81, 0xe7, 
0xff, 0xff, 0x00, 0x00, 0xf8, 0xf8, 0xf8, 0x71, 0x01, 0x03, 0x8f, 0xff, 0x00, 0x00, 0x00, 0xff, 
0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf8, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0xff, 
0xff, 0x00, 0x00, 0x00, 0xe0, 0x83, 0x0f, 0x3f, 0x00, 0x00, 0xff, 0xff, 0x07, 0x01, 0x01, 0xf8, 
0xfc, 0xf8, 0x00, 0x01, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xf8, 0xf8, 0xfe, 
0xfe, 0xfe, 0xfc, 0xf8, 0xf8, 0xff, 0xff, 0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xf8, 0xf8, 0xf8, 0xfb, 
0xff, 0xff, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0xf8, 
0xf9, 0xf9, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xf9, 0xf9, 0xf9, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xff, 
0xff, 0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xfe, 0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0xf9, 
0xf9, 0xf9, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff
};

uint32_t i = 0;
uint32_t j = 0;

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);

  Wire.begin();

  delay(1000);
  
  // 3.Software Configuration as below
  // Set MUX Ratio
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xA8);
  Wire.write(0x3F);
  Wire.endTransmission();
  delay(1);

  // Set Display Offset
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xD3);
  Wire.write(0x00);
  Wire.endTransmission();
  delay(1);

  // Set Display Start Line
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0x40);
  Wire.endTransmission();
  delay(10);

  // Set Segment re-map
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xA0);
  Wire.endTransmission();
  delay(1);

  // Set COM Output Scan Direction
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xC0);
  Wire.endTransmission();
  delay(1);

  // Set COM Pins
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xDA);
  Wire.write(0x02);
  Wire.endTransmission();
  delay(1);

  // Set Contrast
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0x81);
  Wire.write(0x7F);
  Wire.endTransmission();
  delay(1);

  // Disable Entire Display ONn
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xA4);
  Wire.endTransmission();
  delay(1);

   // Set Normal Display
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xA6);
  Wire.endTransmission();
  delay(1); 

  // Set Osc Frequency
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xD5);
  Wire.write(0x80);
  Wire.endTransmission();
  delay(1);

  // Enable charge pump regulator
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0x8D);
  Wire.write(0x14);
  Wire.endTransmission();//00,8D,14
  delay(1);

  // Display ON
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xAF);
  Wire.endTransmission();
  delay(1);
  
    for(i=0; i<8; i++)
  {
    //set PAGEn (n 0~7)
    Wire.beginTransmission(0x3C);
    Wire.write(0x00);
    Wire.write(0x22);
    Wire.write(i);
    Wire.write(0x07);
    Wire.endTransmission();
    delay(1); 
    //Set column to 0
    Wire.beginTransmission(0x3C);
    Wire.write(0x00);
    Wire.write(0x21);
    Wire.write(0x00);
    Wire.write(0x7F);
    Wire.endTransmission();
    delay(1); 

    // Draw Pixels
    Wire.beginTransmission(0x3C);
    Wire.write(0x40);
    for(j=0; j<128; j++)
    {
      Wire.write( NaN[i*128 + j] );
    }
    Wire.endTransmission();
    delay(1);
  }
}

void loop(){

}
  

沒意外的話你已經能看到圖形出現在你的OLED

;但意外還是發生了,圖形並不正確




上列程式的初始設定是照datasheet最後的流程圖寫入的,視乎有些地方需要調整

硬體Set COM Pins Hardware Configuratio (DAh)寫入值由0x02h改為12h

  • A[4]=0b, Sequential COM pin configuration
  • A[4]=1b(RESET), Alternative COM pin configuration
  • A[5]=0b(RESET), Disable COM Left/Right remap
  • A[5]=1b, Enable COM Left/Right remap
  // Set COM Pins
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xDA);
  Wire.write(0x12);
  Wire.endTransmission();
  delay(10);

修改後的結果如下




圖形180度翻轉 (改變COM0到COMn的寫入順序)

Set COM Output Scan Direction寫入值由0xC0h改為C8h

  • C0h, X[3]=0b: normal mode (RESET) Scan from COM0 to COM[N –1]
  • C8h, X[3]=1b: remapped mode. Scan from COM[N-1] to COM0
  • Where N is the Multiplex ratio.

  // Set COM Output Scan Direction
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xC8);
  Wire.endTransmission();
  delay(10);

圖形是轉向了;可卻呈現鏡向的情況


Set Segment Re-map寫入值由A0h改為A1h

  • A0h, X[0]=0b: column address 0 is mapped to SEG0 (RESET)
  • A1h, X[0]=1b: column address 127 is mapped to SEG0
  // Set Segment re-map
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xA1);
  Wire.endTransmission();
  delay(10);

結果



修改後的程式

#include "Wire.h"

const unsigned char NaN [] PROGMEM = {
// 'arduino_logo', 128x64px
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 
0x3f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x3f, 0x0f, 0x07, 
0x07, 0x03, 0x01, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 
0xe0, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x01, 0x01, 0x03, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 
0xff, 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x01, 0x01, 0x03, 
0x07, 0x07, 0x0f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 
0x80, 0xf0, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 
0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 
0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0xf0, 0xfc, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0x7f, 0x7f, 
0x7f, 0x7f, 0x07, 0x07, 0x07, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xf0, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x03, 0x1f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 
0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x0f, 0x07, 0x01, 0x00, 0x00, 0x00, 
0x80, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xf8, 
0xf8, 0xf8, 0xc0, 0xc0, 0xc0, 0xf8, 0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0xe0, 0xc0, 
0x80, 0x80, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 
0x0f, 0x0f, 0x07, 0x07, 0x03, 0x01, 0x01, 0x00, 0x80, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 
0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x80, 0x00, 0x01, 0x01, 0x03, 0x07, 0x07, 0x0f, 
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x80, 
0x80, 0xc0, 0xe0, 0xf8, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 
0xf8, 0xfc, 0xfc, 0xfc, 0xfc, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xf8, 
0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xfc, 0xfc, 0xfc, 0xfe, 0xfe, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x03, 0x00, 
0x70, 0x00, 0x01, 0x0f, 0x7f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x01, 0x81, 0xe7, 
0xff, 0xff, 0x00, 0x00, 0xf8, 0xf8, 0xf8, 0x71, 0x01, 0x03, 0x8f, 0xff, 0x00, 0x00, 0x00, 0xff, 
0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf8, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0xff, 
0xff, 0x00, 0x00, 0x00, 0xe0, 0x83, 0x0f, 0x3f, 0x00, 0x00, 0xff, 0xff, 0x07, 0x01, 0x01, 0xf8, 
0xfc, 0xf8, 0x00, 0x01, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xf8, 0xf8, 0xfe, 
0xfe, 0xfe, 0xfc, 0xf8, 0xf8, 0xff, 0xff, 0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xf8, 0xf8, 0xf8, 0xfb, 
0xff, 0xff, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0xf8, 
0xf9, 0xf9, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xf9, 0xf9, 0xf9, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xff, 
0xff, 0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xfe, 0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0xf9, 
0xf9, 0xf9, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff
};

uint32_t i = 0;
uint32_t j = 0;

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);

  Wire.begin();

  delay(1000);

  // Set MUX Ratio
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xA8);
  Wire.write(0x3F);
  Wire.endTransmission();
  delay(1);

  // Set Display Offset
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xD3);
  Wire.write(0x00);
  Wire.endTransmission();
  delay(1);

  // Set Display Start Line
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0x40);
  Wire.endTransmission();
  delay(1);

  // Set Segment re-map
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xA1);
  Wire.endTransmission();
  delay(1);

  // Set COM Output Scan Direction
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xC8);
  Wire.endTransmission();
  delay(1);

  // Set COM Pins
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xDA);
  Wire.write(0x12);
  Wire.endTransmission();
  delay(1);

  // Set Contrast
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0x81);
  Wire.write(0x7F);
  Wire.endTransmission();
  delay(1);

  // Disable Entire Display ONn
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xA4);
  Wire.endTransmission();
  delay(1);

   // Set Normal Display
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xA6);
  Wire.endTransmission();
  delay(1); 

  // Set Osc Frequency
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xD5);
  Wire.write(0x80);
  Wire.endTransmission();
  delay(1);

  // Enable charge pump regulator
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0x8D);
  Wire.write(0x14);
  Wire.endTransmission();//00,8D,14
  delay(1);

  // Display ON
  Wire.beginTransmission(0x3C);
  Wire.write(0x00);
  Wire.write(0xAF);
  Wire.endTransmission();
  delay(1);
  
  for(i=0; i<8; i++)
  {
    //set PAGEn (n 0~7)
    Wire.beginTransmission(0x3C);
    Wire.write(0x00);
    Wire.write(0x22);
    Wire.write(i);
    Wire.write(0x07);
    Wire.endTransmission();
    delay(1); 
    //Set column to 0
    Wire.beginTransmission(0x3C);
    Wire.write(0x00);
    Wire.write(0x21);
    Wire.write(0x00);
    Wire.write(0x7F);
    Wire.endTransmission();
    delay(1); 

    // Draw Pixels
    Wire.beginTransmission(0x3C);
    Wire.write(0x40);
    for(j=0; j<128; j++)
    {
      Wire.write( NaN[i*128 + j] );
    }
    Wire.endTransmission();
    delay(1);
  }
}

void loop(){

}


水平移動

使用下列兩行指令即可看到畫面水平移動

0x27,0x00,0x00,0x07,0x07,0x00,0xFF

設定水平移動方向,速度,範圍

  • 26h, X[0]=0, Right Horizontal Scroll
  • 27h, X[0]=1, Left Horizontal Scroll

0x2F

  • 啟動滾動


水平及垂直移動

使用下列兩行指令即可看到畫面水平移動

0x29 0x00 0x00 0x07 0x07 0x01

設定水平及垂直移動方向,速度,範圍

  • 29h, X1X0=01b : Vertical and Right Horizontal Scroll
  • 2Ah, X1X0=10b : Vertical and Left Horizontal Scroll

0x2F

  • 啟動滾動




(1) SSD1306 128x64 OLED 【一】I2C版本
(2) SSD1306 128x64 OLED 【二】 Datasheet