Using OLED to Show a Message and Scrolling Message and Animation
by sister mariaM in Circuits > Arduino
81 Views, 1 Favorites, 0 Comments
Using OLED to Show a Message and Scrolling Message and Animation
This is an OLED circuit with static message and scrolling message and an animation with codes
Supplies
The tools used are OLED yellow and blue 0.98 and jumper wires and Elegoo Uno 3 (Arduino) could be used and computer and Arduino IDE
Downloads
Introduction
This is an Instructables about OLEDs .OLED means Organic Light Emitting Diode It is a display where millions of pixels produce their light .They are used in TV ,and cell phones and displays.
More About OLED
The OLED 0.96 inch is a compact efficient display It uses 128x64 pixels .It doesn't require a backlight .This enhances the image and reduces power consumption
Circuit Connections
This is how to connect the Elegoo Uno or Arduino to OLED;
Vin to 5 volts
GND to GND (ground)
SCL to SCL (if you have it) or A5
SDA to to SDA (if you have it ) or A4
Also install the libraries to Arduino IDE;
Adafruit SSD1306
and
Adafruit GFX
Make sure your Elegoo Uno is the board and you have the correct port on IDE (tools)
Message;static
This is the code for message(static) ;
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The parameter -1 indicates that the display does not have a hardware reset pin
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
// Initialize with the I2C address 0x3C (common default for these displays)
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.begin(9600);
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Clear the internal buffer
display.clearDisplay();
// --- YELLOW ZONE (Top 16 Pixels) ---
display.setTextSize(1); // Small text size
display.setTextColor(SSD1306_WHITE); // 'WHITE' turns the pixel on (shows up Yellow here)
display.setCursor(0, 0); // Start at top-left corner
display.println("--- SYSTEM STATUS ---");
// Draw a dividing line between the yellow and blue zone (around pixel Y=15)
display.drawLine(0, 15, 128, 15, SSD1306_WHITE);
// --- BLUE ZONE (Remaining Pixels) ---
display.setTextSize(2); // Larger text size
display.setCursor(0, 25); // Move cursor into the blue area
display.println("Praise God!");
display.setTextSize(1);
display.setCursor(0, 45);
display.println("Alleluia");
// Push everything from buffer to the actual screen hardware
display.display();
}
void loop() {
// Put your main loop code here to update values dynamically
}
Scrolling Message
This is the code for Scrolling message;
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Starting X position of the text (starts off-screen to the right)
int scrollPosition = SCREEN_WIDTH;
void setup() {
// Use the standard I2C address that worked for your text display
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for(;;);
}
display.setTextSize(2);
display.setTextColor(WHITE);
display.setTextWrap(false); // Crucial: Prevents text from breaking into a new line
}
void loop() {
display.clearDisplay(); // Clear the buffer for the next frame
// Set the moving cursor.
// y = 0 sits in the Yellow zone. y = 30 moves down to the Blue zone.
display.setCursor(scrollPosition, 20);
display.print("Smile!");
display.display(); // Push frame to screen
// Move text 2 pixels to the left for the next frame
scrollPosition -= 2;
// Reset text position back to the right side once it scrolls completely off-screen
// Change -180 depending on how long your text string is
if (scrollPosition < -180) {
scrollPosition = SCREEN_WIDTH;
}
delay(30); // Controls the speed of the scroll (lower numbers = faster)
}
Downloads
Animation
This is the Code for the animation; There is also a site that gives you animation; https://www.oledanimationmaker.com/;
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Star points (can be drawn in the yellow zone)
const int starX[10] = {0, 6, 15, 8, 11, 0, -11, -8, -15, -6};
const int starY[10] = {-16, -5, -5, 2, 13, 7, 13, 2, -5, -5};
// Cross points
const int crossX[12] = {-4, 4, 4, 12, 12, 4, 4, -4, -4, -12, -12, -4};
const int crossY[12] = {-12, -12, -4, -4, 4, 4, 12, 12, 4, 4, -4, -4};
float angle = 0.0;
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
}
void loop() {
display.clearDisplay();
// Draw Rotating Star (Left Side - in yellow zone)
drawRotatedShape(32, 32, starX, starY, 10, angle);
// Draw Rotating Cross (Right Side - in yellow/blue zone)
drawRotatedShape(96, 32, crossX, crossY, 12, angle + 0.5); // Offset angle slightly
display.display();
angle += 0.1; // Rotation speed
if (angle >= TWO_PI) angle = 0;
delay(30);
}
void drawRotatedShape(int cx, int cy, const int* shapeX, const int* shapeY, int numPoints, float rotation) {
int prevX = cx + (shapeX[numPoints - 1] * cos(rotation) - shapeY[numPoints - 1] * sin(rotation));
int prevY = cy + (shapeX[numPoints - 1] * sin(rotation) + shapeY[numPoints - 1] * cos(rotation));
for (int i = 0; i < numPoints; i++) {
int currentX = cx + (shapeX[i] * cos(rotation) - shapeY[i] * sin(rotation));
int currentY = cy + (shapeX[i] * sin(rotation) + shapeY[i] * cos(rotation));
display.drawLine(prevX, prevY, currentX, currentY, WHITE);
prevX = currentX;
prevY = currentY;
}
}
Conclusion
This is how an OLED works and see images and videos .I hope this help you understand OLEDs better.
Thank you