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);
}