Bonjour,
J'utilise un capteur de pH : https://wiki.dfrobot.com/Gravity__Analog_pH_Sensor_Meter_Kit_V2_SKU_SEN0161-V2
Dans le programme de base, pour calibrer le capteur, il faut saisir dans le moniteur série "ENTERPH" (entrée en mode calibrage) puis CALPH (pour calibrer) et enfin EXITPH (pour quitter et sauvegarder).
La documentation se trouve https://github.com/DFRobot/DFRobot_PH
Dans mon projet, je souhaite utiliser des boutons poussoirs pour calibrer l'appareil : il faut donc programmer l'envoi dans le moniteur série des textes cités précédemment. J'ai essayé avec Serial.println("ENTERPH") mais le texte s'affiche dans le moniteur série mais n'a pas l'air d'être traité comme si j'avais saisi ce texte au clavier. Je suppose donc que la commande envoyée avec Serial.println ne fait qu'afficher un texte sans être "évalué" par le moniteur série.
Mon code :
/*
file DFRobot_PH.ino
@ https://github.com/DFRobot/DFRobot_PH
This is the sample code for Gravity: Analog pH Sensor / Meter Kit V2, SKU:SEN0161-V2
In order to guarantee precision, a temperature sensor such as DS18B20 is needed, to execute automatic temperature compensation.
You can send commands in the serial monitor to execute the calibration.
Serial Commands:
enterph -> enter the calibration mode
calph -> calibrate with the standard buffer solution, two buffer solutions(4.0 and 7.0) will be automaticlly recognized
exitph -> save the calibrated parameters and exit from calibration mode
Copyright [DFRobot](http://www.dfrobot.com), 2018
Copyright GNU Lesser General Public License
version V1.0
date 2018-04
*/
#include "DFRobot_PH2.h"
#include <EEPROM.h>
#define PH_PIN A2
#define pinBoutonEnter 2 //bouton ENTER
#define pinBoutonCal 4 //bouton CAL
#define pinBoutonExit 7 //bouton EXIT
//DEFINITION DES VARIABLES DE TEST POUR LA CALIBRATION DU CAPTEUR (transformation de l'appui d'un bouton en l'envoi d'une commande, voir la bibliotheque)
boolean lastBoutonEnter = HIGH; //variable pour connaître l'état du bouton Enter lors du dernier appui
boolean lastBoutonCal = HIGH; //variable pour connaître l'état du bouton Cal lors du dernier appui
boolean lastBoutonExit = HIGH; //variable pour connaître l'état du bouton Exit lors du dernier appu
boolean etatBoutonEnter; //variable pour connaître l'état courant du bouton Enter lors du dernier appui
boolean etatBoutonCal; //variable pour connaître l'état courant du bouton Cal lors du dernier appui
boolean etatBoutonExit; //variable pour connaître l'état courant du bouton Exit lors du dernier appui
boolean testBoutonEnter = 0; //variable pour savoir si on rentre dans la boucle de calibration
boolean testBoutonCal = 0; //variable pour savoir si on valide l'étalonnage
boolean testEtalonnage = 0; //variable pour savoir si l'etalonnage est fini
float voltage, phValue, temperature = 25;
DFRobot_PH ph;
void setup()
{
Serial.begin(250000);
ph.begin();
//Défintion des pins des boutons poussoirs en entrée
pinMode(pinBoutonEnter, INPUT_PULLUP);
pinMode(pinBoutonCal, INPUT_PULLUP);
pinMode(pinBoutonExit, INPUT_PULLUP);
while (testEtalonnage == 0)
{
etalonnage();
}
}
void loop()
{
static unsigned long timepoint = millis();
if (millis() - timepoint > 1000U) { //time interval: 1s
timepoint = millis();
//temperature = readTemperature(); // read your temperature sensor to execute temperature compensation
voltage = analogRead(PH_PIN) / 1024.0 * 5000; // read the voltage
phValue = ph.readPH(voltage, temperature); // convert voltage to pH with temperature compensation
Serial.print("temperature:");
Serial.print(temperature, 1);
Serial.print("^C pH:");
Serial.println(phValue, 2);
}
ph.calibration(voltage, temperature); // calibration process by Serail CMD
}
float readTemperature()
{
//add your code here to get the temperature from your temperature sensor
}
void etalonnage() //fonction qui lance la procédure d'étalonnage du capteur
{
//temperature = readTemperature(); // mesure de la température via la fonction readTemperature dédiée
ph.calibration(voltage, temperature);
// on teste si le bouton ENTER est pressé
etatBoutonEnter = digitalRead(pinBoutonEnter); //si enter est presse etatBoutonEnter=LOW=0 car pin en mode pull up interne
if (etatBoutonEnter == LOW ) //si le bouton était précédemment non appuyé alors lastBoutonEnter=1=HIGH
{
testBoutonEnter = 1;
Serial.println("ENTERPH");
if (lastBoutonCal == HIGH) // on teste si Cal n'est pas appuyé après que le bouton Enter ait été appuyé
while (testBoutonEnter == 1)
{ // on teste si le bouton CAL est pressé --> si oui, on valide l'étalonnage
etatBoutonCal = digitalRead(pinBoutonCal); //on lit l'état du bouton Cal
if (etatBoutonCal == 0) //si le bouton Cal est pressé alors etatBoutonCal=LOW=0 car pin en mode pull up interne
{
//lcd.backlight();
ph.calibration(voltage, temperature, Cal); // calibration process by Serail CMD
testBoutonCal = 1;
}
if (lastBoutonExit == HIGH) // Appui sur Exit après appui sur Enter
while (testBoutonCal == 1)
{
etatBoutonExit = digitalRead(pinBoutonExit);
if (etatBoutonExit == 0)
{
ph.calibration(voltage, temperature, Exit); // calibration process by Serail CMD
delay(1000);
testBoutonEnter = 0;
testBoutonCal = 0;
testEtalonnage = 1;
break;
}
}
}
}
else
{
etatBoutonCal = digitalRead(pinBoutonCal);
etatBoutonExit = digitalRead(pinBoutonExit);
if (etatBoutonExit > lastBoutonExit && etatBoutonCal == 0)
{
ph.calibration(voltage, temperature, Exit); // calibration process by Serail CMD
delay(2000);
}
}
lastBoutonEnter = etatBoutonEnter;
lastBoutonCal = etatBoutonCal;
lastBoutonExit = etatBoutonExit;
}
Pourriez-vous m'aider à résoudre mon problème ?
Merci