//--LIBRARIES CALLING--
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
//--DISPLAY OBJECT--
#define heigth 64
#define width 128
#define rst -1
Adafruit_SSD1306 oled(width,heigth,&Wire,rst);
//--PIN DEFINITION--
#define sensor D0 //Analog Input
//--DHT OBJECT--
#define DHTTYPE DHT22
DHT sTemp(sensor, DHTTYPE);
void setup() {
boardBegin();
Serial.println("DHT SENSOR TEST");
oled.clearDisplay();
oled.println("DHT SENSOR TEST");
oled.display();
delay(2000);
}
void loop() {
float h = sTemp.readHumidity(); //Leemos la Humedad
float t = sTemp.readTemperature(); //Leemos la temperatura en grados Celsius
float f = sTemp.readTemperature(true);
// Clear the OLED display buffer
oled.clearDisplay();
oled.setCursor(0, 10);
// Display Sensor data
oled.println("SENSOR DATA\n");
oled.print("TEMP: "); oled.print(t);oled.println("C\n");
oled.print("HUM: "); oled.print(h);oled.println("%\n");
// Display Sensor data
Serial.print("TEMP:"); Serial.print(t);Serial.print("\t");
Serial.print("HUM:"); Serial.print(h);Serial.print("\n");
// Send buffer to the display (update screen)
oled.display();
// Small delay to control refresh rate
delay(100);
}
void boardBegin(){
//Serial and I2C Comunication, OLED Display, and IMU Sensor initialize
Serial.begin(115200);
Wire.begin();
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)){
Serial.println("Oled Display NOT Found...");
for (;;);
}
oled.setTextColor(WHITE);
oled.clearDisplay();
oled.setTextSize(1);
oled.setCursor(5, 5);
}