SSD1306 and SSD1309 not working with combined DHT and DS18B20 with U8g2

Hallo,

About a year ago I finished a project for my car based on a LCD 16 x 2 with the functions date, time, cabin temperature, outside temperature with frostwarning, board voltage and dimlight on warning.
A simple configuration in fact with a DS3231 clockchip, DS18B20 waterproof type and a DHT11.
I’m content with it and the only reason to choose for this type of LCD is lack of space, 1 DIN is just 50 mm high, a 20 x 4 wiil not fit. So far so good with the changing information on the lower display position.

So I decided to modernise this configuration with an other type of display and purchased an oled screen SSD1309 and after some sleepless nights got it working with SPI. Afterwards oled is not a good solution with intense daylight but that’s another matter.

I ran in this strange problem using the same temperature sensors as I use to use.
Using this script I noticed the next problems:

#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include “DHT.h”
#include <OneWire.h>
#include <DallasTemperature.h>
#define DS18B20 2 //data pin D2 voor DS18B20

#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

//OLED type

//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=/ SCL, / data=/ SDA, / reset=/ U8X8_PIN_NONE); // All Boards without Reset of the Display
U8G2_SSD1309_128X64_NONAME2_F_4W_SW_SPI u8g2(U8G2_R0, /
clock=/ 13, / data=/ 11, / cs=/ 10, / dc=/ 9, / reset=*/ 8);

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

void setup() {
u8g2.begin();
dht.begin();
Serial.begin(9600);
}

float tempValCin;
float tempValCout;
float tempValCDHT;

void loop() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_5x7_tf);

u8g2.setCursor(0,20);
u8g2.print ("TempInDHT: " );
tempValCDHT = dht.readTemperature();//Read temperature (Celsius)
u8g2.print(tempValCDHT,1);

sensors.requestTemperatures();

// u8g2.setCursor(0,30);
//u8g2.print ("TempIn : " );
//tempValCin = sensors.getTempCByIndex(0);
//u8g2.print(tempValCin,1);

// u8g2.setCursor(0,40);
// u8g2.print ("TempOut: " );
//tempValCout = sensors.getTempCByIndex(1);
//u8g2.print(tempValCout,1);

u8g2.sendBuffer(); // transfer internal memory to the display
delay(1000);
}

a. it works with one single DHT but the measuring is not stable, fluctuating.
b. as soon as the DHT and DS18B20 are configurated together there’s no output on screen. No errors seen during compiling by the way.
c. for the above mentioned problems it makes no different to use a SSD1306 on the I2C bus or a SSD1309 on SPI.

Anyhow, it works just all fine with two DS18B20 sensors configured.

Hi Allesklusser,

Did you test your sketch with (debugging via) Serial Monitor with all display instructions commented out? Maybe it is not a display problem but a library problem or a sensor problem. You claim to use a DHT22 while the instructions in your sketch define a DHT11.
groetjes, photoncatcher.

Discovered the problem thanks to this article:

Just install and use the TinyDHT library as suggested in the article and do not use the well known DHT library.

This problem as I already mentioned only appears in combination with the u8g2 displaydriver, with the LCD 2 x 16 it works fine. Does Ollie Kraus know about this matter? It seems not.

The changed code:

#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
//#include "DHT.h"
#include "TinyDHT.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define DS18B20 6 //data pin D6 voor DS18B20

#define DHTPIN  4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

//OLED type

//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // All Boards without Reset of the Display
U8G2_SSD1309_128X64_NONAME2_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 5);

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

void setup() {
  u8g2.begin();
  dht.begin();
  Serial.begin(9600);
}


float tempValCin;              
float tempValCout;              
float tempValCDHT;

void loop() {
u8g2.clearBuffer(); 
u8g2.setFont(u8g2_font_5x7_tf); 

u8g2.setCursor(0,20);
u8g2.print ("TempInDHT: " );
tempValCDHT  = dht.readTemperature();//Read temperature (Celsius)
u8g2.setCursor(60,20);
u8g2.print(tempValCDHT, 1);

sensors.requestTemperatures(); 
 
  u8g2.setCursor(0,30);
  u8g2.print ("TempIn : " );
 tempValCin = sensors.getTempCByIndex(0);
 u8g2.print(tempValCin,1);

   
  u8g2.setCursor(0,40);
  u8g2.print ("TempOut: " );
  tempValCout = sensors.getTempCByIndex(1);
  u8g2.print(tempValCout,1);

u8g2.sendBuffer();          // transfer internal memory to the display
delay(2000);
}