From 2ef005fd1e68e406ad0b26e8a267a39ea3c76f80 Mon Sep 17 00:00:00 2001 From: 2005869 <67071821+2005869@users.noreply.github.com> Date: Tue, 27 Sep 2022 18:53:39 -0300 Subject: [PATCH] display capability --- hardware/.gitignore | 126 +++++++++++++++++++++++++++++++++ hardware/platformio.ini | 16 +++++ hardware/src/display/display.h | 75 ++++++++++++++++++++ hardware/src/main.cpp | 5 +- hardware/src/pinSettings.h | 5 +- 5 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 hardware/src/display/display.h diff --git a/hardware/.gitignore b/hardware/.gitignore index 89cc49c..c072775 100644 --- a/hardware/.gitignore +++ b/hardware/.gitignore @@ -3,3 +3,129 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch + + +# Created by https://www.toptal.com/developers/gitignore/api/c,c++,visualstudiocode,platformio,git +# Edit at https://www.toptal.com/developers/gitignore?templates=c,c++,visualstudiocode,platformio,git + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### C++ ### +# Prerequisites + +# Compiled Object files +*.slo + +# Precompiled Headers + +# Compiled Dynamic libraries + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai + +# Executables + +### Git ### +# Created by git for backups. To disable backups in Git: +# $ git config --global mergetool.keepBackup false +*.orig + +# Created by git when using merge tools for conflicts +*.BACKUP.* +*.BASE.* +*.LOCAL.* +*.REMOTE.* +*_BACKUP_*.txt +*_BASE_*.txt +*_LOCAL_*.txt +*_REMOTE_*.txt + +### PlatformIO ### +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json +.pio + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# Support for Project snippet scope +.vscode/*.code-snippets + +# Ignore code-workspaces +*.code-workspace + +# End of https://www.toptal.com/developers/gitignore/api/c,c++,visualstudiocode,platformio,git \ No newline at end of file diff --git a/hardware/platformio.ini b/hardware/platformio.ini index 9ea587d..f4800fc 100644 --- a/hardware/platformio.ini +++ b/hardware/platformio.ini @@ -20,6 +20,7 @@ lib_deps = knolleary/PubSubClient@^2.8 ESP8266WiFi@^1.0 bblanchon/ArduinoJson@^6.19.4 + thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.3.0 [env:nodemcu-32s] platform = espressif32 @@ -33,3 +34,18 @@ lib_deps = knolleary/PubSubClient@^2.8 ESP8266WiFi@^1.0 bblanchon/ArduinoJson@^6.19.4 + thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.3.0 + +[env:d1_mini] +platform = espressif8266 +board = d1_mini +framework = arduino +upload_port = /dev/ttyUSB0 +monitor_port = /dev/ttyUSB0 +lib_deps = + adafruit/DHT sensor library@^1.4.4 + adafruit/Adafruit Unified Sensor@^1.1.6 + knolleary/PubSubClient@^2.8 + ESP8266WiFi@^1.0 + bblanchon/ArduinoJson@^6.19.4 + thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.3.0 diff --git a/hardware/src/display/display.h b/hardware/src/display/display.h new file mode 100644 index 0000000..1ffb9de --- /dev/null +++ b/hardware/src/display/display.h @@ -0,0 +1,75 @@ +#include // Main Arduino Library +#include "pinSettings.h" // Pin Settings Setup + +// Features +#include "sensors/DHTxx.h" // DHTxx Sensor Code + + +//Display +#include +#include "SSD1306Wire.h" +#include +#include +#include + + + // vars to use with display + String textTemperatureComplete; + String textHumidityComplete; + String textMACComplete; + + +SSD1306Wire display(0x3c, D6, D5, GEOMETRY_128_64); + + +void startDisplay() +{ + display.init(); + display.flipScreenVertically(); +} + + +void refreshDisplay() +{ + // display lines + delay(2000); + display.clear(); // only first time in loop + display.setTextAlignment(TEXT_ALIGN_LEFT); + + // MACADRESS + display.setFont(ArialMT_Plain_10); + textMACComplete += espClientMAC; + if (textMACComplete == "") + { + textMACComplete += "Not Conected"; + } + display.drawString(10, 0, textMACComplete); + Serial.print("MACADRESS: "); + Serial.println(textMACComplete); + display.display(); + textMACComplete = ""; + + // Temperature + display.setFont(ArialMT_Plain_16); + + + + textTemperatureComplete += DHTxxTemperature; + textTemperatureComplete += " ÂșC"; + display.drawString(20, 20, textTemperatureComplete); + display.display(); + textTemperatureComplete = ""; + + // Humidity + display.setFont(ArialMT_Plain_16); + + textHumidityComplete += DHTxxHumidity; + textHumidityComplete += " %"; + display.drawString(70, 40, textHumidityComplete); + display.display(); + textHumidityComplete = ""; + + Serial.println(textTemperatureComplete); + Serial.println(textHumidityComplete); + +} \ No newline at end of file diff --git a/hardware/src/main.cpp b/hardware/src/main.cpp index 891d6ad..c6da3d4 100644 --- a/hardware/src/main.cpp +++ b/hardware/src/main.cpp @@ -6,6 +6,7 @@ #include "sensors/DHTxx.h" // DHTxx Sensor Code #include "wifi/wifi.h" // Wifi Connection #include "mqtt/mqtt.h" // MQTT Code +#include "display/display.h" //Display Code void setup() { @@ -15,6 +16,7 @@ void setup() { DHTxxSetup(); // DHTxx Sensor Setup wifiConnect(); // Wifi Connection mqttConnect(); // MQTT Setup + startDisplay(); // Start and configure display } @@ -23,5 +25,6 @@ void loop() { DHTxxRead(); // DHTxx Sensor Readings DHTxxSerialPrint(); // DHTxx Sensor Serial Print mqttPublish(); // MQTT Publish - + refreshDisplay(); // Show MAC, temperature and humidity in display + } \ No newline at end of file diff --git a/hardware/src/pinSettings.h b/hardware/src/pinSettings.h index faf8e8d..c03dff2 100644 --- a/hardware/src/pinSettings.h +++ b/hardware/src/pinSettings.h @@ -6,7 +6,10 @@ // For ESP8266 use pins 3, 4, 5, 12, 13 or 14 -- // ---------------------------------------------- - #define DHTPIN D3 + #define DHTPIN D3 // Pin for DHT Sensor + #define SDLPIN D5 // Pin for display + #define SDAPIN D6 // Pin for display + // Pin Settings Setup