OLED 64x48 Pixel and Wemos D1 Mini

Hey everybody,

I am wondering why the OLED 0.66" displays (64x48 pixels) are somehow buggy for the D1 Wemos. After analysing a few tutorials, I realized that the display is set-up wrongly for some reason and I had to make a workaround to get the right position data.

Example given. If I define the display like that (as it should be - in my opinion)

#define SCREEN_WIDTH  64 // OLED display width, in pixels
#define SCREEN_HEIGHT 48 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

And trying to put a dot to each pixel of the display by using something like that:

void loop()
{    
  for (int i = 0; i<=SCREEN_HEIGHT; i++)
  {
    for (int j= 0; j<=SCREEN_WIDTH; j++)
    {
      display.drawPixel(j,i, WHITE);
      display.display();     
      Serial.println("Show the data: " + String(i) + "/" + String(j));

      delay(10);
    }
  }
  display.clearDisplay();
  display.display();
}

I only get the left top quarter filled up (and it does not even start at line 0. Therefore, I made a bunch of tests and the working code looks as follows:

#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

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

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

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
  {
   Serial.println("Stopping ... some problems...");
    for(;;);
  }

  delay(2000);
  display.clearDisplay();
  display.display();
  display.setTextColor(WHITE);
  display.println("Starting to fill the screen with dots");
  display.display();
  delay(2000);
  
  display.clearDisplay();
  display.display();
  display.setCursor(0,0);
  Serial.println("Show the dots");

}

void loop()
{
    int offsetWidth = 64/2;
    int offsetHeight = 32/2;

    
  for (int i = offsetHeight; i<=48+offsetHeight; i++)
  {
    for (int j= offsetWidth; j<=20+offsetWidth; j++)
    {
       
      display.drawPixel(j,i, WHITE);
      display.display(); 
      Serial.println("Show the data: " + String(i) + "/" + String(j));

      delay(50);
    }
  }
  display.clearDisplay();
  display.display();
}

Interesting enough and my outcome:

  • I need to set up the display width to 128 pixels rather than 64
  • I need to set up the display height to 64 rather than 48
  • I need to set-up appropriate "offset" values for the height and width position to get the dot to the »real« positions of the screen.

Summing up. By manipulating the code as given above, I can fully load the display with dots. Furthermore, if I am writing any test to position (0,0), Iit will not be displayed (out of range I guess). However, I first need to set the cursor to the desired offset:

display.setCursor(32,16);

I guess I mimik somehow an 128 x 64 display and the offset is in accordance to the mismatch. So we have 64 pixel in width but I need to declare 128. Hence if the OLED pixels would be in the middle, I would have 32 pixels right (not physical available), then 64 pixels (available) and again 32 pixels on the left (not physical available). The same for the width.

Hence, it is somehow obvious why I have to take that offset parameter. Very strange behavior. Nevertheless, it works now, but I am really curious why that happens and how to fix it. After knowing the offset-parameters and the "wrong" display width-heigth initialization, it's okay, but its not the way it should work.

Again, if I initialize the display with 64 and 48, it fails displaying (the data are out of physical range - at least it looks like that).

Any suggestions?

Adafruit sells a 128x32 and a 128x64 that are know to work with their library.
They state:

The driver chip, SSD1306 can communicate in multiple ways including I2C , SPI and 8-bit parallel . However, only the 128x64 display has all these interfaces available. For the 128x32 OLED, only SPI is available.

My guess is it is just a "library" thing. Try another lib.
Maybe:

DanBicks added OLED display to ESP01 using cheap Ebay 0.96" display
Lightweight OLED routines by Mike-Rankin added in this project
WIFI SCAN AND ACQUIRE OLED - Everything ESP8266
Original source: GitHub - costonisp/ESP8266-I2C-OLED: A I2C screen to show messages received from a client-browser.
OLED code supports either SDD1306 or with SH1106 controller

Hey, thank you for your feedback. Indeed, I need to take another library. It's called WEMOS Mini OLED. I simply removed the old libraries and installed this one. Everything works fine :slight_smile:
My fault not to check out other libraries.

Tobi

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.