Skip to content

Commit

Permalink
update range cal calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
MkLHX committed Jun 12, 2019
1 parent 9e3d03e commit bba4931
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
20 changes: 10 additions & 10 deletions src/DFRobot_ESP_PH_WITH_ADC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* ##################################################
* ##################################################
*
* version V1.1
* version V1.2
* date 2019-06
*/

Expand All @@ -37,23 +37,23 @@ DFRobot_ESP_PH_WITH_ADC::~DFRobot_ESP_PH_WITH_ADC()

void DFRobot_ESP_PH_WITH_ADC::begin(int EepromStartAddress)
{
this->_eepromStartAddress = EepromStartAddress;
//check if calibration values (neutral and acid) are stored in eeprom
this->_neutralVoltage = EEPROM.readFloat(EepromStartAddress); //load the neutral (pH = 7.0)voltage of the pH board from the EEPROM
this->_neutralVoltage = EEPROM.readFloat(this->_eepromStartAddress); //load the neutral (pH = 7.0)voltage of the pH board from the EEPROM
if (this->_neutralVoltage == float())
{
this->_neutralVoltage = PH_7_AT_25; // new EEPROM, write typical voltage
EEPROM.writeFloat(EepromStartAddress, this->_neutralVoltage);
EEPROM.writeFloat(this->_eepromStartAddress, this->_neutralVoltage);
EEPROM.commit();
}

this->_acidVoltage = EEPROM.readFloat(EepromStartAddress + (int)sizeof(float)); //load the acid (pH = 4.0) voltage of the pH board from the EEPROM
this->_acidVoltage = EEPROM.readFloat(this->_eepromStartAddress + (int)sizeof(float)); //load the acid (pH = 4.0) voltage of the pH board from the EEPROM
if (this->_acidVoltage == float())
{
this->_acidVoltage = PH_4_AT_25; // new EEPROM, write typical voltage
EEPROM.writeFloat(EepromStartAddress + (int)sizeof(float), this->_acidVoltage);
EEPROM.writeFloat(this->_eepromStartAddress + (int)sizeof(float), this->_acidVoltage);
EEPROM.commit();
}
this->_eepromStartAddress = EepromStartAddress;
}

float DFRobot_ESP_PH_WITH_ADC::readPH(float voltage, float temperature)
Expand Down Expand Up @@ -180,7 +180,7 @@ void DFRobot_ESP_PH_WITH_ADC::phCalibration(byte mode)
case 2:
if (enterCalibrationFlag)
{
if ((this->_voltage > PH_8_VOLTAGE) && (this->_voltage < PH_6_VOLTAGE))
if ((this->_voltage > PH_VOLTAGE_NEUTRAL_LOW_LIMIT) && (this->_voltage < PH_VOLTAGE_NEUTRAL_HIGH_LIMIT))
{ // buffer solution:7.0
Serial.println();
Serial.print(F(">>>Buffer Solution:7.0"));
Expand All @@ -189,7 +189,7 @@ void DFRobot_ESP_PH_WITH_ADC::phCalibration(byte mode)
Serial.println();
phCalibrationFinish = 1;
}
else if ((this->_voltage > PH_5_VOLTAGE) && (this->_voltage < PH_3_VOLTAGE))
else if ((this->_voltage > PH_VOLTAGE_ACID_LOW_LIMIT) && (this->_voltage < PH_VOLTAGE_ACID_HIGH_LIMIT))
{ //buffer solution:4.0
Serial.println();
Serial.print(F(">>>Buffer Solution:4.0"));
Expand All @@ -214,12 +214,12 @@ void DFRobot_ESP_PH_WITH_ADC::phCalibration(byte mode)
Serial.println();
if (phCalibrationFinish)
{
if ((this->_voltage > PH_8_VOLTAGE) && (this->_voltage < PH_5_VOLTAGE))
if ((this->_voltage > PH_VOLTAGE_NEUTRAL_LOW_LIMIT) && (this->_voltage < PH_VOLTAGE_NEUTRAL_HIGH_LIMIT))
{
EEPROM.writeFloat(this->_eepromStartAddress, this->_neutralVoltage);
EEPROM.commit();
}
else if ((this->_voltage > PH_5_VOLTAGE) && (this->_voltage < PH_3_VOLTAGE))
else if ((this->_voltage > PH_VOLTAGE_ACID_LOW_LIMIT) && (this->_voltage < PH_VOLTAGE_ACID_HIGH_LIMIT))
{
EEPROM.writeFloat(this->_eepromStartAddress + (int)sizeof(float), this->_acidVoltage);
EEPROM.commit();
Expand Down
24 changes: 17 additions & 7 deletions src/DFRobot_ESP_PH_WITH_ADC.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* ##################################################
* ##################################################
*
* version V1.1
* version V1.2
* date 2019-06
*/

Expand All @@ -28,14 +28,24 @@
//first you need to define the raw voltage for your circuit
//the raw voltage for neutral pH 7.0 and acid pH 4.0 at 25 °c
//for the actual circuit => ESP32 + ADC (ADS1115)
#define PH_4_AT_25 1521
#define PH_7_AT_25 1134

/*new ranges when read value behind adc*/
#define PH_8_VOLTAGE 900
#define PH_6_VOLTAGE 1250
#define PH_5_VOLTAGE 1400
#define PH_3_VOLTAGE 1700
#define PH_VOLTAGE_ACID_OFFSET 200
#define PH_VOLTAGE_NEUTRAL_OFFSET 200
#define PH_8_VOLTAGE 995 //linear culculation
#define PH_7_AT_25 1134 //laboratory measurement with isolation circuit, PH meter V2.0 and PH probe from DFRobot kit
#define PH_6_VOLTAGE 1250 //linear culculation
#define PH_5_VOLTAGE 1380 //linear culculation
#define PH_4_AT_25 1521 //laboratory measurement with isolation circuit, PH meter V2.0 and PH probe from DFRobot kit
#define PH_3_VOLTAGE 1700 //linear culculation

#define PH_VOLTAGE_NEUTRAL_LOW_LIMIT PH_8_VOLTAGE - PH_VOLTAGE_NEUTRAL_OFFSET
#define PH_VOLTAGE_NEUTRAL_HIGH_LIMIT PH_6_VOLTAGE + PH_VOLTAGE_NEUTRAL_OFFSET
#define PH_VOLTAGE_ACID_LOW_LIMIT PH_5_VOLTAGE - PH_VOLTAGE_ACID_OFFSET
#define PH_VOLTAGE_ACID_HIGH_LIMIT PH_3_VOLTAGE + PH_VOLTAGE_ACID_OFFSET

//instead of 900 cause buffer 7.0 render 972 with outdor probe
//instead of 1400 cause buffer 4.0 render 1320 with outdoor probe

#define ReceivedBufferLength 10 //length of the Serial CMD buffer

Expand Down

0 comments on commit bba4931

Please sign in to comment.