SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
mikelo
 
Posts: 16
Joined: Sat Jan 05, 2013 1:09 am

SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by mikelo »

When I was trying to compile the code to Teensy 3.1 with Arduino 1.0.5, it shows me the message below

/Users/MikeLo/Documents/Arduino/libraries/AdafruitSSD1306/Adafruit_SSD1306.cpp: In member function 'void Adafruit_SSD1306::display()':
/Users/MikeLo/Documents/Arduino/libraries/AdafruitSSD1306/Adafruit_SSD1306.cpp:432:26: error: 'TWBR' was not declared in this scope

Does anyone know how to solve this problem?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by adafruit_support_rick »

The library is written for Arduino. The teensy 3.1 is a completely different processor architecture, and the library is not completely compatible with it.

I was working on an Arduino Due port of the library. Let me see if I can make it work with a Teensy 3.1 as well. I'll let you know.

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by pburgess »

Hey Rick - I was merging a bunch of pull requests last night, Due support is taken care of.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by paulstoffregen »

Does anyone know how to solve this problem?
Install the latest version of Teensyduino, either 1.18-rc2 or 1.18-rc3.

You probably using 1.17, which supports Teensy 3.1 but several of the libraries were not updated for 3.1. Simply installing the latest version will fix this problem.

adafruit_support_rick wrote:The teensy 3.1 is a completely different processor architecture, and the library is not completely compatible with it.
Actually Rick, the 128x32 I2C OLED has been tested with Teensy 3.0 and 3.1. It works great. But the latest software is needed.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by paulstoffregen »

pburgess wrote:Hey Rick - I was merging a bunch of pull requests last night, Due support is taken care of.
Oh, I'll retest it soon. Sometimes Due support breaks Teensy 3.X, especially if the code assumes #if defined(__arm__) can mean only Arduino Due. Yes, that's happened several times on various libraries. Simple to fix for library authors... but annoying for users.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by paulstoffregen »

Just tested the latest code on Teensy 3.1. It's works great.

Well, the library still requires editing the .h file to set 32 lines. Also, Arduino's 2 robot libraries cause conflicts with Adafruit_GFX. I just deleted the robot libs. But with the robot libs out of the way and the .h file edited, Adafruit_SSD1306 works great on Teensy 3.1.

Here's a photo:
oled.JPG
oled.JPG (58.09 KiB) Viewed 1350 times

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by pburgess »

Sometimes Due support breaks Teensy 3.X [...] Simple to fix for library authors... but annoying for users.
Say, been meaning to ask, what's your Preferred Canonical Way™ of distinguishing among them, so I can follow it in the future? These two lines are from the NeoPixel and SSD1306 libraries, respectively:

Code: Select all

#if defined(__MK20DX128__) || defined(__MK20DX256__) // Teensy 3.0 & 3.1
#ifdef __SAM3X8E__ // Due
Good 'nuff?
Just tested the latest code on Teensy 3.1. It's works great.
Yay!

There's some kludgetacular stuff to get 400 KHz I2C going on the Due. Dunno if the Teensy uses the same 100 KHz default as Arduino...if so, the difference w/400KHz is very pronounced, so it might be worth doing the extra bit of ugly register-grappling.

Code: Select all

Well, the library still requires editing the .h file to set 32 lines.
Blargh, yeah. I was just poking around with ideas for this last night, but kind of hit a wall. Separate classes for the two sizes are required (because it's subclassed from Adafruit_GFX, requiring fixed dimensions in the constructor), doesn't seem so bad until you realize that there are some virtual functions that need to be uniquely defined for each subclass, and it ends up being either a lot of duplicitous code (which I don't like, because size) or wrapper functions around common code (which I don't like, because speed). If I can settle on an approach, I might give the lib a thorough de-cobwebbification.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by paulstoffregen »

For a lot of libraries, especially most of Adafruit's, it's best to just let the AVR code compile for Teensy3. Something like this:

Code: Select all

#if defined(__AVR__) || defined(TEENSYDUINO)

#elif defined(__SAM3X8e__)

#endif
Obviously this doesn't work if you get too specific on AVR stuff, but it does work for nearly everything Adafruit publishes. Teensyduino automatically translates commonly used AVR registers like PORTD, DDRD, TWBR, SPSR, SPDR, SREG into equivalent native code. This particular library is a perfect example, where it only depends on the Wire library and TWBR. Your AVR specific code "just works" on Teensy 3.1 and set the I2C to 400 kHz, just by writing to TWBR.

But for more specific code, "#if defined(__MK20DX128__) || defined(__MK20DX256__)" would be technically correct. Generally that's only needed in much lower level libraries, like NeoPixel.


The situation with the robot libraries is really annoying. In fact, I'm about to put a patch in the java code to specifically not check those 2 libraries if a Teensy board is selected. Yup, resorting to such a dirty hack makes me feel a bit icky, but I'm getting really tired of people hitting this problem over and over again.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by paulstoffregen »

I think I've found the place in the IDE where the root library conflicts happens. It's Base.addLibraries().

Currently the last library found is used. I'm working on a patch that will always give preference to a library that has the same name as the header file. So Adafruit_GFX will be used with Adafruit_GFX.h is found in the sketch and never some other library like Robot_Control that just happens to have a (very old) copy of Adafruit_GFX.h.

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by pburgess »

The Robot issue will be fixed if they would just plop out a new release of the IDE! A pull request was already made (and accepted) with a new Adafruit_GFX library. In fact, it's probably fine in 1.5.5. But I don't know when (or even if) there will be a 1.0.6 release.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by paulstoffregen »

But what happens months or years after 1.0.6 when Adafruit_GFX updates again with some awesome new stuff, like variable size anti-aliased fonts or something?

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by paulstoffregen »

Oh, I see... they moved Adafruit_GFX.h to a subdirectory and then added a non-conflicting name.

The whole library matching process is still able to match the wrong library. This really ought to be more reliable.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by paulstoffregen »

I created a patch and submitted it to Arduino.

https://github.com/arduino/Arduino/pull/1853

I'm also going to put this into the Teensyduino 1.18 installer. Since it's not the ugly Teensy-only kludge I'd imagined earlier, it should fix these problems even when using Arduino Uno or Leonardo or Mega, simply by having Teensyduino 1.18 installed.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by paulstoffregen »

The Arduino developers have merged my patch, so it'll be in 1.0.6.... when/if 1.0.6 ever releases.

I'm going to release Teensyduino 1.18 later today, with this patch in the installer.

mikelo
 
Posts: 16
Joined: Sat Jan 05, 2013 1:09 am

Re: SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

Post by mikelo »

thank you Paul. Does that mean I load the example code of SSD 1306 will work just fine without edition any code? by the way, do I connect them to pin 18 and 19? Do I have to use pull up resister.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”