Code uploaded successfully. But the screen doesn't display according to the code

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define I2C_ADDRESS 0x3C

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  Serial.begin(9600);
  Wire.begin(D2, D1);
  
  if (!display.begin(SSD1306_SWITCHCAPVCC, I2C_ADDRESS)) {
    Serial.println(F("OLED ไม่พร้อมทำงาน!"));
    for (;;);
  }
  
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.print(F("Hello, World!"));
  display.display();
}

void loop() {
}

Selecting the correct library usually the solution. Your OLED might not have the hardware for SH1306. Show a good picture of the components on the reverse side.

1 Like

That screen pattern is what you get when you use a SSD1306 library with an SH1106G controller. Use the proper library.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.