Adafruit SSD1306 Library [Ported]

UPDATE: Adafruit_SSD1306 Ported by @peekay123 below! https://community.spark.io/t/problems-porting-adafruit-ssd1306-library-solved/3505/12


I’ve been trying to port the Adafruit SSD1306 library. I’ve gotten the GFX part to compile cleanly, but the SSD1306 stuff is complaining. I anticipate it’s my C++ naivete more than anything. Could someone help me debug this? The code is here on Github.

    In file included from ../inc/spark_wiring.h:30:0,
    from ../inc/application.h:31,
    from Adafruit_GFX.h:3,
    from Adafruit_GFX.cpp:34:
    ../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
    In file included from ../inc/spark_wiring.h:30:0,
    from Adafruit_SSD1306.cpp:22:
    ../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
    In file included from Adafruit_SSD1306.cpp:25:0:
    Adafruit_SSD1306.h:19:18: error: 'RwReg' does not name a type
    In file included from Adafruit_SSD1306.cpp:25:0:
    Adafruit_SSD1306.h:143:3: error: 'PortReg' does not name a type
    Adafruit_SSD1306.cpp: In member function 'void Adafruit_SSD1306::begin(uint8_t, uint8_t)':
    Adafruit_SSD1306.cpp:161:5: error: 'csport' was not declared in this scope
    Adafruit_SSD1306.cpp:161:57: error: 'digitalPinToPort' was not declared in this scope
    Adafruit_SSD1306.cpp:161:58: error: 'portOutputRegister' was not declared in this scope
    Adafruit_SSD1306.cpp:162:41: error: 'digitalPinToBitMask' was not declared in this scope
    Adafruit_SSD1306.cpp:163:5: error: 'dcport' was not declared in this scope
    Adafruit_SSD1306.cpp:169:6: error: 'clkport' was not declared in this scope
    Adafruit_SSD1306.cpp:171:6: error: 'mosiport' was not declared in this scope
    Adafruit_SSD1306.cpp: In member function 'void Adafruit_SSD1306::ssd1306_command(uint8_t)':
    Adafruit_SSD1306.cpp:295:6: error: 'csport' was not declared in this scope
    Adafruit_SSD1306.cpp:297:6: error: 'dcport' was not declared in this scope
    Adafruit_SSD1306.cpp: At global scope:
    Adafruit_SSD1306.cpp:386:6: error: prototype for 'void Adafruit_SSD1306::dim(bool)' does not match any in class 'Adafruit_SSD1306'
    In file included from Adafruit_SSD1306.cpp:25:0:
    Adafruit_SSD1306.h:131:8: error: candidate is: void Adafruit_SSD1306::dim(uint8_t)
    Adafruit_SSD1306.cpp: In member function 'void Adafruit_SSD1306::ssd1306_data(uint8_t)':
    Adafruit_SSD1306.cpp:409:6: error: 'csport' was not declared in this scope
    Adafruit_SSD1306.cpp:411:6: error: 'dcport' was not declared in this scope
    Adafruit_SSD1306.cpp: In member function 'void Adafruit_SSD1306::display()':
    Adafruit_SSD1306.cpp:441:6: error: 'csport' was not declared in this scope
    Adafruit_SSD1306.cpp:442:6: error: 'dcport' was not declared in this scope
    Adafruit_SSD1306.cpp:455:26: error: 'TWBR' was not declared in this scope
    Adafruit_SSD1306.cpp: In member function 'void Adafruit_SSD1306::fastSPIwrite(uint8_t)':
    Adafruit_SSD1306.cpp:492:8: error: 'clkport' was not declared in this scope
    Adafruit_SSD1306.cpp:493:20: error: 'mosiport' was not declared in this scope
    Adafruit_SSD1306.cpp:494:20: error: 'mosiport' was not declared in this scope
    make: *** [Adafruit_SSD1306.o] Error 1

These are low level commands to directly read from the microcontroller which seems like isn't on the spark core.

Some other libraries we tried porting using those functions as well and no one has said anything about how it can be replaced..

Right but we have other errors too, namely:

In file included from Adafruit_SSD1306.cpp:25:0:
Adafruit_SSD1306.h:19:18: error: 'RwReg' does not name a type
In file included from Adafruit_SSD1306.cpp:25:0:
Adafruit_SSD1306.h:143:3: error: 'PortReg' does not name a type

I can’t find those anywhere in the Arduino code or these Adafruit Libs.

huslage, others have discussed porting this library but I don’t believe it’s been done yet. I had ported the GFX library for the Sharp Memory display but not the SSD1306. I will take a look at this library to see what I can do. :smile:

I saw those in the Arduino.h file :smile:

huslage, are you wanting to use the display in I2C or SPI mode?

peekay123, it doesn’t make a difference to me.

It looks to me like digitalPinToPort eventually does some AVR assembler to read an address from PROGMEM. We don’t really have an interface to something like PROGMEM, afaik, so we would probably need to just abstract this away. The ultimate result of that macro is: http://garretlab.web.fc2.com/en/arduino/inside/avr/pgmspace.h/LPM_enhanced.html

huslage, it’s easy to get lost in the technicalities of the code when porting. I’ve done a lot of these and they pretty much work the same way. All the PROGMEM stuff is no longer necessary since the Spark has a unified memory architecture. As for the pin manipulation, it can all be replaced with digitalWrite() commands since they are faster on the Spark than on an arduino. I can try and have a port for you later today. :smile:

Ah great. Thanks so much.

Could you guys post a link to the GFX files please. I also look forward to @peekay123 's effort, I have been wanting to get my Adafruit OLED 128x64 working with the Sparkcore.

My GFX files are in the github link above. We will certainly share the love :smile:

huslage, everything is compiling using web IDE. I modified your surfsoon-oled.ino file to include the correct code for the Adafruit libary. Note that I configured your code to use I2C and the display RST line is on D4, both of which can be changed.

I posted the code and two Adafruit examples for the 128x64 display on my github. I don’t have one of those displays so you have to be the guinea pig! Let me know how it goes. :smile:

3 Likes

Awesome. Thanks peekay! I’ll let you know.

It’s working great. No problems so far.

2 Likes

I Just took a look at Github files and i’m a little confused.

My thinking is that i should be looking for one file that includes the required library .cpp and .h code.

would you just run through what files go where in a bit more detail please.

thanks

BusterSpark, the web IDE can take more than one file using tabs. A tab is created when you create a new app. In that tab, you paste one of the demo .ino programs. Then, create two more tabs by clicking the small circular icon next to the first tab and name the first of the new tabs Adafruit_SSD1306.h and the second will automatically be name to .cpp. Cut an paste the github code for those fine in there. When you create those new tabs, the IDE will add a #include line at the top of the demo code in the first tab. You must remove that because the includes are already in the file. After that, do a verify and off you go! :smile:

1 Like

Trying to test this example but get the below error.
What do I miss?
Tested both the ssd1306 and surfsoon example without any luck.

In file included from …/inc/spark_wiring.h:30:0,
from …/inc/application.h:31,
from Adafruit_GFX.h:4,
from Adafruit_GFX.cpp:34:
…/…/core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning “Defaulting to Release Build” [-Wcpp]
In file included from …/inc/spark_wiring.h:30:0,
from …/inc/application.h:31,
from Adafruit_GFX.h:4,
from Adafruit_SSD1306.cpp:19:
…/…/core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning “Defaulting to Release Build” [-Wcpp]
In file included from …/inc/spark_wiring.h:30:0,
from …/inc/application.h:31,
from ssd1306_128x64_spi.cpp:4:
…/…/core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning “Defaulting to Release Build” [-Wcpp]
ssd1306_128x64_spi.cpp:21:26: fatal error: Adafruit_GFX.h: No such file or directory
compilation terminated.
make: *** [ssd1306_128x64_spi.o] Error 1

Error: Could not compile. Please review your code.

mippen, if you are using the web IDE and you have multiple files, you should have a tab called "Adafruit_GFX.h". The IDE is not finding this tab.

Is it my spelling thats wrong?
Tried a couple of times with copy/paste on the tab names.

mippen, replace the “<” and “>” in the includes with double quotes like this:

#include "application.h"
#include "Adafruit_GFX.h"

I missed those in the demo file you picked! :open_mouth: