Help with U2G8 library

Hi,

I'm doing an skeych with an Arduino Nano, an I2C display, a DHT22 temperature and humidity sensor and a BMP180 pressure sensor.

As I had problems with RAM memory using the Adafruit libraries, some people recomend me to use the U2G8 library.

This is a preliminary code, but I have several questions.

/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 * PROGRAMA:  Estació meteorologica U8G2
 * VERSIO:    0.1
 * DATA:      18/08/23
 * PLACA:     Arduino Nano
 * DESCRIPCIO:Tenim un sensor de temperatura i humitat DHT22 i un sensor de presió i temperatura.
        A través d'un modul Bluetooth HC06 enviem les lectures a una APP movil programada amb APP INVENTOR.
        Per el cable USB enviem la lectura de les dades a un programa de Windows en Visual C# o a un programa e Linux en Gambas3
* VERSIONS: 0.0 Programa que envia valors dummie de Temperatura, Humitat i Pressió per porvar la funcionalitat de la APP movil        
*           0.1 Usem U8G2. Afegim els grafics
 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
#include <SoftwareSerial.h>     //Llibreria per afegir rt serie per software

const int RX=7;                 //Pin de RX per soft per al modul Bluettoth HC06
const int TX=8;                 //Pin de Tx per soft per al modul Bluettoth HC06

float temp, hum, pres;      //Valors de la temperatura, humitat i presió
String valor;
SoftwareSerial sw(RX,TX);       //Definem un element de tipus SoffwareSerial conectat als pins 7 (Rx) i 8 (TX)
uint8_t draw_state = 0;
#include <Arduino.h>
#include <U8g2lib.h>
//U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);                    //Constructor del display
//U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
U8G2_ST7567_ENH_DG128064I_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//Constructor del display
/*------------------------------------------
 * grafic de la carátula
 *-----------------------------------------*/
#define CARAWIDTH  69
#define CARAHEIGHT 64
const unsigned char CARATULA[] PROGMEM = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x26, 0x02, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0xc0, 0x66, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0xcc, 0x7e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xff,
   0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x1f, 0x01, 0x00,
   0x00, 0x00, 0x00, 0x00, 0xf3, 0x01, 0xcf, 0xc0, 0x1f, 0x00, 0x00, 0x00,
   0x00, 0x7e, 0x00, 0xfc, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00,
   0xf8, 0xf0, 0xff, 0x00, 0x00, 0x00, 0xe0, 0x1c, 0x00, 0xf0, 0xf9, 0xf0,
   0x01, 0x00, 0x00, 0x80, 0x0f, 0x00, 0xf8, 0x3f, 0xc0, 0x01, 0x00, 0x00,
   0x00, 0x0f, 0x00, 0xfc, 0x1f, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00,
   0x3e, 0x1f, 0x80, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x0f, 0x0e, 0x80,
   0x03, 0x00, 0x00, 0x80, 0x07, 0x80, 0x07, 0x06, 0x80, 0x03, 0x00, 0x00,
   0x00, 0x07, 0x80, 0x03, 0x04, 0x80, 0x7f, 0x00, 0x00, 0xc0, 0x07, 0xc0,
   0x01, 0x00, 0xc0, 0xff, 0x00, 0x00, 0xe0, 0x07, 0xf8, 0x01, 0x00, 0xe0,
   0xff, 0x01, 0x00, 0x00, 0x06, 0xfc, 0x70, 0x00, 0xf0, 0xc1, 0x03, 0x00,
   0x00, 0x0f, 0xfe, 0x78, 0x00, 0x60, 0x80, 0x07, 0x00, 0xc0, 0x0f, 0xc7,
   0xdc, 0x00, 0xe0, 0x0f, 0x07, 0x00, 0x40, 0x1c, 0x43, 0xcc, 0x00, 0xf8,
   0x1f, 0x07, 0x00, 0x00, 0xbe, 0x01, 0x06, 0x00, 0xfc, 0x3e, 0x07, 0x00,
   0x00, 0xff, 0x81, 0x07, 0x00, 0x1c, 0x78, 0x07, 0x00, 0x00, 0xf1, 0xc0,
   0x07, 0x00, 0x00, 0x70, 0x07, 0x00, 0x00, 0xf8, 0xc0, 0x06, 0x00, 0x00,
   0xf0, 0x0f, 0x00, 0x00, 0x7c, 0x40, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x00,
   0x00, 0x74, 0x60, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x03, 0x00, 0x38, 0x60,
   0x00, 0x00, 0x00, 0xf8, 0xf3, 0x07, 0x00, 0x18, 0x20, 0x00, 0x00, 0x00,
   0x78, 0x00, 0x0f, 0x00, 0xb8, 0x37, 0x00, 0x00, 0x00, 0x38, 0x00, 0x1e,
   0x00, 0xff, 0x17, 0x00, 0x00, 0x00, 0x70, 0x00, 0x1e, 0xf0, 0xff, 0x13,
   0x00, 0x00, 0x20, 0x70, 0x00, 0x1e, 0xfe, 0x03, 0x00, 0x00, 0x00, 0xf0,
   0x7f, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f, 0x80, 0x0f,
   0x07, 0x00, 0x00, 0x00, 0x18, 0x80, 0x0f, 0xe0, 0x07, 0x0f, 0xf8, 0x1f,
   0x00, 0x18, 0x00, 0x00, 0xf0, 0x01, 0xfe, 0xff, 0x7f, 0x00, 0x1c, 0x00,
   0x00, 0xfc, 0x00, 0xfc, 0x1f, 0xf8, 0x00, 0x0e, 0x00, 0x00, 0x3e, 0x00,
   0x40, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0xe0, 0x0f, 0x00, 0x00, 0x00, 0xc0,
   0xff, 0x7f, 0xc0, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
   0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x00,
   0x00, 0x00, 0xc0, 0x00, 0x03, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
   0x80, 0x03, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x80, 0x03, 0x0e,
   0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc0, 0x03, 0x0e, 0x00, 0x00, 0x00,
   0x00, 0x00, 0xf0, 0xc0, 0x03, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
   0x80, 0x01, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x18, 0xe0, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1c, 0x70, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x07, 0x1c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07,
   0x1e, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x78, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x70, 0x00, 0x00, 0x00, 0x00 };
/*------------------------------------------
 * grafic del termómetre
 *-----------------------------------------*/
#define TERWIDTH 34
#define TERHEIGHT 60


const unsigned char TERMOMETRE[] PROGMEM = {
   0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xff,
   0x03, 0x00, 0x00, 0x80, 0x87, 0x03, 0x00, 0x00, 0x80, 0x03, 0x07, 0x00,
   0x00, 0xc0, 0x01, 0x07, 0x00, 0x00, 0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0,
   0x01, 0x06, 0x00, 0x00, 0xc0, 0x01, 0x06, 0xff, 0x03, 0xc0, 0x01, 0x06,
   0xff, 0x03, 0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0, 0x01, 0x06, 0x00, 0x00,
   0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0, 0x01, 0x06, 0x3e, 0x00, 0xc0, 0x01,
   0x06, 0x3f, 0x00, 0xc0, 0x01, 0x06, 0x3f, 0x00, 0xc0, 0x01, 0x06, 0x00,
   0x00, 0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0,
   0x01, 0x06, 0xff, 0x03, 0xc0, 0x01, 0x06, 0xff, 0x03, 0xc0, 0x01, 0x06,
   0x00, 0x00, 0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0, 0x39, 0x06, 0x00, 0x00,
   0xc0, 0x39, 0x06, 0x1e, 0x00, 0xc0, 0x39, 0x06, 0x3f, 0x00, 0xc0, 0x39,
   0x06, 0x3f, 0x00, 0xc0, 0x39, 0x06, 0x00, 0x00, 0xc0, 0x39, 0x06, 0x00,
   0x00, 0xc0, 0x39, 0x06, 0x00, 0x00, 0xc0, 0x39, 0x06, 0xff, 0x03, 0xc0,
   0x39, 0x06, 0xff, 0x03, 0xc0, 0x39, 0x06, 0x00, 0x00, 0xc0, 0x39, 0x06,
   0x00, 0x00, 0xc0, 0x39, 0x06, 0x00, 0x00, 0xc0, 0x39, 0x06, 0x00, 0x00,
   0xe0, 0x39, 0x0e, 0x00, 0x00, 0xf0, 0x39, 0x1e, 0x00, 0x00, 0x78, 0x38,
   0x38, 0x00, 0x00, 0x3c, 0xfc, 0x70, 0x00, 0x00, 0x1c, 0xf7, 0xe3, 0x00,
   0x00, 0x8e, 0xe1, 0xc7, 0x00, 0x00, 0xce, 0xe0, 0xcf, 0x01, 0x00, 0x66,
   0xf0, 0xcf, 0x01, 0x00, 0x27, 0xfc, 0x9f, 0x01, 0x00, 0x27, 0xfc, 0x9f,
   0x03, 0x00, 0x27, 0xfe, 0x9f, 0x03, 0x00, 0x27, 0xfe, 0x9f, 0x03, 0x00,
   0xe7, 0xff, 0x9f, 0x03, 0x00, 0xe7, 0xff, 0x9f, 0x01, 0x00, 0xe6, 0xff,
   0xcf, 0x01, 0x00, 0xce, 0xff, 0xcf, 0x01, 0x00, 0x8e, 0xff, 0xe7, 0x00,
   0x00, 0x1c, 0xff, 0xe3, 0x00, 0x00, 0x3c, 0xfc, 0x70, 0x00, 0x00, 0x78,
   0x00, 0x3c, 0x00, 0x00, 0xf0, 0x01, 0x1e, 0x00, 0x00, 0xc0, 0xff, 0x0f,
   0x00, 0x00, 0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00 };



/*------------------------------------------
 * grafic de la gota
 *-----------------------------------------*/
#define GOTAWIDTH   41
#define GOTAHEIGHT  60

const unsigned char GOTA[] PROGMEM = {
   0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00,
   0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0x03, 0x00, 0x00,
   0x00, 0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x07, 0x00, 0x00,
   0x00, 0xe0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0x00,
   0x00, 0xf0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x3f, 0x00, 0x00,
   0x00, 0xf8, 0xff, 0x3f, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x7f, 0x00, 0x00,
   0x00, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x01, 0x00,
   0x00, 0xff, 0xff, 0xff, 0x01, 0x00, 0x80, 0xff, 0xff, 0xff, 0x03, 0x00,
   0xc0, 0xff, 0xff, 0xff, 0x07, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00,
   0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x1f, 0x00,
   0xf0, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xf8, 0xff, 0xff, 0x3f, 0x3f, 0x00,
   0xf8, 0xff, 0xff, 0x3f, 0x3c, 0x00, 0xfc, 0xff, 0xff, 0x1f, 0x7c, 0x00,
   0xfc, 0xff, 0xff, 0x1f, 0x78, 0x00, 0xfe, 0xff, 0xff, 0x1f, 0xf0, 0x00,
   0xfe, 0xff, 0xff, 0x1f, 0xf0, 0x00, 0xfe, 0xff, 0xff, 0x0f, 0xe0, 0x00,
   0xfe, 0xff, 0xff, 0x0f, 0xe0, 0x00, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0x01,
   0xff, 0xff, 0xff, 0x07, 0xe0, 0x01, 0xff, 0xff, 0xff, 0x07, 0xc0, 0x01,
   0xff, 0xff, 0xff, 0x03, 0xc0, 0x01, 0xff, 0xff, 0xff, 0x03, 0xc0, 0x01,
   0xff, 0xff, 0xff, 0x01, 0xc0, 0x01, 0xff, 0xff, 0xff, 0x01, 0xc0, 0x01,
   0xff, 0xff, 0xff, 0x01, 0xc0, 0x01, 0xff, 0xff, 0xff, 0x01, 0xe0, 0x01,
   0xfe, 0xff, 0xff, 0x01, 0xe0, 0x00, 0xfe, 0xff, 0xff, 0x01, 0xe0, 0x00,
   0xfe, 0xff, 0xff, 0x03, 0xf0, 0x00, 0xfe, 0xff, 0xff, 0x03, 0xf0, 0x00,
   0xfc, 0xff, 0xff, 0x07, 0x78, 0x00, 0xfc, 0xff, 0xff, 0x0f, 0x7e, 0x00,
   0xf8, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x1f, 0x00,
   0xf0, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00,
   0xc0, 0xff, 0xff, 0xff, 0x07, 0x00, 0x80, 0xff, 0xff, 0xff, 0x03, 0x00,
   0x00, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x7f, 0x00, 0x00,
   0x00, 0xf0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00 };

/*------------------------------------------
 * grafic del manómetre
 *-----------------------------------------*/
#define MANWIDTH  60
#define MANHEIGHT 60

const unsigned char MANOMETRE[] PROGMEM = {
   0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
   0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x03, 0x00, 0x00,
   0x00, 0x00, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
   0xff, 0x3f, 0x00, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0xe0, 0x7f, 0x00, 0x00,
   0x00, 0xf8, 0x0f, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xfc, 0x03, 0x00,
   0x00, 0xfc, 0x03, 0x00, 0x00, 0xfe, 0x00, 0x60, 0x00, 0xf8, 0x07, 0x00,
   0x00, 0x7f, 0x00, 0x60, 0x00, 0xe0, 0x0f, 0x00, 0x80, 0x3f, 0x00, 0xff,
   0x0f, 0xc0, 0x1f, 0x00, 0xc0, 0x1f, 0xe0, 0xff, 0x7f, 0x80, 0x3f, 0x00,
   0xc0, 0x0f, 0xf8, 0x03, 0xfc, 0x01, 0x3f, 0x00, 0xe0, 0x07, 0x7c, 0x00,
   0xe0, 0x03, 0x7e, 0x00, 0xf0, 0x43, 0x1f, 0x00, 0x80, 0x27, 0xfc, 0x00,
   0xf0, 0xc1, 0x0f, 0x00, 0x00, 0x3e, 0xf8, 0x00, 0xf8, 0xc1, 0x03, 0x00,
   0x00, 0x3c, 0xf8, 0x01, 0xf8, 0xc0, 0x01, 0x00, 0x00, 0x38, 0xf0, 0x01,
   0x7c, 0xe0, 0x00, 0x00, 0x00, 0x70, 0xe0, 0x03, 0x7c, 0x70, 0x00, 0x00,
   0x00, 0xf0, 0xe0, 0x03, 0x7c, 0x70, 0x00, 0x00, 0x00, 0xe0, 0xc0, 0x03,
   0x3e, 0x38, 0x00, 0x00, 0x00, 0xc0, 0xc1, 0x07, 0x3e, 0x38, 0x00, 0x00,
   0x20, 0xc0, 0xc1, 0x07, 0x1e, 0x18, 0x00, 0x00, 0x10, 0x80, 0x81, 0x07,
   0x1e, 0x1c, 0x00, 0x00, 0x08, 0x80, 0x83, 0x07, 0x1f, 0x1c, 0x00, 0x00,
   0x04, 0x80, 0x83, 0x0f, 0x1f, 0x0c, 0x00, 0x00, 0x06, 0x00, 0x83, 0x0f,
   0x1f, 0x0c, 0x00, 0xf0, 0x03, 0x00, 0x83, 0x0f, 0x1f, 0x0c, 0x00, 0xf8,
   0x01, 0x00, 0x83, 0x0f, 0x1f, 0x0e, 0x00, 0xf8, 0x01, 0x00, 0x87, 0x0f,
   0x1f, 0x0e, 0x00, 0xf8, 0x01, 0x00, 0x87, 0x0f, 0x1f, 0x0f, 0x00, 0xfc,
   0x01, 0x00, 0x8f, 0x0f, 0x1f, 0x0e, 0x00, 0xfe, 0x00, 0x00, 0x87, 0x0f,
   0x1f, 0x0c, 0x00, 0x0f, 0x00, 0x00, 0x83, 0x0f, 0x1f, 0x1c, 0x00, 0x06,
   0x00, 0x80, 0x83, 0x0f, 0x1e, 0x1c, 0x00, 0x00, 0x00, 0x80, 0x83, 0x07,
   0x1e, 0x18, 0x00, 0x00, 0x00, 0x80, 0x81, 0x07, 0x3e, 0x38, 0x00, 0x00,
   0x00, 0xc0, 0xc1, 0x07, 0x3e, 0x38, 0x00, 0x00, 0x00, 0xc0, 0xc1, 0x07,
   0x3c, 0x70, 0x00, 0x00, 0x00, 0xe0, 0xe0, 0x03, 0x7c, 0xf0, 0x00, 0x00,
   0x00, 0xf0, 0xe0, 0x03, 0x7c, 0xe0, 0x00, 0x00, 0x00, 0x70, 0xe0, 0x03,
   0xf8, 0xc0, 0x01, 0x00, 0x00, 0x38, 0xf0, 0x01, 0xf8, 0x81, 0x03, 0x00,
   0x00, 0x1c, 0xf8, 0x01, 0xf0, 0x81, 0x01, 0x00, 0x00, 0x18, 0xf8, 0x00,
   0xf0, 0xc3, 0x00, 0x00, 0x00, 0x30, 0xfc, 0x00, 0xe0, 0x07, 0x00, 0x00,
   0x00, 0x00, 0x7e, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00,
   0xc0, 0x1f, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x80, 0x3f, 0x00, 0x00,
   0x00, 0xc0, 0x1f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0xe0, 0x0f, 0x00,
   0x00, 0xfe, 0x01, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x00, 0xfc, 0x03, 0x00,
   0x00, 0xfc, 0x03, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x80, 0xff, 0x01, 0x00,
   0x00, 0xe0, 0xff, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
   0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00,
   0x00, 0x00, 0xfc, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
   0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00 };
void setup()
{
  //Iniciem les variables
  temp=10.25;
  hum=20.56;
  pres=1000;
  sw.begin(9600);             //Iniciem el port serie virtual sw a 9600 bauds
  Serial.begin(9600);         //Iniciem el port serie a 9600 bauds
  u8g2.setI2CAddress(0x3F * 2);
  u8g2.begin();               //Iniciem el display
}

void loop() 
{
  //Convertim les dades a formar csv
  valor = (String) temp + "," + (String) hum + "," + (String) pres;
  Serial.println(valor);      //Enviem per el port serie
  sw.println(valor);          //Enviem per el port serie virtual bluetooth
  //delay(4000);                 // It should be slower than the Clock Interval
  temp++;                     //Actualitzem el valor dummie
  hum++;                      //Actualitzem el valor dummie
  pres++;                     //Actualitzem el valor dummie
  u8g2.firstPage();  
  do {
    draw();
  } while( u8g2.nextPage() );
  
  // increase the state
  draw_state++;
  if ( draw_state >= 4*8 )
    draw_state = 0;

  // delay between each page
  delay(200);
}

void u8g2_prepare(void) {
  //u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.setFont(u8g2_font_10x20_mr);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setDrawColor(1);
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);
}

void draw(void) 
{
  u8g2_prepare();
  switch(draw_state >> 3) 
  {
    case 0:
      caratula(); 
      break;
    case 1: 
      temperatura();
      break;
    case 2: 
      humitat();
      break;
    case 3: 
      presio();
      break;
  } 
}

void caratula()
{
  u8g2.setDrawColor(1); // White
  u8g2.drawXBMP((128-CARAWIDTH)/2,0,CARAWIDTH,CARAHEIGHT,CARATULA);
}

void temperatura()
{
  String valor;
  valor=(String)temp;
  valor=valor+"ºC";
  //u8g2.setBitmapMode(false /* solid */);
  u8g2.setDrawColor(1); // White
  u8g2.drawXBMP(0,2,TERWIDTH,TERHEIGHT,TERMOMETRE);
  u8g2.drawStr(TERWIDTH,20,"24.86ºC");
  /*
  u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // set fonts
u8g2.setCursor(30,30); // set cursor position lcd
u8g2.print(temp,2); // write variable to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display*/
}

void humitat()
{
  u8g2.setDrawColor(1); // White
  u8g2.drawXBMP(1,2,GOTAWIDTH,GOTAHEIGHT,GOTA);
  u8g2.drawStr(GOTAWIDTH,20,"75.36%");
}

void presio()
{
  u8g2.setDrawColor(1); // White
  u8g2.drawXBMP(1,2,MANWIDTH,MANHEIGHT,MANOMETRE);
  u8g2.drawStr(MANWIDTH+10,10,"1010");
  u8g2.drawStr(MANWIDTH+10,30,"mbar");
}

With the u8g2.drawStr() I can shiiw strungs in the display. But how can I show variables? I need to show the content of temp, hum and pres but I do not know how to do this with U8G2 library.

Which functions does the LIB documentation show?
Any example code given?

Home · olikraus/u8g2 Wiki · GitHub

Simple answer, do not use drawStr(), use setCursor() to position the cursor then use .print() to display the data.

There is no need to use setDrawColor() every time you display something, that is only needed when the color changes, and it looks like you always use setDrawColor(1).

Thank you David.

Finally I could codify correctly te bitmaps by using GIMP.

Hi again,

your solution works, but I do not end to understand the logic of FirstPage() structure with the U8G2 library.

/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 * PROGRAMA:  Estació meteorologica U8G2
 * VERSIO:    0.1
 * DATA:      18/08/23
 * PLACA:     Arduino Nano
 * DESCRIPCIO:Tenim un sensor de temperatura i humitat DHT22 i un sensor de presió i temperatura.
        A través d'un modul Bluetooth HC06 enviem les lectures a una APP movil programada amb APP INVENTOR.
        Per el cable USB enviem la lectura de les dades a un programa de Windows en Visual C# o a un programa e Linux en Gambas3
* VERSIONS: 0.0 Programa que envia valors dummie de Temperatura, Humitat i Pressió per porvar la funcionalitat de la APP movil        
*           0.1 Usem U8G2. Afegim els grafics
 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
#include <SoftwareSerial.h>     //Llibreria per afegir rt serie per software

const int RX=7;                 //Pin de RX per soft per al modul Bluettoth HC06
const int TX=8;                 //Pin de Tx per soft per al modul Bluettoth HC06

float temp, hum, pres;      //Valors de la temperatura, humitat i presió
String valor;
SoftwareSerial sw(RX,TX);       //Definem un element de tipus SoffwareSerial conectat als pins 7 (Rx) i 8 (TX)
uint8_t draw_state = 0;
#include <Arduino.h>
#include <U8g2lib.h>
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);                    //Constructor del display SH1106
//U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);                 //Constructor del display
//U8G2_ST7567_ENH_DG128064I_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);                  //Constructor del display
//Constructor del display
/*------------------------------------------
 * grafic de la carátula
 *-----------------------------------------*/
#define CARAWIDTH  69
#define CARAHEIGHT 64
const unsigned char CARATULA[] PROGMEM = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x26, 0x02, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0xc0, 0x66, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0xcc, 0x7e, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0xff,
   0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x1f, 0x01, 0x00,
   0x00, 0x00, 0x00, 0x00, 0xf3, 0x01, 0xcf, 0xc0, 0x1f, 0x00, 0x00, 0x00,
   0x00, 0x7e, 0x00, 0xfc, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00,
   0xf8, 0xf0, 0xff, 0x00, 0x00, 0x00, 0xe0, 0x1c, 0x00, 0xf0, 0xf9, 0xf0,
   0x01, 0x00, 0x00, 0x80, 0x0f, 0x00, 0xf8, 0x3f, 0xc0, 0x01, 0x00, 0x00,
   0x00, 0x0f, 0x00, 0xfc, 0x1f, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00,
   0x3e, 0x1f, 0x80, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x0f, 0x0e, 0x80,
   0x03, 0x00, 0x00, 0x80, 0x07, 0x80, 0x07, 0x06, 0x80, 0x03, 0x00, 0x00,
   0x00, 0x07, 0x80, 0x03, 0x04, 0x80, 0x7f, 0x00, 0x00, 0xc0, 0x07, 0xc0,
   0x01, 0x00, 0xc0, 0xff, 0x00, 0x00, 0xe0, 0x07, 0xf8, 0x01, 0x00, 0xe0,
   0xff, 0x01, 0x00, 0x00, 0x06, 0xfc, 0x70, 0x00, 0xf0, 0xc1, 0x03, 0x00,
   0x00, 0x0f, 0xfe, 0x78, 0x00, 0x60, 0x80, 0x07, 0x00, 0xc0, 0x0f, 0xc7,
   0xdc, 0x00, 0xe0, 0x0f, 0x07, 0x00, 0x40, 0x1c, 0x43, 0xcc, 0x00, 0xf8,
   0x1f, 0x07, 0x00, 0x00, 0xbe, 0x01, 0x06, 0x00, 0xfc, 0x3e, 0x07, 0x00,
   0x00, 0xff, 0x81, 0x07, 0x00, 0x1c, 0x78, 0x07, 0x00, 0x00, 0xf1, 0xc0,
   0x07, 0x00, 0x00, 0x70, 0x07, 0x00, 0x00, 0xf8, 0xc0, 0x06, 0x00, 0x00,
   0xf0, 0x0f, 0x00, 0x00, 0x7c, 0x40, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x00,
   0x00, 0x74, 0x60, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x03, 0x00, 0x38, 0x60,
   0x00, 0x00, 0x00, 0xf8, 0xf3, 0x07, 0x00, 0x18, 0x20, 0x00, 0x00, 0x00,
   0x78, 0x00, 0x0f, 0x00, 0xb8, 0x37, 0x00, 0x00, 0x00, 0x38, 0x00, 0x1e,
   0x00, 0xff, 0x17, 0x00, 0x00, 0x00, 0x70, 0x00, 0x1e, 0xf0, 0xff, 0x13,
   0x00, 0x00, 0x20, 0x70, 0x00, 0x1e, 0xfe, 0x03, 0x00, 0x00, 0x00, 0xf0,
   0x7f, 0x00, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f, 0x80, 0x0f,
   0x07, 0x00, 0x00, 0x00, 0x18, 0x80, 0x0f, 0xe0, 0x07, 0x0f, 0xf8, 0x1f,
   0x00, 0x18, 0x00, 0x00, 0xf0, 0x01, 0xfe, 0xff, 0x7f, 0x00, 0x1c, 0x00,
   0x00, 0xfc, 0x00, 0xfc, 0x1f, 0xf8, 0x00, 0x0e, 0x00, 0x00, 0x3e, 0x00,
   0x40, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0xe0, 0x0f, 0x00, 0x00, 0x00, 0xc0,
   0xff, 0x7f, 0xc0, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
   0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x00,
   0x00, 0x00, 0xc0, 0x00, 0x03, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
   0x80, 0x03, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x80, 0x03, 0x0e,
   0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc0, 0x03, 0x0e, 0x00, 0x00, 0x00,
   0x00, 0x00, 0xf0, 0xc0, 0x03, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
   0x80, 0x01, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x18, 0xe0, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1c, 0x70, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x07, 0x1c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07,
   0x1e, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x1e, 0x78, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x70, 0x00, 0x00, 0x00, 0x00 };
/*------------------------------------------
 * grafic del termómetre
 *-----------------------------------------*/
#define TERWIDTH 34
#define TERHEIGHT 60


const unsigned char TERMOMETRE[] PROGMEM = {
   0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xff,
   0x03, 0x00, 0x00, 0x80, 0x87, 0x03, 0x00, 0x00, 0x80, 0x03, 0x07, 0x00,
   0x00, 0xc0, 0x01, 0x07, 0x00, 0x00, 0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0,
   0x01, 0x06, 0x00, 0x00, 0xc0, 0x01, 0x06, 0xff, 0x03, 0xc0, 0x01, 0x06,
   0xff, 0x03, 0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0, 0x01, 0x06, 0x00, 0x00,
   0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0, 0x01, 0x06, 0x3e, 0x00, 0xc0, 0x01,
   0x06, 0x3f, 0x00, 0xc0, 0x01, 0x06, 0x3f, 0x00, 0xc0, 0x01, 0x06, 0x00,
   0x00, 0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0,
   0x01, 0x06, 0xff, 0x03, 0xc0, 0x01, 0x06, 0xff, 0x03, 0xc0, 0x01, 0x06,
   0x00, 0x00, 0xc0, 0x01, 0x06, 0x00, 0x00, 0xc0, 0x39, 0x06, 0x00, 0x00,
   0xc0, 0x39, 0x06, 0x1e, 0x00, 0xc0, 0x39, 0x06, 0x3f, 0x00, 0xc0, 0x39,
   0x06, 0x3f, 0x00, 0xc0, 0x39, 0x06, 0x00, 0x00, 0xc0, 0x39, 0x06, 0x00,
   0x00, 0xc0, 0x39, 0x06, 0x00, 0x00, 0xc0, 0x39, 0x06, 0xff, 0x03, 0xc0,
   0x39, 0x06, 0xff, 0x03, 0xc0, 0x39, 0x06, 0x00, 0x00, 0xc0, 0x39, 0x06,
   0x00, 0x00, 0xc0, 0x39, 0x06, 0x00, 0x00, 0xc0, 0x39, 0x06, 0x00, 0x00,
   0xe0, 0x39, 0x0e, 0x00, 0x00, 0xf0, 0x39, 0x1e, 0x00, 0x00, 0x78, 0x38,
   0x38, 0x00, 0x00, 0x3c, 0xfc, 0x70, 0x00, 0x00, 0x1c, 0xf7, 0xe3, 0x00,
   0x00, 0x8e, 0xe1, 0xc7, 0x00, 0x00, 0xce, 0xe0, 0xcf, 0x01, 0x00, 0x66,
   0xf0, 0xcf, 0x01, 0x00, 0x27, 0xfc, 0x9f, 0x01, 0x00, 0x27, 0xfc, 0x9f,
   0x03, 0x00, 0x27, 0xfe, 0x9f, 0x03, 0x00, 0x27, 0xfe, 0x9f, 0x03, 0x00,
   0xe7, 0xff, 0x9f, 0x03, 0x00, 0xe7, 0xff, 0x9f, 0x01, 0x00, 0xe6, 0xff,
   0xcf, 0x01, 0x00, 0xce, 0xff, 0xcf, 0x01, 0x00, 0x8e, 0xff, 0xe7, 0x00,
   0x00, 0x1c, 0xff, 0xe3, 0x00, 0x00, 0x3c, 0xfc, 0x70, 0x00, 0x00, 0x78,
   0x00, 0x3c, 0x00, 0x00, 0xf0, 0x01, 0x1e, 0x00, 0x00, 0xc0, 0xff, 0x0f,
   0x00, 0x00, 0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00 };



/*------------------------------------------
 * grafic de la gota
 *-----------------------------------------*/
#define GOTAWIDTH   41
#define GOTAHEIGHT  60

const unsigned char GOTA[] PROGMEM = {
   0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00,
   0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0x03, 0x00, 0x00,
   0x00, 0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x07, 0x00, 0x00,
   0x00, 0xe0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0x00,
   0x00, 0xf0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x3f, 0x00, 0x00,
   0x00, 0xf8, 0xff, 0x3f, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x7f, 0x00, 0x00,
   0x00, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x01, 0x00,
   0x00, 0xff, 0xff, 0xff, 0x01, 0x00, 0x80, 0xff, 0xff, 0xff, 0x03, 0x00,
   0xc0, 0xff, 0xff, 0xff, 0x07, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00,
   0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x1f, 0x00,
   0xf0, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xf8, 0xff, 0xff, 0x3f, 0x3f, 0x00,
   0xf8, 0xff, 0xff, 0x3f, 0x3c, 0x00, 0xfc, 0xff, 0xff, 0x1f, 0x7c, 0x00,
   0xfc, 0xff, 0xff, 0x1f, 0x78, 0x00, 0xfe, 0xff, 0xff, 0x1f, 0xf0, 0x00,
   0xfe, 0xff, 0xff, 0x1f, 0xf0, 0x00, 0xfe, 0xff, 0xff, 0x0f, 0xe0, 0x00,
   0xfe, 0xff, 0xff, 0x0f, 0xe0, 0x00, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0x01,
   0xff, 0xff, 0xff, 0x07, 0xe0, 0x01, 0xff, 0xff, 0xff, 0x07, 0xc0, 0x01,
   0xff, 0xff, 0xff, 0x03, 0xc0, 0x01, 0xff, 0xff, 0xff, 0x03, 0xc0, 0x01,
   0xff, 0xff, 0xff, 0x01, 0xc0, 0x01, 0xff, 0xff, 0xff, 0x01, 0xc0, 0x01,
   0xff, 0xff, 0xff, 0x01, 0xc0, 0x01, 0xff, 0xff, 0xff, 0x01, 0xe0, 0x01,
   0xfe, 0xff, 0xff, 0x01, 0xe0, 0x00, 0xfe, 0xff, 0xff, 0x01, 0xe0, 0x00,
   0xfe, 0xff, 0xff, 0x03, 0xf0, 0x00, 0xfe, 0xff, 0xff, 0x03, 0xf0, 0x00,
   0xfc, 0xff, 0xff, 0x07, 0x78, 0x00, 0xfc, 0xff, 0xff, 0x0f, 0x7e, 0x00,
   0xf8, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x1f, 0x00,
   0xf0, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00,
   0xc0, 0xff, 0xff, 0xff, 0x07, 0x00, 0x80, 0xff, 0xff, 0xff, 0x03, 0x00,
   0x00, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x7f, 0x00, 0x00,
   0x00, 0xf0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00 };

/*------------------------------------------
 * grafic del manómetre
 *-----------------------------------------*/
#define MANWIDTH  60
#define MANHEIGHT 60

const unsigned char MANOMETRE[] PROGMEM = {
   0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
   0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x03, 0x00, 0x00,
   0x00, 0x00, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
   0xff, 0x3f, 0x00, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0xe0, 0x7f, 0x00, 0x00,
   0x00, 0xf8, 0x0f, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xfc, 0x03, 0x00,
   0x00, 0xfc, 0x03, 0x00, 0x00, 0xfe, 0x00, 0x60, 0x00, 0xf8, 0x07, 0x00,
   0x00, 0x7f, 0x00, 0x60, 0x00, 0xe0, 0x0f, 0x00, 0x80, 0x3f, 0x00, 0xff,
   0x0f, 0xc0, 0x1f, 0x00, 0xc0, 0x1f, 0xe0, 0xff, 0x7f, 0x80, 0x3f, 0x00,
   0xc0, 0x0f, 0xf8, 0x03, 0xfc, 0x01, 0x3f, 0x00, 0xe0, 0x07, 0x7c, 0x00,
   0xe0, 0x03, 0x7e, 0x00, 0xf0, 0x43, 0x1f, 0x00, 0x80, 0x27, 0xfc, 0x00,
   0xf0, 0xc1, 0x0f, 0x00, 0x00, 0x3e, 0xf8, 0x00, 0xf8, 0xc1, 0x03, 0x00,
   0x00, 0x3c, 0xf8, 0x01, 0xf8, 0xc0, 0x01, 0x00, 0x00, 0x38, 0xf0, 0x01,
   0x7c, 0xe0, 0x00, 0x00, 0x00, 0x70, 0xe0, 0x03, 0x7c, 0x70, 0x00, 0x00,
   0x00, 0xf0, 0xe0, 0x03, 0x7c, 0x70, 0x00, 0x00, 0x00, 0xe0, 0xc0, 0x03,
   0x3e, 0x38, 0x00, 0x00, 0x00, 0xc0, 0xc1, 0x07, 0x3e, 0x38, 0x00, 0x00,
   0x20, 0xc0, 0xc1, 0x07, 0x1e, 0x18, 0x00, 0x00, 0x10, 0x80, 0x81, 0x07,
   0x1e, 0x1c, 0x00, 0x00, 0x08, 0x80, 0x83, 0x07, 0x1f, 0x1c, 0x00, 0x00,
   0x04, 0x80, 0x83, 0x0f, 0x1f, 0x0c, 0x00, 0x00, 0x06, 0x00, 0x83, 0x0f,
   0x1f, 0x0c, 0x00, 0xf0, 0x03, 0x00, 0x83, 0x0f, 0x1f, 0x0c, 0x00, 0xf8,
   0x01, 0x00, 0x83, 0x0f, 0x1f, 0x0e, 0x00, 0xf8, 0x01, 0x00, 0x87, 0x0f,
   0x1f, 0x0e, 0x00, 0xf8, 0x01, 0x00, 0x87, 0x0f, 0x1f, 0x0f, 0x00, 0xfc,
   0x01, 0x00, 0x8f, 0x0f, 0x1f, 0x0e, 0x00, 0xfe, 0x00, 0x00, 0x87, 0x0f,
   0x1f, 0x0c, 0x00, 0x0f, 0x00, 0x00, 0x83, 0x0f, 0x1f, 0x1c, 0x00, 0x06,
   0x00, 0x80, 0x83, 0x0f, 0x1e, 0x1c, 0x00, 0x00, 0x00, 0x80, 0x83, 0x07,
   0x1e, 0x18, 0x00, 0x00, 0x00, 0x80, 0x81, 0x07, 0x3e, 0x38, 0x00, 0x00,
   0x00, 0xc0, 0xc1, 0x07, 0x3e, 0x38, 0x00, 0x00, 0x00, 0xc0, 0xc1, 0x07,
   0x3c, 0x70, 0x00, 0x00, 0x00, 0xe0, 0xe0, 0x03, 0x7c, 0xf0, 0x00, 0x00,
   0x00, 0xf0, 0xe0, 0x03, 0x7c, 0xe0, 0x00, 0x00, 0x00, 0x70, 0xe0, 0x03,
   0xf8, 0xc0, 0x01, 0x00, 0x00, 0x38, 0xf0, 0x01, 0xf8, 0x81, 0x03, 0x00,
   0x00, 0x1c, 0xf8, 0x01, 0xf0, 0x81, 0x01, 0x00, 0x00, 0x18, 0xf8, 0x00,
   0xf0, 0xc3, 0x00, 0x00, 0x00, 0x30, 0xfc, 0x00, 0xe0, 0x07, 0x00, 0x00,
   0x00, 0x00, 0x7e, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00,
   0xc0, 0x1f, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x80, 0x3f, 0x00, 0x00,
   0x00, 0xc0, 0x1f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0xe0, 0x0f, 0x00,
   0x00, 0xfe, 0x01, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x00, 0xfc, 0x03, 0x00,
   0x00, 0xfc, 0x03, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x80, 0xff, 0x01, 0x00,
   0x00, 0xe0, 0xff, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
   0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00,
   0x00, 0x00, 0xfc, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
   0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00 };
void setup()
{
  //Iniciem les variables
  temp=10.25;
  hum=20.56;
  pres=1000;
  sw.begin(9600);                   //Iniciem el port serie virtual sw a 9600 bauds
  Serial.begin(9600);               //Iniciem el port serie a 9600 bauds
  //u8g2.setI2CAddress(0x3F * 2);   //Solament per al display ST7567S
  u8g2.begin();                     //Iniciem el display
}

void loop() 
{
  //Convertim les dades a formar csv
  valor = (String) temp + "," + (String) hum + "," + (String) pres;
  Serial.println(valor);      //Enviem per el port serie
  sw.println(valor);          //Enviem per el port serie virtual bluetooth
  //delay(4000);                 // It should be slower than the Clock Interval
  llegirtemp();
  llegirhum();                      //Actualitzem el valor dummie
  llegirpres();                     //Actualitzem el valor dummie
  u8g2.firstPage();  
  do {
    draw();
  } while( u8g2.nextPage() );
  
  // increase the state
  draw_state++;
  if ( draw_state >= 4*8 )
    draw_state = 1*8;

  // delay between each page
  delay(200);
}

void u8g2_prepare(void) {
  //u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.setFont(u8g2_font_10x20_mr);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setDrawColor(1);
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);
}

void draw(void) 
{
  u8g2_prepare();
  switch(draw_state >> 3) 
  {
    case 0:
      caratula(); 
      break;
    case 1: 
      temperatura();
      break;
    case 2: 
      humitat();
      break;
    case 3: 
      presio();
      break;
  } 
}

void caratula()
{
  u8g2.setDrawColor(1); // White
  u8g2.drawXBMP((128-CARAWIDTH)/2,0,CARAWIDTH,CARAHEIGHT,CARATULA);
}

void temperatura()
{
  String valor;
  valor=(String)temp;
  valor=valor+"ºC";
  //u8g2.setBitmapMode(false /* solid */);
  u8g2.setDrawColor(1); // White
  u8g2.drawXBMP(0,2,TERWIDTH,TERHEIGHT,TERMOMETRE);
  u8g2.setCursor(TERWIDTH,20);
  u8g2.print(temp);
  u8g2.print("ºC");
  //u8g2.drawStr(TERWIDTH,20,"24.86ºC");
  /*
  u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // set fonts
u8g2.setCursor(30,30); // set cursor position lcd
u8g2.print(temp,2); // write variable to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display*/
}

void humitat()
{
  u8g2.setDrawColor(1); // White
  u8g2.drawXBMP(1,2,GOTAWIDTH,GOTAHEIGHT,GOTA);
  u8g2.setCursor(GOTAWIDTH,20);
  u8g2.print(hum);
  u8g2.print("%");
  //u8g2.drawStr(GOTAWIDTH,20,"75.36%");
}

void presio()
{
  u8g2.setDrawColor(1); // White
  u8g2.drawXBMP(1,2,MANWIDTH,MANHEIGHT,MANOMETRE);
  u8g2.setCursor(MANWIDTH,10);
  u8g2.print(pres);
  u8g2.setCursor(MANWIDTH,30);
  u8g2.print("mbar");
  //u8g2.drawStr(MANWIDTH+10,10,"1010");
  //u8g2.drawStr(MANWIDTH+10,30,"mbar");
}

void llegirtemp()
{
  temp++;
}
void llegirhum()
{
  hum++;
}

void llegirpres()
{
  pres++;
}

I made my code based on the grafictest.ino that comes with U8G2 library.

What I see that happens is that the FirstPage() structure goes slow showing one icon and value, but the loop goes faster, and then when I'm in the Temp screen the valuie increases several times, the same with humidity and pressure.

Is like loop() and FirstPage() run in paralel.
The screens are show several seconds.
In addition I want that 1st screen only was shown the first time, for this reason I wrote the code

// increase the state
  draw_state++;
  if ( draw_state >= 4*8 )
    draw_state = 1;

  // delay between each page
  delay(200);

But it does not work and the loop shows ever a sequence with the 5 pages.

You are incrementing draw_state by 1, but in your draw() routine, you shift it 3 bits. This means that you call the same function 8 times in a row (0..7 -> case 0), then the next function 8 times in a row (8..15 -> case 1) etc. but each time through loop(), you are incrementing your variables

Thank you for tour answer. Do you know dome tutorial or website with a Code explanación for the firdtpsge structure?

There is an explanation here: https://github.com/olikraus/u8glib/wiki/tpictureloop

The basic idea is that the library divides the display up into several subsections (pages), and only uses a memory buffer large enough for a single page.

The firstPage() function lets the library know you are starting at the first page of the display.

The do... while nextPage() loop executes the display functions repeatedly, once for each page of the display.

Inside the do..while, all of the display functions are processed, but anything outside of the current page is ignored. Only something that will appear on the page currently being worked on will be placed in the display buffer.

The call to nextPage() writes the buffer to the display, and advances to the next page. When the last page has been processed, nextPage() returns false and the do...while terminates.

It is very important that you do not change the value of any of the variables inside the do...while, because portions of a character can be in more than one page. Directly reading a sensor in a display function can lead to having the display show the upper half of one number with the lower half of a different number.

Thank you

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