OLED, I2C (9)

Inter-integrated Circuit (I2C) is a communication protocol that is used to connect many embedded devices. In our case, we are going to use it to connect an Organic LED (OLED), a tiny screen for more display goodness.

Assuming that you ordered your chip from someplace else (Aliexpress/Ebay), you might not be able to find documentation for this module. Alongside serving as a tutorial for the ULCK kit, this also serves as a guide to getting most OLED modules to work with other platforms.

Programming

Your OLED module other than the VCC/VDD and GND, has two other lines, SDA and SCL/SCK. These you'll have to connect to the respective SDA and SCL/SCK output pins on your device.

For the ESP8266 module, we will be using Adafruit's I2C Library and Adafruit's GFX Library to display images. But we have to make a few changes in order to get our screen to work.

Find where your Libraries folder is (usually in ~/Arduino/Libraries) and open the Adafruit_SSD1306.h file that you have just downloaded. Assuming that your OLED screen is 128 x 64, find the line #define SSD1306_128_64 and uncomment it. If this is not done the images on the OLED module might appear to be stretched. If there any other uncommented lines, comment them. Make sure only one of those four lines are defined.

Now going to the code, to start quickly, we'll be using Adafruit's I2C 128 x 64 example. In the code, instead of using display.begin(SSD1306_SWITCHCAPVCC, 0x3D), and change 0x3D to 0x3C.

Also note that if you are using a WeMos Mini, you will have to change the line #define OLED_RESET 4 to #define OLED_RESET 0 in the example sketch for your OLED to work because pin 4 is used for SDA communications on the WeMos board.

For the ATTINY85 module, Digispark's OLED example works without additional editing. You should be able to upload your code and get your OLED screen working immediately.

Both the ESP8266 and the ATTINY85 are compatible, however, while the ATTINY85 might be running up to its limit at 80% of memory used with the Digispark OLED sketch, for the ESP8266, the Adafruit example sketch takes up about 20% of its total memory.