Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- // Pin definitions for SSD1306 OLED display connections
- // OLED display pin labels: VCC, GND, D0, D1, RES, DC, CS
- // ESP32 DEVKIT V1 connections:
- #define OLED_CLK 18 // D0 - GPIO18 (VSPI CLK)
- #define OLED_MOSI 23 // D1 - GPIO23 (VSPI MOSI)
- #define OLED_RESET 17 // RES - GPIO17
- #define OLED_DC 5 // DC - GPIO5
- #define OLED_CS 19 // CS - GPIO19 (VSPI CS0)
- // Display dimensions (128x64 is common for SSD1306 OLEDs)
- #define SCREEN_WIDTH 128
- #define SCREEN_HEIGHT 64
- // Initialize the display
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
- OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
- void setup() {
- Serial.begin(115200);
- Serial.println("ESP32 OLED Test");
- // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
- if(!display.begin(SSD1306_SWITCHCAPVCC)) {
- Serial.println(F("SSD1306 allocation failed"));
- for(;;); // Don't proceed, loop forever
- }
- // Clear the buffer
- display.clearDisplay();
- // Show initial display buffer contents on the screen
- display.display();
- delay(2000); // Pause for 2 seconds
- // Display text
- display.clearDisplay();
- display.setTextSize(1); // Normal 1:1 pixel scale
- display.setTextColor(SSD1306_WHITE); // Draw white text
- display.setCursor(0, 0); // Start at top-left corner
- display.println(F("Hello, ESP32!"));
- display.println(F("Connected to OLED"));
- display.println();
- display.print(F("OLED is working!"));
- display.display();
- }
- void loop() {
- // Your main code here, to run repeatedly
- // This example just keeps the initial text on the display
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement