Two SPI OLED SSD1306

Hello,

I'm trying to use two SPI OLED SSD1306 oled in an application which uses Adafruit_SSD1306. But the second display does not initialize.

Here it part of the code:

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

#define OLED1_SCK 2
#define OLED1_SDA 3
#define OLED1_RESET 4 // Both Displays
#define OLED1_DC 5
#define OLED1_CS 6

// OLED - Display 02
#define OLED2_SCK 7
#define OLED2_SDA 8
#define OLED2_RESET 9 // Both Displays
#define OLED2_DC 10
#define OLED2_CS 11

Adafruit_SSD1306 display1(128, 64, OLED1_SDA, OLED1_SCK, OLED1_DC, OLED1_RESET, OLED1_CS); // (uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin, int8_t cs_pin)
Adafruit_SSD1306 display2(128, 64, OLED2_SDA, OLED2_SCK, OLED2_DC, OLED2_RESET, OLED2_CS); // (uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin, int8_t cs_pin)

void setup(){
Serial.begin(9600);

pinMode(left, INPUT);
pinMode(right, INPUT);

bool flag = true;
flag = display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display1.clearDisplay();
if(flag == false){
Serial.println("Disp1");
}
flag = display2.begin(SSD1306_SWITCHCAPVCC, 0x3D);
if(flag == false){
Serial.println("Disp2");
}
display2.clearDisplay();
}

I have got flag == false, in flag = display2.begin(SSD1306_SWITCHCAPVCC, 0x3D);

Please, could you help me?

if CS is a chip select, can the others except reset be common?

flag = display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);

This looks like you're using the begin method for I2C, not the one for SPI.

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Have you Googled using 2 SPI OLED SSD1306 arduino

There are quite a few examples.

Tom.... :slight_smile: