67 lines
1.3 KiB
Arduino
67 lines
1.3 KiB
Arduino
|
#include <Wire.h>
|
||
|
|
||
|
#include "lib/esp8266-dht22/dht22.h"
|
||
|
#include "lib/esp8266-dht22/dht22.c"
|
||
|
#include "lib/HC_LiquidCrystal_I2C/HC_LiquidCrystal_I2C.h"
|
||
|
#include "lib/HC_LiquidCrystal_I2C/HC_LiquidCrystal_I2C.cpp"
|
||
|
|
||
|
// ~~~
|
||
|
|
||
|
// LCD Display Settings
|
||
|
#define LCD_PIN_SDA 12
|
||
|
#define LCD_PIN_SCL 14
|
||
|
|
||
|
// DHT22 Settings
|
||
|
#define DHT_TYPE DHT22
|
||
|
// Pin D1 on the NodeMCU v0.9
|
||
|
#define DHT_PIN_DATA 5
|
||
|
|
||
|
// ~~~
|
||
|
|
||
|
HC_LiquidCrystal_I2C lcd(0x3F,20,4);
|
||
|
|
||
|
// ~~~
|
||
|
|
||
|
void dht_init() {
|
||
|
Serial.print("Initialising the DHT - ");
|
||
|
DHT_init(DHT_PIN_DATA, DHT_TYPE, 1);
|
||
|
DHT_begin();
|
||
|
|
||
|
Serial.println("done");
|
||
|
Serial.print("Waiting to warm DHT22 up - ");
|
||
|
delay(2000 - millis()); // Give the DHT22 time to warm up
|
||
|
}
|
||
|
void lcd_init() {
|
||
|
// Deprecated, but in this instance there's nothing we can do about it
|
||
|
// since we aren't running I2C over the default pins (default pins? what
|
||
|
// default pins?)
|
||
|
Wire.pins(LCD_PIN_SDA, LCD_PIN_SCL);
|
||
|
lcd.begin();
|
||
|
}
|
||
|
|
||
|
void setup() {
|
||
|
lcd_init();
|
||
|
dht_init();
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
lcd.backlight();
|
||
|
|
||
|
float temp, humidity;
|
||
|
|
||
|
lcd.setCursor(0, 0);
|
||
|
temp = readTemperature(false);
|
||
|
humidity = readHumidity();
|
||
|
|
||
|
lcd.print("Temperature: ");
|
||
|
lcd.print(temp);
|
||
|
lcd.print("C");
|
||
|
|
||
|
lcd.setCursor(0, 1);
|
||
|
lcd.print("Humidity: ");
|
||
|
lcd.print(humidity);
|
||
|
lcd.print("%");
|
||
|
|
||
|
delay(1000);
|
||
|
}
|