You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
6.9 KiB
277 lines
6.9 KiB
// ----- TeZ ---- DHT Display on OLED screen -----
|
|
//* OLED DISPLAY 3.3V(VCC), GND, SCL (21), SDA (22) [ESP32]
|
|
//* model: SSD1306 Resolution: 128 x 64 (small = 128 x 32)
|
|
// FONTS >> in file OLEDdisplayFonts.h
|
|
// ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24
|
|
// SansSerif_plain_10, SansSerif_plain_12
|
|
// Dingbats__12
|
|
// Monospaced_plain_8, Monospaced_plain_10, Monospaced_plain_12, Monospaced_bold_10, Monospaced_bold_16, Monospaced_bold_24 //
|
|
// ceated with http://oleddisplay.squix.ch/
|
|
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
|
|
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
|
|
// https://learn.adafruit.com/dht/overview
|
|
|
|
//F.M. ENCSYS edit 1
|
|
|
|
#include "OTA.h"
|
|
#include "OSC.h"
|
|
|
|
#include <Adafruit_Sensor.h>
|
|
#include <DHT.h>
|
|
#include <DHT_U.h>
|
|
#include <Wire.h>
|
|
#include <Adafruit_GFX.h>
|
|
#include "fontdef.h"
|
|
//#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
|
|
#include "SSD1306Wire.h"
|
|
#include "OLEDDisplayUi.h"
|
|
#include <driver/adc.h>
|
|
|
|
// Initialize the OLED display using Wire library
|
|
SSD1306Wire display(0x3c, 21, 22);
|
|
|
|
#define DHTPIN 25 // Digital pin connected to the DHT sensor
|
|
|
|
// Uncomment the type of sensor in use:
|
|
#define DHTTYPE DHT11 // DHT 11
|
|
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
|
|
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
|
|
DHT_Unified dht(DHTPIN, DHTTYPE);
|
|
|
|
uint32_t delayMS;
|
|
|
|
//bool light = false;
|
|
|
|
int LEDpin = 16;
|
|
//int SMOKETIME = 5000;
|
|
//bool SMOKEFLAG = true;
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
void setup() {
|
|
|
|
APConnect();
|
|
setupOTA();
|
|
Udp.begin(rxport);
|
|
|
|
//Serial.begin(115200);
|
|
|
|
pinMode(LEDpin, OUTPUT);
|
|
pinMode(4, OUTPUT);
|
|
|
|
digitalWrite(4, false);
|
|
fog = false;
|
|
|
|
|
|
|
|
// Initialising the OLED display
|
|
display.init();
|
|
display.flipScreenVertically();
|
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
|
display.clear();
|
|
|
|
display.setFont(Monospaced_bold_16);
|
|
display.drawString(0, 0, "Hello Human!");
|
|
display.setFont(Monospaced_plain_12);
|
|
display.drawString(20, 30, "How are you");
|
|
display.drawString(40, 50, "today?");
|
|
|
|
display.display();
|
|
|
|
delay(3000);
|
|
|
|
|
|
|
|
|
|
// Initialize DHT device.
|
|
dht.begin();
|
|
Serial.println(F("DHTxx Unified Sensor Example"));
|
|
// Print temperature sensor details.
|
|
sensor_t sensor;
|
|
dht.temperature().getSensor(&sensor);
|
|
Serial.println(F("------------------------------------"));
|
|
Serial.println(F("Temperature Sensor"));
|
|
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
|
|
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
|
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
|
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
|
|
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
|
|
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
|
|
Serial.println(F("------------------------------------"));
|
|
// Print humidity sensor details.
|
|
dht.humidity().getSensor(&sensor);
|
|
Serial.println(F("Humidity Sensor"));
|
|
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
|
|
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
|
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
|
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%"));
|
|
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%"));
|
|
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%"));
|
|
Serial.println(F("------------------------------------"));
|
|
// Set delay between sensor readings based on sensor details.
|
|
delayMS = sensor.min_delay / 1000;
|
|
}
|
|
|
|
void humiditycontrol()
|
|
{
|
|
delay(delayMS);
|
|
// Get humidity event and compare it to the wanted value
|
|
sensors_event_t event;
|
|
dht.humidity().getEvent(&event);
|
|
|
|
if ((int(event.relative_humidity)) > (int(humidityctrl))){
|
|
fogstate = false;
|
|
}
|
|
else {
|
|
//delay(100);
|
|
// delay(delayMS);
|
|
fogstate = true;
|
|
//if (prevfogstate != fogstate){
|
|
//delay(100);
|
|
//}
|
|
}
|
|
|
|
}
|
|
|
|
void fogcontrol()
|
|
{
|
|
if (fogstate == 1){
|
|
digitalWrite(4, true);
|
|
delay (100);
|
|
prevfogstate = bool(fogstate);
|
|
digitalWrite(4, false);
|
|
delay (5000);
|
|
//prevfogstate = int(fogstate);
|
|
|
|
}
|
|
|
|
else if (fogstate == 0){
|
|
|
|
if (prevfogstate != fogstate){
|
|
//delay (100);
|
|
//digitalWrite(4, true);
|
|
delay (100);
|
|
digitalWrite(4, false);
|
|
|
|
prevfogstate = bool(fogstate);
|
|
}
|
|
else{
|
|
digitalWrite(4, false);
|
|
}
|
|
}
|
|
}
|
|
///////////////////////////////////////////////////////
|
|
void loop() {
|
|
|
|
osc_message_pump();
|
|
ArduinoOTA.handle();
|
|
|
|
|
|
// FOG SWITCH
|
|
//delay(SMOKETIME);
|
|
//SMOKEFLAG = !(SMOKEFLAG);
|
|
//digitalWrite(4, fog);
|
|
digitalWrite(LEDpin, light);
|
|
|
|
|
|
humiditycontrol();
|
|
fogcontrol();
|
|
/////////////////////// atomizer toggle
|
|
|
|
|
|
|
|
Serial.println(int(humidityctrl));
|
|
Serial.print(F("fog state: "));
|
|
if (fogstate == 1){
|
|
Serial.println (F("active"));
|
|
}
|
|
else{
|
|
Serial.println (F("off"));
|
|
}
|
|
|
|
|
|
//////////////////
|
|
|
|
// SENSOR AND DISPLAY
|
|
display.clear();
|
|
|
|
// Delay between measurements.
|
|
delay(delayMS);
|
|
// Get temperature event and print its value.
|
|
sensors_event_t event;
|
|
dht.temperature().getEvent(&event);
|
|
if (isnan(event.temperature)) {
|
|
Serial.println(F("Error reading temperature!"));
|
|
}
|
|
else {
|
|
display.setFont(Monospaced_bold_16);
|
|
display.drawString(0, 10, "Temp:");
|
|
display.drawString(50, 10, String(int(event.temperature)) + " c" );
|
|
|
|
Serial.print(F("Temperature: "));
|
|
Serial.print(event.temperature);
|
|
Serial.println(F("°C"));
|
|
}
|
|
// Get humidity event and print its value.
|
|
dht.humidity().getEvent(&event);
|
|
if (isnan(event.relative_humidity)) {
|
|
Serial.println(F("Error reading humidity!"));
|
|
}
|
|
else {
|
|
display.setFont(Monospaced_bold_16);
|
|
display.drawString(0, 50, "Hum:");
|
|
display.drawString(50, 50, String(int(event.relative_humidity)) + " %");
|
|
|
|
Serial.print(F("Humidity: "));
|
|
Serial.print(event.relative_humidity);
|
|
Serial.println(F("%"));
|
|
Serial.println (int(event.relative_humidity));
|
|
Serial.println(fog);
|
|
}
|
|
|
|
|
|
display.display();
|
|
|
|
|
|
// printBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
////////////////////////////////////////////
|
|
void printBuffer(void) {
|
|
// Initialize the log buffer
|
|
// allocate memory to store 8 lines of text and 30 chars per line.
|
|
display.setLogBuffer(5, 30);
|
|
|
|
// Some test data
|
|
const char* test[] = {
|
|
"Hello",
|
|
"World" ,
|
|
"----",
|
|
"Show off",
|
|
"how",
|
|
"the log buffer",
|
|
"is",
|
|
"working.",
|
|
"Even",
|
|
"scrolling is",
|
|
"working"
|
|
};
|
|
|
|
for (uint8_t i = 0; i < 11; i++) {
|
|
display.clear();
|
|
// Print to the screen
|
|
display.println(test[i]);
|
|
// Draw it to the internal screen buffer
|
|
display.drawLogBuffer(0, 0);
|
|
// Display it on the screen
|
|
display.display();
|
|
delay(500);
|
|
}
|
|
|
|
}
|
|
|