Problème codage Project VW T4

Bonjour,

Voici ma petit histoire,
débutant avec l'Arduino j'ai un petit Project pour mon camion VW T4 j'ai besoin de commander
4 relais avec l'écran Nextion et de lire ma température moteur sur le nextion.

J'ai donc fait tout mon montage 4 relais PWM400 relier a D6 D7 D8 D9 et le capteur de température VMA320 relier a A1.

j'arrive a faire fonctionner mes 4 relais avec un code copier sur le net nickel et pareille avec ma sonde de température.

Le Problème quand je fait un mixte des deux problème: Compilation error: expected unqualified-id before 'if'

Vraiment merci de votre aide je vais bientôt prendre une formation pour le codage et des cours de Français au passage merci de votre compréhensions.

#include "EasyNextionLibrary.h"
#define baudrate 9600
EasyNex myNex(Serial);
//Variables
uint16_t analog;
uint16_t voltage;
bool ledstate;
const int REFRESH_TIME = 100;
unsigned long refresh_timer = millis();
void setup() {
  myNex.begin(9600);
 	pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
}
void loop(){
   myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
                         // from Nextion touch panel. Actually, you should place it in your loop function.
}

void trigger1(){
  // To call this void send from Nextion's component's Event:  printh 23 02 54 01
  // In this exmaple, we send this command from the Release Event of b1 button (see the HMI of this example)
  // You can send  the same `printh` command, to call the same function, from more than one component, depending on your needs
  
   digitalWrite(6, !digitalRead(6)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
  if(digitalRead(6) == HIGH){
    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
    
  }else if(digitalRead(7) == LOW){
    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
  }
}
void trigger2(){
  /* Create a button on Nextion
   * Write in the Touch Release Event of the button
   * this command:    printh 23 02 54 00
   * Every time the button is pressed, the trigger0() function will run
   * and the code inside will be executed once
   */
  digitalWrite(7, !digitalRead(7)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
  if(digitalRead(7) == HIGH){
    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
    
  }else if(digitalRead(7) == LOW){
    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
  }
}
void trigger3(){
  /* Create a button on Nextion
   * Write in the Touch Release Event of the button
   * this command:    printh 23 02 54 00
   * Every time the button is pressed, the trigger0() function will run
   * and the code inside will be executed once
   */
  digitalWrite(8, !digitalRead(8)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
  if(digitalRead(8) == HIGH){
    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
    
  }else if(digitalRead(8) == LOW){
    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
  }
}
void trigger4(){
  /* Create a button on Nextion
   * Write in the Touch Release Event of the button
   * this command:    printh 23 02 54 00
   * Every time the button is pressed, the trigger0() function will run
   * and the code inside will be executed once
   */
  digitalWrite(9, !digitalRead(9)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
  if(digitalRead(9) == HIGH){
    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
    
  }else if(digitalRead(9) == LOW){
    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
  }
  } 
  if((millis()-refresh_timer) > REFRESH_TIME){ //IMPORTANT do not have serial print commands in the loop without a delay
                                              // or an if statement with a timer condition like this one.
                                              
      int tempData = analogRead(A0);  // Read the analog pin
      voltage = map(tempData, 0, 1024, 0, 5000); // same like: voltage = analogRead(A0)*5000/1024
    
      /* We Re-map the value of tempData from 0-1024 (steps) to 0-5000 millivolt
       * connect the pins of a Potentiometer on A0 pin, 5v (5000 millivolt) and GND. Outer pins to 5v and GND, middle pin to A0
       * https://www.arduino.cc/en/tutorial/potentiometer
       * Turn it over and read values from 0 to 5000 millivolts
       */
               
      myNex.writeNum("Nvoltage.val", voltage); // Nvoltage.val is a variable that we have create on Nextion.        
                                              // we send the value of the voltage variable on Arduino
                             // you can use the same name for variables on Nextion for easy recognition with a capital N in front
                             // Avoid the use of big variable names as every character is one byte to serial. 
                             // In here we use big names for the sake of example.
      refresh_timer = millis();  // Set the timer equal to millis, create a time stamp to start over the "delay"
     
    } 
    
    

Bonjour,

Ce n'est pas un projet fini, sujet déplacé dans la section principale du forum français.

Le } qui est avant le if incriminé devrait être à la fin du programme.

Bonjour Kamill

Super merci le téléversement fonctionne.

Mais cela fonction pas comme il faut du coup les 4 relais ce commande comme il le faut. Mais la barre de température se rafraichie que quand je j'appuis sur trigger 4.

Bonjour jimmymaker44

Tu as toute cette partie en dehors de tout:

 if((millis()-refresh_timer) > REFRESH_TIME){ //IMPORTANT do not have serial print commands in the loop without a delay
                                              // or an if statement with a timer condition like this one.
                                              
      int tempData = analogRead(A0);  // Read the analog pin
      voltage = map(tempData, 0, 1024, 0, 5000); // same like: voltage = analogRead(A0)*5000/1024
    
      /* We Re-map the value of tempData from 0-1024 (steps) to 0-5000 millivolt
       * connect the pins of a Potentiometer on A0 pin, 5v (5000 millivolt) and GND. Outer pins to 5v and GND, middle pin to A0
       * https://www.arduino.cc/en/tutorial/potentiometer
       * Turn it over and read values from 0 to 5000 millivolts
       */
               
      myNex.writeNum("Nvoltage.val", voltage); // Nvoltage.val is a variable that we have create on Nextion.        
                                              // we send the value of the voltage variable on Arduino
                             // you can use the same name for variables on Nextion for easy recognition with a capital N in front
                             // Avoid the use of big variable names as every character is one byte to serial. 
                             // In here we use big names for the sake of example.
      refresh_timer = millis();  // Set the timer equal to millis, create a time stamp to start over the "delay"
     
    } 

Déplaces la dans loop()

Cordialement
jpbbricole

Bonjour jbbricole :smiley:

quand il est dans la boucle ce que ca me dit a la compilation ; Compilation error: expected unqualified-id before 'if'

#include "EasyNextionLibrary.h"
#define baudrate 9600
EasyNex myNex(Serial);
//Variables
uint16_t analog;
uint16_t voltage;
bool ledstate;
const int REFRESH_TIME = 100;
unsigned long refresh_timer = millis();
void setup() {
  myNex.begin(9600);
 	pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
}
void loop(){
   myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
                         // from Nextion touch panel. Actually, you should place it in your loop function.
}

void trigger1(){
  // To call this void send from Nextion's component's Event:  printh 23 02 54 01
  // In this exmaple, we send this command from the Release Event of b1 button (see the HMI of this example)
  // You can send  the same `printh` command, to call the same function, from more than one component, depending on your needs
  
   digitalWrite(6, !digitalRead(6)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
  if(digitalRead(6) == HIGH){
    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
    
  }else if(digitalRead(7) == LOW){
    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
  }
}
void trigger2(){
  /* Create a button on Nextion
   * Write in the Touch Release Event of the button
   * this command:    printh 23 02 54 00
   * Every time the button is pressed, the trigger0() function will run
   * and the code inside will be executed once
   */
  digitalWrite(7, !digitalRead(7)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
  if(digitalRead(7) == HIGH){
    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
    
  }else if(digitalRead(7) == LOW){
    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
  }
}
void trigger3(){
  /* Create a button on Nextion
   * Write in the Touch Release Event of the button
   * this command:    printh 23 02 54 00
   * Every time the button is pressed, the trigger0() function will run
   * and the code inside will be executed once
   */
  digitalWrite(8, !digitalRead(8)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
  if(digitalRead(8) == HIGH){
    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
    
  }else if(digitalRead(8) == LOW){
    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
  }
}
void trigger4(){
  /* Create a button on Nextion
   * Write in the Touch Release Event of the button
   * this command:    printh 23 02 54 00
   * Every time the button is pressed, the trigger0() function will run
   * and the code inside will be executed once
   */
  digitalWrite(9, !digitalRead(9)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
  if(digitalRead(9) == HIGH){
    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
    
  }else if(digitalRead(9) == LOW){
    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
  }
}
if((millis()-refresh_timer) > REFRESH_TIME){ //IMPORTANT do not have serial print commands in the loop without a delay
                                              // or an if statement with a timer condition like this one.
                                              
      int tempData = analogRead(A0);  // Read the analog pin
      voltage = map(tempData, 0, 1024, 0, 5000); // same like: voltage = analogRead(A0)*5000/1024
    
      /* We Re-map the value of tempData from 0-1024 (steps) to 0-5000 millivolt
       * connect the pins of a Potentiometer on A0 pin, 5v (5000 millivolt) and GND. Outer pins to 5v and GND, middle pin to A0
       * https://www.arduino.cc/en/tutorial/potentiometer
       * Turn it over and read values from 0 to 5000 millivolts
       */
               
      myNex.writeNum("Nvoltage.val", voltage); // Nvoltage.val is a variable that we have create on Nextion.        
                                              // we send the value of the voltage variable on Arduino
                             // you can use the same name for variables on Nextion for easy recognition with a capital N in front
                             // Avoid the use of big variable names as every character is one byte to serial. 
                             // In here we use big names for the sake of example.
      refresh_timer = millis();  // Set the timer equal to millis, create a time stamp to start over the "delay"
}


Voilà la version corrigée:

#include "EasyNextionLibrary.h"
#define baudrate 9600
EasyNex myNex(Serial);
//Variables
uint16_t analog;
uint16_t voltage;
bool ledstate;
const int REFRESH_TIME = 100;
unsigned long refresh_timer = millis();
void setup() {
	myNex.begin(9600);
	pinMode(A0, INPUT);
	pinMode(A1, INPUT);
	pinMode(6, OUTPUT);
	pinMode(7, OUTPUT);
	pinMode(8, OUTPUT);
	pinMode(9, OUTPUT);
}
void loop(){
	myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
	// from Nextion touch panel. Actually, you should place it in your loop function.
	if((millis()-refresh_timer) > REFRESH_TIME){ //IMPORTANT do not have serial print commands in the loop without a delay
		// or an if statement with a timer condition like this one.
		
		int tempData = analogRead(A0);  // Read the analog pin
		voltage = map(tempData, 0, 1024, 0, 5000); // same like: voltage = analogRead(A0)*5000/1024
		
		/* We Re-map the value of tempData from 0-1024 (steps) to 0-5000 millivolt
		* connect the pins of a Potentiometer on A0 pin, 5v (5000 millivolt) and GND. Outer pins to 5v and GND, middle pin to A0
		* https://www.arduino.cc/en/tutorial/potentiometer
		* Turn it over and read values from 0 to 5000 millivolts
		*/
		
		myNex.writeNum("Nvoltage.val", voltage); // Nvoltage.val is a variable that we have create on Nextion.
		// we send the value of the voltage variable on Arduino
		// you can use the same name for variables on Nextion for easy recognition with a capital N in front
		// Avoid the use of big variable names as every character is one byte to serial.
		// In here we use big names for the sake of example.
		refresh_timer = millis();  // Set the timer equal to millis, create a time stamp to start over the "delay"
	}
}

void trigger1(){
	// To call this void send from Nextion's component's Event:  printh 23 02 54 01
	// In this exmaple, we send this command from the Release Event of b1 button (see the HMI of this example)
	// You can send  the same `printh` command, to call the same function, from more than one component, depending on your needs
	
	digitalWrite(6, !digitalRead(6)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(6) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(7) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}
void trigger2(){
	/* Create a button on Nextion
	* Write in the Touch Release Event of the button
	* this command:    printh 23 02 54 00
	* Every time the button is pressed, the trigger0() function will run
	* and the code inside will be executed once
	*/
	digitalWrite(7, !digitalRead(7)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(7) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(7) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}
void trigger3(){
	/* Create a button on Nextion
	* Write in the Touch Release Event of the button
	* this command:    printh 23 02 54 00
	* Every time the button is pressed, the trigger0() function will run
	* and the code inside will be executed once
	*/
	digitalWrite(8, !digitalRead(8)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(8) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(8) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}
void trigger4(){
	/* Create a button on Nextion
	* Write in the Touch Release Event of the button
	* this command:    printh 23 02 54 00
	* Every time the button is pressed, the trigger0() function will run
	* and the code inside will be executed once
	*/
	digitalWrite(9, !digitalRead(9)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(9) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(9) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}

Je te laisse jouer au jeu des différences :wink:

Cordialement
jpbbricole

ho oui ok super. mais je ne c'est pas le pourquoi du comment il doit écrie comme ca?

C'est que soit que tu n'a pas copier tout la branche conditionnelle, soit tu ne l'a pas collé au bon endroit.
Par contre si tu laisse un IF en dehors d'une fonction, le compilateur va t'indiquer qu'il y a un problème avec ce IF.

Ta phrase est quand même compliqué à déchiffré :slight_smile:
tu dois mettre ton IF, dans un code accésssible, donc une fonction.
Si tu veux que ton programme passe par ce IF, il faut donc que cette fonction soit elle aussi accéssible. soit en le mettant dans la fonction Loop ou Setup, soit que l'enchainement de fonction arrive sur ton IF.

Bonjour,
merci de votre précision.
je n'avais pas compris juste la fonction de base setup et Loop donc là déjà on part avec un problème hihihi.
je commence à comprendre quand on perd de zéro en autodidacte pas simple.
mais aureusement qu'il y a du monde sur les forums pour nous aider on se sent moins seule. une chose que je comprends par c'est (0, 1024, 0, 5000) donc ma sonde de température est lue en millivolt de 0 a 5000 ( 5000 = 5V) comment peut on traduire c'est millivolt en degré précise pas simple bha ca dépend pour qui MDR.

Je ne sais pas trop, mais des sites comme locoduino ou eskimon sont à lire ne long et en travers avant de venir sur le forum à mon avis :wink:

En regle generale c'est indiqué dans la datasheet de ta sonde.

Le data sheets du module de température Welmann n'est pas trés précis à ce sujet.

Par contre si on cherche le data sheets du capteur seul (celui qui est monté sur le module, on trouve

Screenshot_20240513-202355~2

On voit sur cette courbe que la résistance diminue avec la température.

Si on met en série avec ce capteur une résistance de 10k comme indiqué sur le kit Welmann, et que l'on alimente le tout en 5V, on a un pont diviseur.

Quand la température est de -55°C le capteur fait 10k, en série avec 10k, ça donne 2.5V.

Quand la température est de +125°C, la résistance du capteur est de 2 Ohms, en série avec 10k, ça donne 0V.

Ça c'est déja une chose, c'est à toi d'en déduire la formule magique, pour l'instant, je calle :thinking:

A moins que:

Tension au milieu du pont diviseur = 2,5-[(55+T°C)x0,014

Super, merci pour les précisions je ne savais pas que l'on pouvait trouver toutes ces valeurs sur internet.
Moi j'ai relevé physiquement les valeurs hoho!!!, j'aurais pus gagner du temps.
Mais le problème n'est pas là, le problème c'est comment indiquer à Arduino de donner les bonnes valeurs au Nextion? Je n'arrive pas à coder Arduino et/ou le Nextion.
Jimmy

Salut!!!

bon j'ai dépatouiller tout ca mes valeur sont nickel tout marche bien pour la température top mais quand je rajoute me ligne de code dans la boucle je ne peut plus actionner mes interrupteur sur mon nextion ou alors il faut cliquer très rapide plain de fois. a mon avis un problème dans le loop.

#include "EasyNextionLibrary.h"
#define baudrate 9600
EasyNex myNex(Serial);
//Variables
uint16_t analog;
uint16_t voltage;
bool ledstate;
const int REFRESH_TIME = 100;
unsigned long refresh_timer = millis();
int ThermistorPin1 = A1;
int ThermistorPin2 = A2;
int Vo;
int Vo1;
float R1 = 10000;
float logR2, R2, T, Tc1, Tc2, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;


void setup() {
	myNex.begin(9600);
	pinMode(A0, INPUT);
	pinMode(A1, INPUT);
  pinMode(A2, INPUT);
	pinMode(6, OUTPUT);
	pinMode(7, OUTPUT);
	pinMode(8, OUTPUT);
	pinMode(9, OUTPUT);
}
void loop(){myNex.NextionListen(); 
 
 
    myNex.writeNum("Temp1.val", Tc1); 
     myNex.writeNum("Temp2.val", Tc2); 

  



 Vo = analogRead(ThermistorPin1);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc1 = T - 273.15;
  Tf = (Tc1 * 9.0)/ 5.0 + 32.0; 


Vo1 = analogRead(ThermistorPin2);
  R2 = R1 * (1023.0 / (float)Vo1 - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc2 = T - 273.15;
  Tf = (Tc2 * 9.0)/ 5.0 + 32.0;

  }


void trigger1(){
	// To call this void send from Nextion's component's Event:  printh 23 02 54 01
	// In this exmaple, we send this command from the Release Event of b1 button (see the HMI of this example)
	// You can send  the same `printh` command, to call the same function, from more than one component, depending on your needs
	
	digitalWrite(6, !digitalRead(6)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(6) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(7) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}
void trigger2(){
	/* Create a button on Nextion
	* Write in the Touch Release Event of the button
	* this command:    printh 23 02 54 00
	* Every time the button is pressed, the trigger0() function will run
	* and the code inside will be executed once
	*/
	digitalWrite(7, !digitalRead(7)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(7) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(7) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}
void trigger3(){
	/* Create a button on Nextion
	* Write in the Touch Release Event of the button
	* this command:    printh 23 02 54 00
	* Every time the button is pressed, the trigger0() function will run
	* and the code inside will be executed once
	*/
	digitalWrite(8, !digitalRead(8)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(8) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(8) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}
void trigger4(){
	/* Create a button on Nextion
	* Write in the Touch Release Event of the button
	* this command:    printh 23 02 54 00
	* Every time the button is pressed, the trigger0() function will run
	* and the code inside will be executed once
	*/
	digitalWrite(9, !digitalRead(9)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(9) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(9) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}

hello
voici ta loop

void loop()
{
  myNex.NextionListen();
  myNex.writeNum("Temp1.val", Tc1);
  myNex.writeNum("Temp2.val", Tc2);
  Vo = analogRead(ThermistorPin1);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
  Tc1 = T - 273.15;
  Tf = (Tc1 * 9.0) / 5.0 + 32.0;
  Vo1 = analogRead(ThermistorPin2);
  R2 = R1 * (1023.0 / (float)Vo1 - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
  Tc2 = T - 273.15;
  Tf = (Tc2 * 9.0) / 5.0 + 32.0;
}

ton micro passe son temps à l'exécuter ( en boucle ).

d'autre part, tu as 4 fonctions "trigger" .

ton programme ne s'en occupe pas car dans ta boucle, il n'est fait aucun appel à ces fonctions "trigger".

ajoute l'appel des fonctions dans ta loop

trigger1();
trigger2();
trigger3();
trigger4();

j'ai tester et les relais s'ouvre et se ferme super vite sans que je puisse rien faire.

void loop(){myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
	// from Nextion touch panel. Actually, you should place it in your loop function.


		
		analogRead(A0);  //read the throw away first value
int tempData = (analogRead(A0) + analogRead(A0)) / 2;   

		myNex.writeNum("Temp1.val", Tc); 
    refresh_timer = millis();

 Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc = T - 273.15;
  Tf = (Tc * 9.0)/ 5.0 + 32.0; 
  
 
   analogRead(A1);  
 tempData = (analogRead(A1) + analogRead(A1)) / 2;   

		myNex.writeNum("Temp2.val", Tc1); 
    refresh_timer = millis();

 Vo = analogRead(ThermistorPin1);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc1 = T - 273.15;
  Tf = (Tc1 * 9.0)/ 5.0 + 32.0; 
  
trigger1();
trigger2();
trigger3();
trigger4();

 
}

et la quand je fait ca fonctionne nickel mais j'ai la même info sur mes deux tempe normal il y a que un Tc il prenne l'info sur le même Tc

#include "EasyNextionLibrary.h"
#define baudrate 9600
EasyNex myNex(Serial);
//Variables
uint16_t analog;
uint16_t voltage;
int lectura_pot;
bool ledstate;
const int REFRESH_TIME = 100;
unsigned long refresh_timer = millis();
int ThermistorPin = A0;
int ThermistorPin1 = A1;
int Vo;
float R1 = 10000;
float logR2, R2, T, Tf;
float Tc;

float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;


//
void setup() {
	myNex.begin(9600);
	pinMode(A0, INPUT);
	pinMode(A1, INPUT);
  pinMode(A3, INPUT);
	pinMode(6, OUTPUT);
	pinMode(7, OUTPUT);
	pinMode(8, OUTPUT);
	pinMode(9, OUTPUT);
}
//
void loop(){myNex.NextionListen(); // WARNING: This function must be called repeatedly to response touch events
	// from Nextion touch panel. Actually, you should place it in your loop function.


		
		analogRead(A0);  //read the throw away first value
int tempData = (analogRead(A0) + analogRead(A0)) / 2;   

		myNex.writeNum("Temp1.val", Tc); 
    myNex.writeNum("Temp2.val", Tc);
    refresh_timer = millis();

 Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  Tc = T - 273.15;
  Tf = (Tc * 9.0)/ 5.0 + 32.0; 
  
 
}
void trigger1(){
	// To call this void send from Nextion's component's Event:  printh 23 02 54 01
	// In this exmaple, we send this command from the Release Event of b1 button (see the HMI of this example)
	// You can send  the same `printh` command, to call the same function, from more than one component, depending on your needs
	
	digitalWrite(6, !digitalRead(6)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(6) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(7) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}
void trigger2(){
	/* Create a button on Nextion
	* Write in the Touch Release Event of the button
	* this command:    printh 23 02 54 00
	* Every time the button is pressed, the trigger0() function will run
	* and the code inside will be executed once
	*/
	digitalWrite(7, !digitalRead(7)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(7) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(7) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}
void trigger3(){
	/* Create a button on Nextion
	* Write in the Touch Release Event of the button
	* this command:    printh 23 02 54 00
	* Every time the button is pressed, the trigger0() function will run
	* and the code inside will be executed once
	*/
	digitalWrite(8, !digitalRead(8)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(8) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(8) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}
void trigger4(){
	/* Create a button on Nextion
	* Write in the Touch Release Event of the button
	* this command:    printh 23 02 54 00
	* Every time the button is pressed, the trigger0() function will run
	* and the code inside will be executed once
	*/
	digitalWrite(9, !digitalRead(9)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
	if(digitalRead(9) == HIGH){
		myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
		myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
		
		}else if(digitalRead(9) == LOW){
		myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
		myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
	}
}

Les écrans Nextion sont peu utilisés sur ce forum, surtout en raison de leur prix élevé. Par contre, ils sont accompagnés d'un logiciel qui permet de définir une interface homme machine. C'est là que sont définies des fonctions telles que trigger1, trigger2 etc. Elles sont associées à des boutons mais ça ne se voit pas dans le code. Il doit y avoir quelque part un fichier de configuration pour les déclarer.

@jimmymaker44 Est-ce que tu peux fournir le lien vers le site où tu as trouvé le code initial ?

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