Advertisement
microrobotics

D1 Mini 0.66 inch OLED display

May 8th, 2023
1,593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. To use a 0.66-inch OLED display (64x48 resolution) with a D1 Mini board, you can use the "Adafruit_SSD1306" and "Adafruit_GFX" libraries. First, install these libraries through the Arduino Library Manager.
  3.  
  4. This code initializes the OLED display and prints "Hello, World!" on it. You can modify the text and the position of the text by changing the parameters in the display.print() and display.setCursor() functions, respectively.
  5.  
  6. Here's an example code to display "Hello, World!" on the 0.66-inch OLED display:
  7. */
  8.  
  9. #include <Wire.h>
  10. #include <Adafruit_GFX.h>
  11. #include <Adafruit_SSD1306.h>
  12.  
  13. // OLED display parameters
  14. #define SCREEN_WIDTH 64
  15. #define SCREEN_HEIGHT 48
  16. #define OLED_RESET -1
  17. #define I2C_ADDRESS 0x3C
  18.  
  19. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  20.  
  21. void setup() {
  22.   // Initialize the OLED display
  23.   Wire.begin();
  24.   if (!display.begin(SSD1306_SWITCHCAPVCC, I2C_ADDRESS)) {
  25.     Serial.println(F("SSD1306 allocation failed"));
  26.     for (;;);
  27.   }
  28.   display.display();
  29.   delay(2000);
  30.  
  31.   // Clear the buffer
  32.   display.clearDisplay();
  33.  
  34.   // Display text on the OLED
  35.   display.setTextSize(1);
  36.   display.setTextColor(WHITE);
  37.   display.setCursor(0, 0);
  38.   display.print(F("Hello, World!"));
  39.   display.display();
  40. }
  41.  
  42. void loop() {
  43.   // Nothing to do in the loop
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement