You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello
I’m encountering an issue while using the ESP32-S3 with the EasyNextion library. Previously, I was working with the ESP8266, and everything functioned perfectly. However, after switching to the ESP32-S3, I can’t seem to get anything to work.
For reference, on the ESP32-S3, the Nextion display is connected to pins 9 and 10.
I am sending values to screen but nothing happen, code was working for esp8266.
Apologies for the poorly formatted code; I had it neatly organized in tabs but couldn’t upload it properly.
This is what i am seeing in serial port:
wartość licz: 0.00 Czas: 14:05:56 n1.val=22���n2.val=33��� wartość licz: 0.00 Czas: 14:06:01 n1.val=22���n2.val=33��� wartość licz: 0.00 Czas: 14:06:06 n1.val=22���n2.val=33��� wartość licz: 0.00 Czas: 14:06:11 n1.val=22���n2.val=33��� wartość licz: 0.00 Czas: 14:06:16
`#include <WiFi.h>
#include <HardwareSerial.h>
#include <Wire.h>
#include <RTClib.h>
#include "EasyNextionLibrary.h"
#include <NTPClient.h>
#include <WiFiUdp.h>
//#include "variables.h"
#include <FastLED.h>
unsigned long odczyt_licznika_milis = 0;
const long odczyt_licznika_czas = 5000; // 5s
unsigned long odczyt_delay = 0;
const long delay_50ms = 5000;
int temperatura_zadana_bojler = 25;
int temperatura_zadana_buffor_dolny = 50;
int temperatura_zadana_buffor_gorny = 50;
int temp_zadana_4 = 50;
int temperatura_act_bojler;
int temperatura_act_buffor_dolny;
int temperatura_act_buffor_gorny;
int temperatureC4;
int histereza_bojler = 5;
int histereza_buffor_dolny = 5;
int histereza_buffor_gorny = 5;
int histereza_4 = 5;
int test2 = 5;
int taryfa_nocna_h = 22;
int taryfa_nocna_m = 0;
int taryfa_dzienna_h = 6;
int taryfa_dzienna_m = 0;
int adjust_hour_RTC;
int adjust_minute_RTC;
float licz = 0;
uint8_t currentPage;
const char* ssid = "ssid";
const char* password = "password";
WiFiUDP udp;
NTPClient timeClient(udp, "pool.ntp.org", 3600, 60000); // 3600 to offset (sekundy) dla strefy czasowej (np. 3600 dla CET)
// Konfiguracja pinów dla ESP32
#define RXD2 16//17 // RX dla modbus 35 na zlaczu
#define TXD2 17//16 // TX dla modbus 36 na zlaczu
#define txEnPin 18 // Pin Enable 37 na zlaczu
#define RXD3 9 // RX3 dla Nextion
#define TXD3 10 // TX3 dla Nextion (inny pin)
#define SDA_PIN 21 // Domyślny pin SDA dla ESP32
#define SCL_PIN 22 // Domyślny pin SCL dla ESP32
EasyNex myNex(Serial2); // Używamy Serial2 zamiast SoftwareSerial
HardwareSerial ModbusSerial(2); // Drugi port sprzętowy UART
unsigned char ibuf[128];
float liczAVcc = 0;
int x = 12;
String response = "";
void setup() {
Serial.begin(115200);
delay(200);
Serial.println("\nUruchamianie...");
Serial.println("Łączenie z WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Łączenie...");
delay(100);
}
Serial.println("Połączono z WiFi!");
delay(1000);
timeClient.begin();
delay(500);
Serial.println("Otrzymywanie czasu NTP...");
delay(1000);
// Inicjalizacja Serial2 dla Nextion
Serial2.begin(9600, SERIAL_8N1, RXD3, TXD3);
delay(100);
myNex.begin(9600);
// Inicjalizacja sprzętowego portu UART dla Modbusa
ModbusSerial.begin(9600, SERIAL_8N1, RXD2, TXD2);
pinMode(txEnPin, OUTPUT);
digitalWrite(txEnPin, LOW);
// Inicjalizacja I2C
Wire.begin(SDA_PIN, SCL_PIN);
delay(1000);
Serial.println("Setup zakończony.");
}
void loop() {
unsigned long currentMillis = millis();
myNex.NextionListen();
//currentPage = myNex.currentPageId;
timeClient.update();
if (currentMillis - odczyt_delay >= delay_50ms){
odczyt_delay = currentMillis;
//Time();
//readTemp1();
readTemp2();
readTemp3();
// readTemp4();
// zadana_temperatura_1();
// zadana_temperatura_2();
// zadana_temperatura_3();
// zadana_temperatura_4();
// zadana_histereza_1();
// zadana_histereza_2();
// zadana_histereza_3();
// zadana_histereza_4();
}
if (currentMillis - odczyt_licznika_milis >= odczyt_licznika_czas){
odczyt_licznika_milis = currentMillis;
MOC();
zapytaniedoLicznika(0);
timeClient.update();
Serial.println("");
Serial.print("Czas: ");
Serial.println(timeClient.getFormattedTime());
}
if (ModbusSerial.available() > 0) {
parsujDanezLicznika();
}
}
void zapytaniedoLicznika(unsigned char startadr) {
unsigned char Inputs[] = { 0x02, 0x04, 0x00, 0x18, 0x00, 0x02, 0xFF, 0xFF };
wyslij_po_rs(Inputs, 6);
}
void parsujDanezLicznika() {
delay(50);
int licz = 0;
while (ModbusSerial.available() && licz < 32) {
ibuf[licz] = ModbusSerial.read();
licz++;
}
if (licz == 0) {
Serial.println("Nie odebrano żadnych danych!");
return;
}
if (licz < 5) {
Serial.println("Pakiet zbyt krótki!");
return;
}
uint16_t inCRC = (ibuf[licz - 1] << 8) + ibuf[licz - 2];
uint16_t calcCRC = calculateCRC(ibuf, licz - 2);
if (inCRC != calcCRC) {
Serial.printf("Błąd CRC! Obliczone: 0x%04X, Odebrane: 0x%04X\n", calcCRC, inCRC);
return;
}
liczAVcc = bin2float(3);
if (liczAVcc >= 9.5) x = 9;
else if (liczAVcc >= 8.5) x = 8;
else if (liczAVcc >= 7.5) x = 7;
else if (liczAVcc >= 6.5) x = 6;
else if (liczAVcc >= 5.5) x = 5;
else if (liczAVcc >= 4.5) x = 4;
else if (liczAVcc >= 3.5) x = 3;
else if (liczAVcc >= 2.5) x = 2;
else if (liczAVcc >= 1.5) x = 1;
else x = 0;
}
float bin2float(int istart) {
uint32_t bin = ((uint32_t)ibuf[istart] << 24) | ((uint32_t)ibuf[istart + 1] << 16) |
((uint32_t)ibuf[istart + 2] << 8) | (uint32_t)ibuf[istart + 3];
float result;
memcpy(&result, &bin, sizeof(float));
return result;
}
uint16_t calculateCRC(unsigned char *buf, int len) {
uint16_t crc = 0xFFFF;
for (int pos = 0; pos < len; pos++) {
crc ^= (uint16_t)buf[pos];
for (int i = 8; i != 0; i--) {
if ((crc & 0x0001) != 0) {
crc >>= 1;
crc ^= 0xA001;
} else {
crc >>= 1;
}
}
}
return crc;
}
void wyslij_po_rs(unsigned char inbuf[20], int ile) {
uint16_t CRC16 = calculateCRC(inbuf, ile);
inbuf[ile] = CRC16 & 0xFF;
inbuf[ile + 1] = (CRC16 >> 8) & 0xFF;
while (ModbusSerial.available()) ModbusSerial.read();
digitalWrite(txEnPin, HIGH);
delay(20);
ModbusSerial.write(inbuf, ile + 2);
ModbusSerial.flush();
delay(5);
digitalWrite(txEnPin, LOW);
}
void MOC() {
myNex.writeNum("x0.val", liczAVcc); // wysyłanie wartości do komponentu x0 na wyświetlaczu
Serial.println("");
Serial.print("wartość licz: ");
Serial.print(liczAVcc);
}
void Time(){
// Wyświetlenie tylko godziny w formacie HH:MM:SS
//Serial.print("Godzina: ");
//Serial.print(now.hour(), DEC);
//Serial.print(":");
//Serial.println(now.minute(), DEC);
//Serial.print(":");
//Serial.print(now.second(), DEC);
//String response = test1234; //String(now.hour()) + ":" + String(now.minute()) + ":" + String(now.second());
//Serial.print("t7.txt=");
//Serial.print("\"");
//Serial.print("Hot!");
//Serial.print(message);
//Serial.print("\"");
//Serial.write(0xff);
//Serial.write(0xff);
//Serial.write(0xff);
//delay(50);
// Tworzymy string z czasem
//Serial.print("t7.txt=\""); // Otwieramy cudzysłów
//Serial.print(timeStr); // Wyświetlamy zmienną z czasem
//Serial.print("\""); // Zamykamy cudzysłów
//Serial.write(0xff);
//Serial.write(0xff);
//Serial.write(0xff);
}
void Taryfy(){
String timeStr_n = String(taryfa_nocna_h) + ":" + String(taryfa_nocna_m) + ": 00";
myNex.writeStr("t8.txt", timeStr_n);
String timeStr_d = String(taryfa_dzienna_h) + ":" + String(taryfa_dzienna_m) + ": 00";
myNex.writeStr("t9.txt", timeStr_d);
}
void readTemp1(){
temperatura_act_bojler = 11;
myNex.writeNum("n0.val=", temperatura_act_bojler);
//Serial.print("n0.val=");
//Serial.print(temperatura_act_bojler);
//Serial.write(0xff);
//Serial.write(0xff);
//Serial.write(0xff);
//delay(10);
}
void readTemp2(){
temperatura_act_buffor_dolny = 22;
Serial.print("n1.val=");
Serial.print(temperatura_act_buffor_dolny);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(10);
}
void readTemp3(){
temperatura_act_buffor_gorny = 33;
Serial.print("n2.val=");
Serial.print(temperatura_act_buffor_gorny);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(10);
}
void readTemp4(){
temperatureC4 = 44;
Serial.print("n3.val=");
Serial.print(temperatureC4);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(50);
delay(10);
}
void zadana_temperatura_1(){ // TEMPERATURA ZADANA BOJLER
Serial.print("n10.val=");
Serial.print(temperatura_zadana_bojler);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(10);
}
void zadana_temperatura_2(){ // TEMPERATURA ZADANA BUFFOR GÓRA
Serial.print("n11.val=");
Serial.print(temperatura_zadana_buffor_dolny);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(10);
}
void zadana_temperatura_3(){ // TEMPERATURA ZADANA BUFFOR DÓŁ
Serial.print("n12.val=");
Serial.print(temperatura_zadana_buffor_gorny);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(10);
}
void zadana_temperatura_4(){ // TEMPERATURA ZADANA REZERWA
Serial.print("n13.val=");
Serial.print(temp_zadana_4);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(10);
}
void zadana_histereza_1(){ // TEMPERATURA ZADANA BOJLER
Serial.print("n20.val=");
Serial.print(histereza_bojler);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(10);
}
void zadana_histereza_2(){ // TEMPERATURA ZADANA BUFFOR GÓRA
Serial.print("n21.val=");
Serial.print(histereza_buffor_dolny);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(10);
}
void zadana_histereza_3(){ // TEMPERATURA ZADANA BUFFOR DÓŁ
Serial.print("n22.val=");
Serial.print(histereza_buffor_gorny);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(10);
}
void zadana_histereza_4(){ // TEMPERATURA ZADANA REZERWA
Serial.print("n23.val=");
Serial.print(histereza_4);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
delay(10);
}
/* Create a button on Nextion
* Write in the Touch Release Event of the button
* this command: printh 23 02 54 01
* Every time the button is pressed, the trigger1() function will run
* and the code inside will be executed once
*/
/* trigger() is the most important method of the library.
* And this is because, it gives you the ability to use the predefined functions and run your code from there.
* These predefined functions are named trigger1(), trigger2(), trigger3()... up to trigger50().
* You can use them as a simple void out of the loop, in which you will have written a block of code to run every time it is called.
* You can call those trigger() functions and run the code they contain anytime by simply writing in a Nextion Event the command:
* `printh 23 02 54 XX` , where `XX` the id for the triggerXX() in HEX.
* Example: printh 23 02 54 01 to call trigger1() ... printh 23 02 54 0A to call trigger10() and so on...
*/
void trigger1(){ // sterowanie led
/* Create a button on Nextion
* Write in the Touch Release Event of the button
* this command: printh 23 02 54 01
* Every time the button is pressed, the trigger1() function will run
* and the code inside will be executed once
*/
digitalWrite(13, !digitalRead(13)); // If LED_BUILTIN is ON, turn it OFF, or the opposite
if(digitalRead(13) == 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(13) == 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(){ //dodanie tempo zadanej do temp1
temperatura_zadana_bojler = temperatura_zadana_bojler + 5;
}
void trigger3(){ // odjecie 5 od temp1
temperatura_zadana_bojler = temperatura_zadana_bojler - 5;
}
void trigger4(){ //dodanie do temp2
temperatura_zadana_buffor_dolny = temperatura_zadana_buffor_dolny + 5;
}
void trigger5(){ //odjecie od temp2
temperatura_zadana_buffor_dolny = temperatura_zadana_buffor_dolny - 5;
}
void trigger6(){ //doadnia edo temp 3
temperatura_zadana_buffor_gorny = temperatura_zadana_buffor_gorny + 5;
}
void trigger7(){ // odjecie od temp 3
temperatura_zadana_buffor_gorny = temperatura_zadana_buffor_gorny - 5;
}
void trigger8(){ //dodanie do temp 4
temp_zadana_4 = temp_zadana_4 + 5;
}
void trigger9(){ //odjecie od temp 4
temp_zadana_4 = temp_zadana_4 - 5;
}
void trigger10(){ //DODANIE DO HISTEREZY 1
histereza_bojler = histereza_bojler + 1;
}
void trigger11(){ //ODJĘCIE OD HISTEREZY 1
histereza_bojler = histereza_bojler - 1;
}
void trigger12(){ //DODANIE DO HISTEREZY 2
histereza_buffor_dolny = histereza_buffor_dolny + 1;
}
void trigger13(){ //ODJECIE OD HISTEREZY 2
histereza_buffor_dolny = histereza_buffor_dolny - 1;
}
void trigger14(){ //DODANIE DO HISTEREZY 3
histereza_buffor_gorny = histereza_buffor_gorny + 1;
}
void trigger15(){ //ODJECIE OD HISTEREZY 3
histereza_buffor_gorny = histereza_buffor_gorny - 1;
}
void trigger16(){ //DODANIE DO HISTEREZY 4
histereza_4 = histereza_4 + 1;
}
void trigger17(){ //ODJECIE OD HISTEREZY 4
histereza_4 = histereza_4 - 1;
}
void trigger18(){ //Zapis czasu
}
void trigger19(){ //Zapis taryfy nocnej
taryfa_nocna_h = myNex.readNumber("n60.val");
taryfa_nocna_m = myNex.readNumber("n61.val");
}
void trigger20(){ //Zapis taryfy dziennej
taryfa_dzienna_h = myNex.readNumber("n62.val");
taryfa_dzienna_m = myNex.readNumber("n63.val");
}
`
The text was updated successfully, but these errors were encountered:
Hello
I’m encountering an issue while using the ESP32-S3 with the EasyNextion library. Previously, I was working with the ESP8266, and everything functioned perfectly. However, after switching to the ESP32-S3, I can’t seem to get anything to work.
For reference, on the ESP32-S3, the Nextion display is connected to pins 9 and 10.
I am sending values to screen but nothing happen, code was working for esp8266.
Apologies for the poorly formatted code; I had it neatly organized in tabs but couldn’t upload it properly.
This is what i am seeing in serial port:
wartość licz: 0.00 Czas: 14:05:56 n1.val=22���n2.val=33��� wartość licz: 0.00 Czas: 14:06:01 n1.val=22���n2.val=33��� wartość licz: 0.00 Czas: 14:06:06 n1.val=22���n2.val=33��� wartość licz: 0.00 Czas: 14:06:11 n1.val=22���n2.val=33��� wartość licz: 0.00 Czas: 14:06:16
`
The text was updated successfully, but these errors were encountered: