I have an issue with using two libraries together, namely SPI.h that is installed together with an Arduino and Adafruit_SSD1306.h. My code was getting stuck so I stripped it down to the bare minimum to find where the problem occurs. Here's the stripped down code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>

//Screen Resoluttion
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_Res A3
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_Res);

#define _ssPin  7

void setup()   {  
  pinMode(OLED_Res, OUTPUT);
  pinMode(_ssPin, OUTPUT);
  Serial.println("Serial set up");   
  Serial.println("SPI set up");
  Serial.println("I2C set up");
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  Serial.println("Screen set up");

void loop()                    
  Serial.println("Loop entered");

I am debugging the code using serial monitor. The code as it stands right now hangs after I2C initialization. If I uncomment either SPI.begin() or display.begin(...) it jumps into the loop. Which leads me to think there might be a conflict between the two libraries. Which is weird considering I haven't found a similar issue on the internet and I doubt these two libraries are rarely used.

  • You might be suffering from a lack of memory. The SSD1306 library requires a lot of memory to operate which doesn't leave much for other things.
    – Majenko
    Oct 11 '20 at 12:18
  • This is a known issue. The thing is the code doesn't run anything else. There are 1463 bytes available, plenty enough for the frame buffer + overhead. And I've run SSD1306 library with much more parallel workload in the past, and now I'm just trying to initialize an SPI library, so I highly doubt it's a memory issue. Oct 11 '20 at 12:30

I used the same code provided by you and uploaded it in the arduino uno and it was working fine for me. I am attaching the image for reference. I guess there might be some other issue image

  • Wow, maybe it's something with my hardware then.. I'll try to run it on another board, thanks for the help Oct 12 '20 at 5:18
  • Your welcome let us know if it works
    – Maaz Sk
    Oct 12 '20 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.