IntroductionI noticed keenly priced OLED screens started appearing on eBay a long while ago. I bought a few, but at the time there wasn't much information on how to drive them. I found a C library on a Chinese website that I was able to cajole into MikroC for the PIC microprocessors but it was never really useful as I didn't implement any fonts. Time has moved on and now there are a few well executed drivers out there. I have tried a couple of different ones and this is a writeup on the approach that worked for me on the Arduino.
What is it, why would I want one?The OLED screen is a very crisp 128 x 64 pixel mono screen. The ones I buy have 16 rows of yellow pixels at the top and 48 rows of blue pixels at the bottom. They are really good for giving feedback about what is happening in your Arduino code and little projects like this Arduino watch:
|Time / Date / Temperature and Compass module|
Buying the OLED ScreenThere are a variety of similar screens available from Adafruit, if you need something other than 128x64pixels or feel more comfortable dealing with a UK supplier take a look at them. Here is a different layout of OLED i2c sceen from Adafruit through Pimoroni.
I buy them from eBay, not only are they cheap but it's very easy. Search for 'Arduino OLED i2c'. The cheapest price currently is £2.57 posted from China. I have bought 10 screens this way and so far they have all arrived working. At that price you can afford to buy one more than you need perhaps.
There are also SPI versions available, SPI and i2c are different communication standards used to communicate between electronic devices. This write up is about i2c screens. (Adafruit do a driver for SPI driven screens which I believe works with the SPI eBay screens but I haven't tried this.)
Wiring it upThe i2c communications uses 2 wires. One for Data and one for a Clock. These pins can be found on the pinout diagram for an Arduino as SDA for Data and SCL for clock. Just add 5v power and you are ready to go.
This is the pinout for an Arduino UNO
Connect the OLED screen to your Arduino as follows:
SCL goes to SCL
SDA goes to SDA
Vcc goes to 5v
GND goes to GND
It is that simple!
Lots more informationA slightly different device but the information here is mostly applicable: http://www.geekonfire.com/wiki/index.php?title=I2C_OLED_Panel(128x64)
Getting and installing the libraryThis is the best library I have found and it works very well for me. As well as line and basic shape drawing you get two font sizes and a bitmap editor.
To download the library:
Go to the resources of the link above. Direct link: http://www.geekonfire.com/wiki/index.php?title=I2C_OLED_Panel(128x64)#Resources
Click on the link for the Arduino library to download it.
I recommend the automatic library installation in Arduino, which is explained here: http://arduino.cc/en/Guide/Libraries
Once you have installed the library your Arduino environment should have these menus available (I have just upgraded to Arduino 1.6.0 which came out today!).
|The GOFi2cOLED Library showing as installed|
|GOFi2cOLED files added to the Examples|
Firing it up!The best way to start is to look at the Examples supplied. Load up an example you like the look of from the File > Examples > GOFi2cOLED menu and upload it to your Arduino.
Oh no, it didn't work!It might not work straight away. In i2c you can have many different devices on the communications bus and each device needs an address. The library assumes the address of your OLED screen is 0x3D, so far all of the screens I have bought have had an address of 0x3C.
You might need to change the i2c address used, look at the void setup() section of code:
//default address is 0x3D.
//address changed to 0x3C.
And re upload the code.
|Animated heart sketch running on my Arduino UNO|
If your screen still doesn't work, double check the wiring and try downloading a sketch that will sniff the i2c addresses and show you if the screen is correctly attached to the i2c bus and what address it is showing as. Simply put that address into the code and you shoild be good to go.