I am working on using a DS18B20 for two temperatures.
I used the 'get the ID from the sensor' method vs. the discover the sensor ID and then hard code it.
I am using a small OLED, 128x32 and the U8G2 ( or U8x8) OLED library.
The ESP8266 specifically, the WEMOS D1 mini, is the micro used.
I removed the BME280 as I need the more waterproof DS18B20 sensors.
for this test, I just used the TO92 case DS18B20 sensor
I am a bit hesitant to post my code as it is just something I kludeged together.
/*
* using 8x8 display driver with 128x32 display
*
*
* esp8266 pins used
rst unused TX
AO unused RX
D0 D1 I2C SCL
D5 CLK D2 I2C SDA
D6 MISO D3 1-wire
D7 MOSI D4 C/S
D8 RESET GND
3V3 5V
NOKIA 5110 with ESP8266
rst = D4 - RST
C/S = D8 - CS
DC = D0 - DC
MOSI = D7 hardware
SCK = D5 hardware
3v3
backlight
ground
I2C
CL = D1 hardware I2C on ESP8266
DA = D2 hardware I2C on ESP8266
1Wire = D3 // any digital pin works
*/
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Arduino.h>
#include <U8x8lib.h>
// U8G2_PCD8544_84X48_1_4W_HW_SPI u8g2(U8G2_R2, /* cs=*/ D8, /* dc=*/ D0, /* reset=*/ D4); // Nokia 5110 Display
// U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // D1 & D2
U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C
// ***************************************************************************
#define ONE_WIRE_BUS D3
// ***************************************************************************
// #define TEMPERATURE_PRECISION 12
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
DeviceAddress DS18one, DS18two; // arrays to hold device addresses
// from the BME280
float tem1, tem2, hum1, hum2, pres1, pres2, gas_t1, gas_t2 ;
unsigned long then , then1; // for timing blink without delay, not used
void setup() // +++++++++++++++++++++++++++++++++++++ SETUP +++++++++++++++++++++++
{
Serial.begin(115200);
sensors.begin();
u8x8.begin();
delay(2000);
// locate devices on the bus
// Serial.print("Locating OneWire devices..."); Serial.print("Found ");
// Serial.print(sensors.getDeviceCount(), DEC); Serial.println(" devices.");
if (!sensors.getAddress(DS18one, 0)) Serial.println("Unable to find address for Device 0");
if (!sensors.getAddress(DS18two, 1)) Serial.println("Unable to find address for Device 1");
sensors.setResolution(DS18one, 12);
sensors.setResolution(DS18two, 12);
then = millis();
} // ================================================= END SETUP =============================
void loop()
{
sensors.requestTemperatures();
delay(10);
gas_t1 = sensors.getTempF(DS18one);
gas_t1 = ( gas_t1 - .2) ; // correct mismatched temperature sensors
Serial.print("DS18-1: ");
Serial.print(gas_t1);
Serial.print("*F\t");
delay(10);
gas_t2 = sensors.getTempF(DS18two);
Serial.print(" DS18-2: ");
Serial.print(gas_t2);
Serial.println("*F\t");
// u8x8.clear();
u8x8.setFont(u8x8_font_px437wyse700b_2x2_r);
u8x8.setCursor(0, 0); u8x8.print("T1=");
u8x8.setCursor(0, 2); u8x8.print("T2=");
u8x8.setCursor(6, 0); u8x8.print(gas_t1,1);
u8x8.setCursor(6, 2); u8x8.print(gas_t2,1);
} // ================================================= END LOOP =============================