ESP8266 with TWO separate DS18B20 temp sensors, TWO one-wire buses!

Yes, you can connect up to 5 (or more?) DS18B20 one-wire sensors chained onto one pin, and address them individually based on it's unique address..

However you need to know the component's address if you want to read it directly...

For the project I have at hand, I want to read two sensors, each on it's own bus, there fore I know exactly, physically, where a sensor is going and replace it if needed.  Also there is no need to know it's burnt in address in order to access it.

 

 

Note: I2C 1602 LCD not shown in wireup

 

 

// 11-30-2020 Oh Good!  This one works!!

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows

// GPIO where the DS18B20 is connected to, ESP8266
const int oneWireBusA = 14;    
const int oneWireBusB = 12;  


// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWireA(oneWireBusA);
OneWire oneWireB(oneWireBusB);


// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensorsA(&oneWireA);
DallasTemperature sensorsB(&oneWireB);


String TempFa = String(8);  //sensor A
String TempFb = String(8);  //sensor B


byte DegSym[8] = {
  B01110,
  B01010,
  B01110,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};



byte TempF[8] = {
  B00000,
  B00000,
  B00000,
  B01110,
  B01000,
  B01100,
  B01000,
  B01000
};



void setup() {



lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight 

 lcd.createChar(0,DegSym);
  lcd.createChar(1,TempF);

  // Start the Serial Monitor
  Serial.begin(115200);
  
  // Start the DS18B20 sensor
  sensorsA.begin();
  sensorsB.begin();

}

void loop() {


 
 sensorsA.requestTemperatures(); // Send the command to get temperatures
 sensorsB.requestTemperatures(); // Send the command to get temperatures

 lcd.clear();  // get the temps from the sensors first, then CLS otherwise there is a lag 
               // between CLS and printing the temp
 
    float tempCa = sensorsA.getTempCByIndex(0);
    Serial.print("Temp C: ");
    Serial.print(tempCa);
    Serial.print(" Temp F: ");
    Serial.println(DallasTemperature::toFahrenheit(tempCa)); // Converts tempC to Fahrenheit
    TempFa = DallasTemperature::toFahrenheit(tempCa);
    if (TempFa == "-196.60") {
    TempFa = "Error";
    }
    lcd.setCursor(0, 0);
    lcd.print("TempA: " + TempFa);
    lcd.write(0);
    lcd.write(1);





    float tempCb = sensorsB.getTempCByIndex(0);
    Serial.print("Temp C: ");
    Serial.print(tempCb);
    Serial.print(" Temp F: ");
    Serial.println(DallasTemperature::toFahrenheit(tempCb)); // Converts tempC to FahrenheiT
    TempFb = DallasTemperature::toFahrenheit(tempCb);
    if (TempFb == "-196.60") {
    TempFb = "Error";
    }
    lcd.setCursor(0, 1);
    lcd.print("TempB: " + TempFb);
    lcd.write(0);
    lcd.write(1);
delay(5000);
  

}

 

Comments are closed