SH1106 OLED - Adafruit library not compiling

tspringer

Member
I would like to use an SH1106 I2C OLED in a project. Google and a search of the forum do not provide a clear answer of whether this is easily accomplished. Adafruit provides a library (Adafruit_SH1106-master) and an example of use. However, when I try to test the library on the Teensy 4.1 using the provided example program, the compiler generates a series of error messages when compiling the library files. Have any of you been able to get this library to work? Is there a functional alternative if not?

I have had no problems working with the Adafruit library for SH1306 OLEDs working with a Teensy 4.1. I have attached the example SH1106 I2C program from Adafruit. Here are the error messages that the compiler generates:

In file included from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/core_pins.h:33,
from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/wiring.h:39,
from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/WProgram.h:46,
from C:\Users\Michael\AppData\Local\Temp\arduino\sketches\A71F12D0E38BEF0A781D55C47A96A9A9/pch/Arduino.h:6,
from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\libraries\Wire/WireIMXRT.h:32,
from C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\libraries\Wire/Wire.h:26,
from c:\Users\Michael\Documents\Arduino\libraries\Adafruit_SH1106-master\Adafruit_SH1106.cpp:35:
c:\Users\Michael\Documents\Arduino\libraries\Adafruit_SH1106-master\Adafruit_SH1106.cpp: In member function 'void Adafruit_SH1106::begin(uint8_t, uint8_t, bool)':
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/pins_arduino.h:142:71: error: cannot convert 'volatile uint32_t*' {aka 'volatile long unsigned int*'} to 'PortReg*' {aka 'volatile unsigned char*'} in assignment
142 | #define portOutputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 0))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
| |
| volatile uint32_t* {aka volatile long unsigned int*}
c:\Users\Michael\Documents\Arduino\libraries\Adafruit_SH1106-master\Adafruit_SH1106.cpp:179:19: note: in expansion of macro 'portOutputRegister'
179 | csport = portOutputRegister(digitalPinToPort(cs));
| ^~~~~~~~~~~~~~~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/pins_arduino.h:142:71: error: cannot convert 'volatile uint32_t*' {aka 'volatile long unsigned int*'} to 'PortReg*' {aka 'volatile unsigned char*'} in assignment
142 | #define portOutputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 0))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
| |
| volatile uint32_t* {aka volatile long unsigned int*}
c:\Users\Michael\Documents\Arduino\libraries\Adafruit_SH1106-master\Adafruit_SH1106.cpp:181:19: note: in expansion of macro 'portOutputRegister'
181 | dcport = portOutputRegister(digitalPinToPort(dc));
| ^~~~~~~~~~~~~~~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/pins_arduino.h:142:71: error: cannot convert 'volatile uint32_t*' {aka 'volatile long unsigned int*'} to 'PortReg*' {aka 'volatile unsigned char*'} in assignment
142 | #define portOutputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 0))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
| |
| volatile uint32_t* {aka volatile long unsigned int*}
c:\Users\Michael\Documents\Arduino\libraries\Adafruit_SH1106-master\Adafruit_SH1106.cpp:187:21: note: in expansion of macro 'portOutputRegister'
187 | clkport = portOutputRegister(digitalPinToPort(sclk));
| ^~~~~~~~~~~~~~~~~~
C:\Users\Michael\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4/pins_arduino.h:142:71: error: cannot convert 'volatile uint32_t*' {aka 'volatile long unsigned int*'} to 'PortReg*' {aka 'volatile unsigned char*'} in assignment
142 | #define portOutputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 0))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
| |
| volatile uint32_t* {aka volatile long unsigned int*}
c:\Users\Michael\Documents\Arduino\libraries\Adafruit_SH1106-master\Adafruit_SH1106.cpp:189:21: note: in expansion of macro 'portOutputRegister'
189 | mosiport = portOutputRegister(digitalPinToPort(sid));
| ^~~~~~~~~~~~~~~~~~

exit status 1

Compilation error: exit status 1
 

Attachments

  • sh1106_128x64_i2c.ino
    9.4 KB · Views: 51
Thanks for the suggestion. Tried that library, still no compile. Thy type of compile error that is occurring makes me think that this is an Adafruit problem, and probably isn't Teensy specific. I will hop over there and see if I can get some help on their forum.
 
Install Arduino Libraries
Using these OLEDs with Arduino sketches requires that two libraries be installed: Adafruit_SSD1306, which handles the low-level communication with the hardware, and Adafruit_GFX, which builds atop this to add graphics functions like lines, circles and text.
If you read the Adafruit instructions for the SH1106 128X64 module they say use the SH1306 library. See above.

Also see here.
 
Thanks for the suggestions BriComp. I had already tried the Adafruit_SSD1306 library. It compiles, but the OLED display is more or less random pixels. I found yet another library, that also compiles. The OLED display looks different, but is still a garbled mess. I don't want to spend any more time trying to get this OLED to work when I can revert to using the SH1306 OLEDs and make progress on the overall project that I have in mind. Yeah, I am wimp for giving up. Thanks to all for trying to help.
 
Understandable if you have something that works...
But still curious on what 1106 display (the problem child) you actually have. Do you have a link to one of them?

Kurt
 
Thanks KurtE. I am curious too. Here is a link to the Amazon page for the SH1106 OLED that I am using.

https://www.amazon.com/Alinan-Displ...efix=alinan+1.3+oled+white,aps,78&sr=8-3&th=1

Careful if you swap this 1106 with a 1306 OLED -- ground and VCC are reversed, and I was lucky not to have fried something before I noticed.

I am beginning to wonder if the Arduino IDE's compiler might be partly boluxed. I just ran into a library for a MX1508 dual H-bridge that also fails to compile (I am posting about that in another thread). I have never had problems with compiling libraries before, so either I am experiencing a run of bad luck, or there is something awry with the compiler. Anyway, thanks again for your time and interest.

Tim
 
Been there and just did that... And luckily did not fry it...

I don't have that display, but I do have:
https://www.amazon.com/gp/product/B00O2KDQBE

And forgot to ask if you did the thing that usually gets me.
That is make sure you have the right I2C address.

For example with the one I pointed to, I am using the Adafruit_SSD1306 library. And running the ssd1306_128x64_i2c.ino.
And at first build nothing worked. Then I changed:
#define SCREEN_ADDRESS 0x3c ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32

and now it is running.

And in any case would recommend running: example sketch: Wire -> Scanner.

And when I run it on my setup I see:
Code:
I2C Scanner
Scanning...
Device found at address 0x3C  (SSD1306,DigisparkOLED)
done
 
Kurte, I ran the I2C scanner and strangely, it found the OLED at 0x3C and identified it as (SSD1306,DigisparkOLED), just like yours. I tried writing to the OLED one last time according to the scanner info, and still the screen was garbled. Perhaps the supposed SH1106 OLEDS that I got very are cheap knockoffs that are not quite right. Anyway, thanks for ideas to try out.
 
Back
Top