SSD1306 and i2c query

I’m trying to get a SSD1306 oled display to work but it’s i2c not SPI. I’ve found loads of examples for SPI but nothing to show how to get an i2c display to work.
Can anyone give me an example or link to one? I think I’m correct in assuming D0 is SDA and D1 is SCL on my Core board but what do I need to tell the library to use it?

#include <Adafruit_SSD1306.h>

#define OLED_RESET A0

Adafruit_SSD1306 display(OLED_RESET);

void display_init()
{
  display.begin(SSD1306_SWITCHCAPVCC);
  display.display(); // show the splash screen
  delay(2000);
  display.clearDisplay(); // clear the screen buffer
  display.display();  
}
void setup() {
display.println("SSD1306");
}

Should this work?

Your example won’t work because after you call println, you need to call display or it won’t display.

display.println("SSD1306");
display.display();

There is an example in the docs of using the SSD1306 by I2C. The working code is available there as well.

Most I2C SSD1306 displays don’t have a reset so pass -1 if you don’t have a RESET line connected.

Adafruit_SSD1306 display(-1);

Also you may need to specify the I2C address on the begin line. It’s usually 0x3C, but it could be 0x3D.

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
1 Like

Thanks for the help but I can’t get the example to compile. It gives me the following error,

/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/bin/ld: target/workspace.elf section `.data' will not fit in region `APP_FLASH'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/bin/ld: region `APP_FLASH' overflowed by 184 bytes
collect2: error: ld returned 1 exit status
../build/module.mk:232: recipe for target 'target/workspace.elf' failed
make: *** [target/workspace.elf] Error 1

I tried stripping it down to the absolute basic show a single pixel but still get the same error. I’m using the library Adafruit_SSD1306_RK, not Adafruit_SSD1306, is this the one you mean?

Do you actually have a Spark Core? There probably isn’t enough flash to use a SSD1306 because the fonts need to be stored in flash on the Particle device and space if very limited on the Core. If you have a different type of device, make sure it’s selected (gold star to the left of the name in the Web IDE).

Yes, I actually have a Spark Core and you’re absolutely correct that it is lack of memory!
Thanks for your help, I didn’t realise it had a lot less memory than my Photon.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.