Disegnare una immagine se non si ricevono dati da porta seriale

Salve a tutti,
Sono alle primissime armi con la programmazione di arduino e durante i ritagli di tempo nelle ultime settimane ho tentato di creare un system monitor per il pc utilizzando un display monocromatico ST7565 con un pro micro attraverso l'uso delle librerie U8g2 e un software che fornisce i dati dal pc.

Con una certa difficoltà sono arrivato ad avere un codice funzionante, ma vorrei aggiungere una funzione che mi disegni un logo (che al momento è lo stesso della splashscreen settata nel setup) quando la scheda non riceve più dati dal pc dopo un tot di tempo.

Al momento il mio codice è questo

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



#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, 0xE7, 0x81, 0xCF, 0x07, 0xDE, 0x03, 
  0x38, 0x0E, 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F, 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.setBusClock(5000000);
  u8g2.begin();
  u8g2.clearBuffer();
  u8g2.setDrawColor(0);
  u8g2.setContrast(230);

  u8g2.firstPage();  
  do {
    u8g2.drawXBMP( 0, 0, nvidia_logo_width, nvidia_logo_height, nvidia_logo);
  } while( u8g2.nextPage() );
  
  // show splash screen for 2 seconds
  delay(2000);
}



void loop() 
{
  // 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){

  delay(400);
  
  u8g2.firstPage();
  u8g2.setFont(u8g2_font_5x7_tf);
      u8g2.setFontMode(0);
      u8g2.setDrawColor(0);
      
   u8g2.drawXBMP( 0, 0, nvidia_logo_width, nvidia_logo_height, nvidia_logo);

}
else 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

  // 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);
   /*
     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() );
 }
}

 

Il codice si compila senza problemi, ma se non si ricevono più dati dal pc, il logo non viene disegnato.
Ho tentato diversi approcci come visto su alcuni esempi online, ma nonostante tutto l'ultima schermata che rimane sul display dopo la chiusura del software dal pc (e quindi il conseguente stop di dati sulla seriale), sono gli ultimi dati ricevuti.

Qualcuno saprebbe indicarmi dove sbaglio?

Buonasera,

essendo il tuo primo post, nel rispetto del regolamento della sezione Italiana del forum (… punto 13, primo capoverso), ti chiedo cortesemente di presentarti IN QUESTO THREAD (spiegando bene quali conoscenze hai di elettronica e di programmazione ... possibilmente evitando di scrivere solo una riga di saluto) e di leggere con molta attenzione tutto il succitato REGOLAMENTO ... Grazie. :slight_smile:

Guglielmo

P.S.: Ti ricordo che, purtroppo, fino a quando non sarà fatta la presentazione nell’apposito thread, nel rispetto del suddetto regolamento nessuno ti risponderà (eventuali risposte verrebbero cancellate), quindi ti consiglio di farla al più presto. :wink:

Grazie mille dell'appunto e mi scuso!
Mi sono presentato nell'apposito thread come specificato!

if (Serial.available() > 0) {
   saveMillis = millis();
   disconnect == false;
   // qui il tuo codice dove acquisisci e stampi
}

if (millis() - saveMillis > 500) {
   // quando entra qui sono trascorsi 500ms senza ricevere
  // dati. 
  disconnect = true;  // 
}

Dovrebbe funzionare, non l'ho provato.

Ciao.

1 Like

L'ho testato in uno sketch di prova e funziona alla perfezione!

Grazie mille!

Solo un altro problemino ora.
Se la porta seriale rimanda i dati dopo la disconnessione, nello schermo non riappaiono i dati, ma rimane nella schermata di disconnessione

ciao gingino

dovresti far si che al cambio della variabile "disconnect", da true a false, si ricarichi la pagina che vuoi...attenzione che nell'esempio di Maurotec questo:

if (Serial.available() > 0) {
   saveMillis = millis();
   disconnect == false;
   // qui il tuo codice dove acquisisci e stampi
}

va cambiato in questo:

if (Serial.available() > 0) {
   saveMillis = millis();
   disconnect = false;
   // qui il tuo codice dove acquisisci e stampi
}
1 Like

Grazie mille dell'appunto!
Sono riuscito a fare in modo di visualizzare l'immagine solo quando non si ricevono più dati dal pc, ma ora è apparso un altro problema molto strano nell'immagine che prima non si presentava.

L'ultima striscia di 8 pixel risulta coperta da una specie di rettangolo coprendo parte del testo e del background che ho creato per i vari elementi.
La stranezza sta nel fatto che se elimino il logo dal codice o lo modifico perché non copra quella parte di schermo, la pagina con i dati non è più coperta da questo rettangolo.
Ho provato anche a mettere un drawBox al posto del logo ed il risultato è uguale, mentre posizionando un testo in quella zona (sempre al posto del logo) ne viene cancellata solo una striscia.


Questo è come appare se non applico il logo nel codice, che è il risultato esatto


Questo invece è dove viene coperta l'ultima striscia dello schermo, se applico il logo al codice o un altro elemento.

Ho già ricontrollato la disposizione dei vari elementi nel codice e non ho trovato problemi, e se ci fosse un problema di disposizione sarebbero coperti tutti, e non solo questa piccola porzione di schermo

Lascio qui il codice attuale casomai qualcuno avesse idea del perché avviene questa cosa

#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,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0x1F, 0x80, 0x87, 0xF8, 0x01, 0x3F, 0xF0, 0x80, 0x07,
  0xFF, 0xC0, 0xE7, 0xFF, 0xC7, 0xC7, 0xFF, 0x1F, 0x00, 0x0F, 0x7F, 0xC0,
  0x3F, 0xF0, 0x80, 0x07, 0xFF, 0xC0, 0xE7, 0xFF, 0xC7, 0xE7, 0x01, 0x3E,
  0x00, 0x7C, 0x07, 0xF8, 0x3F, 0xF0, 0x80, 0x07, 0xFE, 0xC0, 0xE7, 0xFF,
  0xC1, 0xE7, 0x01, 0x3E, 0x00, 0xF0, 0x00, 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, 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) {
    // quando entra qui sono trascorsi 10000ms senza ricevere
    // dati.
    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();
  }
}

Forse se premi CTRL+T nell'ide per formattare il codice e poi posti io riesco capirci qualcosa in più.

Dal punto di vista logico mi sembra più corretto così:

if ( !disconnect &&  ((millis() - saveMillis) > 30000) ) {

Così ci entra solo se disconnect == false e se sono trascorsi 30000 ms. disconnect = true e quindi non entra una seconda volta e non serve azzerare saveMillis.

La chiamata a data() non si capisce, perché { data; }, poi manca la { in

if (disconnect) {

Aggiorna il tuo ultimo post con il codice formattato dall'ide.

Ciao.

1 Like

Grazie della risposta.
Ho aggiornato il post precedente con la formattazione dall'ide.

Sono arrivato ad una soluzione funzionante.
Grazie ai tuoi ultimi suggerimenti @Maurotec ho aggiustato il codice e ora funziona senza problemi anche se utilizzando

if ( !disconnect &&  ((millis() - saveMillis) > 30000) ) {

e tutto ciò che suggerivi in seguito, per qualche ragione non funzionava a dovere dopo i 30secondi impostati, cosi sono tornato a quanto suggerito nel primo commento e funziona alla perfezione.

Ora provvisoriamente utilizzo lo stesso logo che ho impostato come splashscreen nel setup, che poi modificherò in seguito insieme al layout e agli elementi visualizzati, allegerendo il codice degli elementi non utilizzati.

Lascio qua il codice se qualcuno fosse interessato in futuro

#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, 0xE7, 0x81, 0xCF, 0x07, 0xDE, 0x03,
  0x38, 0x0E, 0xC3, 0xE3, 0x3F, 0xF0, 0x80, 0xC7, 0xC3, 0xC7, 0xE7, 0x81,
  0xCF, 0x07, 0xCF, 0x07, 0x38, 0x0E, 0xE7, 0xE1, 0x3F, 0xF0, 0x80, 0xC7,
  0xC7, 0xC3, 0xE7, 0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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.setContrast(230);
  u8g2.setDrawColor(0);
  u8g2.firstPage();
  do {
    u8g2.drawXBMP( 0, 0, nvidia_logo_width, nvidia_logo_height, nvidia_logo);
  } while ( u8g2.nextPage() );
  
  delay(2000);  // show splash screen for 2 seconds
}


void data() {

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

}

Grazie ancora a @Maurotec e @andreaber per l'aiuto!

void loop() {

  if (millis() - saveMillis > 30000) {
    disconnect = true;
  }
   
  if (disconnect)  {
    u8g2.firstPage();
    do {
      u8g2.setDrawColor(0);
      u8g2.drawXBMP( 0, 0, nvidia_logo_width, nvidia_logo_height, nvidia_logo);
    } while ( u8g2.nextPage() );
  }
  data();
}

Non per fare il pignolo, ma era così che intendevo.

Ciao.

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