From 3a37f93ef7f329d33eb6e17c5102042a4dfb5b35 Mon Sep 17 00:00:00 2001 From: Clement Date: Tue, 11 Apr 2023 12:32:49 +0200 Subject: [PATCH 1/6] feat/add config --- IOT/config.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/IOT/config.ini b/IOT/config.ini index 11acf53..1ceb4e3 100644 --- a/IOT/config.ini +++ b/IOT/config.ini @@ -16,5 +16,6 @@ build_flags = -D API_HOST=\"iot.epi.cb85.software\" - -D EXAMPLE_NUMBER=69 + -D MOYENNE_CALIBRATION=20 + From ca61a66ca6a0bbd82d3c6c81c3d6245241d3c8d6 Mon Sep 17 00:00:00 2001 From: Clement Date: Tue, 11 Apr 2023 12:33:05 +0200 Subject: [PATCH 2/6] feat/ add lib HX711 --- IOT/platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/IOT/platformio.ini b/IOT/platformio.ini index c06a691..469c5e7 100644 --- a/IOT/platformio.ini +++ b/IOT/platformio.ini @@ -38,6 +38,7 @@ monitor_flags = lib_deps = bportaluri/WiFiEsp@^2.2.2 ; gestion des commande 'AT' de l'esp01 arduino-libraries/Arduino_JSON@^0.2.0 ; gestion des json + bogde/HX711@0.7.5 ; lib pour la balance ; example: ; erropix/ESP32 AnalogWrite@^0.2 From d63eff681ee99482c33b1ca1f9e6e1aea9c457f9 Mon Sep 17 00:00:00 2001 From: Clement Date: Tue, 11 Apr 2023 12:35:25 +0200 Subject: [PATCH 3/6] add Balance lib --- IOT/lib/Balance/include/Balance.h | 80 +++++++++++++++++++++++++++++++ IOT/lib/Balance/src/Balance.cpp | 62 ++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 IOT/lib/Balance/include/Balance.h create mode 100644 IOT/lib/Balance/src/Balance.cpp diff --git a/IOT/lib/Balance/include/Balance.h b/IOT/lib/Balance/include/Balance.h new file mode 100644 index 0000000..ad5ef1f --- /dev/null +++ b/IOT/lib/Balance/include/Balance.h @@ -0,0 +1,80 @@ +#ifndef BALANCE_H +#define BALANCE_H +#include +#include + +class Balance { + +public: + + /** + * @brief constructeur + * + * @param doutPin : pin DOUT du module HX711 + * + * @param sckPin : pin horloge du module HX711 + * + * @param poidsRef : valeur de poids posée sur la balance ref en grammes + */ + Balance(int doutPin, int sckPin); + + /** + * @brief determine le poids + * + * @return poids (double) + */ + double getValue(); + + /** + * @brief determine la moyenne poids + * + * @param nbMesure : nombre de mesure effectues pour la moyenne + * + * @return moyenne poids (double) + */ + double getAverage(int nbMesure); + + /** + * @brief tare et scale a 0, et recuperation de la valeur brut du plateau + */ + boolean initCalibration(); + + /** + * @brief initialisation du calibrage + * + * @param[in] poidsRef : poid de reférence pour la calibration + * @param[in] moyenne_calibration : nombre de valeurs a lire pour une mesure + * + * @return renvoi un true si calibration bien effectue + */ + boolean calibration(int poidsRef,int moyenne_calibration); + + //TODO: faire doc setCalibration fact + void setCalibrationFact(int caliFact); + + +private: + + /** + * @brief true = calibration et false = erreur + */ + boolean initialized; + + /** + * @brief Facteur de calibration obtenu par : (val brute poids ref - val brute poids plexiglas)/ poids ref + */ + int calibrationFact; + + /** + * @brief Variable issue de la librairie HX711 qui permet d'utiliser les fonctions de celle-ci + */ + HX711 scale; + + /** + * @brief Valeur moyenne brute du poids sans rien sur la balance juste le plexiglas + */ + long initialVal; + +}; + +#endif diff --git a/IOT/lib/Balance/src/Balance.cpp b/IOT/lib/Balance/src/Balance.cpp new file mode 100644 index 0000000..9858416 --- /dev/null +++ b/IOT/lib/Balance/src/Balance.cpp @@ -0,0 +1,62 @@ +#include "../include/Balance.h" + +Balance::Balance(int doutPin, int sckPin) { + + scale.begin(doutPin, sckPin); + this->initialized = false; + scale.set_scale(); + scale.tare(); + this->initialVal = 0; + this->calibrationFact = 0; +} + +boolean Balance::initCalibration() { + + scale.set_scale(); + scale.tare(); + this->initialVal = scale.read_average(20); + return true; +} + +boolean Balance::calibration(int poidsRef,int moyenne_calibration) { + + int rawValref = 0; // Valeur brute de plexiglas et poids réf + int tempPoids = 0; // C'est la valeur du poids en grammes calculée grâce au facteur de calibration + + rawValref = scale.read_average(moyenne_calibration); + this->calibrationFact = (rawValref - this->initialVal) / poidsRef; + do { + scale.set_scale(calibrationFact); + tempPoids = scale.get_units(5); + if (tempPoids < poidsRef) { + calibrationFact -= 1; + } else if (tempPoids > poidsRef) { + calibrationFact += 1; + } + } while (tempPoids != poidsRef); + return initialized = true; +} + +double Balance::getAverage(int nbMesure) { + + if (initialized == true) { + return scale.get_units(nbMesure); + } else { + return 0; + } +} + +double Balance::getValue() { + + if (initialized == true) { + return scale.get_units(); + } else { + return 0; + } +} + +void Balance::setCalibrationFact(int caliFact){ + this->initialized = true; + this->calibrationFact = caliFact; + scale.set_scale(caliFact); +} From 2fefc9f96d5ec3b05897f6ea1d08d2b457f0cbe6 Mon Sep 17 00:00:00 2001 From: Clement Date: Tue, 11 Apr 2023 12:54:53 +0200 Subject: [PATCH 4/6] feat: test capteur poids OK --- IOT/src/main.cpp | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/IOT/src/main.cpp b/IOT/src/main.cpp index 14f34bd..a5531c1 100644 --- a/IOT/src/main.cpp +++ b/IOT/src/main.cpp @@ -1,12 +1,41 @@ #include -#include "Program.h" +// #include "Program.h" -Program* program; +// Program* program; + +// void setup() { +// program = new Program(); +// } + +// void loop() { +// program->loop(); +// } + + +#include "Balance.h" + +Balance *balance; + +void setup(){ + Serial.begin(MONITOR_SPEED); + balance = new Balance(14,15); + + Serial.print("start calibr : "); + balance->initCalibration(); + + Serial.println("OK"); + + // Serial.print("posé poids"); + // delay(5000); + // Serial.println("OK"); + // balance->calibration(500, MOYENNE_CALIBRATION); + // Serial.println("END calibration"); + + balance->setCalibrationFact(1077); -void setup() { - program = new Program(); } -void loop() { - program->loop(); -} +void loop(){ + // delay(500); + Serial.println(balance->getValue()); +} \ No newline at end of file From c40be321fbaa77842218ba384446522ed0488510 Mon Sep 17 00:00:00 2001 From: Clement Date: Tue, 2 May 2023 10:11:11 +0200 Subject: [PATCH 5/6] feat: balance pin config --- IOT/config.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/IOT/config.ini b/IOT/config.ini index 4d53ba5..4ae1361 100644 --- a/IOT/config.ini +++ b/IOT/config.ini @@ -19,9 +19,13 @@ build_flags = -D ULTRA_SOUND_TRIGD=12 -D ULTRA_SOUND_ECHO=13 + -D POID_DOUT=14 + -D POID_SCK=15 + -D MOYENNE_CALIBRATION=20 -D TRASHCAN_ONE=\"gdnuxl0wlgurtj3\" + -D TRASHCAN_TWO=\"4brip5fwm001bs9\" From 69bd4f57e30e1f2302df4d02a7ac56ac9c81045c Mon Sep 17 00:00:00 2001 From: Clement Date: Tue, 2 May 2023 10:11:22 +0200 Subject: [PATCH 6/6] add balance to main program --- IOT/include/Program.h | 9 +++++++++ IOT/src/Program.cpp | 20 ++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/IOT/include/Program.h b/IOT/include/Program.h index 549809b..9e34e98 100644 --- a/IOT/include/Program.h +++ b/IOT/include/Program.h @@ -3,7 +3,9 @@ #include #include + #include "API.h" +#include "Balance.h" class Program{ public: @@ -28,6 +30,13 @@ private: */ Ultrasonic *ultrasonic; + /** + * @brief capteur poid pour le niveau de remplissage de la poubelle + * + */ + Balance *balance; + + /** * @brief Réference de l'API pour les calls * diff --git a/IOT/src/Program.cpp b/IOT/src/Program.cpp index 710d302..8235270 100644 --- a/IOT/src/Program.cpp +++ b/IOT/src/Program.cpp @@ -4,18 +4,30 @@ int distance; Program::Program(){ + Serial.begin(MONITOR_SPEED); //motitor pour debug + Serial1.begin(MONITOR_SPEED); //port serie pour l'esp + + ///////INITIALISATION OBJ////// this->api = new API(USER_NAME, USER_PASSWORD, API_HOST); - Serial1.begin(MONITOR_SPEED); + this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO); + this->balance = new Balance(POID_DOUT,POID_SCK); + ///////INITIALISATION OK////// + this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1); - Serial.begin(MONITOR_SPEED); - this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO); + Serial.print("start calibr : "); + this->balance->initCalibration(); + Serial.println("OK"); + + this->balance->setCalibrationFact(1077); } void Program::loop(){ distance = this->ultrasonic->read(); - this->api->sendValue(JSONVar::stringify(distance), TRASHCAN_ONE, "W", false); + + //this->api->sendValue(JSONVar::stringify(distance), TRASHCAN_ONE, "W", false); //TODO: faire estimation poubelle plenne + this->api->sendValue(this->balance->getValue(), TRASHCAN_TWO, ,false) Serial.print("Distance in CM: "); Serial.println(distance); delay(10000);