Start a new topic

Onewire value to Nextion hmi.

I have had the text sending fine from my Arduino to the nextion Temp sensor fine DHT sensor but have upgraded to the one wire DS18B20 sensors I am having trouble modifying the code to send the temp value to the Nextion below is the extract original code for the DHT sensor Ben Code: [Select] { // Sump Tank uint16_t dht11val; memset(buffer,0,sizeof(buffer)); { int chk = DHTC.read11(DHT11c_PIN); Serial.print("C Temperature = "); Serial.println(DHTC.temperature); // Serial.print("C Humidity = "); - commented out, did not need the Humidity //Serial.println(DHTC.humidity); - commented out, did not need the Humidity dht11val = DHTC.temperature; itoa(dht11val,buffer,10); ; t1.setText(buffer); // set the text on the Nextion to the temp value tis is the new code, it displays the code to the serial monitor, how do I convert it to a text (or buffer) that I can use to "setText" on the Nextion Code: [Select] Serial.println(); Serial.print("Number of Devices found on bus = "); Serial.println(sensors.getDeviceCount()); Serial.print("Getting temperatures... "); Serial.println(); // Command all devices on bus to read temperature sensors.requestTemperatures(); Serial.print("Probe 01 temperature is: "); Serial.println(sensors.getTempCByIndex(0)); Serial.println(); // t1.setText(buffer); Serial.print("Probe 02 temperature is: "); //Serial.println(sensors.getTempCByIndex(1)); Serial.println(); Many thanks Ben

when you expect help, you also should do your best to make it easy for the ones who are willing to help.


I don't think that anybody out like to even read your above posted code mess ... :-)


please use code tags ...

sorry I have tried, this forum is not IPAD compatible, am now on the laptop, will re post thanks for the advice


I have had the text sending fine from my Arduino to the nextion Temp sensor fine DHT sensor

but have upgraded to the one wire DS18B20 sensors

I am having trouble modifying the code to send the temp value to the Nextion

below is the extract original code for the DHT sensor

Ben


 

{ // Sump Tank
  uint16_t dht11val;
  memset(buffer,0,sizeof(buffer));
{
  int chk = DHTC.read11(DHT11c_PIN);
 Serial.print("C Temperature = ");
 Serial.println(DHTC.temperature);
 // Serial.print("C Humidity = "); - commented out, did not need the Humidity
  //Serial.println(DHTC.humidity); - commented out, did not need the Humidity
  
  dht11val = DHTC.temperature;  

  itoa(dht11val,buffer,10);
;


t1.setText(buffer); // set the text on the Nextion to the temp value 

 

tis is the new code, it displays the code to the serial monitor, how do I convert it to a text (or buffer) that I can use to "setText" on the Nextion


 

Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  Serial.print("Probe 01 temperature is:   ");
  Serial.println(sensors.getTempCByIndex(0));
  Serial.println();
 // t1.setText(buffer);

  Serial.print("Probe 02 temperature is:   ");
 //Serial.println(sensors.getTempCByIndex(1));
 Serial.println();

 


that's no ipad issue, you only must use the tags provided from the input box ...  :-)

I did something along the lines of

(Set all the byte bits first )



Sen1 = (sensors.getTempCByIndex(1));

t1.setText(Sen1);

I got pulsing jumbled text

I am not into the Arduino code itself, but without changes of some Sensor code it won't work ...

In general

    - the DHT contains a Polymer humidity capacitor and a DS18B20 for detecting temperature ...
    - after being queried, the DHT11 returns 41 Bits of Data, Humidity and Temperature ...

    - the DS18B20 is a part of the DHT
    - the DS18B20 as stand-alone sensor surely returns less data than the DHT

that's why you get jumbled text, you just readin still the 41 bytes as expected from the DHT ...

 

I am reading the values fine (from both the DHT and the DS18) in the serial monitor ad the same time serialprint. . But they don't transfer over to the HMI.

****** UPDATE ******


I have this fixed code below, new ticket submitted on how to display decimal on the Nextion, it is only showing the whole number,


 

void doFunction2()
{{ // Temp Outside
    uint16_t dht11val;
    memset(buffer, 0, sizeof(buffer));
    {
      int chk = DHTA.read11(DHT11a_PIN);
      Serial.print("A Temperature = ");
      Serial.println(DHTA.temperature);
      Serial.print("A Humidity = ");
      Serial.println(DHTA.humidity);
    }
    dht11val = DHTA.temperature;
    itoa(dht11val, buffer, 10);
    //t2.setText(buffer);
    t2.setText(buffer);
    dht11val = DHTA.humidity;
    itoa(dht11val, buffer, 10);
    t3.setText(buffer);
    yield();
  }

  { 
// Temp Tank
    uint16_t dht11val;
    memset(buffer, 0, sizeof(buffer));
} 
    Serial.println();
    Serial.print("Number of Devices found on bus = ");
    Serial.println(sensors.getDeviceCount());
    Serial.print("Getting temperatures... ");
    Serial.println();

    // Command all devices on bus to read temperature
    sensors.requestTemperatures();
    char buffer[10];
    Serial.print("Probe 01 temperature is:   ");
    Serial.println(sensors.getTempCByIndex(0));
    Serial.println();
    S1Val = sensors.getTempCByIndex(0);

dtostrf(S1Val, 2, 1, buffer);
   
        t1.setText(buffer);

    Serial.print("Probe 02 temperature is:   ");
    Serial.println(sensors.getTempCByIndex(1));
    Serial.println();
        S2Val = sensors.getTempCByIndex(1);
            itoa(S2Val,buffer,10);
   
        t0.setText(buffer);

    yield();
  }
}

 


That's normal, the function itoa() = Integer to Alpha interprets your values logically as integers.


To transform float values into text, use snprintf().

Thanks. Will try. Ben.
Login or Signup to post a comment