• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino Uno + nextion
#1
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);

}
 
Odpowiedź
#2
pokaż projekt nextion
Arduino zostało wymyślone po to, by robić dobrze jedną prostą rzecz – migać diodą. 
 
Odpowiedź
#3
(10-03-2021, 20:55)Jarewa0606 napisał(a): pokaż projekt nextion
 
Odpowiedź
#4
(10-03-2021, 20:55)Jarewa0606 napisał(a): pokaż projekt nextion
W załaczniku projekt
 
Odpowiedź
#5
Coś nie widać a bez tego to ciężko coś powiedzieć. Bo na uno niby wszystko ok ale nie wiem czy adresowanie dobre...
Arduino zostało wymyślone po to, by robić dobrze jedną prostą rzecz – migać diodą. 
 
Odpowiedź
#6
(11-03-2021, 10:51)Jarewa0606 napisał(a): Coś nie widać a bez tego to ciężko coś powiedzieć. Bo na uno niby wszystko ok ale nie wiem czy adresowanie dobre...
 
Odpowiedź
#7
(11-03-2021, 10:51)Jarewa0606 napisał(a): Coś nie widać a bez tego to ciężko coś powiedzieć. Bo na uno niby wszystko ok ale nie wiem czy adresowanie dobre...
https://drive.google.com/file/d/1Kx9SCrH...sp=sharing
 
Odpowiedź
#8
masz pomylone ID powinno być

NexDSButton bt0 = NexDSButton(0, 3, "bt0"); // Załącz regulator
NexNumber tz = NexNumber(1, 4, "tz"); // Temperatura zadana w piekarniku
NexNumber tw = NexNumber(0, 7, "tw"); // Temperatura w piekarniku
NexNumber th = NexNumber(1, 5, "th"); // Histereza temperatury
Arduino zostało wymyślone po to, by robić dobrze jedną prostą rzecz – migać diodą. 
 
Odpowiedź
#9
Na pewno brakuje w setpie nexInit()
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości