// DHT11, DHT22, LCD I2C, OLED 

#include <DHT.h>
#include <LiquidCrystal_I2C.h> // LCD librairy.h>
#include <Adafruit_GFX.h> // OLED library
#include <Adafruit_SSD1306.h> // OLED library

#define SCREEN_WIDTH 128 // OLED width,  in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

//===============================================================================
// Set up the DHT sensor  and LCD
const int DHT_Pin = 4;                           // The DHT pin
float temperature ;                             // Sensor temperature
float  humidity;                               // Sensor Humidity
int counter;                                  // Data counter
int totalColumns = 16;                       // number of colums pixels on the LCD
int totalRows = 2;                          // number of rows pixels on the LCD
const int delayTime = 500;                 // delay time on between each iteration
const int scrolling_time = 100;           // Scrolling time of the test
DHT dht(DHT_Pin, DHT22); // If you are using the DHT22, you just need to change the value 11 to 22
LiquidCrystal_I2C lcd(0x27, totalColumns, totalRows);  // Define the lcd object from the liduidCrystal class
String staticMessage = "DHT Tutorial";
String scrollingMessage = "Welcome to ESP32 with DHT11 !";

//=============================================================================
// The below function allow us to scroll a test and it is used to scroll the ouput of data of the sensor
void scrollMessage(int row, String message, int delayTime, int totalColumns) {
  for (int i = 0; i < totalColumns; i++) {
    message = " " + message;
  }
  message = message + " ";
  for (int position = 0; position < message.length(); position++) {
    lcd.setCursor(0, row);
    lcd.print(message.substring(position, position + totalColumns));
    delay(delayTime);
  }
}
//=================================================================================
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Hello, ESP32!");
  lcd.init();                        
  lcd.backlight();                  
  lcd.clear();                     
  lcd.setCursor(2, 0);            
  lcd.print(staticMessage);      
  scrollMessage(1, scrollingMessage, scrolling_time, totalColumns);

  //OLED Display
  // initialize OLED display with I2C address 0x3C
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("failed to start SSD1306 OLED"));
    while (1);
  }
  oled.setTextSize(1.5);         // set text size
  oled.setTextColor(WHITE);   // set color
  oled.display(); // OLED display
}

void loop() {

  temperature = dht.readTemperature();
  humidity = dht.readHumidity();
  lcd.clear();
  lcd.setCursor(2, 0);

  lcd.setCursor(0, 1);
  String scrollingMessageHumidity = "Humidity: " + String(humidity);
  scrollMessage(1, scrollingMessageHumidity, scrolling_time, totalColumns);

  String scrollingMessageTemperature = "Temperature: " + String(dht.readTemperature(false)) + "C";
  scrollMessage(1, scrollingMessageTemperature, scrolling_time, totalColumns);
  
  delay(delayTime);
  counter++;

  oled.clearDisplay();
  oled.setCursor(0, 0);

  oled.setCursor(0, 12);
  oled.println("Humidity: " + String(humidity));

  oled.setCursor(0, 24);
  oled.println("Temp (C): " + String(dht.readTemperature(false)) + "C");

  oled.display();

  delay(delayTime);
  counter++;  

}
$abcdeabcde151015202530fghijfghij
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL
Loading
ssd1306
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND