While microcontrollers and single-board computers are unique devices, they can’t do much on their own. For instance, we can’t program or see the results of a microcontroller without connecting it to a device that relays audio or visual output. Therefore, we need modules and other components to extend the board's capabilities. The SSD1306, much like the i2C LED, is an example of a display controller we can interface with a microcontroller to get optical output. But what is it, and how do we use it? The following guide will answer these questions.
What is The SSD1306?
A light meter that uses an Arduino and SSD1306
The SSD1306 is a single-chip monochrome OLED graphic display. Its screen is 128 pixels wide and 64 pixels deep (128x64). Since it’s a monochrome screen, all these individual pixels are white. As you may be able to surmise, the SSD1306’s display is tiny. It’s just under 3 centimeters if you measure it diagonally. Despite its size, it’s straightforward to read due. This fact is due to its bright, high-contrast OLED screen.
The SSD1306 controller chip governs each pixel on the screen - turning it on or off. Many graphic displays require a backlight to make their output more visible. However, since the SSD1306 uses an OLED screen, it produces its light. Thus, it does not require any additional background illumination.
A vital advantage of this facet is that it draws less power. Additionally, it allows the SSD1306 to have high contrast. We can interface the SSD1306 with an SPI or i2C protocol. We can achieve this by using the jumpers on the back of the unit.
The SSD1306 has a built-in boost converter and an onboard regulator. Thus, the SSD1306 is directly compatible with 3V and 5V microcontrollers (no level shifter required).
IIC I2C OLED 128x64 display in blue background
Interfacing the SSD1306 OLED Display with The Arduino
The SSD1306 is practically inexpensive. You should be able to purchase at least ten in bulk for under $20. But how do you use them, and what’s the best way to interface them? You can interface them with any microcontroller or SBC that supports SPI, IIC, or i2C connections. The Arduino Uno is one of the least expensive and most accessible microcontrollers. This section will cover how to connect it to your SSD1306 OLED display.
SSD1306 OLED display module tilted in front of blue background
We’ll use the i2C communication protocol to connect the SSD1306 OLED display to the Arduino Uno. You can click and correspond the pins as follows:
You can wire both components directly or run the connections through a breadboard. Of course, you should be able to connect the SSD1306 to almost any other compatible Arduino board using a similar configuration.
Programming the Arduino Uno and SSD1306
OLED Module with text on it
Wiring the Arduino Uno to the SSD1306 is only the first step. The next step involves using the correct libraries to create and program a digital link between the Arduino Uno and the SSD1306 screen. This action will allow you to control what the SSD1306 shows on its display. You can then use this set-up for projects such as watches, alarms, internet status screens, etc.
Programming the Arduino to control the SSD1306 OLED screen will require you to install the Arduino IDE. You can choose to flash the Arduino using an SD card or connect directly to your computer via a micro-USB cable.
- Run your Arduino IDE
- Click on “Sketch”
- Next, select “Include Library.”
- Select “Manage Libraries” – This action will open the Library Manager
- Type “SSD1306” into the search bar on the top and hit Enter on your keyboard
- Next, click on the package that reads Adafruit SSD1306 by Adafruit – Make sure that you select the latest package
- Once you’ve finished installing the Adafruit SSD1306 library, follow the same process for the GFX library and restart the Arduino IDE.
Useful functions for Programming the Arduino IDE and SSD1306
SSD1306 OLED module
Trying to program the SSD1306 can be a little jarring at first. To help you quickly acclimate yourself, here are a few useful functions:
- clearDisplay(): A part of the display class that clears the screen of all pixels, essentially turning them off.
- SetTextSize(n): This allows you to set the font size of the text that the OLED screen displays – acceptable sizes can range from 1 to 8.
- drawPixel(x,y, color): This allows you to turn on selected pixels on the screen, essentially allowing you to draw text, shapes, and lines. You can learn more about it and its arguments from the Adafruit Graphics Primitives page.
- print(text): This allows you to print a text string onto the SSD1306.
- setCursor(x,y): This will enable you to set the cursor coordinates – where the SSD1306 should start displaying text when you instruct it to print it out.
- Display (): This method refreshes the screen and pushes all the changes so it can display them.
You can use the above to display simple text and potentially sketch a few monochrome graphics on the screen. You can use them to test that you’ve connected and interfaced the SSD1306 to the Arduino Uno. Use the following sketch to print “Hello, world” onto the OLED display.
The above guide explores the SSD1306 and some of its functionality. There is a wide variety of display screens available for your Arduino and Raspberry Pi 4 projects. Some have multi-color capabilities. However, where the SSD1306 stands out is in its bright, high-contrast luminous display. Engineers can take advantage of it to test OLED screens for fitness tracking and intelligent devices. We highly recommend the SSD1306 for first-time projects.