Start a new topic

two ds18b20

my English is bad

google translate


How can I show the temperature range of 2 DS18B20 on the nextion screen. I've done one, but I do not know how to make 2 of them.


 when you show, how you did the one, maybe somebody can help you how to adapt the 2. ...

This is the code of the single.

ino
ahhhh so you are not looking for the Nextion side, you are looking for some Arduino code ... that's a bit different ...

 

Yes I do nextion. But I was weak on the arduino side.

This guy uses two ds18b20s.

http://www.tweaking4all.com/hardware/arduino/arduino-ds18b20-temperature-sensor/


Lets look at the Nextion side once you have both sensors reading.

image

This is what I get when I do it on the sheet

//

// Start oneWireSearch.ino

//

 

uint8_t pin7[][8] = {

  {

0x28, 0xEE, 0xE8, 0x76, 0x1F, 0x16, 0x02, 0x8E },

  {

0x28, 0xEE, 0xAB, 0x82, 0x1F, 0x16, 0x02, 0x56 },

};

// nr devices found: 2

 

//

// End oneWireSearch.ino

//





On the other hand, I get this output.

I arranged my nextion file this way. 2.4 inches

HMI

Try embedding these into your ino.

When #include "Nextion.h" is used, it includes Nex*****.h


#include "Nextion.h"
// #include "NexText.h"
// #include "NexGauge.h"

NexText temp8E = NexText(0,1,"tem");
NexText temp56 = NexText(0,1,"tem1");
NexGauge ptr8E = NexGauge(0,5,"z0");
NexGauge ptr56 = NexGauge(0,6,"z1");


if(addr[7]==0x8E) {
    celsius = (float)raw / 16.0;
    number = ((float)celsius/60)*180+30;
    ptr8E.setValue(number);

    memset(buffer, 0, sizeof(buffer));
    itoa(celsius, buffer, 10);
    temp8E.setText(buffer);
} 

if(addr[7]==0x56) {
    celsius = (float)raw / 16.0;
    number = ((float)celsius/60)*180+30;
    ptr56.setValue(number);

    memset(buffer, 0, sizeof(buffer));
    itoa(celsius, buffer, 10);
    temp56.setText(buffer);
} 

 

Insert the if statements just after your temperature reading where

  your data line is printed out.

This will use the last byte of the ROM identifier to know which

  text/gauge pair to use in the Nextion HMI

I placed it but I get an error.

ino

Add a closing brace to the function around line 105.


Easy mistake, I used to make it often ;) 

    memset(buffer, 0, sizeof(buffer));
    itoa(celsius, buffer, 10);
    temp56.setText(buffer);
  }
}<---------This one is missing.
void setup(void)

 

Thank you. :) fixed. I could send 2 data to the screen. But one shows 87 degrees and the other shows 88 degrees. There is a mistake in the measurement, but where.

image

I did this as a link.

 

    if (type_s) 
    {
        raw = raw << 3;                         /* 9 bit resolution default */
        if (data[7] == 0x10) 
        {
            /* count remain gives full 12 bit resolution */
            raw = (raw & 0xFFF0) + 12 - data[6];
        }
    } 
    else 
    {
        byte cfg = (data[4] & 0x60);
        if (cfg == 0x00) raw = raw << 3; 
        else if (cfg == 0x20) raw = raw << 2; 
        else if (cfg == 0x40) raw = raw << 1; 
        /* default is 12 bit resolution, 750 ms conversion time */
    }

 The measurement error has improved when you remove these codes. Thank you very much for your help :)

Login or Signup to post a comment