Skip to content

Instantly share code, notes, and snippets.

@tranchausky
Created January 20, 2025 15:28
Show Gist options
  • Save tranchausky/fe4e19e56e76f9e3612a927fee559646 to your computer and use it in GitHub Desktop.
Save tranchausky/fe4e19e56e76f9e3612a927fee559646 to your computer and use it in GitHub Desktop.
esp32 s2 mini connect to SSD1306 (33-35)
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Define the OLED display width and height
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Define the I2C address for the OLED
#define OLED_I2C_ADDRESS 0x3C
// Create an instance of the SSD1306 display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
// Initialize the OLED display
if(!display.begin(SSD1306_SWITCHCAPVCC, OLED_I2C_ADDRESS)) {
// if (!display.begin(SSD1306_I2C, OLED_I2C_ADDRESS)) {
Serial.println("SSD1306 allocation failed");
for (;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
// Show initial text
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at the top-left corner
display.println("Hello, ESP32-S2!");
display.println("SSD1306 OLED Demo");
display.display(); // Display the text
delay(2000);
// Draw a demo
display.clearDisplay();
display.drawCircle(64, 32, 20, SSD1306_WHITE); // Circle at the center
display.drawRect(10, 10, 50, 30, SSD1306_WHITE); // Rectangle
display.display();
delay(2000);
// Clear the display for next animations
display.clearDisplay();
}
void loop() {
// Animate a filled rectangle
for (int16_t i = 0; i < SCREEN_WIDTH; i++) {
display.clearDisplay();
display.fillRect(i, 16, 16, 16, SSD1306_WHITE);
display.display();
delay(50);
}
// Clear the display
display.clearDisplay();
}
[env:lolin_s2_mini]
platform = espressif32
board = lolin_s2_mini
framework = arduino
monitor_speed = 115200
lib_deps =
adafruit/Adafruit SSD1306 @ ^2.5.7
adafruit/Adafruit GFX Library @ ^1.11.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment