/**
* Fab Academy Week 4: Output Devices
* Project: SSD1306 OLED Display Test
* Board: Seeed Studio XIAO ESP32C3
* Display: 0.96" OLED (128x64) via I2C
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Screen dimensions in pixels
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The reset pin is not used on most 4-pin OLED modules (-1)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(115200);
// Initialize I2C communication
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
// 0x3C is the most common I2C address for these displays
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
// Set text properties
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 20); // Start at top-left corner (x=0, y=20)
// Print the specific message
display.println(F("Hello Fab Academy,"));
display.setCursor(0, 40);
display.println(F("I am Sunny"));
// Crucial: Push the buffer to the actual hardware display
display.display();
Serial.println("Display updated successfully.");
}
void loop() {
// Static display, no action needed in loop
}