Introduction
This experiment demonstrates how to use an OLED display with the I2C protocol to display text or graphics on the screen. I2C simplifies wiring by using just two data lines for communication.
Components Needed
- OLED Display (0.96 inch)
- Arduino (e.g., Uno, Nano)
- Jumper wires
Circuit Setup
- Connect the VCC pin of the OLED to the 5V pin on the Arduino.
- Connect the GND pin of the OLED to the GND pin on the Arduino.
- Connect the SDA and SCL pins of the OLED to the SDA and SCL pins on the Arduino (A4 and A5 for Arduino Uno).
Ensure the connections are secure and the display is connected properly.
Code for OLED Display
Upload the following code to your Arduino to display text on the OLED screen:
#include
#include
#include
Adafruit_SSD1306 display(128, 64, &Wire, -1);
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.print("Hello, OLED!");
display.display();
}
void loop() {
// No need for continuous code, text is static
}
Explanation
The code initializes the OLED display and writes the text "Hello, OLED!" to the screen. The I2C protocol allows the display to communicate with the Arduino using only two data lines, making it easier to wire compared to parallel communication.
Troubleshooting
- If the display is blank, double-check the wiring, especially the SDA and SCL connections.
- If the display shows garbage text, ensure the correct I2C address is used in the code.