OLED 128x64px SPI - Arduino Connection Diagram

OLED 128x64px SPI - Arduino Connection Diagram

Daniil Zhuk

Information output from the microcontroller often creates more difficulties than the work of the main program itself - after all, it is necessary to “give” a few pins to connect, and a certain amount of memory for the graphics processing library.

Newbies often make a mistake, either trying to stuff a large amount of data onto a small screen (like the Nokia 3310), or vice versa - a huge display that requires high performance is added to even the smallest project.

We will consider a compromise solution - small in size (0.96 ”), but with a sufficient resolution (128 × 64) screen with only 3 wires connected!

MODULE OVERVIEW

 

SSD1306 is a controller on which several variations of display modules are built. Often there are also connecting via the I²C interface, but our today's version is connected via a faster SPI.

The display itself, mounted on the module, is based on OLED technology, which guarantees low consumption, high switching speed (as a result, the largest possible refresh rate of the screen). The screen is two-color, which does not allow to display exact pictures, but it helps to reduce the buffer size for video memory to just 1 Kb, since 8 points are encoded at once in one byte.

An SPI connection provides a connection speed of up to 20 Mbps, with which the I²C interface cannot compete with its requests and complex structure. A connection via parallel interfaces is also available, but modules with such a connection are not widely used.

The module's power supply is 3.3 V, but on the board a stabilizer with a low voltage drop is installed, which allows the display to be powered from both 5 V and 3.3 V directly. It is better to use 5 V power supply - this will unload the already not very powerful 3.3 V stabilizer installed on the Arduino.

The maximum consumption (when all the pixels of the display are on) is about 20 mA, so if necessary it can be powered directly from the pin of the microcontroller.

SCHEME OF CONNECTION TO ARDUINO

  • CS - any pin Arduino
  • SCK - 13 pin (Arduino UNO)
  • MOSI - 11 pin
  • Vcc - 3.3 ... 5V
  • GND - GND

Interface pinouts for other boards can be found on the official website.

CONNECTING TO ARDUINO IDE
There are many libraries for display, and no one forbids you to write your own - the protocol is described in the datasheet. But to simplify the task, we will take the ready-made U8gLib library. It supports a large number of screen controllers, including SSD1306.

After connecting the display to your debug board, open the Arduino IDE (preferably a new version) and look for the Library Manager (Sketch-Add Library-Library Manager). In search, enter u8glib and install any version - the newer the better.

Open any example. At the beginning of the sketch, there will be a large number of commented initialization lines for different controllers. Find among them SSD1306, connecting via SPI and having a resolution of 128 × 64, then uncomment this line and you can upload a sketch!

#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(12, 11, 8, 9, 10);

void setup()
{
/* nothing to do here */
}

void loop()
{
u8g.firstPage();

do
{
int steps = 16;
int dx = 128/steps;
int dy = 64/steps;
int y = 0;
for(int x=0; x<128; x+=dx) {
u8g.drawLine(x, 0, 127, y);
u8g.drawLine(127-x, 63, 0, 63-y);
y+=dy;
}

} while(u8g.nextPage());
}

If the screen does not work, check the power and pins in the description line in the sketch - perhaps the software implementation of the interface is used there and its pins are reassigned, this depends on the parameters passed to the configuration functions.

With this library and Arduino, the screen is able to update data at a frequency of 15 frames per second, and if you use PADI or ESP8266 (with which the library is also compatible), then you can squeeze out and 30 - and that’s enough for confident animations. You can also try the lighter Adafruit_SSD1306 for acceleration, but some of its versions are incompatible with the SPI mode.

Add a comment

* Comments must be approved before being displayed.