OLED Display Graphics (SSD1306 128×64) using arduino uno project with step by step instructions in wowki
OLED Display Graphics Project - Complete Step-by-Step Guide
SSD1306 128×64 with Arduino Uno in Wokwi
What is This Project?
This project demonstrates how to interface an SSD1306 OLED display (128×64 pixels) with an Arduino Uno microcontroller using the I2C communication protocol. You will learn how to display text, shapes, animations, and graphics patterns on the OLED screen.
What Will You Learn?
- How to use I2C communication with Arduino
- OLED display programming techniques
- Creating text displays with multiple sizes
- Drawing geometric shapes (circles, rectangles, triangles)
- Implementing animations (bouncing ball)
- Creating scrolling text effects
- Generating graphics patterns
Prerequisites
Knowledge Requirements:
- Basic understanding of Arduino programming
- Familiarity with C/C++ syntax
- Basic electronics knowledge (voltage, ground, connections)
- Understanding of digital communication protocols (helpful but not required)
Software Requirements:
- Web browser (Chrome, Firefox, Safari, or Edge)
- Internet connection
- Wokwi account (free registration)
What is an OLED Display?
OLED stands for Organic Light-Emitting Diode. Unlike LCD displays that require a backlight, each pixel in an OLED display emits its own light. This results in:
- Better Contrast: True black pixels (completely off)
- Lower Power Consumption: Only lit pixels consume power
- Faster Response Time: No liquid crystal delay
- Wider Viewing Angles: Clear from any angle
SSD1306 Display Specifications
| Specification | Value |
|---|---|
| Resolution | 128 × 64 pixels |
| Display Type | Monochrome (White/Blue on Black) |
| Interface | I2C (Two-wire) |
| Operating Voltage | 3.3V - 5V |
| I2C Address | 0x3C or 0x3D |
| Driver Chip | SSD1306 |
I2C Communication Protocol
What is I2C?
I2C (Inter-Integrated Circuit) is a serial communication protocol that uses only two wires:
- SDA (Serial Data): Carries data between devices
- SCL (Serial Clock): Synchronizes data transmission
Advantages of I2C:
- Only 2 wires needed (saves Arduino pins)
- Multiple devices can share the same bus
- Each device has a unique address
- Supports data rates up to 400 kHz (Fast Mode)
How I2C Works:
- Arduino (Master) sends a START signal
- Master sends device address (0x3C for our OLED)
- Device acknowledges if present
- Master sends commands/data
- Device responds
- Master sends STOP signal
3. COMPONENTS REQUIRED
Hardware Components
1. Arduino Uno (1 unit)
Description: Arduino Uno is a microcontroller board based on the ATmega328P chip.
Specifications:
- Microcontroller: ATmega328P
- Operating Voltage: 5V
- Digital I/O Pins: 14 (6 PWM outputs)
- Analog Input Pins: 6
- Flash Memory: 32 KB
- SRAM: 2 KB
- Clock Speed: 16 MHz
Purpose in Project: Main controller that sends commands and data to the OLED display.
2. SSD1306 OLED Display 128×64 I2C (1 unit)
Description: Compact monochrome display module with I2C interface.
Specifications:
- Screen Size: 0.96 inch (typical)
- Resolution: 128 pixels (width) × 64 pixels (height)
- Colors: Monochrome (White or Blue)
- Interface: I2C (4 pins)
- Viewing Angle: >160°
Purpose in Project: Visual output device to display text, shapes, and graphics.
3. Jumper Wires (4 units)
Types Needed:
- Male-to-Male jumper wires (for breadboard)
- Male-to-Female jumper wires (for direct connection)
Suggested Colors:
- Red wire: Power (VCC to 5V)
- Black wire: Ground (GND to GND)
- Green wire: Clock (SCL to A5)
- Blue wire: Data (SDA to A4)
Purpose in Project: Connect Arduino pins to OLED display pins.
4. UNDERSTANDING THE COMPONENTS
Arduino Uno Pin Layout
Important Pins for This Project:
| Pin Name | Pin Number | Purpose | Connection |
|---|---|---|---|
| 5V | Power Rail | Provides 5V power | To OLED VCC |
| GND | Ground Rail | Common ground | To OLED GND |
| A4 | Analog Pin 4 | I2C SDA (Data) | To OLED SDA |
| A5 | Analog Pin 5 | I2C SCL (Clock) | To OLED SCL |
Why A4 and A5?
On Arduino Uno, the I2C pins are fixed:
- A4 is hardwired to SDA
- A5 is hardwired to SCL
You cannot use other pins for hardware I2C communication.
OLED Display Pin Layout
Standard 4-Pin I2C OLED:
| Pin | Name | Function | Voltage |
|---|---|---|---|
| 1 | GND | Ground | 0V |
| 2 | VCC | Power Supply | 3.3V - 5V |
| 3 | SCL | I2C Clock | Digital Signal |
| 4 | SDA | I2C Data | Digital Signal |
Note: Some displays may have pins in different orders. Always check the labels on your specific module.
5. CIRCUIT CONNECTIONS (DETAILED)
Connection Table
| OLED Pin | Wire Color | Arduino Pin | Description |
|---|---|---|---|
| VCC | Red | 5V | Power supply (positive) |
| GND | Black | GND | Ground (negative) |
| SCL | Green | A5 | I2C Clock line |
| SDA | Blue | A4 | I2C Data line |
Visual Connection Diagram OLED Display Arduino Uno
┌──────────┐ ┌──────────┐ │ GND │────Black────│ GND │ │ VCC │────Red──────│ 5V │ │ SCL │────Green────│ A5 │ │ SDA │────Blue─────│ A4 │ └──────────┘ └──────────┘Why These Specific Pins?
A4 (SDA) and A5 (SCL):
- These are the dedicated hardware I2C pins on Arduino Uno
- Using hardware I2C is faster and more reliable than software I2C
- The Wire library automatically uses these pins
5V vs 3.3V:
- Most OLED modules work with both voltages
- 5V is more common and provides brighter display
- Internal voltage regulator on module protects the display
6. SETTING UP WOKWI ENVIRONMENT
What is Wokwi?
Wokwi is an online simulator for Arduino and other microcontrollers. It allows you to:
- Build circuits virtually
- Write and test code
- See real-time simulation
- Debug without physical hardware
Creating Your Wokwi Project
Method 1: Using Provided Files (Fastest)
Step 1: Access Wokwi
- Open web browser
- Navigate to: https://wokwi.com
- Click "Sign In" (top right)
- Create free account or log in
Step 2: Create New Project
- Click "New Project" button
- Select "Arduino Uno"
- Project workspace opens with default code
Step 3: Load diagram.json
- Look for "diagram.json" tab at top of workspace
- Click on it to open
- Select ALL existing content (Ctrl+A or Cmd+A)
- Press Delete to clear it
- Open the provided diagram.json file
- Copy ALL content (Ctrl+C or Cmd+C)
- Paste into Wokwi diagram.json tab (Ctrl+V or Cmd+V)
- Circuit appears automatically with all connections
Step 4: Load Arduino Code
- Click "sketch.ino" tab
- Select ALL existing content
- Delete it
- Open the provided oled_display_project.ino file
- Copy ALL content
- Paste into Wokwi sketch.ino tab
Step 5: Add Libraries
- Click "+" button next to file tabs
- Select "libraries.txt"
- Paste the content from provided libraries.txt file
- Save the file
Step 6: Start Simulation
- Click green "Start Simulation" button (play icon)
- OLED display should initialize
- Watch demos cycle automatically
7. CODE EXPLANATION (LINE BY LINE)
Section 1: Library Includes
#include <Wire.h>#include <Adafruit_GFX.h>#include <Adafruit_SSD1306.h>
Line 1: Include Wire library for I2C communication Line 2: Include graphics library for drawing functions Line 3: Include SSD1306-specific library
Section 2: Constants and Definitions
#define SCREEN_WIDTH 128#define SCREEN_HEIGHT 64#define OLED_RESET -1#define SCREEN_ADDRESS 0x3C
SCREEN_WIDTH: Display width in pixels (128) SCREEN_HEIGHT: Display height in pixels (64) OLED_RESET: Reset pin configuration (-1 = shared reset) SCREEN_ADDRESS: I2C address (0x3C or 0x3D)
Section 3: Display Object Creation
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);Creates display object with specified dimensions and I2C interface.
Key Functions Used
display.begin() - Initialize the display display.clearDisplay() - Clear the display buffer display.display() - Push buffer to the screen display.setTextSize() - Set text size (1-3) display.setCursor() - Set text position display.println() - Print text display.drawRect() - Draw rectangle outline display.fillRect() - Draw filled rectangle display.drawCircle() - Draw circle outline display.fillCircle() - Draw filled circle display.drawLine() - Draw line display.drawTriangle() - Draw triangle
8. STEP-BY-STEP IMPLEMENTATION
Phase 1: Environment Setup (5 minutes)
- Open web browser and go to wokwi.com
- Log in or create account
- Click "New Project" → "Arduino Uno"
- Verify starting point (Arduino appears, default code present)
Phase 2: Circuit Construction (10 minutes)
Using diagram.json:
- Click "diagram.json" tab
- Delete all content
- Paste provided diagram.json
- Circuit appears automatically
Manual Wiring:
- Add OLED display (search "SSD1306")
- Connect VCC to 5V (red wire)
- Connect GND to GND (black wire)
- Connect SCL to A5 (green wire)
- Connect SDA to A4 (blue wire)
Phase 3: Library Installation (3 minutes)
- Create "libraries.txt" file
- Add two lines:
- Adafruit SSD1306
- Adafruit GFX Library
- Save file
Phase 4: Code Implementation (5 minutes)
- Click "sketch.ino" tab
- Delete default code
- Paste provided Arduino code
- Save project with name
Phase 5: Testing and Validation (7 minutes)
- Click green "Start Simulation" button
- Watch for display initialization
- Observe demo cycle:
- Text Display Demo (2 seconds)
- Shapes Demo (2 seconds)
- Animation Demo (3 seconds)
- Scrolling Text (2 seconds)
- Graphics Pattern (2 seconds)
- Open Serial Monitor (should show "OLED Display Initialized!")
- Verify smooth animations and clear graphics
9. TESTING AND VERIFICATION
Visual Tests
Test 1: Display Clarity
- Text should be sharp and readable
- No flickering or ghosting
- Consistent brightness
Test 2: Shape Accuracy
- Rectangles have clean corners
- Circles are properly round
- Triangles have straight edges
Test 3: Animation Smoothness
- Ball moves without jerking
- Bounces look natural
- Consistent frame rate
Test 4: Scrolling
- Smooth left motion
- No jumping or stuttering
- Text stays aligned
Functional Tests
Initialization Test:
- Serial Monitor shows "OLED Display Initialized!"
- Appears within 2 seconds
- No error messages
Demo Sequence Test:
- All 5 demos execute in order
- Correct timing (2 seconds each, animation 3 seconds)
- Cycle repeats continuously
Comments
Post a Comment