Merge pull request 'feat: capteur_balance' (#35) from feat/balance into master
Reviewed-on: Epitech-T-DEV-811/T-DEV-811#35 Reviewed-by: nico <nicolas.sansd@gmail.com>
This commit is contained in:
commit
19ae3cf10f
@ -24,9 +24,15 @@ build_flags =
|
|||||||
-D ULTRA_SOUND_TRIGD=12
|
-D ULTRA_SOUND_TRIGD=12
|
||||||
-D ULTRA_SOUND_ECHO=13
|
-D ULTRA_SOUND_ECHO=13
|
||||||
|
|
||||||
; API host url
|
; Capteur poids
|
||||||
-D API_HOST=\"iot.epi.cb85.software\"
|
-D POID_DOUT=14
|
||||||
|
-D POID_SCK=15
|
||||||
|
|
||||||
|
-D MOYENNE_CALIBRATION=20
|
||||||
|
|
||||||
|
|
||||||
; trash can ID
|
; trash can ID
|
||||||
-D TRASHCAN_ONE=\"gdnuxl0wlgurtj3\"
|
-D TRASHCAN_ONE=\"gdnuxl0wlgurtj3\"
|
||||||
|
-D TRASHCAN_TWO=\"4brip5fwm001bs9\"
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
#include <DHT.h>
|
#include <DHT.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Ultrasonic.h>
|
#include <Ultrasonic.h>
|
||||||
|
|
||||||
#include "API.h"
|
#include "API.h"
|
||||||
|
#include "Balance.h"
|
||||||
|
|
||||||
class Program{
|
class Program{
|
||||||
public:
|
public:
|
||||||
@ -35,6 +37,13 @@ private:
|
|||||||
*/
|
*/
|
||||||
Ultrasonic *ultrasonic;
|
Ultrasonic *ultrasonic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief capteur poid pour le niveau de remplissage de la poubelle
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Balance *balance;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Réference de l'API pour les calls
|
* @brief Réference de l'API pour les calls
|
||||||
*
|
*
|
||||||
|
80
IOT/lib/Balance/include/Balance.h
Normal file
80
IOT/lib/Balance/include/Balance.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#ifndef BALANCE_H
|
||||||
|
#define BALANCE_H
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <HX711.h>
|
||||||
|
|
||||||
|
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
|
62
IOT/lib/Balance/src/Balance.cpp
Normal file
62
IOT/lib/Balance/src/Balance.cpp
Normal file
@ -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);
|
||||||
|
}
|
@ -41,6 +41,7 @@ lib_deps =
|
|||||||
adafruit/DHT sensor library@^1.4.4 ; DHT11 lib
|
adafruit/DHT sensor library@^1.4.4 ; DHT11 lib
|
||||||
adafruit/Adafruit Unified Sensor@^1.1.9 ; adafruit sensor lib (required by DHT11)
|
adafruit/Adafruit Unified Sensor@^1.1.9 ; adafruit sensor lib (required by DHT11)
|
||||||
ericksimoes/Ultrasonic@^3.0.0 ; lib capteur ultra son
|
ericksimoes/Ultrasonic@^3.0.0 ; lib capteur ultra son
|
||||||
|
bogde/HX711@0.7.5 ; lib pour la balance
|
||||||
; example:
|
; example:
|
||||||
; erropix/ESP32 AnalogWrite@^0.2
|
; erropix/ESP32 AnalogWrite@^0.2
|
||||||
|
|
||||||
|
@ -3,14 +3,22 @@
|
|||||||
int distance;
|
int distance;
|
||||||
|
|
||||||
|
|
||||||
Program::Program(){
|
Program::Program()
|
||||||
Serial1.begin(MONITOR_SPEED);
|
// Serial
|
||||||
Serial.begin(MONITOR_SPEED);
|
Serial.begin(MONITOR_SPEED); // motitor pour debug
|
||||||
|
Serial1.begin(MONITOR_SPEED); // port serie pour l'esp
|
||||||
|
|
||||||
// INIT OBJ
|
///////INITIALISATION OBJ//////
|
||||||
this->dht = new DHT(DHTPIN, DHTTYPE);
|
|
||||||
this->api = new API(USER_NAME, USER_PASSWORD, API_HOST);
|
this->api = new API(USER_NAME, USER_PASSWORD, API_HOST);
|
||||||
this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO);
|
this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO);
|
||||||
|
this->balance = new Balance(POID_DOUT,POID_SCK);
|
||||||
|
this->dht = new DHT(DHTPIN, DHTTYPE);
|
||||||
|
///////INITIALISATION OK//////
|
||||||
|
|
||||||
|
Serial.print("start calibr : ");
|
||||||
|
this->balance->initCalibration();
|
||||||
|
this->balance->setCalibrationFact(1077);
|
||||||
|
Serial.println("OK");
|
||||||
|
|
||||||
//this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
|
//this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
|
||||||
dht->begin();
|
dht->begin();
|
||||||
@ -19,12 +27,14 @@ Program::Program(){
|
|||||||
void Program::loop(){
|
void Program::loop(){
|
||||||
distance = this->ultrasonic->read();
|
distance = this->ultrasonic->read();
|
||||||
|
|
||||||
|
|
||||||
//TODO: envoyer les infos des capteur par la suite
|
//TODO: envoyer les infos des capteur par la suite
|
||||||
|
|
||||||
Serial.println("Temperature = " + String(dht->readTemperature())+" °C");
|
Serial.println("Temperature = " + String(dht->readTemperature())+" °C");
|
||||||
Serial.println("Humidite = " + String(dht->readHumidity())+" %");
|
Serial.println("Humidite = " + String(dht->readHumidity())+" %");
|
||||||
|
|
||||||
//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); //TODO: faire estimation poubelle plenne
|
||||||
Serial.print("Distance in CM: ");
|
Serial.print("Distance in CM: ");
|
||||||
Serial.println(distance);
|
Serial.println(distance);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
@ -1,16 +1,47 @@
|
|||||||
#ifndef TESTING
|
#ifndef TESTING
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#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() {
|
void setup() {
|
||||||
program = new Program();
|
program = new Program();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
program->loop();
|
// delay(500);
|
||||||
|
Serial.println(balance->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user