Correct syntax for using multiple OLEDs under the Adafruit ssd1306 library

I tried looking for an example sketch but there doesn’t appear to be much on the net regarding 2 SPI OLEDs running off 1 AVR. If there is I just haven’t found it I suppose.

I’ve ganged the VCC, GND, D/C, MOSI, CLK between the 2 OLEDs and so only 1 wire from each is going to the nano. The chip select I have individually coming from each OLED to a different digital pin. My problem is how to setup the 2 OLEDs in software and then call functions for each of them as I see fit. Right now, the example sketch contains a constructor that works perfectly fine for 1 OLED but I can’t figure out how to define and use another one.

Can anyone give me the most basic syntax to setup 2 OLEDs to run and how to switch between display variables? I assume you set CS of 1 to low and CS of the other to high and then switch between calling a variable called display1 and display2 to call your methods or something like that but the compiler didn’t like that.

(deleted)

When I did that, the compiler returned an error for display2 in your example, saying that the library didn't recognize that variable.

(deleted)

(deleted)

Well, actually, I'm using the hardware SPI block of code but essentially the declarations are similar. It's the display variable that seems to be giving me trouble though, not the arguments.

#define OLED_DC     6
#define OLED_CS     7
#define OLED_CS2     9
#define OLED_RESET  8
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
Adafruit_SSD1306 display2(OLED_DC, OLED_RESET, OLED_CS2);

(deleted)

Odd. Now that I try to compile it a second time, it's working. False alarm. Thanks for the help.

Is there anything else in the setup (some mention of high voltage conversion from the 3.3V pin??) that needs to be re-initialized for the second OLED or am I good to go with just these 2 changes (second display var and another CS var) ?

(deleted)

So as not to exceed the max current limit? That's good advice. I figured the OLEDs draw practically nothing but better safe than sorry.

(deleted)

Argg… things were going well until I uploaded and ran the sketch on the 2 screens. Either they both do exactly the same thing or only 1 displays while the other appears black. The lines of code switching the chip select appear to do nothing and whether I call display or display2, it doesn’t seem to matter either. Sketch attached.

MultipleOLEDs.ino (9.85 KB)

Might be quicker to resolve if there is a completed sketch floating around where somebody runs 2 OLEDs off the same Arduino alternating back and forth and using SPI.

(deleted)

(deleted)