DS18B20 print adress and then DS18S20

Hello,

I need to make my program detected sensor DS18S20 or DS18B20 ... yet I have program for sensor DS18B20. Please, how make sensor DS18S20 write on displey ??? :frowning:

#include <OneWire.h>                  // Knihovny
#include <DallasTemperature.h>
#include <LiquidCrystal.h>

#define ONE_WIRE_BUS 8
#define DS18B20 8

OneWire ourWire(DS18B20);
DallasTemperature sensors(&ourWire);

OneWire  ds(8);                       // Přiřazení PINu DS18B20
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);    // Vytvoření objektu LCD

int backLight = 13;                   // PIN na osvětlení dipleje
//OneWire oneWire(ONE_WIRE_BUS);
//DallasTemperature sensors(&oneWire);

void setup(void)
  {
  }
  
void loop(void)
  {
  lcd.begin(16, 2);                   // Parametry počet sloupů a řádků
  lcd.clear();                        // Smazání znaků na displeji
  lcd.setCursor(0,0);                 // Nastavení kurzoru na pozici (s, ř)
  getDeviceAddress();                 // Získání adresy
  pinMode(backLight, OUTPUT);         // Osvětlení displeje 
  analogWrite(backLight, 128);        // Osvětlení displeje
  
  sensors.begin();      
  sensors.requestTemperatures();
  lcd.setCursor(0,0);                 // Nastavení cursoru
  float tempC(sensors.getTempCByIndex(0));
  if (tempC == -127.00) {
    lcd.clear();
    lcd.home();
  lcd.print("PripojCidlo");
  } 
  else {
  lcd.print(tempC);
  }
  lcd.setCursor(6,0);
  lcd.print("C");
  delay (3000);
 
}  
  void getDeviceAddress(void) {
  byte i;
  byte addr[8];

//  sensors.begin();                      // Začátek komunikace se senzorem

    while(ds.search(addr))      {
  // lcd.print("DS18B20 adress:");
   lcd.setCursor(0, 1);
    for( i = 0; i < 8; i++) {
      
  //  lcd.setCursor(0, 1);
  //  lcd.print("0x");
     if (addr[i] < 16) {
    lcd.print('0');
                       }
  //  lcd.setCursor(0, 1);
    lcd.print(addr[i], HEX);
     if (i < 7) {
  //  lcd.print(",");
    lcd.leftToRight();
      }
    }
    
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        lcd.setCursor(0, 1);
        lcd.print("Neni hodnota");
        return;
    }
  }
  ds.reset_search();
  return;
}



 /*
{ 
  lcd.setCursor(0,1);  // nastavení cursoru mimo počet zobrazení
  lcd.autoscroll();    // aut. posun
  lcd.print(" ");      // prázdný znak
  delay(800);          // zpoždění  
}

/*


  /*

  lcd.print(sensors.getTempFByIndex(0)); 
  lcd.print((char)223);
  lcd.print("F  ");
   
  lcd.print(sensors.getTempCByIndex(0));
  lcd.print((char)223); 
  lcd.print("C");
  
  delay(500);
}
  */

Kaniiisek:
I need to make my program detected sensor DS18S20 or DS18B20 ...

Do you really need to do that?

The DS18S20 has 9bit resolution only and takes 750ms to convert. The DS18B20 takes the same time to convert @ 12bit. Since you have a delay of 3000 already, both should work with the same code.

You code appears to be a mish-mash of two programmes - one to get the address, and the other to get the temperature by index.

Yes, the codes are from two sources. I need to - connect DS18S20 - the display shows a letter. It's done to the program know that it is connected to the sensor "s"?

Kaniiisek:
Yes, the codes are from two sources.

I submit that, if you need one, you don't need the other, so why have you got both?

Your problem, or intention, is far from clear. While this

It's done to the program know that it is connected to the sensor "s"?

is unintelligible, it seems that you might want to distinguish between DS18B20 and DS18S20. As I said, the code should work with both as there is no operational difference between them. You just might get some joy by converting the return to a string and testing the length of the fraction, i.e. a DS18S20 returns ".5" while a DSB20 might return ".50", or even ".43" but I fail to see the point of the exercise, other than ensuring a way to send the DS18s20 to the garbage bin.

The first byte of the ROM address from a DS18x20 identifies the device type.
If addr[0] == 0x28 then it is a DS18B20
If addr[0] == 0x10 then it is a DS18S20
You could replace this:

 // lcd.print("DS18B20 adress:");

with this:

  if(addr[0] == 0x28)lcd.print("DS18B20 address:");
  else if(addr[0] == 0x10)lcd.print("DS18S20 address:");
  else lcd.print("Unknown device:");

Pete

Thank you... but, please..how make write symbol (S, B) on display - one line and 8 column?

lcd.setCursor() ... ? when I write, code dosnt work.

Sorry for my english.

Solved..

    while(ds.search(addr))       {
      
    if(addr[0] == 0x28) {
    lcd.setCursor(9,0);
    lcd.print("DS18B20"); }
    else if(addr[0] == 0x10) {
    lcd.setCursor(9,0);
    lcd.print("DS18S20");}

I have next problem ...
How modify program and schema for 2wire senzor?????