Advertisement
Guest User

Code Requested

a guest
Apr 16th, 2025
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <Adafruit_GFX.h>
  3. #include <Adafruit_SSD1306.h>
  4.  
  5. // Pin definitions for SSD1306 OLED display connections
  6. // OLED display pin labels: VCC, GND, D0, D1, RES, DC, CS
  7. // ESP32 DEVKIT V1 connections:
  8. #define OLED_CLK 18 // D0 - GPIO18 (VSPI CLK)
  9. #define OLED_MOSI 23 // D1 - GPIO23 (VSPI MOSI)
  10. #define OLED_RESET 17 // RES - GPIO17
  11. #define OLED_DC 5 // DC - GPIO5
  12. #define OLED_CS 19 // CS - GPIO19 (VSPI CS0)
  13.  
  14. // Display dimensions (128x64 is common for SSD1306 OLEDs)
  15. #define SCREEN_WIDTH 128
  16. #define SCREEN_HEIGHT 64
  17.  
  18. // Initialize the display
  19. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
  20. OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
  21.  
  22. void setup() {
  23. Serial.begin(115200);
  24. Serial.println("ESP32 OLED Test");
  25.  
  26. // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  27. if(!display.begin(SSD1306_SWITCHCAPVCC)) {
  28. Serial.println(F("SSD1306 allocation failed"));
  29. for(;;); // Don't proceed, loop forever
  30. }
  31.  
  32. // Clear the buffer
  33. display.clearDisplay();
  34.  
  35. // Show initial display buffer contents on the screen
  36. display.display();
  37. delay(2000); // Pause for 2 seconds
  38.  
  39. // Display text
  40. display.clearDisplay();
  41. display.setTextSize(1); // Normal 1:1 pixel scale
  42. display.setTextColor(SSD1306_WHITE); // Draw white text
  43. display.setCursor(0, 0); // Start at top-left corner
  44. display.println(F("Hello, ESP32!"));
  45. display.println(F("Connected to OLED"));
  46. display.println();
  47. display.print(F("OLED is working!"));
  48. display.display();
  49. }
  50.  
  51. void loop() {
  52. // Your main code here, to run repeatedly
  53. // This example just keeps the initial text on the display
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement