ESP32 显示器 — ESP32-S3 simulation

An interactive ESP32-S3 circuit simulation you can run free in your browser on Velxio, by xanderisme.

Components

Sketch code

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

// 定义屏幕尺寸
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

// 声明屏幕对象,使用 I2C 通信
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  // 1. 开启串口,方便看报错
  Serial.begin(115200);
  Serial.println("开始初始化 I2C...");

  // 2. 指定 I2C 引脚为 1(SDA) 和 2(SCL)
  Wire.begin(1, 2);

  // 3. 初始化屏幕(地址通常为 0x3C)
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("屏幕初始化失败,请检查连线!");
    for(;;); // 如果失败就死循环,不让它往下跑
  }

  Serial.println("屏幕初始化成功!");

  // 4. 清屏并设置文字属性
  display.clearDisplay();
  display.setTextSize(2);                 // 字体大小(2号字比较大)
  display.setTextColor(SSD1306_WHITE);    // 白色字体
  display.setCursor(0, 10);               // 设置光标起点 (X, Y)
  
  // 5. 打印文字
  display.println("Hello");
  display.println("123!");
  
  // 6. 执行显示
  display.display();
}

void loop() {
  // 屏幕测试不需要循环做什么事,空着就行
}

More projects by xanderisme