ASK AN ENGINEER is LIVE now! Click here to watch our weekly show with LADYADA!

SSD128x32 OLED won't compile on Arduino 1.0.5 IDE

by mikelo on Sun Feb 09, 2014 2:37 am

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?
mikelo
 
Posts: 8
Joined: Sat Jan 05, 2013 12:09 am

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

by adafruit_support_rick on Sun Feb 09, 2014 10:50 am

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
adafruit_support_rick
 
Posts: 11404
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

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

by pburgess on Sun Feb 09, 2014 10:08 pm

Hey Rick - I was merging a bunch of pull requests last night, Due support is taken care of.
User avatar
pburgess
 
Posts: 2504
Joined: Sun Oct 26, 2008 1:29 am

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

by paulstoffregen on Mon Feb 10, 2014 1:14 pm

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.
paulstoffregen
 
Posts: 287
Joined: Sun Oct 11, 2009 10:23 am
Location: Portland, Oregon, USA

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

by paulstoffregen on Mon Feb 10, 2014 1:17 pm

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.
paulstoffregen
 
Posts: 287
Joined: Sun Oct 11, 2009 10:23 am
Location: Portland, Oregon, USA

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

by paulstoffregen on Mon Feb 10, 2014 1:28 pm

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 225 times
paulstoffregen
 
Posts: 287
Joined: Sun Oct 11, 2009 10:23 am
Location: Portland, Oregon, USA

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

by pburgess on Mon Feb 10, 2014 2:56 pm

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 | TOGGLE FULL SIZE
#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 | TOGGLE FULL SIZE
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
pburgess
 
Posts: 2504
Joined: Sun Oct 26, 2008 1:29 am

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

by paulstoffregen on Mon Feb 10, 2014 3:09 pm

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 | TOGGLE FULL SIZE
#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.
paulstoffregen
 
Posts: 287
Joined: Sun Oct 11, 2009 10:23 am
Location: Portland, Oregon, USA

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

by paulstoffregen on Mon Feb 10, 2014 4:18 pm

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.
paulstoffregen
 
Posts: 287
Joined: Sun Oct 11, 2009 10:23 am
Location: Portland, Oregon, USA

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

by pburgess on Mon Feb 10, 2014 4:32 pm

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
pburgess
 
Posts: 2504
Joined: Sun Oct 26, 2008 1:29 am

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

by paulstoffregen on Mon Feb 10, 2014 4:37 pm

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?
paulstoffregen
 
Posts: 287
Joined: Sun Oct 11, 2009 10:23 am
Location: Portland, Oregon, USA

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

by paulstoffregen on Mon Feb 10, 2014 4:59 pm

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.
paulstoffregen
 
Posts: 287
Joined: Sun Oct 11, 2009 10:23 am
Location: Portland, Oregon, USA

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

by paulstoffregen on Mon Feb 10, 2014 5:58 pm

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.
paulstoffregen
 
Posts: 287
Joined: Sun Oct 11, 2009 10:23 am
Location: Portland, Oregon, USA

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

by paulstoffregen on Tue Feb 11, 2014 10:26 am

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.
paulstoffregen
 
Posts: 287
Joined: Sun Oct 11, 2009 10:23 am
Location: Portland, Oregon, USA

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

by mikelo on Thu Feb 13, 2014 11:24 pm

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.
mikelo
 
Posts: 8
Joined: Sat Jan 05, 2013 12:09 am