Adafruit SSD1306 [SOLVED]

I’m having trouble working with the Adafruit libraries for their OLED displays. The library (SSD1306) is in the library catalog, but the one in the catalog is configured for a different display than the one I have. In the adafruit_SSD1306.h file, there’s the following:

#define SSD1306_128_64
// #define SSD1306_128_32
// #define SSD1306_96_16

I’m using the 128 x 32 display, so I need to comment out the #define SSD1306_128_64 and uncomment out the #define SSD1306_128_32. Not a big deal, but it kinda makes it hard to use the library. To get this to work, as I understand it, I have to fork the library to my GitHub account, make the changes then import the forked library into the web IDE.

This isn’t easy to do mind you, I’ve got to fork it, then change the folder structure AND make a spark.json file, right? But I got it done albeit with some mishaps.

Anyway, with this library in place, I can’t get the sample code from Adafruit to compile. Apparently there are other libraries used by this library. When I try to compile, I get all sorts of errors,

First of all, during verify I get an error that WProgram.h cannot be found, turns out the culprit is this code:

#if ARDUINO >= 100
#include “Arduino.h”
#define WIRE_WRITE Wire.write
#include “WProgram.h”
#define WIRE_WRITE Wire.send

I found something online that said I need to replace the WProgram.h with:

#include “application.h”

so I’ve done that and gotten around that particular error. Next, I’m getting an:

Adafruit_SSD1306/Adafruit_SSD1306.h:36:17: fatal error: SPI.h: No such file or directory
#include <SPI.h>

I can’t find that file anywhere in the Adafruit code, so I don’t know what to do with this.

What exactly should I be doing to get the Adafruit libraries working in my app? I’ve searched and I can’t find any reference to how to hack these libraries to make them work with the Photon and I could really use your help.

Try this link. Lots of info on how to import into web ide and use that lib.

I have mine on I2C and its plenty fast. I also have one wire temp sensor and dht11 on it. I can snap a pic if you want to replicate my setup. All breadboard right now.

Nothing there really helps me. Looks like there’s a lot of problems with different parts of the Adafruit library. To get further, I forked the SPI library and converted it for Particle, but then I quickly run up against another library that either can’t be found and/or needs to be updated. I knew the Photon wasn’t an arduino, but I thought arduino libraries would would work. Sigh.

It’s not an I2X issue, it’s an Adafruit library issue.

Post your code and I’ll see if I can help. Also layout your pin mappings if you don’t mind.

A bit sacrilegious but I prefer to use Particle Dev [Download here][1] work local, compile in Particle Cloud and flash straight from the IDE. Then to use a lib I find the lib I want, download it from github, put it in the same folder as my main program (whatever.ino) and edit it to suit my needs. Don’t create subfolders, it won’t compile… Here is an example of an nRF24 scanner I wrote, that uses a 128x64 oled and the lib that @peekay123 ported.

You can see the file layout and the adafruit #defines and display.begin statements are all you need to start outputting to your oled after that. For “hello world” you would add the line

display.println("Hello World");

. display.println means write with a carriage return after it and display.display() tells the display to update with the data in the buffer which you sent with the display.println command. Does that help?

Hey Luke,

if i have an OLED 0.96inch 12864 display module blue, am i able to use this same Adafruit library that @peekay123 ported? and if so (and i know this is asking a lot) where can i find a step by step setup (setup pins, import adafruit lib correctly in particle dev etc) ?? Thanks with any help. Ive had my new photon kit for 2 weeks now and cant seem to get the oled working. Im still new to this micro controller process so I’ve only been able to do the blink led part but beyond that, its all still real confusing for me.

I see similar requests quite often, I’ll try to do an unofficial tutorial tomorrow. I’m no expert and Particle is the first microcontroller I used as well but the community was helpful and got me through it. As general advice:
search lots and often, ask questions when you have error, ask questions that indicate you’ve tried/researched throughly and be willing to fail. I’m a try it and see kind of guy and its served me well on here! Happy to help in the ways I can…stay tuned.

1 Like

The Adafruit_SSD1306 library that can be found in Particle Build (Web IDE) does work for the display coming with the kit.

If building in Particle Build (Web IDE) you need to change the includes in the demos to

// e.g.  ssd1306-128x64-spi.ino

#include "Adafruit_SSD1306/Adafruit_GFX.h"
#include "Adafruit_SSD1306/Adafruit_SSD1306.h"

If building with Particle Dev or CLI just leave them as they are

For all IDEs do the wiring like this

// use hardware SPI
// OLED_D0 -> A3 (SPI CLK)
// OLED_D1 -> A5 (SPI MOSI)
#define OLED_DC     D3
#define OLED_CS     D4
#define OLED_RESET  D5

and you need to remove the function (which is some sort of residue of former firmware needs ;-))

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

Thanks @ScruffR , I’m trying that out now. Will let you know if i can get up and working.

It didn’t work for me. Got Error: “build didn’t produce binary Error: Command…” . Thanks for the help alot (I’ve been trying to get at least something “Hello World” on the screen for 2 weeks), i didn’t think it would be this difficult to get products from the Photon kit up and working. I guess Blink LED is the only good deed for beginners.

can you post some more of your error output?

What IDE are you using?

just a quick check (probably not the issue), because so far I have done this everytime I create a new module for the particle… Make sure to use .cpp NOT .c.

1 Like

@ScruffR using Particle Dev. I will re-hook things up and screen shot errors. It was in red at the bottom of Particle Dev. Steps i took: I downloaded the github repo for the library and just changed the things you said change and that error is what came up. I will post screen shots in a sec. brb

@ScruffR #1. Here is my setup with the oled. using your #define D3, D4 & D5 hookup.

#2. Here was the first error after i tried to compile code “No such file” but i deleted the Adafruit_SSD1306

#3. Here is what i had next after I compile but the error is “build didn’t produce binary Error: Comman…”

#4. This is how my folder looks in Particle Dev with the downloaded repo from github. Thanks a lot for your help.

OK, my suggestion to change the #include statements refered to Particle Build (Web IDE). (I’ve added a more explicit comment to reflect this even more clearly)
In Particle Dev you keep the original includes.

And …

… and I think this is the issue …

in Particle Dev you need to remove all non .h/.cpp files except the one .ino you actually want to build.
If you have more than one .ino the compiler doesn’t know which example you actually want in your firmware.

It’s a bit confusing that you don’t get a clearer error message from Dev (yet?).

1 Like

Ok, i will try this and see if that works. Thanks again for the help.

Code compiles with no errors now but Oled Screen is still blank lol I flash the code to my Core and its just blank oled screen. Is it something else I’m suppose to do to have the “Hello World” show up on the screen?

Cut and paste the setup() and loop() code please.

1 Like

#1. setup() & loop() code:

void setup()   {

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  // init done

  display.display(); // show splashscreen
  display.clearDisplay();   // clears the screen and buffer

  // draw a single pixel
  display.drawPixel(10, 10, WHITE);

  // draw many lines

  // draw rectangles

  // draw multiple rectangles

  // draw mulitple circles

  // draw a white circle, 10 pixel radius
  display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);





  // draw the first ~12 characters in the font

  // draw scrolling text

  // text display tests
  display.println("Hello, world!");
  display.setTextColor(BLACK, WHITE); // 'inverted' text
  display.print("0x"); display.println(0xDEADBEEF, HEX);

  // miniature bitmap display
  display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);

  // invert the display

  // draw a bitmap icon and 'animate' movement
  testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);

void loop() {


@LukeUSMC its the same code from @peekay123 Github