AutoOLED is a smart wrapper library for ESP32/Arduino that simplifies working with monochrome OLED displays. It automatically detects whether you are using an SSD1306 or SH1106 display driver and provides a unified, high-performance interface.
- Auto-Detection: No need to hardcode the driver type. The library probes I2C addresses and identifies the controller.
- Unified API: Write your code once, run it on any common 0.96" or 1.3" OLED.
- Adafruit_GFX Compatible: Fully inherits from
Adafruit_GFX, exposing all standard drawing functions (drawLine,drawCircle,print, etc.). - Performance Optimized: Automatically routes calls like
drawFastHLine,fillRect, and text writing to the underlying hardware-specific driver for maximum speed. - Safe: Handles differences between drivers (like scrolling support) gracefully.
- Copy the
AutoOLEDfolder to your project'slib/directory. - Add the dependencies to your
platformio.ini:lib_deps = adafruit/Adafruit GFX Library adafruit/Adafruit SSD1306 adafruit/Adafruit SH110X
#include <AutoOLED.h>
// Create instance (128x64 pixels, reset pin -1 if unused)
AutoOLED display(128, 64, -1);
void setup() {
Serial.begin(115200);
// Initialize (Auto-detects address 0x3C by default)
if (!display.begin()) {
Serial.println("OLED not found!");
while(1);
}
Serial.println("OLED initialized!");
}All standard GFX functions work directly:
display.clearDisplay(); // Always clear buffer first
display.drawPixel(10, 10, WHITE);
display.drawLine(0, 0, 128, 64, WHITE);
display.drawRect(10, 10, 50, 30, WHITE);
display.fillRect(10, 10, 50, 30, WHITE);
display.drawCircle(64, 32, 10, WHITE);
drawTriangle(10, 10, 20, 30, 0, 30, WHITE);
display.display(); // Push buffer to screendisplay.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // White text
display.setCursor(0, 0); // Top-left corner
display.println("Hello!");
display.setTextSize(2); // 2x magnification
display.println("BIG TEXT");
// Inverted Text (Black text on White background)
display.setTextColor(BLACK, WHITE);
display.print("Inverted");display.dim(true); // Dim the display
display.invertDisplay(true); // Invert all colors (Night mode)
display.off(); // Sleep mode (Display OFF)
display.on(); // Wake up (Display ON)bool begin(TwoWire *wire, uint8_t addr): Starts the display. Returnstrueon success.void display(): Sends the buffer to the screen. Must be called to see changes.void clearDisplay(): Clears the internal buffer.
drawPixel(x, y, color)drawLine(x0, y0, x1, y1, color)drawFastVLine(x, y, h, color)/drawFastHLine(x, y, w, color)drawRect(x, y, w, h, color)/fillRect(x, y, w, h, color)drawCircle(x, y, r, color)/fillCircle(x, y, r, color)drawTriangle(x0, y0, x1, y1, x2, y2, color)/fillTriangle(...)drawRoundRect(x, y, w, h, r, color)/fillRoundRect(...)drawBitmap(x, y, bitmap, w, h, color)
setCursor(x, y)setTextSize(size)setTextColor(color)orsetTextColor(fg, bg)setTextWrap(bool)print(data)/println(data)
AutoOLEDType getType(): ReturnsOLED_SSD1306,OLED_SH1106, orOLED_NONE.getPixel(x, y): Returns the color of a pixel in the buffer.setContrast(chunk): Sets display contrast (0-255).