Blinking SSD1322

Hello everybody!

Thanks to members of this forum I learned to wire my SSD1322 to a Nano Clone and I learned with the wiki how to use the u8g2 library.

Quickly, my project is to use a 256*64 OLED screen as case display of my HTPC. I want it to show the actual movie playing, and some other stuff. To do so, I planned to send via serial port the data I want to display, usine the first byte as identifier of what the serial string corresponds to. For the moment, I am only testing and using the Serial monitor to send these strings.
I will join the code at the end.

My problem is that my screen start blinking if one string is too small.Here is a video example. If I use a string that is less than 256px wide for the title variable, the screen blinks. If it is wider, the screen simply stops blinking. Does anybody have an idea why?

Thanks in advance,
Nicolas

The code:

#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>

U8G2_SSD1322_NHD_256X64_2_4W_HW_SPI u8g2(U8G2_R2, 5, 3, 4);
int t;

String Ser;
String C;
String L;
char *T = "1234567890123456789012345678901234567890123456789012345678901234567890";
char *A = "12345678901234567890123456789012345678901234567890123456789012345678901";
char *H = "12  34";
char *R = "0:35:42/2:10:50";

void setup(void) {
  u8g2.begin();
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  u8g2.setFontMode(0);    // enable transparent mode, which is faster
  t = 0;
}


void loop(void) {
  u8g2.firstPage();
  do {
    //informations
    u8g2.setFontPosBottom();
    u8g2.setFont(u8g2_font_helvR14_tf);
    u8g2.drawUTF8(0, 30, T); //titre
    u8g2.setFont(u8g2_font_helvB10_tf);
    u8g2.drawUTF8(0, 50, A); //auteur

    //heure
    u8g2.setFont(u8g2_font_helvB08_tn);
    u8g2.setFontPosTop();
    u8g2.drawUTF8(226, 0, H);
    if (t < 3) {
      u8g2.drawUTF8(234, 0, "     ");
    } else {
      u8g2.drawUTF8(234, 0, "  :  ");
    }

    //barre avancement
    u8g2.drawBox(0, 63, 170, 1);
    u8g2.drawBox(0, 60, 100, 3);
    //texte avancement
    u8g2.setFont(u8g2_font_5x8_tn);
    u8g2.setFontPosBottom();
    u8g2.drawUTF8(180, 64, R);

  } while ( u8g2.nextPage() );
  //Clignotement ":"
  t += 1;
  if (t > 5) {
    t = 0;
  }
  while (Serial.available()) {
    Ser = Serial.readString(); // read the incoming data as string
    L = Ser.substring(1);
    C = Ser.substring(0, 1);
    if (C == "T") {
      strcpy (T, L.c_str());
    } else if (C == "A") {
      strcpy (A, L.c_str());
    } else if (C == "H") {
      strcpy (H, L.c_str());
    } else if (C == "R") {
      strcpy (R, L.c_str());
    }
  }
  delay(50);
}

Hi.

Usually things like this happen when you are updating the screen too often.
You seem to be rewriting the already existing content to the screen over and over again.
To do that, the content needs to be erased, and displayed again.
In your code, i can't see where the erasing is done, but the fact that your screen is blinking, suggests that that is what's going on.
Try to put a very small title and author on screen (a single character for each of those), and an average size title and author.
You'll probably see that the small size ones will blink faster.

If so, keep track of what's already displayed (you're not doing that now).
And only display something which isn't already displayed.
This will mean your clock and the blinking : will be updated far more often than the rest of your screen contents.
It'll also save you lots of time to do other things, if applicable and/or in a future sketch.

Hello!
Thanks for your answer. I tried to put the u8g2 write routine inside the Serial.available loop, and the problem remains. With this new version, the screen is fully updated only when new data is available from serial port, so I don't rewrite everything again and again.

And even if considering you're still right, why does my screen blink when the title is small (The Circle) and doesn't when the title fill the screen? (Valerian ...)
With the same text as previously displayed, the screen keeps blinking, any other idea?..

It takes less time to redraw a short text, than it would to draw a longer text.
See me calling that process drawing instead of calling it writing ?
So does your sketch.
Because of that, the off time will be significant longer in relation to the on time of that text.
Did you do the test i suggested to test that theory ?

If the test confirms the theory, set a flag after writing the contents of your buffer (such as T and A).
Reset this flag if the contents are updated by some serial comms coming in.