Strange issue with U8g2 lib and ST7565 display. Screen doesn't clear properly

Hi all!

I'm working on a PC system monitor using an Arduino pro micro, an ST7565 display and U8g2 lib.

The code works kinda well, but I have a strange problem.

I setup a logo that appear when PC stop sending data, but with it set, I have a rectangle that cover the bottom part of the screen. If I delete it I have no issues. I tried to put a drawBox and I have the same problem. If I put a test in that part of the screen, it doesn't clear and stay above the new page.
I really can't understand why it happen only on the bottom part of the screen.

This is the screen as it should be, but I cannot set the actual splashscreen

This is the screen with splash applied (same results with a drawBox instead of drawXBMP)

And this is the screen if I set some text instead of a draw.

It seems that for some reason the screen doesn't clear property.

This is my actual code

#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif


U8G2_ST7565_64128N_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 8, /* data=*/ 9, /* cs=*/ 4, /* dc=*/ 7, /* reset=*/ 6);



bool disconnect;
double saveMillis = 0;

//-------------------image-------------------

  #define nvidia_logo_width 128
  #define nvidia_logo_height 64

  static const unsigned char nvidia_logo[] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
  0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0xF0, 0xE0, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0xFF, 0x3F, 0xF0, 0xFF, 0xF0,
  0x01, 0xCF, 0xE7, 0xFF, 0xC0, 0x07, 0xFC, 0x00, 0x00, 0x07, 0x1F, 0xFE,
  0x3F, 0xF0, 0xFF, 0xF1, 0x81, 0xCF, 0xE7, 0xFF, 0xC3, 0x07, 0xFC, 0x01,
  0xC0, 0x03, 0x7F, 0xF8, 0x3F, 0xF0, 0xFF, 0xE3, 0x81, 0xCF, 0xE7, 0xFF,
  0xC7, 0x07, 0xFE, 0x01, 0xE0, 0xF0, 0xF0, 0xF0, 0x3F, 0xF0, 0xFF, 0xE7,
  0x83, 0xC7, 0xE7, 0xF3, 0xC7, 0x07, 0xFE, 0x03, 0x78, 0x78, 0xC0, 0xE1,
  0x3F, 0xF0, 0xC0, 0xE7, 0x83, 0xC7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0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
  0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, };

//-------------------------------------------

char c;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
  u8g2.begin();
  u8g2.clearBuffer();
  //u8g2.setDrawColor(0);
  u8g2.setContrast(230);

}


void data() {
  // put your main code here, to run repeatedly:
  String message0;
  String cputemp;
  String cpuload;
  String gputemp;
  String gpuload;
  String ramused;
  String ramavail;
  String ramload;
  String gpumemtot;
  String gpumemused;
  String gpumemload;
  String gpufanload;
  String gpufanrpm;
  String gpupwr;
  String cpuname;
  String gpuname;
  String gpucc;
  String gpumc;
  String gpusc;
  String cpucc;



  if (Serial.available() > 0)
  {

    message0 = Serial.readString();; //total string
    cputemp = message0.substring (2, 4); //cputemp without °c
    // cputemp = message0.substring (2, 6); //cputemp with °c
    cpuload = message0.substring (7, 10); //cpuload
    gputemp = message0.substring (13, 16); //gputemp without °c
    // gputemp = message0.substring (13, 18); //gputemp with °c
    gpuload = message0.substring (19, 22); //gpuload
    ramused = message0.substring (24, 28); //ram used without GB
    // ramused = message0.substring (24, 30); //ram used with GB
    ramavail = message0.substring (33, 37); //ram available without GB
    // ramavail = message0.substring (33, 39); //ram available with GB
    ramload = message0.substring (43, 46); //ramload
    // gpumemtot = message0.substring (52, 55); //gpumem total without GB
    gpumemtot = message0.substring (52, 57); //gpumem total with GB
    gpumemused = message0.substring (61, 66); //gpumem used without GB
    // gpumemused = message0.substring (61, 68); //gpumem used with GB
    gpumemload = message0.substring (74, 77); //gpumem load
    gpufanload = message0.substring (83, 87); //gpufan load
    gpufanrpm = message0.substring (93, 97); //gpufan rpm
    gpupwr = message0.substring (103, 108); //gpupower
    // cpuname = message0.substring (118, 138); //cpu name with brand
    // cpuname = message0.substring (124, 138); //cpu name without brand
    cpuname = message0.substring (129, 138); //cpu name without brand and family
    // gpuname = message0.substring (148, 172); //gpu name with brand
    // gpuname = message0.substring (156, 172); //gpu name without brand
    gpuname = message0.substring (164, 172); //gpu name without brand and family
    gpucc = message0.substring (176, 181); //gpucore clock
    gpumc = message0.substring (186, 190); //gpumem clock
    gpusc = message0.substring (194, 202); //gpushader clock
    cpucc = message0.substring (207, 211); //cpucore clock

    saveMillis = millis();
    disconnect = false;

    // data loop
    u8g2.firstPage();
    do {
      //---------------------------------background---------------------------//
      u8g2.setDrawColor(1);
      u8g2.drawBox(0, 0, 128, 64);
      u8g2.setDrawColor(0);
      u8g2.drawLine(64, 4, 64, 59);
      u8g2.drawLine(60, 0, 64, 4);
      u8g2.drawLine(64, 59, 69, 64);
      u8g2.drawLine(0, 9, 128, 9);
      u8g2.drawTriangle(128, 0, 124, 0, 128, 4);
      u8g2.drawTriangle(0, 59, 0, 64, 5, 64);
      //------------------grid----------
      /*
        u8g2.drawLine(0, 32, 128, 32);
        u8g2.drawLine(64, 0, 64, 64);
        u8g2.drawLine(0, 16, 128, 16);
        u8g2.drawLine(0, 48, 128, 48);
        u8g2.drawLine(32, 0, 32, 64);
        u8g2.drawLine(96, 0, 96, 64);
      */

      //------------------------------------------------------------------//

      //     u8g2.setFont(u8g2_font_trixel_square_tr);
      u8g2.setFont(u8g2_font_5x7_tf);
      u8g2.setFontMode(0);
      u8g2.setDrawColor(0);

      u8g2.setCursor(10, 7);
      u8g2.println(cpuname);
      u8g2.setCursor(28, 47);
      u8g2.println(cpucc + "MHz");
      u8g2.setCursor(1, 47);
      u8g2.println(cpuload);

      u8g2.setCursor(76, 7);
      u8g2.println(gpuname);
      u8g2.setCursor(87, 47);
      u8g2.println(gpucc + "MHz");
      u8g2.setCursor(68, 47);
      u8g2.println(gpuload);

      u8g2.setCursor(1, 57);
      u8g2.println(ramload);

      u8g2.setCursor(68, 57);
      u8g2.println(gpumemload);

      u8g2.setCursor(18, 57);
      u8g2.println(ramused + "/32GB");

      u8g2.setCursor(82, 57);
      u8g2.println(gpumemused + "/4GB");

      u8g2.setFont(u8g2_font_pixeloid20_tf);
      u8g2.setFontMode(0);
      u8g2.setDrawColor(0);

      u8g2.setCursor(13, 36);
      u8g2.println(cputemp);
      u8g2.setCursor(65, 36);
      u8g2.println(gputemp);

      u8g2.setFont(u8g2_font_pixeloid10_centig);
      u8g2.setFontMode(0);
      u8g2.setDrawColor(0);

      u8g2.setCursor(54, 25);
      u8g2.println("°");
      u8g2.setCursor(118, 25);
      u8g2.println("°");

    } while ( u8g2.nextPage() );
  }
}


void loop() {

  if (millis() - saveMillis > 30000) {

    disconnect = true;
    saveMillis = 0;
  }
  //delay(10000);
  if (disconnect)

    u8g2.firstPage();
  do {

    u8g2.setDrawColor(0);
    u8g2.drawXBMP( 0, 0, nvidia_logo_width, nvidia_logo_height, nvidia_logo);


  } while ( u8g2.nextPage() );

  {
    data();
  }
}

I would suspect a memory issue, but the sketch does not appear to use a significant amount of ram (less than 30%). Does the problem get progressively worse over time? If so, get rid of the String variables and use char arrays.

Where did you find the pixeloid font? That is not a font that comes with U8g2.

1 Like

Does the problem get progressively worse over time?

No, it doesn't get worse than this

Where did you find the pixeloid font? That is not a font that comes with U8g2.

It's a custom font that I create with Fony

I somehow miss curly brackets and "else"...

1 Like

Thanks for your answer! Now it works perfectly!

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