For many Arduino projects, there is a need to display information graphically or display more text than what fits on a 16×2 LCD. For that need, consider using SSD1306 OLED Displays.
SSD1306 refers to the controller or driver chip for the display. OLED or Organic Light Emitting Diodes refers to the dot-matrix graphic display system. These displays attach using SPI or I2C thus using less connecting pins versus an LCD.
Here is how to hook-up a I2C SSD1306 OLED display to an Arduino UNO:
The Fritzing diagram source is here. The OLED fritzing part is here.
To write Arduino code for SSD1306 OLED displays, we need to find the I2C address. The MiniPirate sketch I wrote about here can be used to find it. Also there is an I2C scanner sketch here. There are also two libraries needed to control the OLED display:
Adafruit SSD1306 Library Adafruit GFX Library
Once those libraries are added and you have the I2C address, try the following sketch:
#include <SPI.h> #include <Wire.h> #include <Adafruit_SSD1306.h> #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); void setup() { display.begin(SSD1306_SWITCHCAPVCC, 0x3C); } void loop() { display.clearDisplay(); display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(0,0); display.print("HELLO WORLD"); display.display(); delay(10000); }
The I2C address for my OLED Display is 0x3C so the display.begin code is:
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
You will need to change the 0x3C to the address of your display. Also, the library does not detect the resolution of the display. The sample sketches that come with the SSD1306 library mention how to change the library to match the resolution of your display. Basically, look at the code in Adafruit_SSD1306.h and find the lines which define the resolution. Uncomment the one you need and comment the rest. Here is what that code looks like for the OLED display I have:
#define SSD1306_128_64 // #define SSD1306_128_32 // #define SSD1306_96_16
Here is what the OLED Display looks like when displaying text:
Recent Comments