|
| 1 | +#include <Wire.h> |
| 2 | +#include <Adafruit_GFX.h> |
| 3 | +#include <Adafruit_SSD1306.h> |
| 4 | +#include <Adafruit_FeatherOLED.h> |
| 5 | +#include <Adafruit_Sensor.h> |
| 6 | +#include <DHT.h> |
| 7 | +#include <DHT_U.h> |
| 8 | +#include <ESP8266WiFi.h> |
| 9 | + |
| 10 | +Adafruit_FeatherOLED oled = Adafruit_FeatherOLED(); |
| 11 | + |
| 12 | +#define DHTPIN 2 |
| 13 | +#define DHTTYPE DHT22 |
| 14 | +DHT_Unified dht(DHTPIN, DHTTYPE); |
| 15 | + |
| 16 | +void setup() { |
| 17 | + Serial.begin(115200); |
| 18 | + dht.begin(); |
| 19 | + |
| 20 | + oled.init(); |
| 21 | + oled.setBatteryVisible(true); |
| 22 | + |
| 23 | + WiFi.disconnect(); |
| 24 | + WiFi.mode(WIFI_OFF); |
| 25 | + WiFi.forceSleepBegin(); |
| 26 | + delay(1); |
| 27 | + |
| 28 | + Serial.println(""); |
| 29 | + Serial.println("Temp and Humidity code, by Daniel Mruczynski 02/11/2018"); |
| 30 | + Serial.println("Pastebin link (if that still exists): pastebin.com/LCxzJyEZ"); |
| 31 | + |
| 32 | +} |
| 33 | + |
| 34 | +void loop() { |
| 35 | + Serial.println(""); |
| 36 | + oled.clearDisplay(); |
| 37 | + oled.setTextSize(1); |
| 38 | + float battery = analogRead(A0); |
| 39 | +// resistors are 220k and 940k |
| 40 | + battery /= .1897; |
| 41 | + battery /= 1024; |
| 42 | + oled.setBattery(battery); |
| 43 | + oled.renderBattery(); |
| 44 | + Serial.print(battery); |
| 45 | + Serial.println(" V Battery Voltage"); |
| 46 | + |
| 47 | + oled.setTextSize(2); |
| 48 | + oled.setCursor(0, 0); |
| 49 | + |
| 50 | + sensors_event_t event; |
| 51 | + dht.temperature().getEvent(&event); |
| 52 | + Serial.print(event.temperature); |
| 53 | + Serial.println(" Degrees C"); |
| 54 | + oled.print(event.temperature, 1); |
| 55 | + oled.setTextSize(1); |
| 56 | + oled.println("C"); |
| 57 | + |
| 58 | + oled.setCursor(0, 17); |
| 59 | + oled.setTextSize(2); |
| 60 | + |
| 61 | + dht.humidity().getEvent(&event); |
| 62 | + Serial.print(event.relative_humidity); |
| 63 | + Serial.println(" % Relative Humidity"); |
| 64 | + |
| 65 | + oled.print(event.relative_humidity, 1); |
| 66 | + oled.setTextSize(1); |
| 67 | + oled.println("%"); |
| 68 | + |
| 69 | + oled.setCursor(68, 23); |
| 70 | + oled.print("BootyBotV2"); |
| 71 | + |
| 72 | + oled.display(); |
| 73 | + |
| 74 | +// ESP.deepSleep(1e6); |
| 75 | + delay(1000); |
| 76 | +} |
0 commit comments