DS18B20 Issue using OLED

Hi All,

I have a 128 X 64 SH1106 OLED using the UG82 Library to display the temp output of a DS18B20 Sensor.
I am unsure as to why though when I attempt to display the temperature on the OLED or even serial print the temperature with another display being run on the OLED the temperature reading stays at -127 which I believe indicates a fault in the signal???

I have not wired in the sensor using parasitic load. It uses 5v with a 4.7K ohm resistor and the OnWire Lib.

When I use a simple serial print code the sensor displays the temperature fine on the serial monitor.
I think it could be something to do with the OLED or code???

Please help.

#include <Arduino.h>
#include <SPI.h>
#include <U8g2lib.h>
#include <OneWire.h>
#include <DallasTemperature.h>

OneWire bus(2); //SET UP ONE WIRE LIBRARY ON PIN 2
DallasTemperature sensors(&bus); //SETUP DALLAS TEMP TO WORK ON ONEWIRE BUS


//==========================================================================
//  THE BELOW WORKS FOR A SH1106 OLED DISPLAY ON THE U8G2 LIBRARY
//  THIS SETS UP THE OLED TO OPERATE CORRECTLY 
//==========================================================================

U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); 


//=========================================================================
//    THE XBM FILE GOES BELOW - MUST KNOW DEMENSIONS!
//========================================================================
#define Thermo_width 41
#define Thermo_height 64

static const unsigned char Thermo_bits[] PROGMEM = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x83, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x0f, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x0f, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x80, 0xb9, 0x03, 0x00, 0x00,
   0x00, 0xc0, 0x3c, 0x06, 0x00, 0x00, 0x00, 0x60, 0xfe, 0x0c, 0x00, 0x00,
   0x00, 0x20, 0xff, 0x0d, 0x00, 0x00, 0x00, 0xb0, 0xff, 0x1b, 0x00, 0x00,
   0x00, 0x90, 0xff, 0x1b, 0x00, 0x00, 0x00, 0xd0, 0xff, 0x17, 0x00, 0x00,
   0x00, 0xd0, 0xff, 0x17, 0x00, 0x00, 0x00, 0xd0, 0xff, 0x17, 0x00, 0x00,
   0x00, 0x90, 0xff, 0x1b, 0x00, 0x00, 0x00, 0xb0, 0xff, 0x1b, 0x00, 0x00,
   0x00, 0x20, 0xff, 0x0d, 0x00, 0x00, 0x00, 0x60, 0xfe, 0x0c, 0x00, 0x00,
   0x00, 0xc0, 0x38, 0x06, 0x00, 0x00, 0x00, 0x80, 0xc3, 0x03, 0x00, 0x00,
   0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

float temperature; //NOT SURE WHAT THESE ARE FOR YET
char temperatureString[6] = "-"; //NOT SURE WHAT THESE ARE FOR YET

void draw(void) {
// graphic commands to redraw the complete screen should be placed here  
 u8g2.drawXBMP( 10, 0, Thermo_width, Thermo_height, Thermo_bits); // THESE LINES CALL UPON THE SIZING AT THE TOP OF THE BITMAP CODING.
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(43,20,"TEMP");
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(43,40,temperatureString);
}

void setup(void) {
  sensors.begin();
  u8g2.begin();
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(43,20,"IT'S");
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(18,37,"GETTING");
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(30,55,"REAL!");
  } while ( u8g2.nextPage() );
  delay(1000);
}

void loop(void) { 
 // THIS STARTS THE PICTURE LOOP
u8g2.firstPage();
do {
     draw();
    } while( u8g2.nextPage() );

// Update the sensor readings 
sensors.requestTemperatures(); 
  
// Read Temperature 
temperature = sensors.getTempCByIndex(0); 
dtostrf(temperature, 2, 2, temperatureString); 


// rebuild the picture after some delay
delay(1000);
}

Do any of the DS18B20 examples work? Try to get it working without the OLED.

Look a little deeper into the error code. Did it get no data at all, like it's unplugged? Or did it get some data which failed the checksum test?

Hi Yes,

A simple OneWire DS18B20 Serial Print works well. It displays the correct temp on the serial monitor.

Where would I view the error code? Sorry. Just a newbie…

There is no correct output that changes. It would almost be the same as if the sensor was unplugged.

Confirm that it can see the device's address on the bus.

Thanks,

Would I use the multiple sensor address tutorial code to find this?

http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html but I don't think you need this, the 127 implies no connection - and intermittently, it would appear. Parasite power is never a good idea, I bet you don't have good reason for using it and, if it fixed the problem, it would only be by accident because you were more diligent with the wiring. If you are using a cheapo breadboard, check it out.

It is also possible that you have a power supply problem, but I understand the DS18B20 runs on practically nothing.

Thanks for the reply,

I am not using parasitic power supply to the sensor. I rewired the sensor and used a new breadboard to no avail…
I have used the following sketch and it works perfectly. The serial monitor displays the correct temperature. From this I assume that the sensor is not the issue, it must be an issue with the code that is causing an interference of sorts???

#include <DS18B20.h> // Includes Temp sensor 
#include <OneWireHub.h> // Includes One Wire Hub


//Include libraries
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);


//===========================================================================
//       SETUP - The Initial SetUp - Only Condcuted Once on Start up
//===========================================================================
void setup(void)
{
  Serial.begin(9600); //Begin serial communication
  sensors.begin();
  delay(2000);
}


//===========================================================================
//       LOOP - Carries over and over again - Reading and displaying data
//===========================================================================

void loop(void)
{ 
  // Send the command to get temperatures
  sensors.requestTemperatures();  
  Serial.print("Temperature is:  ");
  Serial.print(sensors.getTempCByIndex(0),0); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire.
                                              // The ,0 at the end of the line calls for no decimal places after temperature output.
  Serial.println( " Deg C"); // Print After Temperature of sensor
  
  delay(1000); //Update value every 1 sec.
}

Also I have found that the address tutorial from Hacktronics will not display an address. I am unsure why this is? My baudrate is 9600 but there is no text at all displayed when I run the sketch for looking up the DS18B20 address.

Could it be the order the code is in? It uses all the same

#include <Arduino.h>
#include <SPI.h>
#include <U8g2lib.h>
#include <OneWire.h>
#include <DallasTemperature.h>

OneWire bus(2); //SET UP ONE WIRE LIBRARY ON PIN 2
DallasTemperature sensors(&bus); //SETUP DALLAS TEMP TO WORK ON ONEWIRE BUS


//==========================================================================
//  THE BELOW WORKS FOR A SH1106 OLED DISPLAY ON THE U8G2 LIBRARY
//  THIS SETS UP THE OLED TO OPERATE CORRECTLY 
//==========================================================================

U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); 


//=========================================================================
//    THE XBM FILE GOES BELOW - MUST KNOW DEMENSIONS!
//========================================================================
#define Thermo_width 41
#define Thermo_height 64

static const unsigned char Thermo_bits[] PROGMEM = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x83, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x0f, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x0f, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x01, 0x00, 0x00,
   0x00, 0x00, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x80, 0xb9, 0x03, 0x00, 0x00,
   0x00, 0xc0, 0x3c, 0x06, 0x00, 0x00, 0x00, 0x60, 0xfe, 0x0c, 0x00, 0x00,
   0x00, 0x20, 0xff, 0x0d, 0x00, 0x00, 0x00, 0xb0, 0xff, 0x1b, 0x00, 0x00,
   0x00, 0x90, 0xff, 0x1b, 0x00, 0x00, 0x00, 0xd0, 0xff, 0x17, 0x00, 0x00,
   0x00, 0xd0, 0xff, 0x17, 0x00, 0x00, 0x00, 0xd0, 0xff, 0x17, 0x00, 0x00,
   0x00, 0x90, 0xff, 0x1b, 0x00, 0x00, 0x00, 0xb0, 0xff, 0x1b, 0x00, 0x00,
   0x00, 0x20, 0xff, 0x0d, 0x00, 0x00, 0x00, 0x60, 0xfe, 0x0c, 0x00, 0x00,
   0x00, 0xc0, 0x38, 0x06, 0x00, 0x00, 0x00, 0x80, 0xc3, 0x03, 0x00, 0x00,
   0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

float temperature; //NOT SURE WHAT THESE ARE FOR YET
char temperatureString[6] = "-"; //NOT SURE WHAT THESE ARE FOR YET

void draw(void) {
// graphic commands to redraw the complete screen should be placed here  
 u8g2.drawXBMP( 10, 0, Thermo_width, Thermo_height, Thermo_bits); // THESE LINES CALL UPON THE SIZING AT THE TOP OF THE BITMAP CODING.
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(43,20,"TEMP");
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(43,40,temperatureString);
}

void setup(void) {
  sensors.begin();
  u8g2.begin();
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(43,20,"IT'S");
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(18,37,"GETTING");
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(30,55,"REAL!");
  } while ( u8g2.nextPage() );
  delay(1000);
}

void loop(void) { 
 // THIS STARTS THE PICTURE LOOP
u8g2.firstPage();
do {
     draw();
    } while( u8g2.nextPage() );

// Update the sensor readings 
sensors.requestTemperatures(); 
  
// Read Temperature 
temperature = sensors.getTempCByIndex(0); 
dtostrf(temperature, 2, 2, temperatureString); 


// rebuild the picture after some delay
delay(1000);
}

mack85n: I am not using parasitic power supply to the sensor.

Good idea. Keep it that way..

I rewired the sensor and used a new breadboard to no avail....

I guess having the data go to serial OK proves the wiring is kosher.

I have used the following sketch and it works perfectly. The serial monitor displays the correct temperature. From this I assume that the sensor is not the issue, it must be an issue with the code that is causing an interference of sorts???

I can't see where there would be interference. DS18b20 is quite separate from I2C or SPI. Have you tried a simple HelloWorld with the display by itself? I must admit I failed miserably to do this, but I got a result using a simpler library. It was SSD1306AsciiAVRi2C.h and was all I needed. I don't know if these simpler libraries would be relevant to you.

That's what I have ascertained. The wiring, sensor and supply must be OK.

It must be in the sketch or the various libraries.......

I will try to remove various aspects of the code and see how that goes, starting with the bitmap.

I haven't tried the other libraries like the Adafruit and GFX as I like the U8G2 but I may need to.

I forgot to point out that, while I don't think it is relevant to the problem, I have never had any trouble with the Hacktronics address finder, or heard of anybody else having trouble. For all that, you get a result with the sensors and the display side is suss..

mack85n, it seems that I have the same problem.

I found out that as soon the program reaches the initial u8g2.begin(); the sensorvalues are all -127.00.

Did you find a working alternative ?