The SSD1306 OLED, manufactured by RIDEN (Part ID: SSD1306), is a versatile monochrome display driver designed for OLED screens. It is widely used in embedded systems due to its compact size, low power consumption, and high contrast display. The SSD1306 supports resolutions such as 128x64 pixels and offers communication via I2C or SPI interfaces, making it an excellent choice for microcontroller-based projects.
The SSD1306 OLED module typically has 4 or 7 pins, depending on the interface used. Below is the pinout for the I2C and SPI configurations:
Pin | Name | Description |
---|---|---|
1 | GND | Ground (0V reference) |
2 | VCC | Power supply (3.3V or 5V) |
3 | SCL | I2C clock line |
4 | SDA | I2C data line |
Pin | Name | Description |
---|---|---|
1 | GND | Ground (0V reference) |
2 | VCC | Power supply (3.3V or 5V) |
3 | SCK | SPI clock line |
4 | MOSI | SPI data line (Master Out Slave In) |
5 | CS | Chip select (active low) |
6 | DC | Data/Command control pin |
7 | RES | Reset pin (active low) |
VCC
pin to a 3.3V or 5V power source and the GND
pin to ground.SCL
and SDA
pins to the corresponding I2C pins on your microcontroller.SCK
, MOSI
, CS
, DC
, and RES
to the appropriate pins on your microcontroller.SCL
and SDA
lines.RES
pin to a GPIO pin for proper initialization.Below is an example of how to use the SSD1306 OLED with an Arduino UNO via the I2C interface:
#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
// Create an SSD1306 display object (I2C address is typically 0x3C)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Initialize the OLED display
if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Halt execution if initialization fails
}
// Clear the display buffer
display.clearDisplay();
// Display a welcome message
display.setTextSize(1); // Set text size to 1
display.setTextColor(SSD1306_WHITE); // Set text color to white
display.setCursor(0, 0); // Set cursor position to top-left
display.println(F("Hello, SSD1306!")); // Print message
display.display(); // Update the display with the buffer content
delay(2000); // Wait for 2 seconds
}
void loop() {
// Example: Draw a rectangle on the display
display.clearDisplay(); // Clear the display buffer
display.drawRect(10, 10, 50, 30, SSD1306_WHITE); // Draw a rectangle
display.display(); // Update the display
delay(1000); // Wait for 1 second
}
Display Not Turning On:
VCC
and GND
).0x3C
) is used in the code.No Communication with Microcontroller:
SCL
and SDA
).Flickering or Corrupted Display:
Library Errors:
Q: Can the SSD1306 OLED work with 5V microcontrollers?
A: Yes, the module is compatible with both 3.3V and 5V systems.
Q: What is the maximum resolution supported by the SSD1306?
A: The SSD1306 supports resolutions up to 128x64 pixels.
Q: How do I change the I2C address of the module?
A: The I2C address can typically be changed by modifying solder jumpers on the module. Refer to the module's datasheet for details.
Q: Can I use the SSD1306 OLED with platforms other than Arduino?
A: Yes, the SSD1306 is compatible with various platforms, including Raspberry Pi, ESP32, and STM32.
This concludes the documentation for the SSD1306 OLED. For further assistance, refer to the manufacturer's datasheet or community forums.