U8G2 SH1106 Faulty Rendering

Hello!

So im trying to display the content of a string at a 1.3 OLED Screen.

The Hardware i use:

  • D1 Mini
  • I2C OLED Display 1.3 AZDelievery

The Problem:

  • Sometimes the bottom page is messed up, see the following picture, somtimes noisy pixels.

My constructor:

U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);

My Setup:

void setup() {
  myservo.attach(16);
  
  u8g2.begin();
  u8g2.setFont(u8g2_font_ncenB08_tr);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setDrawColor(1);
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);
  Serial.begin(9600);
  
  EEPROM.begin(512);
  idSaved = EEPROM.get(142, idSaved);
  wasRead = EEPROM.get(144, wasRead);
}

In a Sub-Function launched in loop:

Serial.println("B-Modus!");
    u8g2.firstPage();
    u8g2.setFont(u8g2_font_ncenB08_tr);
    do{
      for(int i = 0; i <= message.length(); i++){
        int x = i % 129;
        int y = i / 129;
        if(message[i] == '1'){
          u8g2.drawPixel(x,y);
 
        }
      }
  }while(u8g2.nextPage());
  }

What i tried:
Using F-Mode in Constructer and clearbuffer/sendbuffer but still the messed up display!

Can somebody help me or have anyone an idea?
I think it has something to do with a full buffer or something :confused:

Okay it seems, i cant attach a picture. The bottom half of the picture is most of the times noisy, off center or just black.

Please post a link to the actual item that you bought. e.g. Ebay sale page

Using F buffer or 1 buffer will make no difference to a D1 mini. It has plenty of SRAM memory.

Post a buildable sketch. Then readers can replicate your problem on the same screen and similar CPU board.
Try to make a sketch that does not require third party libraries (except U8g2lib of course)

Paste in a code window or attach as a INO or ZIP file.

David.

#include <U8g2lib.h>
#include <Servo.h>
#include <Wire.h>
#include "credentials.h"
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <EEPROM.h>

const char* ssid = "Top";
const char* password = ""; //My WLAN-Password :P
const String url = "URL to a GIST-Repository";


U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
u8g2_uint_t offset;
u8g2_uint_t width;


String modus;
Servo myservo; 
int pos = 90;
int lightValue;
String line;
char idSaved;
int increment = -1;
bool wasRead;  

void setup() {
  myservo.attach(16);
  
  u8g2.begin();
  u8g2.setFont(u8g2_font_ncenB08_tr);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setDrawColor(1);
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);
  Serial.begin(9600);
  
  EEPROM.begin(512);
  idSaved = EEPROM.get(142, idSaved);
  wasRead = EEPROM.get(144, wasRead);
}

void loop(){
    
  if (WiFi.status() != WL_CONNECTED) {
    wifiConnect();
  }

  
  if(wasRead){
    
    getGistMessage();   
  }
  
  while(!wasRead){   
    spinServo();    // Drehe Herz
    lightValue = analogRead(0);      // Lese Helligkeitswert
    Serial.println(lightValue);
    if(lightValue > 300) { 
      wasRead = 1;
      EEPROM.write(144, wasRead);
      EEPROM.commit();
    }
  }
}

void spinServo(){
    myservo.write(pos);      
    delay(50);    // Warte 50ms um den Servo zu drehen

    if(pos == 65 || pos == 115){ // Drehbereich zwischen 75°-105°
      increment *= -1;
    }
    pos += increment;
}

/*void drawText(){
  u8g2.clearBuffer();          // clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
  width = u8g2.getUTF8Width(text); 
  u8g2.drawStr((64-(width/2)),10,text);  // write something to the internal memory
  u8g2.sendBuffer();          // transfer internal memory to the display
  delay(1000); 
}*/

void drawMessage(const String& message) {

  // Unterscheide zwischen Text und Bild
  if(modus[0] == 't'){
    u8g2.clearBuffer();
    Serial.println("T-Modus!");
    Serial.println(message);
    u8g2.setFont(u8g2_font_ncenB08_tr);
    width = u8g2.getUTF8Width(message.c_str());
    u8g2.drawStr(64-(width/2),0,message.c_str());  // write something to the internal memory
    u8g2.sendBuffer();    
    Serial.println("Nachricht ausgegeben!");
  } 
  else {
    u8g2.clearBuffer();
    Serial.println("B-Modus!");
    u8g2.setFont(u8g2_font_ncenB08_tr);
      for(int i = 0; i <= message.length(); i++){
        int x = i % 129;
        int y = i / 129;
      
        if(message[i] == '1'){
          u8g2.drawPixel(x,y);
 
        }
      }
      u8g2.sendBuffer(); 
  }
}  

void getGistMessage() {
  Serial.println("getGistMessage Checkpoint 1");
  const int httpsPort = 443;
  const char* host = "gist.githubusercontent.com";
  const char fingerprint[] = "70 94 DE DD E6 C4 69 48 3A 92 70 A1 48 56 78 2D 18 64 E0 B7";
  
  WiFiClientSecure client;
  client.setFingerprint(fingerprint);
  if (!client.connect(host, httpsPort)) {
    Serial.println("Client Verbindung fehlgeschlagen");
    return; // Verbindung fehlgeschlagen
  }
  Serial.println("getGistMessage Checkpoint 2");
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: ESP8266\r\n" +
               "Connection: close\r\n\r\n");

  while (client.connected()) {
    String temp = client.readStringUntil('\n');
    if (temp == "\r") {
      break;
    }
  }
  Serial.println("getGistMessage Checkpoint 3");
  String id = client.readStringUntil('\n'); 
  if(id[0] != idSaved){ // Neue Nachricht
    wasRead = 0;
    idSaved = id[0];
    EEPROM.write(142, idSaved);
    EEPROM.write(144, wasRead);
    EEPROM.commit(); 
    Serial.println("Neue Nachricht!");

    modus = client.readStringUntil('\n');
    line = client.readStringUntil(0);
    Serial.println("getGistMessage Checkpoint 7");
    Serial.println(modus);
    Serial.println(idSaved);
    drawMessage(line);
  }
  Serial.println("getGistMessage Checkpoint 4");
}

void wifiConnect() {
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("WLAN verbinden!");
    WiFi.begin(ssid, password);
  
    // Warte auf Verbindung
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
    }
  }
  if (WiFi.status() == WL_CONNECTED){
      Serial.println("WLAN verbunden!");
  }
}

Ah okay, thanks for the info! Based on this Info i will send you the F-Mode and sendbuffer/clearbuffer.

It gets a large String with 128x64 chars either '1'/'0'. Based on this info it draws a Pixel and sends it to the buffer.

The whole code is based on this repo: GitHub - julisa99/Lovebox: DIY project to lasercut a lovebox on your own (see https://en.lovebox.love/), which would cost almost $100.

Please post a real sketch that illustrates your problem.
You still have not posted a link to your 1.3 inch display.

I don't want to build a "LoveBox". Nor do I know what messages it is supposed to receive.

I am happy to answer questions on a SH1106 display.

David.

Sorry David for the inconvenience and thank you for the help!
Link to the Display: https://www.amazon.de/AZDelivery-Display-Arduino-Raspberry-Gratis/dp/B078J78R45/ref=cm_cr_arp_d_product_top?ie=UTF8

The following sketch breaks down the basic funcionality of the display but it seems to be working flawlessly.
Because of this i guess the reading of the String from Gist is faulty. I have to dig deeper, im open and thankful for any proposals :slight_smile:

String tmp = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111000000000000000000000001111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111110000000000000000111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111000000000000111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111000000000011111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111100000011111111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000001111111110000111111111100001111111111000011111111100000000000000000000000000000000000000000000000000000000000000000000000000000011111110000000001111111100111111110000000000111111100000000000000000000000000000000000000000000000000000000000000000000000000001111110000000000000111111001111111000000000000111111000000000000000000000000000000000000000000000000000000000000000000000000000111111000000000000000111111111111000000000000000111111000000000000000000000000000000000000000000000000000000000000000000000000001111110000000000000000111111111100000000000000000111110000000000000000000000000000000000000000000000000000000000000000000000000011111000000000000000001111111111000000000000000001111100000000000000000000000000000000000000000000000000000000000000000000000000111110000000000000000001111111100000000000000000011111100000000000000000000000000000000000000000000000000000000000000000000000011111000000000000000000001111110000000000000000000011111000000000000000000000000000000000000000000000000000000000000000000000000111110000000000000000000011111100000000000000000000111110000000000000000000000000000000000000000000000000000000000000000000000001111100000000000000000000011110000000000000000000001111100000000000000000000000000000000000000000000000000000000000000000000000011111000000000000000000000011000000000000000000000011111000000000000000000000000000000000000000000000000000000000000000000000000111110000000000000000000000000000000000000000000000111110000000000000000000000000000000000000000000000000000000000000000000000001111100000000000000000000000000000000000000000000001111100000000000000000000000000000000000000000000000000000000000000000000000001111100000000000000000000000000000000000000000000111111000000000000000000000000000000000000000000000000000000000000000000000000011111000000000000000000000000000000000000000000001111100000000000000000000000000000000000000000000000000000000000000000000000000111110000000000000000000000000000000000000000000011111000000000000000000000000000000000000000000000000000000000000000000000000001111110000000000000000000000000000000000000000001111110000000000000000000000000000000000000000000000000000000000000000000000000001111100000000000000000000000000000000000000000011111000000000000000000000000000000000000000000000000000000000000000000000000000011111000000000000000000000000000000000000000000111110000000000000000000000000000000000000000000000000000000000000000000000000000111111000000000000000000000000000000000000000011111100000000000000000000000000000000000000000000000000000000000000000000000000000111111000000000000000000000000000000000000001111110000000000000000000000000000000000000000000000000000000000000000000000000000001111110000000000000000000000000000000000000011111100000000000000000000000000000000000000000000000000000000000000000000000000000001111110000000000000000000000000000000000001111110000000000000000000000000000000000000000000000000000000000000000000000000000000001111110000000000000000000000000000000000011111100000000000000000000000000000000000000000000000000000000000000000000000000000000011111100000000000000000000000000000000001111110000000000000000000000000000000000000000000000000000000000000000000000000000000000011111100000000000000000000000000000000111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111100000000000000000000000000000011111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111100000000000000000000000000001111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111100000000000000000000000000111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111100000000000000000000000011111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111110000000000000000000011111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111110000000000000000001111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111110000000000000000111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111000000000000111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000011111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111100000011111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111110011111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
#include <Wire.h>
#include <U8g2lib.h>
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
u8g2_uint_t offset;
u8g2_uint_t width;


void setup() {
  u8g2.begin();
  u8g2.setFont(u8g2_font_ncenB08_tr);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setDrawColor(1);
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);

}

void loop() {
  u8g2.clearBuffer();
  u8g2.drawStr(0,0,"test");
  u8g2.sendBuffer();
  delay(500);
  u8g2.clearBuffer();
  for(int i = 0; i <= tmp.length(); i++){
        int x = i % 128;
        int y = i / 128;
      
        if(tmp[i] == '1'){
          u8g2.drawPixel(x,y);
 
        }
      }
   u8g2.sendBuffer();
   delay(500); 

}

I had to cut the length of the string because of the forums limitation.