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.