// PLEASE BE VERY SURE TO EDIT YOUR PINS ON LINES 12 AND 14 // PLEASE BE VERY SURE TO EDIT YOUR PINS ON LINES 12 AND 14 // PLEASE BE VERY SURE TO EDIT YOUR PINS ON LINES 12 AND 14 // PLEASE BE VERY SURE TO EDIT YOUR PINS ON LINES 12 AND 14 // PLEASE BE VERY SURE TO EDIT YOUR PINS ON LINES 12 AND 14 // PLEASE BE VERY SURE TO EDIT YOUR PINS ON LINES 12 AND 14 #include #include #include U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ GPIO_NUM_9, /* data=*/ GPIO_NUM_8); #define DHTPIN GPIO_NUM_3 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); void setup() { u8g2.begin(); u8g2.clearBuffer(); Serial.begin(115200); u8g2.setFont(u8g2_font_6x10_tf); u8g2.drawStr(0, 0, "Initializing..."); u8g2.sendBuffer(); delay(1000); dht.begin(); u8g2.clearBuffer(); u8g2.drawStr(0, 0, "Ready!"); u8g2.sendBuffer(); delay(1000); } void loop() { float indoorTemp = dht.readTemperature(true); if (isnan(indoorTemp)) { Serial.println("Failed to read from DHT sensor!"); indoorTemp = 0; } u8g2.clearBuffer(); u8g2.setFont(u8g2_font_logisoso32_tf); char tempBuffer[10]; snprintf(tempBuffer, sizeof(tempBuffer), "%.1f", indoorTemp); uint8_t width = u8g2.getStrWidth(tempBuffer); uint8_t x = (128 - width) / 2; uint8_t y = 40; u8g2.setCursor(x, y); u8g2.print(tempBuffer); u8g2.setFont(u8g2_font_6x10_tf); uint8_t textWidth = u8g2.getStrWidth("Fahrenheit"); u8g2.setCursor((128 - textWidth) / 2, y + 20); u8g2.print("Fahrenheit"); u8g2.sendBuffer(); Serial.print("Indoor Temp: "); Serial.println(indoorTemp); delay(15000); }