Bibliothèque qui me renvoie une valeur "bizarre"

Bonjour,

J'essaye de modifier la bibliothèque de mon capteur pour obtenir en fin une valeur qui correspond à la mesure : soit 7 ou 4 (si bonne solution utilisée pour l'étalonnage) soit 0 (si erreur lors de l'étalonnage).
J'ai rajouté dans la fonction calibration la mise à jour d'une variable resultatEtalonnage ( qui vaut donc 0, 4 ou 7) : l'objectif étant dans mon programme Arduino d'utiliser cette variable selon la valeur prise par l'étalonnage.
Le problème est que la valeur que j'obtiens ne correspond pas à ce que j'attends : je devrais n'avoir que 0, 4 ou 7 or en sortie du programme, la variable vaut toujours 2.
J'ai essayé de voir d'où pouvait provenir cette valeur mais je n'arrive pas à déceler mon erreur.

Quelqu'un pourrait-il m'aider à résoudre mon problème ?
Merci d'avance

ma bibliothèque .cpp :

/*
 * file DFRobot_PH.cpp * @ https://github.com/DFRobot/DFRobot_PH
 *
 * Arduino library for Gravity: Analog pH Sensor / Meter Kit V2, SKU: SEN0161-V2
 *
 * Copyright   [DFRobot](http://www.dfrobot.com), 2018
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-04
 */


#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include "DFRobot_PH.h"
#include <EEPROM.h>



#define EEPROM_write(address, p) {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) EEPROM.write(address+i, pp[i]);}
#define EEPROM_read(address, p)  {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) pp[i]=EEPROM.read(address+i);}

#define PHVALUEADDR 0x00    //the start address of the pH calibration parameters stored in the EEPROM

DFRobot_PH::DFRobot_PH()
{
    this->_temperature    = 25.0;
    this->_phValue        = 7.0;
    this->_acidVoltage    = 2032.44;    //buffer solution 4.0 at 25C
    this->_neutralVoltage = 1500.0;     //buffer solution 7.0 at 25C
    this->_voltage        = 1500.0;
}

DFRobot_PH::~DFRobot_PH()
{

}

void DFRobot_PH::begin()
{
    EEPROM_read(PHVALUEADDR, this->_neutralVoltage);  //load the neutral (pH = 7.0)voltage of the pH board from the EEPROM
    Serial.print("_neutralVoltage:");
    Serial.println(this->_neutralVoltage);
    if(EEPROM.read(PHVALUEADDR)==0xFF && EEPROM.read(PHVALUEADDR+1)==0xFF && EEPROM.read(PHVALUEADDR+2)==0xFF && EEPROM.read(PHVALUEADDR+3)==0xFF){
        this->_neutralVoltage = 1500.0;  // new EEPROM, write typical voltage
        EEPROM_write(PHVALUEADDR, this->_neutralVoltage);
    }
    EEPROM_read(PHVALUEADDR+4, this->_acidVoltage);//load the acid (pH = 4.0) voltage of the pH board from the EEPROM
    Serial.print("_acidVoltage:");
    Serial.println(this->_acidVoltage);
    if(EEPROM.read(PHVALUEADDR+4)==0xFF && EEPROM.read(PHVALUEADDR+5)==0xFF && EEPROM.read(PHVALUEADDR+6)==0xFF && EEPROM.read(PHVALUEADDR+7)==0xFF){
        this->_acidVoltage = 2032.44;  // new EEPROM, write typical voltage
        EEPROM_write(PHVALUEADDR+4, this->_acidVoltage);
    }
	//Serial.println("Appuyer ETALON  ");
	//Serial.println("pour etalonnage ");
	//Serial.println("ou attendre 10 s");
	//Serial.println("pour mesurer pH ");
}

float DFRobot_PH::readPH(float voltage, float temperature)
{
    float slope = (7.0-4.0)/((this->_neutralVoltage-1500.0)/3.0 - (this->_acidVoltage-1500.0)/3.0);  // two point: (_neutralVoltage,7.0),(_acidVoltage,4.0)
    float intercept =  7.0 - slope*(this->_neutralVoltage-1500.0)/3.0;
    //Serial.print("pente:");
    //Serial.print(slope);
    //Serial.print(",intercept:");
    //Serial.println(intercept);
    this->_phValue = slope*(voltage-1500.0)/3.0+intercept;  //y = k*x + b
    return _phValue;
}


byte DFRobot_PH::calibration(float voltage, float temperature,char* cmd)
{
    this->_voltage = voltage;
    this->_temperature = temperature;
    strupr(cmd);
    phCalibration(cmdParse(cmd));  // if received Serial CMD from the serial monitor, enter into the calibration mode
}

byte DFRobot_PH::calibration(float voltage, float temperature)
{
    this->_voltage = voltage;
    this->_temperature = temperature;
    if(cmdSerialDataAvailable() > 0){
        phCalibration(cmdParse());  // if received Serial CMD from the serial monitor, enter into the calibration mode
    }
}

boolean DFRobot_PH::cmdSerialDataAvailable()
{
    char cmdReceivedChar;
    static unsigned long cmdReceivedTimeOut = millis();
    while(Serial.available()>0){
        if(millis() - cmdReceivedTimeOut > 500U){
            this->_cmdReceivedBufferIndex = 0;
            memset(this->_cmdReceivedBuffer,0,(ReceivedBufferLength));
        }
        cmdReceivedTimeOut = millis();
        cmdReceivedChar = Serial.read();
        if (cmdReceivedChar == '\n' || this->_cmdReceivedBufferIndex==ReceivedBufferLength-1){
            this->_cmdReceivedBufferIndex = 0;
            strupr(this->_cmdReceivedBuffer);
            return true;
        }else{
            this->_cmdReceivedBuffer[this->_cmdReceivedBufferIndex] = cmdReceivedChar;
            this->_cmdReceivedBufferIndex++;
        }
    }
    return false;
}

byte DFRobot_PH::cmdParse(const char* cmd)
{
    byte modeIndex = 0;
    if(strstr(cmd, "ENTERPH")      != NULL){
        modeIndex = 1;
    }else if(strstr(cmd, "EXITPH") != NULL){
        modeIndex = 3;
    }else if(strstr(cmd, "CALPH")  != NULL){
        modeIndex = 2;
    }
    return modeIndex;
}

byte DFRobot_PH::cmdParse()
{
    byte modeIndex = 0;
    if(strstr(this->_cmdReceivedBuffer, "ENTERPH")      != NULL){
        modeIndex = 1;
    }else if(strstr(this->_cmdReceivedBuffer, "EXITPH") != NULL){
        modeIndex = 3;
    }else if(strstr(this->_cmdReceivedBuffer, "CALPH")  != NULL){
        modeIndex = 2;
    }
    return modeIndex;
}

byte DFRobot_PH::phCalibration(byte mode)
{
    char *receivedBufferPtr;
    static boolean phCalibrationFinish  = 0;
	byte resultatEtalonnage;
    static boolean enterCalibrationFlag = 0;
	Serial.println("avant le switch");
	Serial.println(resultatEtalonnage);
    switch(mode){
        case 0:
        if(enterCalibrationFlag){
            Serial.println(F(">>>Command Error<<<"));
        }
        break;

        case 1:
		Serial.println("case 1");
		Serial.println(resultatEtalonnage);
        enterCalibrationFlag = 1;
        phCalibrationFinish  = 0;
        Serial.println();
        Serial.println(F(">>>Mode étalonnage du pHmètre<<<"));
        Serial.println(F(">>>Mettre la sonde de pH dans la solution tampon 4.0 ou 7.0<<<"));
		Serial.println(F(">>>Attendre quelques mesures de pH"));
		Serial.println(F(">>>Puis saisir CALPH<<<"));
		Serial.println(F(">>>pour annuler saisir EXITPH<<<"));
        Serial.println();
        break;

        case 2:
		Serial.println("case 2");
		Serial.println(resultatEtalonnage);
        if(enterCalibrationFlag){
            if((this->_voltage>1322)&&(this->_voltage<1678)){        // buffer solution:7.0{
                Serial.println();
                Serial.print(F(">>>Solution tampon : 7.0"));
                this->_neutralVoltage =  this->_voltage;
                Serial.println(F(",Taper EXITPH pour sauvegarder et quitter<<<"));
                Serial.println();
                phCalibrationFinish = 1;
            }else if((this->_voltage>1854)&&(this->_voltage<2210)){  //buffer solution:4.0
                Serial.println();
                Serial.print(F(">>>Solution tampon : 4.0"));
				
                this->_acidVoltage =  this->_voltage;
                Serial.println(F(",Taper EXITPH pour sauvegarder et quitter<<<<<<")); 
                Serial.println();
                phCalibrationFinish = 1;
            }else{
                Serial.println();
                Serial.print(F(">>>Changer de solution tampon<<<"));
                Serial.println();                                    // not buffer solution or faulty operation
                phCalibrationFinish = 0;
            }
        }
        break;

        case 3:
		Serial.println("case 3");
		Serial.println(resultatEtalonnage);
        if(enterCalibrationFlag){
            Serial.println();
            if(phCalibrationFinish){
                if((this->_voltage>1322)&&(this->_voltage<1678)){
                    EEPROM_write(PHVALUEADDR, this->_neutralVoltage);
					resultatEtalonnage = 7;
					Serial.println("case 3 ; valeur 7");
                }else if((this->_voltage>1854)&&(this->_voltage<2210)){
                    EEPROM_write(PHVALUEADDR+4, this->_acidVoltage);
					resultatEtalonnage = 4;
					Serial.println("case 3 ; valeur 4");
                }
                Serial.print(F(">>>Etalonnage réussi"));
            }else{
                Serial.print(F(">>>Echec de l'étalonnage Failed"));
				Serial.println();
				resultatEtalonnage = 0;
				Serial.println("case 3 ; else");
				Serial.println(resultatEtalonnage);
            }
            Serial.println(F(",Exit PH Calibration Mode<<<"));
            Serial.println();
            phCalibrationFinish  = 0;
            enterCalibrationFlag = 0;
			Serial.println(resultatEtalonnage);
			
        }
        break;
		
	}
	Serial.println("après le switch");
	Serial.println(resultatEtalonnage);
	Serial.println();
	return resultatEtalonnage;
}

Mon programme (j'ai ajouté à la main une valeur de tension pour le capteur concerné ) :

#include "DFRobot_PH.h"         //module pHmétrique

DFRobot_PH ph;
const unsigned long PROGMEM flux = 250000; //flux de la liaison série
float voltage, phValue, temperature = 25;

byte TestEtalonnage =7 ; // variable pour savoir si l'étalonnage est correct;


const char Enter[] = "ENTERPH" ;
const char Cal[] = "CALPH" ;
const char Exit[] = "EXITPH" ;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(flux);
  ph.begin();
  float resultatvoltage = 2000; //valeur possible mesurée par le capteur
  Serial.println(resultatvoltage);
  Serial.println(TestEtalonnage);
  phValue = ph.readPH(resultatvoltage, temperature); // convert voltage to pH with temperature compensation
  ph.calibration(resultatvoltage, temperature, Enter); // on envoie la commande ENTEREC au module pour commencer la calibration
  delay(100);
  ph.calibration(resultatvoltage, temperature, Cal); // on envoie la commande ENTEREC au module pour commencer la calibration
  delay(100);
  TestEtalonnage = ph.calibration(resultatvoltage, temperature, Exit); // on envoie la commande ENTEREC au module pour commencer la calibration
  Serial.println(TestEtalonnage);
  delay(2000);
}

void loop() {
  // put your main code here, to run repeatedly:
  
}

ces 2 fonctions promettent de retourner un byte mais n'ont pas de return....

sinon dans la fonction qui retourne resultatEtalonnage, il y a plusieurs chemin pour lesquels la variable ne sera pas initialisée

déclarez la déjà avec une valeur par défaut (une variable locale n'est pas initialisée à 0 par défaut comme les globales, elle prend une valeur aléatoire (ce qui a en mémoire sur la pile à l'adresse réservée pour cette variable))

  byte resultatEtalonnage = 255;

si vous voyez 255 en sortie, c'est qu'elle n'a pas été affectée

vous devriez activer les options de compilation détaillée, le compilateur doit donner des warning sur un certain nombre de choses

Bonjour,

J'avais vu cela effectivement : initialement, les fonctions de calibration étaient des void mais comme je devais modifier la dernière étape de calibration pour obtenir un byte, j'ai été obligé de tout passer en byte sans quoi j'obtenais une erreur lors de la compilation.

J'ai essayé en initialisant la variable, elle m'indique bien la valeur d'initialisation au départ mais à la fin, j'obtiens toujours le même chiffre (2) qui ne correspond à aucune valeur normalement retournée.

La compilation détaillée me donne ceci qui ne paraît pas poser problème (à ma lecture !) :

:\arduino-1.8.19\arduino-builder -dump-prefs -logger=machine -hardware D:\arduino-1.8.19\hardware -hardware D:\arduino-1.8.19\portable\packages -tools D:\arduino-1.8.19\tools-builder -tools D:\arduino-1.8.19\hardware\tools\avr -tools D:\arduino-1.8.19\portable\packages -built-in-libraries D:\arduino-1.8.19\libraries -libraries D:\arduino-1.8.19\portable\sketchbook\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10819 -build-path C:\Users\LEBOUL~1\AppData\Local\Temp\arduino_build_63714 -warnings=none -build-cache C:\Users\LEBOUL~1\AppData\Local\Temp\arduino_cache_841074 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=D:\arduino-1.8.19\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=D:\arduino-1.8.19\hardware\tools\avr -prefs=runtime.tools.avrdude.path=D:\arduino-1.8.19\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=D:\arduino-1.8.19\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=D:\arduino-1.8.19\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=D:\arduino-1.8.19\hardware\tools\avr -verbose C:\Users\LEBOUL~1\AppData\Local\Temp\arduino_modified_sketch_105930\sketch_feb25a.ino
D:\arduino-1.8.19\arduino-builder -compile -logger=machine -hardware D:\arduino-1.8.19\hardware -hardware D:\arduino-1.8.19\portable\packages -tools D:\arduino-1.8.19\tools-builder -tools D:\arduino-1.8.19\hardware\tools\avr -tools D:\arduino-1.8.19\portable\packages -built-in-libraries D:\arduino-1.8.19\libraries -libraries D:\arduino-1.8.19\portable\sketchbook\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10819 -build-path C:\Users\LEBOUL~1\AppData\Local\Temp\arduino_build_63714 -warnings=none -build-cache C:\Users\LEBOUL~1\AppData\Local\Temp\arduino_cache_841074 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=D:\arduino-1.8.19\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=D:\arduino-1.8.19\hardware\tools\avr -prefs=runtime.tools.avrdude.path=D:\arduino-1.8.19\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=D:\arduino-1.8.19\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=D:\arduino-1.8.19\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=D:\arduino-1.8.19\hardware\tools\avr -verbose C:\Users\LEBOUL~1\AppData\Local\Temp\arduino_modified_sketch_105930\sketch_feb25a.ino
Using board 'uno' from platform in folder: D:\arduino-1.8.19\hardware\arduino\avr
Using core 'arduino' from platform in folder: D:\arduino-1.8.19\hardware\arduino\avr
Detecting libraries used...
"D:\\arduino-1.8.19\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-ID:\\arduino-1.8.19\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\arduino-1.8.19\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714\\sketch\\sketch_feb25a.ino.cpp" -o nul
Alternatives for DFRobot_PH.h: [DFRobot_PH-master]
ResolveLibrary(DFRobot_PH.h)
  -> candidates: [DFRobot_PH-master]
"D:\\arduino-1.8.19\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-ID:\\arduino-1.8.19\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\arduino-1.8.19\\hardware\\arduino\\avr\\variants\\standard" "-ID:\\arduino-1.8.19\\libraries\\DFRobot_PH-master" "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714\\sketch\\sketch_feb25a.ino.cpp" -o nul
Using cached library dependencies for file: D:\arduino-1.8.19\libraries\DFRobot_PH-master\DFRobot_PH.cpp
Alternatives for EEPROM.h: [EEPROM@2.0]
ResolveLibrary(EEPROM.h)
  -> candidates: [EEPROM@2.0]
Generating function prototypes...
"D:\\arduino-1.8.19\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-ID:\\arduino-1.8.19\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\arduino-1.8.19\\hardware\\arduino\\avr\\variants\\standard" "-ID:\\arduino-1.8.19\\libraries\\DFRobot_PH-master" "-ID:\\arduino-1.8.19\\hardware\\arduino\\avr\\libraries\\EEPROM\\src" "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714\\sketch\\sketch_feb25a.ino.cpp" -o "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"D:\\arduino-1.8.19\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compilation du croquis...
"D:\\arduino-1.8.19\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-ID:\\arduino-1.8.19\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\arduino-1.8.19\\hardware\\arduino\\avr\\variants\\standard" "-ID:\\arduino-1.8.19\\libraries\\DFRobot_PH-master" "-ID:\\arduino-1.8.19\\hardware\\arduino\\avr\\libraries\\EEPROM\\src" "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714\\sketch\\sketch_feb25a.ino.cpp" -o "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714\\sketch\\sketch_feb25a.ino.cpp.o"
Compiling libraries...
Compiling library "DFRobot_PH-master"
Utilisation du fichier déjà compilé : C:\Users\LEBOUL~1\AppData\Local\Temp\arduino_build_63714\libraries\DFRobot_PH-master\DFRobot_PH.cpp.o
Compiling library "EEPROM"
Compiling core...
Using precompiled core: C:\Users\LEBOUL~1\AppData\Local\Temp\arduino_cache_841074\core\core_arduino_avr_uno_db287fe97f216e6b19294796468b89a1.a
Linking everything together...
"D:\\arduino-1.8.19\\hardware\\tools\\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714/sketch_feb25a.ino.elf" "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714\\sketch\\sketch_feb25a.ino.cpp.o" "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714\\libraries\\DFRobot_PH-master\\DFRobot_PH.cpp.o" "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714/..\\arduino_cache_841074\\core\\core_arduino_avr_uno_db287fe97f216e6b19294796468b89a1.a" "-LC:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714" -lm
"D:\\arduino-1.8.19\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714/sketch_feb25a.ino.elf" "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714/sketch_feb25a.ino.eep"
"D:\\arduino-1.8.19\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714/sketch_feb25a.ino.elf" "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714/sketch_feb25a.ino.hex"
Utilisation de la bibliothèque DFRobot_PH-master prise dans le dossier : D:\arduino-1.8.19\libraries\DFRobot_PH-master (legacy)
Utilisation de la bibliothèque EEPROM version 2.0 dans le dossier: D:\arduino-1.8.19\hardware\arduino\avr\libraries\EEPROM 
"D:\\arduino-1.8.19\\hardware\\tools\\avr/bin/avr-size" -A "C:\\Users\\LEBOUL~1\\AppData\\Local\\Temp\\arduino_build_63714/sketch_feb25a.ino.elf"
Le croquis utilise 5912 octets (18%) de l'espace de stockage de programmes. Le maximum est de 32256 octets.
Les variables globales utilisent 411 octets (20%) de mémoire dynamique, ce qui laisse 1637 octets pour les variables locales. Le maximum est de 2048 octets.

Merci pour ton aide

Que voyez vous dans la console série ?


L'affichage est correct (et logique) dans le déroulé du programme sauf la dernière ligne qui affiche 2 alors qu'il devrait conserver 4

Il vient de quel endroit cet affichage ? Il faudrait rajouter un peu de traces

Quand tune variable change de valeur alors que on ne fait rien pour la modifier, C’est généralement qu’on a un débordement de tableau ou un usage d’un pointeur malencontreux qui vient écraser la valeur comme mémoire.

Il faudrait vérifier par exemple que toutes les cString sont bien terminées par un caractère nul.

(Je lis sur mon iPhone donc pas pratique pour analyser en détails)

Il s'agit de la copie d'écran du moniteur série.

Qu'appelles-tu "rajouter un peu de traces" ?

Je ne suis pas assez aguerri pour savoir comment le faire.

Je voulais dire quelle est la ligne de code qui l’imprime ?

Pour la seconde question il s’agit de rajouter plus de print pour suivre plus finement ce qu’il se passe. Par exemple avant et après chaque modif de la variable et en entrée et sortie des fonctions

Re,

En rajoutant un peu plus de Serial.println, j'ai trouvé l'erreur : elle se situait dans la fonction de calibration qui ne renvoyait pas le bytecorrespondant.
Merci

Bravo!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.