Nextion display

Hello Guys!
I am new to arduino and the nextion display!
I have a project that we are using 6 ds18b20 sensors and 1 DHT22 sensor for temperature and humidity.
The problem now is that only the first sensor in t10 doesnt changes in the Nextion display..but in the serial monitor is fine! Also i have changed the display with another one and the problem still remains
Please give me some feedback..

My code is

#include <Nextion.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>

#define sensor_pin1 7
#define sensor_pin2 32
#define sensor_pin3 33
#define sensor_pin4 34
#define sensor_pin5 35
#define sensor_pin6 36
#define DHTPIN 10
#define DHTTYPE DHT22
DHT dht(DHTPIN,DHTTYPE);

OneWire oneWire(sensor_pin1);         // setup a oneWire instance
OneWire oneWire1(sensor_pin2);
OneWire oneWire2(sensor_pin3);
OneWire oneWire3(sensor_pin4);
OneWire oneWire4(sensor_pin5);
OneWire oneWire5(sensor_pin6);

DallasTemperature sensor_1(&oneWire); // pass oneWire to DallasTemperature library
DallasTemperature sensor_2(&oneWire1);
DallasTemperature sensor_3(&oneWire2);
DallasTemperature sensor_4(&oneWire3);
DallasTemperature sensor_5(&oneWire4);
DallasTemperature sensor_6(&oneWire5);

float humi,tempC;
float tempCelsius1,tempCelsius2,tempCelsius3,tempCelsius4,tempCelsius5,tempCelsius6;



void setup() {
 
 Serial.begin(9600);
 dht.begin();
 sensor_1.begin();    // initialize the sensors
 sensor_2.begin();
 sensor_3.begin();
 sensor_4.begin();
 sensor_5.begin();
 sensor_6.begin();
 
  
}

void loop() {

  humi=dht.readHumidity();
  tempC=dht.readTemperature();
   //Print temp and humidity values to serial monitor
    Serial.print("Humidity: ");
    Serial.print(humi);
    Serial.print(" %, Temp: ");
    Serial.print(tempC);
    Serial.println(" Celsius");
   
    
   sensor_1.requestTemperatures();  // send the command to get temperatures
   sensor_2.requestTemperatures();
   sensor_3.requestTemperatures();
   sensor_4.requestTemperatures();
   sensor_5.requestTemperatures();
   sensor_6.requestTemperatures();

   tempCelsius1=sensor_1.getTempCByIndex(0);// read temperature in Celsius for the 1st sensor_1
   tempCelsius2=sensor_2.getTempCByIndex(0);
   tempCelsius3=sensor_3.getTempCByIndex(0);
   tempCelsius4=sensor_4.getTempCByIndex(0);
   tempCelsius5=sensor_5.getTempCByIndex(0);
   tempCelsius6=sensor_6.getTempCByIndex(0);

   sendTemperatureToNextion();

   delay(1000);

}
void sendTemperatureToNextion()
{
   String command1 = "t10.txt=\""+String(tempCelsius1,1)+"\"";
   Serial.print(command1);
   endNextionCommand();
   String command2 = "t11.txt=\""+String(tempCelsius2,1)+"\"";
   Serial.print(command2);
   endNextionCommand();
   String command3 = "t12.txt=\""+String(tempCelsius3,1)+"\"";
   Serial.print(command3);
   endNextionCommand();
   String command4 = "t13.txt=\""+String(tempCelsius4,1)+"\"";
   Serial.print(command4);
   endNextionCommand();
   String command5 = "t14.txt=\""+String(tempCelsius5,1)+"\"";
   Serial.print(command5);
   endNextionCommand();
   String command6 = "t15.txt=\""+String(tempCelsius6,1)+"\"";
   Serial.print(command6);
   endNextionCommand();
   String command7 = "t16.txt=\""+String(humi,1)+"\"";
   Serial.print(command7);
   endNextionCommand();
   String command8 = "t17.txt=\""+String(tempC,1)+"\"";
   Serial.print(command8);
   endNextionCommand();
}
   
   void endNextionCommand()
{
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}

Please choose the forum category carefully. You posted in the uncategorized category explicitly tagged as

Could you take a few moments to Learn How To Use The Forum. It will help you get the best out of the forum in the future.

Thank you.

I've moved your post to a more suitable category for this time.

The meaning of onewire is

ALL sensors connected on onewire

usually you define a single onewire-object and all sensors share the same ground, Vcc, and datawire. This is the special feature of onewire-sensors

I do not understand what you want to say with

does this mean
your second sensor changes the text of textfield t11
your third sensor changes the text of textfield t12
....

You should post the exact type of your microcontroller.
Most microcontrollers have too few RAM to work with variable-type String over a longer time

variable-type String leads to memory-fragmentation and program crash over time
you should either use arrays of chars or the SafeString-library

As your problem seems to be related to the Nextion-Screen-definition you should attach the nextion-projectfile to a posting and hope that some nextion-experts are online to analyse it

No. One wire means you access 1-wire devices made by Maxim/Dallas

You can create multiple OneWire objects, one for each pin and the library is designed for this.
➜ Even though you can connect many 1 wire devices to the same pin, if you have a large number of devices, smaller groups or just individual sensors each on their own pin can help isolate wiring problems.

there is nothing wrong with that

i have only problem with the variable in t10.txt
it appears that the data changes in my serial monitor but on the Nextion display doesn't change over time
Yes , all the other sensors change the time both on serial monitor and Nextion display..
Mention that i have ARDUINO MEGA and the display is NX8048T070_011

Well you wrote some additional information. Still hard to analyse what is ging on on this small base of information.

To say it very clear and very explicit:
printing the values of

String command1 = "t10.txt=\""+String(tempCelsius1,1)+"\"";
   Serial.print(command1);

to serial the monitor shows a changing value?

Your lines of code

look identic except for the variable-names and the nextion textfield-names

As you did not provide your nextion-project-file you will have to check if the textfield-name

is correct.

Another thing is to change the order of the printing and observe if always the textfield that comes first does not change

And at least posting what you really get in the serial monitor would be very helpful too
and posting pictures of what can be really seen on your nextion display will help.

For analysing your problem serial printing will be very useful.
But only under the pre-condition that you use Arduino IDE Version 1.8.19.

The new IDE Version 2.X.Y has a fundamental problem with the serial monitor
In Arduino-IDE-Version 2.X.Y the serial monitor is crippled .

You can't make effective use of it.

This is a problem that has been discussed for more than a half year now, but the Arduino-IDE-development-team refuses to work on a solution.

This means your solution is to work with Arduino-IDE 1.8.19. There is a possability to have Arduino-IDE 1.8.19 on the same computer without interfering with IDE 2.X.Y.

This is done through making the Arduino-IDE Version 1.8.19 as a portable version. The portable version 1.8.19 does not interfere with a Arduino-IDE 2.X.Y-Installation.
Arduino-IDE Version 1.8.19 does have less bells and whistles than IDE 2.X.Y but compiles and uploads just the same. And serial printing works like a charm.

You can read in this tutorial how to install Arduino-IDE 1.8.19 as portable version
tutorial how to install Arduino-IDE Version 1.8.19 as portable

Your code prints only to Serial, which is the serial port which connects to the PC and serial monitor.

To update the display, you need to print to whichever serial port the display is connected to, by printing to Serial1, Serial2 or Serial3.

If the posted code does show reactions on the nextion-display this means
user @serafeim_mavros is connecting the USB-Cable for programming
or
the nextion display to IO-pins 0,1

@serafeim_mavros
if you connect both at the same time this interferes with each other and leads to unpredictable results.

As you are using an Arduino Mega you should do what user @PaulRB recommended
using Serial1 or Serial2 for sending data to your nextion-display.

This will enable to print to the serial monitor and to the nextion-display at the same time
most effective when using Arduino-IDE 1.8.19 instead of IDE 2.2.1

1 Like

Guys sorry for my late reply..
I connect the nextion to rx1 and tx1 and i use the serial1 port and all variables now changes to the display!
Thank you very much for the support!

Thank you!
The problem is the serial because both of the serial monitor and the display are on the same serial port

I know. I was expecting you to reply saying "I have the display connected to pins 0, 1" and I would have said "you can't do that because those are already in use".

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