From d814d16733667baf5a05a3ad16154d70f6f15ccd Mon Sep 17 00:00:00 2001 From: Clement Date: Sun, 14 May 2023 09:05:23 +0200 Subject: [PATCH 1/4] feat: add oled screen lib --- IOT/lib/OledScreen/include/OledScreen.h | 53 +++++++++++++++++ IOT/lib/OledScreen/src/OledScreeen.cpp | 76 +++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 IOT/lib/OledScreen/include/OledScreen.h create mode 100644 IOT/lib/OledScreen/src/OledScreeen.cpp diff --git a/IOT/lib/OledScreen/include/OledScreen.h b/IOT/lib/OledScreen/include/OledScreen.h new file mode 100644 index 0000000..7870b00 --- /dev/null +++ b/IOT/lib/OledScreen/include/OledScreen.h @@ -0,0 +1,53 @@ +#ifndef OLED_SCREEN_H +#define OLED_SCREEN_H + +#include + + +class OledScreen { +public: + + /** + * @brief Construct a new Oled Screen object + * + * @param screenWidth The width of the screen + * @param screenHeight The height of the screen + * @param oledResetPin The pin used to reset the screen (default: -1) + */ + OledScreen(int screenWidth, int screenHeight, int oledResetPin = -1); + + /** + * @brief display welcome screen + */ + void welcome(); + + /** + * @brief print the total amount on the screen + * + * @param amount The total amount to print in centimes + */ + void printAmount(int amount); + + + /** + * @brief Clear the screen + */ + void clear(); + + /** + * @brief messsage for wifi waiting + * + */ + void wifiWaiting(); + + + void printVal(String distance, String poid, String humitemp); + +private: + + Adafruit_SSD1306* display; + +}; + + +#endif \ No newline at end of file diff --git a/IOT/lib/OledScreen/src/OledScreeen.cpp b/IOT/lib/OledScreen/src/OledScreeen.cpp new file mode 100644 index 0000000..c88b6b2 --- /dev/null +++ b/IOT/lib/OledScreen/src/OledScreeen.cpp @@ -0,0 +1,76 @@ +#include "../include/OledScreen.h" + +OledScreen::OledScreen(int screenWidth, int screenHeight, int oledResetPin) { + this->display = new Adafruit_SSD1306(screenWidth, screenHeight, &Wire, oledResetPin); + if (!display->begin(SSD1306_SWITCHCAPVCC, 0x3C)) { + Serial.println(F("SSD1306 allocation failed")); + for (;;); // Don't proceed, loop forever + } + this->display->clearDisplay(); +} + +void OledScreen::welcome() { + this->display->clearDisplay(); + this->display->setCursor(0, 0); + this->display->setTextSize(2); + this->display->setTextColor(WHITE); + this->display->println(F("\nBienvenue!")); + this->display->display(); +} + +void OledScreen::printVal(String distance, String poid, String humitemp){ + this->display->clearDisplay(); + this->display->setCursor(0, 0); + this->display->setTextSize(2); + this->display->setTextColor(WHITE); + this->display->print(F("Dist:")); + this->display->print(distance); + this->display->println(); + this->display->print(F("Poids:")); + this->display->print(poid); + this->display->println(); + this->display->print(F("humi:")); + this->display->print(humitemp.substring(0,humitemp.indexOf("/"))); + this->display->println(); + this->display->print(F("temp:")); + this->display->print(humitemp.substring(humitemp.indexOf("/")+1,humitemp.length())); + this->display->println(); + this->display->display(); +} + + + +void OledScreen::printAmount(int amount) { + this->display->clearDisplay(); + this->display->setCursor(0, 0); + this->display->setTextSize(2); + this->display->setTextColor(WHITE); + this->display->println(F(" Total: ")); + this->display->println(); + + this->display->print(amount / 100); + this->display->print(F(",")); + int centimes = amount % 100; + if (centimes < 10) { + this->display->print(F("0")); + } + this->display->println(centimes); + this->display->print(F(" EUR")); + this->display->display(); +} + + +void OledScreen::wifiWaiting() { + this->clear(); + this->display->setCursor(0, 0); + this->display->setTextSize(2); + this->display->setTextColor(WHITE); + this->display->println(F("Connection\n")); + this->display->println(F(" WiFi...\n")); + this->display->println(); + this->display->display(); +} + +void OledScreen::clear() { + this->display->clearDisplay(); +} \ No newline at end of file From f2bd530d4ee16e8f7bf0ebe5999d708ca1ae4040 Mon Sep 17 00:00:00 2001 From: Clement Date: Sun, 14 May 2023 09:05:57 +0200 Subject: [PATCH 2/4] feat: add config and oled screen lib --- IOT/config.ini | 9 +++++++++ IOT/platformio.ini | 1 + 2 files changed, 10 insertions(+) diff --git a/IOT/config.ini b/IOT/config.ini index f08cdf3..0481ac1 100644 --- a/IOT/config.ini +++ b/IOT/config.ini @@ -14,6 +14,14 @@ build_flags = -D MONITOR_SPEED=${config.monitor_speed} ; DO NOT TOUCH --- END + ; taille ecran oled + ; 3,3v + -D OLED_WIDTH=128 + -D OLED_HEIGHT=64 + ; pin de reset de l'ecran oled + -D OLED_RESET=-1 + + ; DHT pin and type ; 5v -D DHTTYPE=\"DHT11\" @@ -25,6 +33,7 @@ build_flags = -D ULTRA_SOUND_ECHO=13 ; Capteur poids + ; 3,3v -D POID_DOUT=14 -D POID_SCK=15 diff --git a/IOT/platformio.ini b/IOT/platformio.ini index c0a72ad..ecb8e44 100644 --- a/IOT/platformio.ini +++ b/IOT/platformio.ini @@ -42,6 +42,7 @@ lib_deps = adafruit/Adafruit Unified Sensor@^1.1.9 ; adafruit sensor lib (required by DHT11) ericksimoes/Ultrasonic@^3.0.0 ; lib capteur ultra son bogde/HX711@0.7.5 ; lib pour la balance + adafruit/Adafruit SSD1306@^2.5.7 ; librairie pour l'ecran oled ; example: ; erropix/ESP32 AnalogWrite@^0.2 From b0c90360b80495c2ac6849f187cdf58c82be5fa6 Mon Sep 17 00:00:00 2001 From: Clement Date: Sun, 14 May 2023 09:06:08 +0200 Subject: [PATCH 3/4] feat: use oled screen lib --- IOT/include/Program.h | 7 +++++++ IOT/src/Program.cpp | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/IOT/include/Program.h b/IOT/include/Program.h index 075a386..4edd211 100644 --- a/IOT/include/Program.h +++ b/IOT/include/Program.h @@ -10,6 +10,7 @@ #include "Ultrason.h" #include "HumiTemp.h" #include "Balance.h" +#include "OledScreen.h" class Program{ public: @@ -46,6 +47,12 @@ private: */ Capteur *balance; + /** + * @brief OledScreen + * + */ + OledScreen* screen; + /** * @brief Réference de l'API pour les calls * diff --git a/IOT/src/Program.cpp b/IOT/src/Program.cpp index b7eb6d1..d2afe08 100644 --- a/IOT/src/Program.cpp +++ b/IOT/src/Program.cpp @@ -6,6 +6,10 @@ Program::Program(){ Serial1.begin(MONITOR_SPEED); Serial.begin(MONITOR_SPEED); + //////Oled Screen///// + this->screen = new OledScreen(OLED_WIDTH, OLED_HEIGHT, OLED_RESET); + this->screen->wifiWaiting(); + ////////API/////// this->api = new API(USER_NAME, USER_PASSWORD, API_HOST); this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1); @@ -16,12 +20,17 @@ Program::Program(){ this->dht = new HumiTemp(DHTPIN, DHTTYPE, DHT_FULL); this->balance = new Balance(POID_DOUT,POID_SCK, POID_FULL); this->balance->tar(1077); + + this->screen->clear(); } void Program::loop(){ String distance = this->ultrasonic->read(); String humitemp = this->dht->read(); String poid = this->balance->read(); + + + this->screen->printVal(distance, poid, humitemp); this->api->sendValue(distance, TRASHCAN_ONE, this->ultrasonic->getValType(), this->ultrasonic->isFull()); Serial.print("Distance in CM = " + distance); From b9b6d71ba041d99a3eaaa68f1aca1fda05c41152 Mon Sep 17 00:00:00 2001 From: Clement Date: Sun, 14 May 2023 09:09:13 +0200 Subject: [PATCH 4/4] feat: commentaire for doc --- IOT/lib/OledScreen/include/OledScreen.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/IOT/lib/OledScreen/include/OledScreen.h b/IOT/lib/OledScreen/include/OledScreen.h index 7870b00..d2a7f6e 100644 --- a/IOT/lib/OledScreen/include/OledScreen.h +++ b/IOT/lib/OledScreen/include/OledScreen.h @@ -40,7 +40,13 @@ public: */ void wifiWaiting(); - + /** + * @brief show the sensor value + * + * @param distance length value + * @param poid weith value + * @param humitemp humidity and temperature value + */ void printVal(String distance, String poid, String humitemp); private: