Multiple 128*64 SPI OLEDs under U8glib?

Hi! I recently bought some SPI SSD1306 oleds from Banggood (this one specifically). I assumed that since they were using SPI and would run on the same library I could use them with a single arduino. I have successfully run the hello world sketch on a single display, but haven't been able to make it work with two at the same time. I have posted the code below - this is my first time using U8glib so I apologize in advance if it is something really simple I'm missing.

To further complicate the matter, these SPI oleds lack a chip select pin. Is it possible to use one MOSI, MISO, and RST per display since they can't be selected through a CS pin? I know it will use more pins but that's a small price to pay compared to ordering more and waiting for them to arrive from China.

The code I've been trying to use:

#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9, 8);      // pin 10 has nothing attached since the module is always selected
U8GLIB_SSD1306_128X64 u8g2(5, 4, 7, 3, 2);      // pin 7 has nothing attached since the module is always selected
void setup() {
  // put your setup code here, to run once:
if ( u8g.getMode() == U8G_MODE_BW ) {
	u8g.setColorIndex(1);     	// pixel on
  }
}
void draw(void) {
  // graphic commands to redraw the complete screen should be placed here 
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 0, 22, "Hello");
}
void draw2(void) {
  u8g2.setFont(u8g_font_unifont);
  u8g2.drawStr( 0, 22, "World");
}
void loop(void) {
  // put your main code here, to run repeatedly:
  u8g.firstPage(); 
  do {
	draw();
  } while( u8g.nextPage() );
  u8g2.firstPage(); 
  do {
	draw();
  } while( u8g2.nextPage() );
  delay(100);
}

Thanks in advance for any suggestions!

Hi

Try to use "draw2()" in the second loop.

Oliver

That worked! Thank you so much!

Sorry to bring this thread back from the dead, but did you ever try to do this with displays with CS pins? i.e sharing the same MOSI pins etc but different CS pins for different displays?

Thats where I am right now trying to send data to two different displays, I've spent hours googling for solutions and although I've found many threads on the subject they all have dead ends..

This is my code.. all I get is "Display 2" on the second display, the first display is blank..

#include "U8glib.h"

U8GLIB_SH1106_128X64 display1(4, 5, 6, 7, 8);
U8GLIB_SH1106_128X64 display2(4, 5, 3, 7, 8);

void setup(void)
{
  display1.setColorIndex(1);
  display2.setColorIndex(1);
  pinMode(8, OUTPUT);
}
void loop(void)
{
  display1.firstPage();
  do
  {
    draw1();
  } while ( display1.nextPage() );

  display2.firstPage();
  do
  {
    draw2();
  } while ( display2.nextPage() );

  delay(100);
}

void draw1(void)
{
  display1.setFont(u8g_font_unifont);
  display1.drawStr(0, 22, "Display 1");
}
void draw2(void)
{
  display2.setFont(u8g_font_unifont);
  display2.drawStr(0, 22, "Display 2");
}

Hi
I do not see a software problem. Is your wiring ok?

Oliver

Hello Oliver,

I believe so, over the evening I assembled and dissassembled the equipment many times, so the chances of making an error every time are slim :slight_smile:
Unless, of course, the error is in my schematic..

The two displays share the same GND and VDD, they also share the 4 SPI connections, but they have seperate CS lines..

I know its not the display itself, I have 3 and have swapped them from location to location (in reality one display IS duff, the joy of buying cheap stuff from China!) but these two I'm using are tested and good.

I'm at a loss as to how to proceed.

bench setup

Hi.

Your setup (by the way "hosted" on some crap server which doesn't allow posting pictures on forums), makes it easy for you to do some measurements on those displays.
You could try to find out whether display #1 gets its select signal or not.
But you can do the same test by connecting display #1 parallel to the select signal of #2 and vice versa.
Or connect that pin to a fixed level, to see what happens next.

For testing/debugging purposes, it could turn out to be a good idea to build in some large delay()s in your code so you can see the different stages in your code happening.

Hi,

I had the same issue. It is the reset pin. At least my LCD can accept reset signal when not selected by CS pin.
You need separated SC and Reset pin for each display.

Even with new library

Regarding the reset line with multiple displays: There is a discussion in the u8g2 FAQ:

Oliver