Nextion display temperature DS18B20

I have an arduino uno and the nextion basic. I want to display the temperature using the DS18B20 sensor. I succeed in displaying the waveform. I succeed in displaying the temp in a number field. But I dont succeed in showing them both using the code beneath. When I delete the n3.setValue rule I see the waveform working. When I add the n3.setvalue rule I see the number working. How is that possible?

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Nextion.h>
 
#define SENSOR_PIN 2
OneWire oneWire(SENSOR_PIN );
DallasTemperature sensors(&oneWire);
 
NexWaveform s0 = NexWaveform  (0, 1, "s0");
NexNumber n3 = NexNumber      (0, 5, "n3");
 
void setup() {
  Serial.begin(9600);
  sensors.begin();
  nexInit();
}
void loop() {
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
  
    
  s0.addValue(0, temp);       // wavevorm
  n3.setValue(temp);          // number

  delay( 500 );
}

I connected the arduino mega and now it succeed both!

While you can use a Uno with a Nextion my advice is don't as it has only one serial port, which is used by the serial monitor. Use a board with at least 1 spare serial port, for example Mega or Nano Every.

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