Sabernetics I2C OLED display / Adafruit SSD1306 library problem

tomfrisch

Well-known member
I got a Sabernetics I2C OLED display from kickstarter a while back, and decided to try and use it with Teensy3, then I ran into some problems.
The display comes with arduino libraries and examples, which look to be based on the code in the Adafruit SSD1306 and GFX libraries.

The code from Sabernetics is here: http://sabernetics.com/wp-content/uploads/2012/06/OLED_I2C.zip

When I compile, I get an error that /util/delay.h was missing from SSD1306.cpp. Following advice in this thread I removed references to that header, but then it gave me: "error: 'TWBR' was not declared in this scope"

Any suggestions on how to get this to work?

-Tom
 
When I compile, I get an error that /util/delay.h was missing from SSD1306.cpp. Following advice in this thread I removed references to that header, but then it gave me: "error: 'TWBR' was not declared in this scope"

Looks like they manually alter the TWBR register (an AVR specific register) in the Adafruit_SSD1306.cpp file, specifically the display() function where they "boost" it to 400kHz (woo~). How unportable of them.

Well if it's going to be unportable you can do better than that. I've uploaded a revised version that compiles ok for me on Teensy3. To use it you will also want to grab the 'v5' I2C library from here:
http://forum.pjrc.com/threads/21680-New-I2C-library-for-Teensy3

The modifications I did are as follows (very minor):

  • In MiniOLED and MiniOLED_Multi example sketches, line 7:
    changed #include <Wire.h> to #include <i2c_t3.h>

  • In Adafruit_SSD1306.cpp, line 23:
    changed #include <Wire.h> to #include <i2c_t3.h>

  • In Adafruit_SSD1306.cpp, line 167:
    changed Wire.begin() to Wire.begin(I2C_MASTER,0,I2C_PINS_18_19,I2C_PULLUP_EXT,I2C_RATE_400);
    This sets up Teensy3 as the Master, using I2C pins 18/19, external pullups, and 400kHz rate.

  • In Adafruit_SSD1306.cpp, line 336-375:
    Commented out the TWBR lines for altering the baud rate.

Those examples compile ok for me now, but I can't test them since I don't have the hardware. One thing you can do however, once you check it works, is an actual boost - by altering the I2C rate on line 167 above you can achieve perhaps a real boost in display performance. Refer to the I2C thread above for the different rates you can try.
 

Attachments

  • OLED_I2C_t3.zip
    16.1 KB · Views: 352
nox- thanks so much for your help!

I installed the v5 version of your I2C library, and your altered version of the OLED_I2C_t3 library.

When I compiled I got errors about the /util/delay.h missing. So I found this post about it- which says to comment out the /util/delay.h, and then make some changes to the makefile, and the Adafruit GFX library. I made those, and am now able to compile without errors.

Switched the pin for the reset to the correct pin.... and we have contact!

photo.JPG

-Tom
 
Last edited:
Hmm, IIRC I didn't see anything about delay.h when I compiled (I am running latest Teensyduino). In any event, good to see it worked. That is a really small display.
 
Here is my first attempt at TWBR emulation to set 400 kHz speed.

Copy this file to libraries/Wire. Please let me know if it works for you?
 

Attachments

  • Wire.h
    3.4 KB · Views: 369
Back
Top