//#include <SimpleDHT.h>
#include "DHTesp.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// for DHT22,
// VCC: 5V or 3V
// GND: GND
// DATA: 2
const int DHT_PIN = 12;
DHTesp dhtSensor;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
//#define LOGO_HEIGHT 30
//#define LOGO_WIDTH 30
static const unsigned char PROGMEM logo_bmp[] ={ };
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
display.clearDisplay();
display.setTextColor(1);
display.setTextSize(1);
display.setCursor(0,10);
display.print("Temperature:");
display.print(String(data.temperature, 2));
display.print("°C");
display.display();
display.setCursor(0,20);
display.print("Humidity: ");
display.print(String(data.humidity, 2));
display.print("%");
display.display();
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}