OLED display malfunctioning

Hi there,

I am relatively new to the Arduino environment, and I recently bought a 1.3" 128x64 OLED Monochrome display, and when I tested some code, the screen was filled with a mostly white screen with scattered black spots. I am almost certain that my wiring is correct (GND - ground, VCC - 5v, CLK - 11, MOSI - 9, RES - 13, DC - 11 and CS - 12). The following is my code:

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

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for SSD1306 display connected using software SPI (default case):
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
  OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

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

  // initialize OLED display with address 0x3C for 128x64
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (true);
  }

  delay(2000);
  display.setTextSize(2);          // text size
  display.setTextColor(WHITE);     // text color
  display.setCursor(0, 10);        // position to display
  display.println("Hello World!"); // text to display
  display.display();               // show on OLED
} 

void loop() {
}

The code compiles fine.

Thanks.

can you try to use another pin (say 4) for OLED_RESET?

I tried to wire the reset to an alternate pin, but the result was the same.

which '1.3" 128x64 OLED Monochrome display' did you get? (link / specs)

I got my OLED from a local store.
https://www.jaycar.com.au/duinotech-1-3-inch-monochrome-oled-display/p/XC3728?pos=4&queryId=f08ffec156e472c66cb3e526dbb98484&sort=relevance

it seems it's using a SH1106 driver, not the SSD1306 you've been trying to use.

have you looked at the test code they propose?

#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9); // SCK = 13, MOSI = 11, CS = 10, A0 = 9

I had a similar issue with SSD1306, RESET=-1 helped

Thanks for the link. I am horrified by the price.

I am also disappointed with no pcb photo.
1.3 inch OLED are normally SH1106 and not SSD1306.
However there are some 1.3 inch SSD1315 OLEDs

If we could see the pcb we could identify SSD1306, SH1106, SSD1315 with a bit of guesswork.
We can identify for certainty by running a sketch.

I suggest that you check your wiring. A good tip is to add the wire color as a comment to your defines.

David.

Thank you for your help, however, after I had downloaded the required library from here - (U8glib - Arduino Reference), there are a lot of error messages and it didn't compile altogether. Since the error was about "mui.h" I removed the MUIU8g2 library, and the error messages became:

Arduino: 1.8.12 (Mac OS X), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

ssd1306_128x64_spi:5:1: error: 'U8GLIB_SH1106_128X64' does not name a type; did you mean 'U8X8_KS0108_128X64'?
U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9); // SCK = 13, MOSI = 11, CS = 10, A0 = 9
^~~~~~~~~~~~~~~~~~~~
U8X8_KS0108_128X64
/var/folders/76/2830y9d144l2_vcf2spgwhk40000gp/T/arduino_modified_sketch_69896/ssd1306_128x64_spi.ino: In function 'void draw()':
ssd1306_128x64_spi:8:2: error: 'u8g' was not declared in this scope
u8g.setFont(u8g_font_unifont);
^~~
/var/folders/76/2830y9d144l2_vcf2spgwhk40000gp/T/arduino_modified_sketch_69896/ssd1306_128x64_spi.ino:8:2: note: suggested alternative: 'u8'
u8g.setFont(u8g_font_unifont);
^~~
u8
/var/folders/76/2830y9d144l2_vcf2spgwhk40000gp/T/arduino_modified_sketch_69896/ssd1306_128x64_spi.ino: In function 'void setup()':
ssd1306_128x64_spi:14:1: error: 'u8g' was not declared in this scope
u8g.setRot180();
^~~
/var/folders/76/2830y9d144l2_vcf2spgwhk40000gp/T/arduino_modified_sketch_69896/ssd1306_128x64_spi.ino:14:1: note: suggested alternative: 'u8'
u8g.setRot180();
^~~
u8
ssd1306_128x64_spi:18:24: error: 'U8G_MODE_R3G3B2' was not declared in this scope
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
^~~~~~~~~~~~~~~
ssd1306_128x64_spi:21:29: error: 'U8G_MODE_GRAY2BIT' was not declared in this scope
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
^~~~~~~~~~~~~~~~~
ssd1306_128x64_spi:24:29: error: 'U8G_MODE_BW' was not declared in this scope
else if ( u8g.getMode() == U8G_MODE_BW ) {
^~~~~~~~~~~
/var/folders/76/2830y9d144l2_vcf2spgwhk40000gp/T/arduino_modified_sketch_69896/ssd1306_128x64_spi.ino:24:29: note: suggested alternative: 'LB_MODE_1'
else if ( u8g.getMode() == U8G_MODE_BW ) {
^~~~~~~~~~~
LB_MODE_1
ssd1306_128x64_spi:27:29: error: 'U8G_MODE_HICOLOR' was not declared in this scope
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
^~~~~~~~~~~~~~~~
/var/folders/76/2830y9d144l2_vcf2spgwhk40000gp/T/arduino_modified_sketch_69896/ssd1306_128x64_spi.ino: In function 'void loop()':
ssd1306_128x64_spi:32:2: error: 'u8g' was not declared in this scope
u8g.firstPage();
^~~
/var/folders/76/2830y9d144l2_vcf2spgwhk40000gp/T/arduino_modified_sketch_69896/ssd1306_128x64_spi.ino:32:2: note: suggested alternative: 'u8'
u8g.firstPage();
^~~
u8
exit status 1
'U8GLIB_SH1106_128X64' does not name a type; did you mean 'U8X8_KS0108_128X64'?

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I have already color-coded it with each wire a different color to avoid confusion.

+1 on this

I did a comprehensive search on the internet and unfortunately, I couldn't find the pcb to it.

Can't you post good quality picture (in focus) of your actual board (both sides)

just take a picture and drop it directly in an answer to the forum. It will upload and we can have a look at it.

Thank you to everyone who has helped me in my problem. As instructed in the user manual, the required library was U8glib, rather than the U2g2 library I had accidentally downloaded, as it was the first result when I searched "U2glib" in the manage libraries section. The OLED turned out to be a SH1106, rather than a SSD1306 that I had initially assumed it was. Thank you again for all your help.

Have fun !

You should use U8g2lib
U8glib is no longer maintained