10-03-2021, 20:07
Witam wszystkich,
Zaczynam swoją drogę z Arduino i robię projekt, który nastręcza mi mały problem. Otóż mój projekt to regulator temperatury z interfejsem HMI. Według założeń chciałbym zadawać czas, temperaturę oraz histerezę z hmi i dostawać wartości zwrotne jak pozostały czas cyklu oraz aktualną temeraturę w obiekcie nagrzewanym. Czasu jeszcze nie uwzględniłem w moim kodzie ale mam problem z wymiana danych miedzy arduino a Nextion. Czy ktoś mógłby zweryfikować moj kod programu i podać mi wskazówki co zrobiłem źle?
#define Wentylator 7
#define Grzalka 8
int Zalacz_cykl;
int TemZadana;
int Histereza;
#include <Nextion.h>
#include "max6675.h"
int thermoCLK = 4;
int thermoCS = 5;
int thermoDO = 6;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
NexDSButton bt0 = NexDSButton(0, 8, "bt0"); // Załącz regulator
NexNumber tz = NexNumber(1, 5, "tz"); // Temperatura zadana w piekarniku
NexNumber tw = NexNumber(0, 7, "tw"); // Temperatura w piekarniku
NexNumber th = NexNumber(1, 7, "th"); // Histereza temperatury
NexTouch *nex_listen_list[] =
{
&bt0, // Dual state button added
&tz,
&th,
NULL // String terminated
}; // End of touch event list
void bt0PushCallback(void *ptr) // Press event for dual state button bt0
{
uint32_t number5 = 0; // Create variable to store value we are going to get
bt0.getValue(&number5); // Read value of dual state button to know the state (0 or 1)
if (number5 == 1) { // If dual state button is equal to 1 (meaning is ON)...
digitalWrite(13, HIGH); // Turn ON internal LED
Zalacz_cykl = 1;
} else { // Since the dual state button is OFF...
digitalWrite(13, LOW); // Turn OFF internal LED
Zalacz_cykl = 0;
}
}
void tzPushCallback(void *ptr) // Press event for dual state button bt0
{
uint32_t number4 = 0; // Create variable to store value we are going to get
tz.getValue(&number4); // Read variable (inside the display) called vah and stored on variable number4
int TemZadana = number4;
}
void thPushCallback(void *ptr) // Press event for dual state button bt0
{
uint32_t number3 = 0; // Create variable to store value we are going to get
th.getValue(&number3); // Read variable (inside the display) called vah and stored on variable number4
int Histereza = number3;
}
void setup() // Start of setup
{
Serial.begin(9600);
bt0.attachPush(bt0PushCallback); // Dual state button bt0 press
tz.attachPush(tzPushCallback);
th.attachPush(thPushCallback);
pinMode(13, OUTPUT);
}
void loop()
{
delay(1000);
int Temp = thermocouple.readCelsius();
//
Serial.print("tw.val="); // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
Serial.print(Temp); // This is the value you want to send to that object and atribute mentioned before.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
if(Zalacz_cykl){
if((TemZadana-Histereza)>Temp) {
digitalWrite(Wentylator,HIGH);
digitalWrite(Grzalka,HIGH);
}
else{
digitalWrite(Wentylator,HIGH);
digitalWrite(Grzalka,LOW);
}
}
nexLoop(nex_listen_list);
}
Zaczynam swoją drogę z Arduino i robię projekt, który nastręcza mi mały problem. Otóż mój projekt to regulator temperatury z interfejsem HMI. Według założeń chciałbym zadawać czas, temperaturę oraz histerezę z hmi i dostawać wartości zwrotne jak pozostały czas cyklu oraz aktualną temeraturę w obiekcie nagrzewanym. Czasu jeszcze nie uwzględniłem w moim kodzie ale mam problem z wymiana danych miedzy arduino a Nextion. Czy ktoś mógłby zweryfikować moj kod programu i podać mi wskazówki co zrobiłem źle?
#define Wentylator 7
#define Grzalka 8
int Zalacz_cykl;
int TemZadana;
int Histereza;
#include <Nextion.h>
#include "max6675.h"
int thermoCLK = 4;
int thermoCS = 5;
int thermoDO = 6;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
NexDSButton bt0 = NexDSButton(0, 8, "bt0"); // Załącz regulator
NexNumber tz = NexNumber(1, 5, "tz"); // Temperatura zadana w piekarniku
NexNumber tw = NexNumber(0, 7, "tw"); // Temperatura w piekarniku
NexNumber th = NexNumber(1, 7, "th"); // Histereza temperatury
NexTouch *nex_listen_list[] =
{
&bt0, // Dual state button added
&tz,
&th,
NULL // String terminated
}; // End of touch event list
void bt0PushCallback(void *ptr) // Press event for dual state button bt0
{
uint32_t number5 = 0; // Create variable to store value we are going to get
bt0.getValue(&number5); // Read value of dual state button to know the state (0 or 1)
if (number5 == 1) { // If dual state button is equal to 1 (meaning is ON)...
digitalWrite(13, HIGH); // Turn ON internal LED
Zalacz_cykl = 1;
} else { // Since the dual state button is OFF...
digitalWrite(13, LOW); // Turn OFF internal LED
Zalacz_cykl = 0;
}
}
void tzPushCallback(void *ptr) // Press event for dual state button bt0
{
uint32_t number4 = 0; // Create variable to store value we are going to get
tz.getValue(&number4); // Read variable (inside the display) called vah and stored on variable number4
int TemZadana = number4;
}
void thPushCallback(void *ptr) // Press event for dual state button bt0
{
uint32_t number3 = 0; // Create variable to store value we are going to get
th.getValue(&number3); // Read variable (inside the display) called vah and stored on variable number4
int Histereza = number3;
}
void setup() // Start of setup
{
Serial.begin(9600);
bt0.attachPush(bt0PushCallback); // Dual state button bt0 press
tz.attachPush(tzPushCallback);
th.attachPush(thPushCallback);
pinMode(13, OUTPUT);
}
void loop()
{
delay(1000);
int Temp = thermocouple.readCelsius();
//
Serial.print("tw.val="); // This is sent to the nextion display to set what object name (before the dot) and what atribute (after the dot) are you going to change.
Serial.print(Temp); // This is the value you want to send to that object and atribute mentioned before.
Serial.write(0xff); // We always have to send this three lines after each command sent to the nextion display.
Serial.write(0xff);
Serial.write(0xff);
if(Zalacz_cykl){
if((TemZadana-Histereza)>Temp) {
digitalWrite(Wentylator,HIGH);
digitalWrite(Grzalka,HIGH);
}
else{
digitalWrite(Wentylator,HIGH);
digitalWrite(Grzalka,LOW);
}
}
nexLoop(nex_listen_list);
}