SPI- why doesn't it work?

Getting SPI class errors, and it doesn’t make sense. SPI library is included.

I get a lot more SPI errors when I delete the include.

I need to get past this, because the lines I need for the OLED aren’t raising errors. I’m almost up to my Arduino IDE speed.

Hmm, looks like the issue discussed here, class instances (aka objects) like *_spi need to be setup before usage.
If this is not the solution, please share a bit more information about your code and lib folder setup to check if SPI library can be accessed (I don’t think there’s an issue, else the compiler would have moaned about missing include or type errors).

1 Like
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSerif9pt7b.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {

  pinMode(13, OUTPUT);

    pinMode(2, OUTPUT);



  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64

    Serial.println(F("SSD1306 allocation failed"));

    for(;;); // Don't proceed, loop forever



// Show initial display buffer contents on the screen --

  // the library initializes this with an Adafruit splash screen.


  delay(2000); // Pause for 2 seconds

  // Draw a single pixel in white

  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after

  // drawing commands to make them visible on screen!



void loop() {









  Serial.println("Hello world");


  display.setTextSize(1);             // Normal 1:1 pixel scale

  display.setTextColor(SSD1306_WHITE);        // Draw white text

  display.setCursor(0,0);             // Start at top-left corner

  display.println(F("Hello, world!"));



I understand that there are things in this C++ file that won’t work in C, but I have no way of knowing what they are.

People are telling me the instructions are out of order.

Hmm, in this case it really looks like a problem with your <SPI.h> included by the adafruit library. I don’t know which platform/framework/board you are developing on, but maybe your specific board’s SPI implementation library doesn’t work with Adafruit’s library expectations (maybe your SPI library does not declare SPIClass at all).

  • Please look at where the library <SPI.h> is being pulled from
  • Have a look at its contents and see whether the compiler-moaned classes are defined in there.
  • If not, maybe the libary you’re using does fit your board, but not the Adafruit implementation or the other way round. In this case, you’d need to manually include the “correct” SPI library - the one Adafruit is depending on - to the project and hope that it works fine with your board.

Sorry for not being able to solve this for you.

I managed to put the example to work.

Thanks for your help, but I’m using the I2C OLED.