OLED (128×64) to Arduino

Note : This article has been amended since the original video (30-08-19)  and will no longer match exactly what you see. This is due to changes over the years to the Adafruit driver software, to the point where the video and article are not perfect matches to what now see. The article below however better matches the current Adafruit libraries. 

Kit List
1 x OLED screen 128×64  single colour with I²C
1 x Arduino Nano or clone (Other Arduinos can be used but check the connection table show later)
4 x jumper wires

Introduction
Here we look at connecting a 128×64 single colour OLED screen to an Arduino. Some time ago these screens supported both SPI and I²C and had around 6pins. The ones available now – at time of writing (not counting any from Adafruit) seem to support just I²C. This is fine and although I²C can be a little slower than the SPI protocol/connections it has not made any difference to the projects that I’ve currently used it with.

If you’ve not done so, why not have a look at the Video-Blog showing how to connect and use these screens, show here

The OLED Screen
The screen I’m using is shown below and if you can source one like this with the same connections you should have very few problems getting yours up and running using this tutorial.

Connection Table
The following shows the connections required to the various Arduino models, in addition after the table is the connection diagram specific to the Arduino Nano.

OLED ConnectionNano ConnectionPro-MicroUnoLeonardo
VDD5V5V5V5V
GNDGNDGNDGNDGND
SCKA53A5 (*)#3
SDAA42A4 (*)2

*Refer to online pin-out for location of these pins

Why these pins?
The screen uses a technology call I²C, the two connections labelled as SCK and SDA. These receive the information as to which pixels to switch on etc. The micro-controller on the Arduino has the ability to use this communication built into the actual hardware. You could replicate the functionality with any digital pin but that would require you writing fairly complex software that would use up code space and clock cycles on your micro-controller. So all this complexity is handled for us, neat 🙂

Refer to the diagram below showing the nano connections (click for larger).

The software
Once connected up its time to test. We need two libraries from Adafruit to do this. The first is the driver code that talks to the OLED. The second as a graphics library that lets us use various commands to write text, draw different shapes and plot graphics to the display. First off install the driver software. Go to “Sketch->Include Library->Manage Libraries”.

Type in “ssd1306” and install the one from Adafruit industries.

Ready to demo (still might not work!)

Enter or copy and paste the following code into a new Arduino Sketch. Ensure your port is set correctly and you have selected the correct board to upload to (in my case it’s the Nano).

Compile and upload the code. If it works then great, you’ve done it, if not then the most likely culprit(apart from bad wiring – please check!) is the I²C address of your display. These tend to be either 0x3C or 0x3D. So first try changing the line

#define OLED_Address 0x3D

to

#define OLED_Address 0x3C

and recompile/upload. If this doesn’t work it may be that your screen has an even different address to the most common ones.  In this case you need to load a  I²C address scanner onto your Arduino to get the screen to return its address and use that one in the code above. See this Link for a suitable scanner.

Well, that’s it for this article, hope it was useful. Why not look at some of our projects that use these screens for more inspiration or have a look at the Adafruit demo program which comes supplied with the library, you’ll find that in this menu location in your Arduino software (don’t forget to change the I2C address if required!)

File->Examples->Adafruit SSD1306->ssd1306_128x64_i2c

Enjoy and Learn 🙂