Tempo écran tft

Bonjour,
Je travaille sur ESP32 et mon écran est un écran d'adafruit 3.5 pouces featherwing.

J'aimerais savoir si c'est possible de faire sur le même écran tft plusieurs actualisations.
C'est à dire de mon programme :
actualiser la température toute les 10 secondes et l'humidité toutes les 30 secondes par exemple.
La mon programme me fait un décalage m'affiche la température puis l'humidité après.

Mon programme :

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
unsigned long delayTime;

#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_HX8357.h"

#ifdef ESP32
   #define STMPE_CS 32
   #define TFT_CS   15
   #define TFT_DC   33
   #define SD_CS    14
#endif


#define TFT_RST -1

// Use hardware SPI and the above for CS/DC
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);


void setup() {
  Serial.begin(115200);
  
    while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));
    unsigned status;
    status = bme.begin();  
     if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        while (1) delay(10);
    }    
    Serial.println("-- Default Test --");
    delayTime = 1000;
    Serial.println();

  
  Serial.println("HX8357D Test!"); 
  tft.begin();

  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(HX8357_RDPOWMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDCOLMOD);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDDIM);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDDSDR);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 
  
  Serial.println(F("Benchmark                Time (microseconds)"));

  Serial.println(F("Done!"));
}


void loop(void) {

   Serial.print("Temperature = ");
   Serial.print(bme.readTemperature());
   Serial.println(" °C");

  tft.setRotation(1);
  tft.fillScreen(HX8357_WHITE);
  
  tft.setCursor(0,25);
  tft.setTextColor(HX8357_BLUE);
  tft.setTextSize(3);
  tft.println("Temperature :");
  tft.setCursor(0, 50);
  tft.setTextColor(HX8357_BLUE);
  tft.setTextSize(3);
  tft.println(bme.readTemperature());
  delay(5000);
  tft.setCursor(300, 175);
  tft.setTextColor(HX8357_GREEN);
  tft.setTextSize(3);
  tft.println("Humidite :");
  tft.setCursor(300, 200);
  tft.setTextColor(HX8357_GREEN);
  tft.setTextSize(3);
  tft.println(bme.readHumidity());
  delay(5000);
  
  


}

oui c'est possible. il faut juste gérer 2 "timers" différents et ne pas utiliser delay().
La structure du code pourrait être celle ci:

uint32_t chronoTemperature;
const uint32_t dureeTemperature = 10000; // en ms = 10s

uint32_t chronoHumidite;
const uint32_t dureeHumidite = 30000; // en ms = 30s


void setup() {
  Serial.begin(115200); while (!Serial);
}

void loop() {
  uint32_t maintenant = millis();

  if (maintenant - chronoTemperature >= dureeTemperature) {
    Serial.println("Mise à jour température");

    // lecture et affichage à effectuer ici 

    chronoTemperature = maintenant;
  }

  if (maintenant - chronoHumidite >= dureeHumidite) {
    Serial.println("Mise à jour humidite");

    // lecture et affichage à effectuer ici 

    chronoHumidite = maintenant;
  }
}

Le programme il fait ce que tu lui dis de faire.
Actuellement, tu lui dis d'afficher la température, d'attendre 5 secondes, d'afficher l'humidité, d'attendre 5 secondes et de recommencer.
Si tu veux un cadencement différent, il va falloir modifier le déroulement de ta séquence dans loop().
Tu vas avoir 2 séquences concourantes avec des temporisations différentes, ce qui n'est pas très pratique à gérer avec delay().
Tu devrais regarder le fonctionnement de BlinkWithoutDelay, dans les exemples de codes installés avec l'IDE, car cela permet de faire exécuter des tâches en fonction du temps.

Merci pour ton exemple, j'ai donc remplacer et je constate que j'ai le "le même problème"

L'actualisation des valeurs ce fait que quand mon écran se rafraichit.
dans mon cas au bout de 20 secondes ducoup et lorsque que je met pas mon delay 20000, ça ne fonctionne pas l'écran clignotte .
mon programme :

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
unsigned long delayTime;

#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_HX8357.h"

#ifdef ESP32
   #define STMPE_CS 32
   #define TFT_CS   15
   #define TFT_DC   33
   #define SD_CS    14
#endif


#define TFT_RST -1

// Use hardware SPI and the above for CS/DC
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);

uint32_t chronoTemperature;
const uint32_t dureeTemperature = 5000; // en ms = 10s

uint32_t chronoHumidite;
const uint32_t dureeHumidite = 10000; // en ms = 30s

void setup() {
  Serial.begin(57600);
  
    while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));
    unsigned status;
    status = bme.begin();  
     if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        while (1) delay(10);
    }    
    Serial.println("-- Default Test --");
    delayTime = 1000;
    Serial.println();

  
  Serial.println("HX8357D Test!"); 
  tft.begin();

  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(HX8357_RDPOWMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDCOLMOD);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDDIM);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDDSDR);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 
  
  Serial.println(F("Benchmark                Time (microseconds)"));

  Serial.println(F("Done!"));
}


void loop(void) {
  uint32_t maintenant = millis();

  

   Serial.print("Temperature = ");
   Serial.print(bme.readTemperature());
   Serial.println(" °C");

  tft.setRotation(1);
  tft.fillScreen(HX8357_WHITE);
  
  tft.setCursor(0,25);
  tft.setTextColor(HX8357_BLUE);
  tft.setTextSize(3);
  tft.println("Temperature :");
  
  if (maintenant - chronoTemperature >= dureeTemperature) {
    Serial.println("Mise à jour température");

    tft.setCursor(0, 50);
  tft.setTextColor(HX8357_BLUE);
  tft.setTextSize(3);
  tft.println(bme.readTemperature());

    chronoTemperature = maintenant;
  }

  tft.setCursor(300, 175);
  tft.setTextColor(HX8357_GREEN);
  tft.setTextSize(3);
  tft.println("Humidite :");
  
  if (maintenant - chronoHumidite >= dureeHumidite) {
    Serial.println("Mise à jour humidite");

   tft.setCursor(300, 200);
  tft.setTextColor(HX8357_GREEN);
  tft.setTextSize(3);
  tft.println(bme.readHumidity());

    chronoHumidite = maintenant;
  }
delay(20000);
}

ben vous avez conservé les affichages à chaque tour de la loop? il ne faut pas... ➜ il faut afficher juste quand c'est le moment. (et peut-être mettre un rectangle de la couleur du fond pour effacer ce qu'il y avait avant, pas forcément besoin de ré-afficher les étiquettes)

Désolé, je n'ai pas compris :sweat_smile: je dois changer / enlever quoi dans mon programme ?

tous les affichages sur l'écran TFT de la loop qui ne sont pas dans les blocs if (maintenant - xxx >= xxx) {

1 Like

niquel ça fonctionne je vais essayer de l'incorporer dans mon gros programme maintenant :slight_smile:

amusez vous bien :slight_smile:

1 Like

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