bonjour à tous,
je vous présente mon projet qui sera calqué sur la base d'un projet déjà créer la source est:
je voudrais déjà avoir votre avis sur le code et si ce projet intéresse du monde dans la communauté Arduino/aquariophilie
pour info j'ai des bases de programmation mais pas en C++ ![]()
j'arrive à comprendre le code mais par contre il me faut tout apprendre (langage)
dite moi si les commentaires en français laissé sur le code sont correctes
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h> // je sais pas pourquoi
#include <Ethernet.h> // librairie du ethernet du mega si je me trompe pas
#include <BlynkSimpleEthernet.h> // librairie du ethernet de blynk
char auth[] = ""; //Insert auth token between the " " // mot de passe pour se connecter a blynk a récupérer sur l'application
#include <SimpleTimer.h> //here is the SimpleTimer library // librairie horloge
SimpleTimer timer; // Create a Timer object called "timer"!
#include <LiquidCrystal.h>//LCD library //librairie pour le LDC 16X2 peut evolution de ce cote par la suite en ecran tactile
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const byte pHpin = A8; // Connect the sensor's Po output to an analogue pin - whichever one you choose // entrée de la sonde PH
const int relayPin = 38; //Connect to the relay that will control the power to a pH regulating pump or valve // sortie pour la commande du relay et electrovanne
//The ethernet button is used to tell the arduino board if it's connected to the internet through the ethernet cable or not. If the button is turned off, then it won't spend time trying to connect to the server.
int inPin = 22; //Just wire this pin dirrectly to GND if you want to leave ethernet constantly on. If you want to test the code before connecting to the servers, leave the pin disconnected.
int ethbutton = digitalRead(inPin); // utilisation ou non du réseau Ethernet peut être évolution avec du Wifi
WidgetLED led1(V7); //Connect a LED widget to Virtual pin 7 in the app // led affiché sur l'appli blynk CO2 on/off
int pinA = 40; // Connected to CLK on KY-040 Rotary Encoder //entrée pour réglage de horloge ou étalonnage sonde ??
int pinB = 42; // Connected to DT on KY-040 Rotary Encoder // entrée pour réglage de horloge ou étalonnage sonde ??
//SW(button) pin on KY-040 is not used
float encoderPosCount = 80; //default setpoint at startup set to 8.0 // entrée pour réglage de horloge ou étalonnage sonde ??
int pinALast; // derniere valeur relevé pour la calibration ou horloge
int aVal; // je ne sait pas
boolean bCW; // je ne sait pas
// Variables:- // varible utilisé pour la calibration de la sonde
float Po;
float pH = 10;
//position du reglage PH sur l'apli blink pin virtuel sur l'appli blink
BLYNK_WRITE(3){
encoderPosCount = param.asInt(); //Connect a slider widget to virtual pin 3 in the app. Slider range should be 0 to 140.
}
// calibration de la sonde
void ph(){
Po = (1023 - analogRead(pHpin));
Serial.print(Po); //This is the raw voltage value for the pH module // valeur des tensions correspondant au PH mesuré suivant les caractéristique de la sonde utilisé
//Calibration values:
//405@pH7
//290@ph4
// affichage des valeur sur LCD 16x2
Serial.print(", ph =");
float pHm = map(Po, 290, 406, 400, 700); //maps voltage(Po) from calibration values at 4.00 and 7.00 pH
float pH = (pHm/100);
Serial.println(pH, 2);
lcd.setCursor(0, 0);
lcd.print("pH: "); //Print pH value to the LCD
lcd.setCursor(3, 0);
lcd.print(pH);
lcd.setCursor(0, 1);
lcd.print("Setpoint:");
Serial.println(", setpoint=");
Serial.println((encoderPosCount/10));
Blynk.virtualWrite(V0, pH);
if (pH > (encoderPosCount/10)) //This if/else statement turns the valve on if the pH value is above the setpoint, or off if it's below the setpoint. Modify according to your need.
{ // commande du relay pour le CO2 + changement affichage des valeur du PH sur le LCD 16x2
digitalWrite(relayPin, HIGH);
lcd.setCursor(8, 0);
lcd.print("CO2:ON*");
led1.on();
}
else
{
digitalWrite(relayPin, LOW);
lcd.setCursor(8, 0);
lcd.print("CO2:OFF");
led1.off();
}
}
//point de consigne demandé récupéré sur l'apli blink et retransmis sur l'arduino
void blynker() {//Writes the setpoint value to a gague widget.Connect the gague widget to virtual pin 1
Blynk.virtualWrite(V1, (encoderPosCount/10));
}
void encoder(){ //function for reading values from the rotary encoder // la je sais pas peut être pour la calibration potentiomètre KY-040 et affichage sur LCd 16x2
aVal = digitalRead(pinA);
if (aVal != pinALast){ // Means the knob is rotating
// if the knob is rotating, we need to determine direction
// We do that by reading pin B.
if (digitalRead(pinB) != aVal) { // Means pin A Changed first - We're Rotating Clockwise
encoderPosCount ++;
bCW = true;
lcd.setCursor(10, 1);
lcd.print((encoderPosCount/10));
} else {// Otherwise B changed first and we're moving CCW
bCW = false;
encoderPosCount--;
lcd.setCursor(10, 1);
lcd.print((encoderPosCount/10));
}
Serial.print ("Rotated: ");
if (bCW){
Serial.println ("clockwise");
}else{
Serial.println("counterclockwise");
}
if (encoderPosCount > 139)
{
encoderPosCount = 139;
}
if (encoderPosCount < 1)
{
encoderPosCount = 1;
}
Serial.print("Encoder Position: ");
Serial.println(encoderPosCount);
}
pinALast = aVal;
}
void setpointwriter() { //Writes the setpoint to the LCD // écriture de la valeur du ph sur le LCD 16x22
lcd.setCursor(10, 1);
lcd.print((encoderPosCount/10));
}
// initialisation du système
void setup(){
Serial.begin(9600); // initialize serial communications at 9600 bps // initialisation vitesse du port ethenet
lcd.begin(16, 2); // set up the LCD's number of columns and rows: // initialisation Du LCD 16X2
pinMode(relayPin, OUTPUT); // le relay est une sortie
timer.setInterval(5000, ph); // je sait pas
pinMode(inPin, INPUT_PULLUP); // inpin est une entrée pullup je sait pas
pinMode(13, OUTPUT); // pin 13 est une entrée je ne sait pas ce que cette entrée active
if (ethbutton == LOW) {
Blynk.begin(auth, "blynk-cloud.com"); // initialisation authentification Blink
timer.setInterval(2000, blynker); //the number for the timers sets the interval for how frequently the function is called. Keep it above 1000 to avoid spamming the server. //fréquence de rafraichissement
}
timer.setInterval(10000, ph);
timer.setInterval(2000, setpointwriter);
}
// activation désactivation réseau Ethernet entrée 22
void loop(){
if (ethbutton == LOW) {
Blynk.run();
}
encoder();
timer.run();
}
pour info je n’ai pas le matériel en possession et que je vais vite en besogne
car à la place du LCD je voudrai y mettre un écran tactile pour que la supervision soit plus joli et y faire les réglages directement dessus (comme le genre d'interface graphique que l'on peut retrouver sur blink)
pour cela es ce possible et comment le rajouter dans le code déjà écrit ? et avec quel logiciel utilisez vous pour réaliser les interfaces graphiques pour les écrans tactile ?
je voudrais aussi rajouté un module wifi et/ou Bluetooth pour la diversité de connexion et interaction avec d'autre appareils (pareil comment rajouter le code dans le code déjà écrit ?)
je sais je que j'en demande beaucoup car je débute mais j’apprends vite si vous prenez le temps de m’expliquer
merci d'avance pour vos réponses
Matchang