Pinting variables into screen

Hello to all,

I have a small problem I would like to print the variables (teperature, preasure etc...) on my screen.
The code I am using is small modification from the internet, but I am not able to do it work in correct way. It don't show the nubers, but it show the "code":

But I would like to have it like this:

Mistake of screen next to the house is only printing eror that is not problem. Problem are the values printing. There I am not able to get the right results.

The code is like this:

/*
   Knihovna GxEPD pro praci s e-ink displejem
   Vychazi z knihovny Adafruit GFX
   https://github.com/ZinggJM/GxEPD
*/
#include <GxEPD.h>
// Vyber modelu displeje (GDEH029A1 je 2,9" Waveshare)
#include <GxGDEH029A1/GxGDEH029A1.cpp>
#include <GxIO/GxIO_SPI/GxIO_SPI.cpp>
#include <GxIO/GxIO.cpp>

/*
   Bitmapy ikon prevedene do poli pixelu pomoci
   weboveho nastroje image2cpp: http://javl.github.io/image2cpp
   Delka a sirka obrazku musi byt nasobkem 2
*/
#include "obr.h"

/* 
   Rastrovy fonty pro knihovnu Adafruit GFX
   Vytvoril jsem je pomoci weboveho nastroje Font Converter:
   http://oleddisplay.squix.ch/
*/
#include "Lato_Heavy_35.h"
#include "Lato_Medium_21.h"

// ESP8266 Web Server
// připojení potřebných knihoven
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <Streaming.h>

// incializace webserveru na portu 80
ESP8266WebServer server(80);

//deklarace
WiFiClient client;

// Knihovna pro dekodovani JSON
// https://github.com/bblanchon/ArduinoJson
#include <ArduinoJson.h>


// Teplotní čidlo DS18B20 + Teploměr a vlhkoměr DHT11/22
// připojení knihoven
// Teplotní čidlo DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>

//Teploměr a vlhkoměr DHT11/22
#include <DHT.h>

// nastavení čísla vstupního pinu
const int pinCidlaDS = 2;  //2 je pin D4 -  Teplotní čidlo DS18B2
const int pinDHT = 12; //12 je pin D6 - Teploměr a vlhkoměr DHT11/22

// odkomentování správného typu čidla
#define typDHT11 DHT11     // DHT 11

// inicializace DHT senzoru s nastaveným pinem a typem senzoru
DHT mojeDHT(pinDHT, typDHT11);

// vytvoření instance oneWireDS z knihovny OneWire
OneWire oneWireDS(pinCidlaDS);
// vytvoření instance senzoryDS z knihovny DallasTemperature
DallasTemperature senzoryDS(&oneWireDS);

#include <stdio.h>

/*
  Displej je pripojeny skrze rozhrani SPI
  Na desce Wemos LOLIN32 takto:
  BUSY -> 4, RST -> 16, DC -> 17, CS -> 5, CLK -> 18, DIN -> 23
  Na desce NodeMcu Lua ESP8266 CH340 WI-fi takto:
  BUSY = D1 (5) / RST = D3 (0) / DC = D2 (4) / CS = D8 (15) / CLK = D5 (14) / DIN = D7 (13) GND = GND = 3.3V = 3V3
*/
GxIO_Class io(SPI, SS, 4, 0);
GxEPD_Class displej(io, 0, 5);

// vytvoření proměnných s názvem WiFi sítě a heslem
const char* nazevWifi = "******";
const char* hesloWifi = "******";


// Funkce setup se zpracuje jen jednou po startu mikrokontroleru
void setup() {
   // Nastartovani seriove linky
  Serial.begin(115200);
  // Nastartovani displeje
  displej.init();
  // Nastaveni orientace displeje na sirku
  // Po smeru hodinovych rucicek (0 = na vysku, 1 = na sirku atd.)
  displej.setRotation(1);

  // zapnutí komunikace knihovny s teplotním čidlem DS18B20
  senzoryDS.begin();
  // zapnutí komunikace s teploměrem DHT
  mojeDHT.begin();

/*
 Nastavení přopojení k WiFi 
*/
  Serial.print("Prihlasuji se k Wi-Fi ");
  // zahájení komunikace po sériové lince
  Serial.begin(9600);
  // zahájení komunikace po WiFi s připojením
  // na router skrze zadané přihl. údaje
  WiFi.begin(nazevWifi, hesloWifi);
  // čekání na úspěšné připojení k routeru,
  // v průběhu čekání se vytiskne každých
  // 500 milisekund tečka po sériové lince
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // odřádkování a výpis informací o úspěšném připojení
  // včetně přidelené IP adresy od routeru
  Serial.println("");
  Serial.print("Pripojeno k WiFi siti ");
  Serial.println(nazevWifi);
  Serial.print("IP adresa: ");
  Serial.println(WiFi.localIP());
  // kontrola funkčnosti MDNS
  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder je zapnuty.");
  }
//wifi atd.. 
  // pravidelné volání detekce klienta,
  // v případě otevření stránky se provedou
  // funkce nastavené výše
    // zahájení aktivity HTTP serveru
  server.begin();
  Serial.println("HTTP server je zapnuty.");


   
        // Zavolam funkci pro vykresleni udaju na displej
       // nakresli(teplotaDoma, teplotaVenku, vlhkostDoma, vlhkostVenku, luxmetr, tlak, pocasi);
      }
   //**** }
    // Pokud se nepodarilo stahnout data, vypisu do seriove linky chybu
 // } else {
 //   Serial.printf("Nepodarilo se stahnout data: %s\n", http.errorToString(httpKod).c_str());
 //}
//}

/* Funkci loop tentokrat nepouziji, jakmile se totiz
   mikrokontroler po 30 sekundach probudi ze spanku, vse zacne nanovo
   a opet se zpracuje funcke setup
*/


void mereni() {
    // načtení informací ze všech připojených čidel na daném pinu
  senzoryDS.requestTemperatures();

  // pomocí funkcí readTemperature a readHumidity načteme
  // do proměnných tep a vlh informace o teplotě a vlhkosti,
  // čtení trvá cca 250 ms
  float tep = mojeDHT.readTemperature();
  float vlh = mojeDHT.readHumidity();


 // kontrola, jestli jsou načtené hodnoty čísla pomocí funkce isnan
  if (isnan(tep) || isnan(vlh)) {
    // při chybném čtení vypiš hlášku
    Serial.println("Chyba při čtení z DHT senzoru!");
  } else {
    // pokud jsou hodnoty v pořádku,
    // vypiš je po sériové lince
    Serial.print("Teplota: "); 
    Serial.print(tep);
    Serial.print(" stupnu Celsia, ");
    Serial.print("vlhkost: "); 
    Serial.print(vlh);
    Serial.println("  %");
  }
  
  // výpis teploty na sériovou linku, při připojení více čidel
  // na jeden pin můžeme postupně načíst všechny teploty
  // pomocí změny čísla v závorce (0) - pořadí dle unikátní adresy čidel
  Serial.print("Teplota cidla DS18B20: ");
  Serial.print(senzoryDS.getTempCByIndex(0));
  Serial.println(" stupnu Celsia");
  // pauza pro přehlednější výpis
  float tep1 = senzoryDS.getTempCByIndex(0);
  delay(1000);


  
}


// Funkce pro vykresleni udaju na obrazovku
void nakresli()
{
 
  
float teplotaDoma = senzoryDS.getTempCByIndex(0);
float teplotaVenku = 8.2;
float vlhkostDoma = mojeDHT.readHumidity();
float vlhkostVenku = 54.00;
float tlak = 997.54;
uint16_t luxmetr = 1458;
uint8_t pocasi = 0;

  
  // Podle typu pocasi nakreslim velkou ikonu deste nebo slunicka
  switch (pocasi) {
    case 0:
      /* Nakresleni obrazku obrDest (pole pixelu v samostatnem
         hlavickovem souboru) o velikosti 128x128 px na pozici
         160x0 a to cernou barvou, protoze muj e-inkovy displej
         umi zobrazit jen cerny, nebo bily pixel
      */
      displej.drawBitmap(obrDest, 160, 0, 128, 128, GxEPD_BLACK, 1);
      break;
    case 1:
      displej.drawBitmap(obrSlunce, 160, 0, 128, 128, GxEPD_BLACK, 1);
      break;
  }

  // Nastaveni barvy pisma na cernou
  displej.setTextColor(GxEPD_BLACK);

  // Nakresleni bloku s venkovnimi hodnotami
  // Ikona stromu, teplota, vlhkost a intenzita svetla
  displej.drawBitmap(obrStromy, 10, 10, 30, 30, GxEPD_BLACK, 1);
  displej.setFont(&Lato_Heavy_35);
  displej.setCursor(50, 40);
  displej.print(teplotaVenku, 1);
  displej.setFont(&Lato_Medium_21);
  displej.setCursor(10, 65);
  displej.printf("%.0f%%  %u lx", (vlhkostVenku * 100), luxmetr);

  // Nakresleni bloku s vnitrnimi hodnotami
  // Ikona domecku, teplota, vlhkost a tlak vzduchu
  displej.drawBitmap(obrDomecek, 10, 70, 30, 30, GxEPD_BLACK, 1);
  displej.setFont(&Lato_Heavy_35);
  displej.setCursor(50, 100);
  displej.print(teplotaDoma, 1);
  displej.setFont(&Lato_Medium_21);
  displej.setCursor(10, 120);
  displej.printf("%.0f%%  %.2f hPa", (vlhkostDoma * 100), tlak);

 

  // Zatim vse kreslim jen do pameti
  // Teprve nyni vykreslim pole pixelu na obrazovku
  displej.update();
  delay(10000);
}


void loop() {
 
 mereni();
 nakresli();
}

Do you think that you can help me and find what I am doing wrong?
Thank you all in advance!

OK. It doesn't look too bad but it is clear that some of the formatting characters are appearing instead of the formatted text.
I find your code is a bit difficult to read because the comments and variable names etc are in Czech and it's obvious from your post that English is not your first language.

Anyway,

If you've got something like this:

displej.printf("%.0f%%  %.2f hPa", (vlhkostDoma * 100), tlak);

and you are seeing "%.0f%% %.2f hPa" on the display, it appears that the printf() method is not doing any formatting.

Maybe start by looking at a work around. That is format the string for display yourself and see what happens:

displej.printf("51%  997.54 hPa");

Also compare any changes you have made to the original code.

6v6gt:
OK. It doesn't look too bad but it is clear that some of the formatting characters are appearing instead of the formatted text.
I find your code is a bit difficult to read because the comments and variable names etc are in Czech and it's obvious from your post that English is not your first language.

Anyway,

If you've got something like this:

[b]displej.printf("%.0f%%  [color=red]%.2f[/color] hPa", (vlhkostDoma * 100), tlak);

[/b]



and you are seeing "%.0f%% **%.2f** hPa" on the display, it appears that the printf() method is not doing any formatting.

Maybe start by looking at a work around. That is format the string for display yourself and see what happens:


displej.printf("51%  997.54 hPa");



Also compare any changes you have made to the original code.

%f is for floating point, which, although many Arduino users require it, the developers insist on shoving dtostrf down our throats and don't even provide the OPTION to use it.

How much code does dtostrf use compared to standard floating point support?

The Arduino devs are spending 25 cents to save a quarter.........

If I am not mistaken, you are using an ESP8266.
Version 2.4.0 of the core has printf() float support.

Ah yes. I just found that myself and the text reported by the OP is similar to this Floating point format support in sprintf · Issue #1179 · esp8266/Arduino · GitHub
Certain cores eg ARM were already supported.

The original article that describes the OP's project is ESP32 based: Pojďme programovat elektroniku: Vyzkoušíme elektronický papír, který proslavil čtečku Kindle – Živě.cz