Code samples for driving a display with Photon through I2C

I’m thinking of getting this I2C Display to drive using a Particle Photon through this breakout board. My problem is that, unlike other products on the product site, there don’t seem to be any code samples for this particular product on site. I tried to Google around but could only find code examples for a Adafruit Display that is connected directly to an Arduino through a 10 way cable.

Has anyone managed to control a similar device using a similar setup?

Thank you!

@osprey, the display module uses a standard SSD1306 display in I2C mode. You can find a library (ADAFRUIT_SSD1306 on the web IDE which should work. Make sure you modify the I2C address of the display in the sample code.

If that library dosen’t work, you can use the one in my repo, using the beginner-128x64-OLED-I2C.ino example to use I2C.

Cheers!

1 Like

Thanks mate, that’s exactly what I was hoping for!

1 Like

I finally got the device and tried your code but I am getting the following error:

Adafruit_GFX/Adafruit_GFX.cpp:36:0: warning: "pgm_read_byte" redefined [enabled by default]
 #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
 ^
In file included from ../wiring/inc/spark_wiring.h:37:0,
                 from ./inc/application.h:36,
                 from Adafruit_GFX/Adafruit_GFX.h:4,
                 from Adafruit_GFX/Adafruit_GFX.cpp:34:
../wiring/inc/spark_wiring_arduino.h:32:0: note: this is the location of the previous definition
 #define pgm_read_byte(x)      (*(x))
 ^
Adafruit_SSD1306/Adafruit_GFX.cpp:36:0: warning: "pgm_read_byte" redefined [enabled by default]
 #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
 ^
In file included from ../wiring/inc/spark_wiring.h:37:0,
                 from ./inc/application.h:36,
                 from Adafruit_SSD1306/Adafruit_GFX.h:4,
                 from Adafruit_SSD1306/Adafruit_GFX.cpp:34:
../wiring/inc/spark_wiring_arduino.h:32:0: note: this is the location of the previous definition
 #define pgm_read_byte(x)      (*(x))
 ^
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::invertDisplay(bool)':
Adafruit_SSD1306/Adafruit_GFX.cpp:420: multiple definition of `Adafruit_GFX::drawLine(short, short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:420: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::drawRoundRect(short, short, short, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:462: multiple definition of `Adafruit_GFX::drawRect(short, short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:462: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::drawFastVLine(short, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:470: multiple definition of `Adafruit_GFX::drawFastVLine(short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:470: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::drawFastHLine(short, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:476: multiple definition of `Adafruit_GFX::drawFastHLine(short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:476: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::fillRect(short, short, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:482: multiple definition of `Adafruit_GFX::fillRect(short, short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:482: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::fillScreen(unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:489: multiple definition of `Adafruit_GFX::fillScreen(unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:489: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::invertDisplay(bool)':
Adafruit_SSD1306/Adafruit_GFX.cpp:727: multiple definition of `Adafruit_GFX::invertDisplay(bool)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:727: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::Adafruit_GFX(short, short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:297: multiple definition of `Adafruit_GFX::Adafruit_GFX(short, short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:297: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::Adafruit_GFX(short, short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:297: multiple definition of `Adafruit_GFX::Adafruit_GFX(short, short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:297: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::drawCircle(short, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:311: multiple definition of `Adafruit_GFX::drawCircle(short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:311: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::drawCircleHelper(short, short, short, unsigned char, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:345: multiple definition of `Adafruit_GFX::drawCircleHelper(short, short, short, unsigned char, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:345: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::fillCircleHelper(short, short, short, unsigned char, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:388: multiple definition of `Adafruit_GFX::fillCircleHelper(short, short, short, unsigned char, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:388: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::fillCircle(short, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:381: multiple definition of `Adafruit_GFX::fillCircle(short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:381: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::drawRoundRect(short, short, short, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:495: multiple definition of `Adafruit_GFX::drawRoundRect(short, short, short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:495: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::fillRoundRect(short, short, short, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:510: multiple definition of `Adafruit_GFX::fillRoundRect(short, short, short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:510: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::drawTriangle(short, short, short, short, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:522: multiple definition of `Adafruit_GFX::drawTriangle(short, short, short, short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:522: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::fillTriangle(short, short, short, short, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:531: multiple definition of `Adafruit_GFX::fillTriangle(short, short, short, short, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:531: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::drawBitmap(short, short, unsigned char const*, short, short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:608: multiple definition of `Adafruit_GFX::drawBitmap(short, short, unsigned char const*, short, short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:608: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::drawChar(short, short, unsigned char, unsigned short, unsigned short, unsigned char)':
Adafruit_SSD1306/Adafruit_GFX.cpp:641: multiple definition of `Adafruit_GFX::drawChar(short, short, unsigned char, unsigned short, unsigned short, unsigned char)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:641: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::write(unsigned char)':
Adafruit_SSD1306/Adafruit_GFX.cpp:621: multiple definition of `Adafruit_GFX::write(unsigned char)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:621: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::setCursor(short, short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:675: multiple definition of `Adafruit_GFX::setCursor(short, short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:675: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::setTextSize(unsigned char)':
Adafruit_SSD1306/Adafruit_GFX.cpp:680: multiple definition of `Adafruit_GFX::setTextSize(unsigned char)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:680: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::setTextColor(unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:686: multiple definition of `Adafruit_GFX::setTextColor(unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:686: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::setTextColor(unsigned short, unsigned short)':
Adafruit_SSD1306/Adafruit_GFX.cpp:690: multiple definition of `Adafruit_GFX::setTextColor(unsigned short, unsigned short)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:690: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::setTextWrap(bool)':
Adafruit_SSD1306/Adafruit_GFX.cpp:695: multiple definition of `Adafruit_GFX::setTextWrap(bool)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:695: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::getRotation()':
Adafruit_SSD1306/Adafruit_GFX.cpp:700: multiple definition of `Adafruit_GFX::getRotation()'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:700: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::setRotation(unsigned char)':
Adafruit_SSD1306/Adafruit_GFX.cpp:703: multiple definition of `Adafruit_GFX::setRotation(unsigned char)'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:703: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::width()':
Adafruit_SSD1306/Adafruit_GFX.cpp:721: multiple definition of `Adafruit_GFX::width()'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:721: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o): In function `Adafruit_GFX::height()':
Adafruit_SSD1306/Adafruit_GFX.cpp:725: multiple definition of `Adafruit_GFX::height()'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):Adafruit_GFX/Adafruit_GFX.cpp:725: first defined here
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):(.rodata._ZTV12Adafruit_GFX+0x0): multiple definition of `vtable for Adafruit_GFX'
../../../build/target/user/platform-6/libuser.a(Adafruit_GFX.o):(.rodata._ZTV12Adafruit_GFX+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [31b971c9c4fa1ca1feb25690ef1465d8a4d9c5a1f27b2aa1669348dc4d08.elf] Error 1
1 Like

You need to remove your own import of Adafruig_GFX since Adafruit_SSD1306 library brings its own private copy of it :confused:

I’d guess you’ll have an #include "Adafruit_SSD1306/Adafruit_GFX.h" or #include "Adafruit_GFX.h" and an #include "Adafruit_GFX/Adafruit_GFX.h"
That’s a recipe for troubles.

2 Likes

Indeed. That was the problem. Thanks!

1 Like

@osprey glad you got it working! Thanks for all the help @peekay123 @ScruffR!!

1 Like

Total novice here

I’m trying to compile Adafruits ssd1306-128x64-12c.ino example for use on a Particle.io Electron platform.

When run the compile I get the following error

“/firmware/wiring/src/spark_wiring_random.cpp:5: multiple definition of `random(int)’”

Any idea… Pete

@pdonich, simply remove or comment out the random() function definition:

//int random(int maxRand) {
//    return rand() % maxRand;
//}