Hello friends.
I try to get the example from the lib to work: GitHub - GreenPonik/DFRobot_ESP_PH_BY_GREENPONIK: Read PH on ESP32 by using Gravity: Analog pH Sensor / Meter Kit V2, SKU:SEN0161-V2
I am using an ESP32 and a Nextion Display.
The exampleCode:
/*
* file DFRobot_ESP_PH_BY_GREENPONIK.ino
* @ https://github.com/GreenPonik/DFRobot_ESP_PH_BY_GREENPONIK
*
* 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
*
* Based on the @ https://github.com/DFRobot/DFRobot_PH
* Copyright [DFRobot](http://www.dfrobot.com), 2018
* Copyright GNU Lesser General Public License
*
* ##################################################
* ##################################################
* ########## Fork on github by GreenPonik ##########
* ############# ONLY ESP COMPATIBLE ################
* ##################################################
* ##################################################
*
* version V1.1
* date 2019-06
*/
#include "DFRobot_ESP_PH.h"
#include "EEPROM.h"
DFRobot_ESP_PH ph;
#define ESPADC 4096.0 //the esp Analog Digital Convertion value
#define ESPVOLTAGE 3300 //the esp voltage supply value
#define PH_PIN 35 //the esp gpio data pin number
float voltage, phValue, temperature = 25;
void setup()
{
Serial.begin(115200);
EEPROM.begin(32);//needed to permit storage of calibration value in eeprom
ph.begin();
}
void loop()
{
static unsigned long timepoint = millis();
if (millis() - timepoint > 1000U) //time interval: 1s
{
timepoint = millis();
//voltage = rawPinValue / esp32ADC * esp32Vin
voltage = analogRead(PH_PIN) / ESPADC * ESPVOLTAGE; // read the voltage
Serial.print("voltage:");
Serial.println(voltage, 4);
//temperature = readTemperature(); // read your temperature sensor to execute temperature compensation
Serial.print("temperature:");
Serial.print(temperature, 1);
Serial.println("^C");
phValue = ph.readPH(voltage, temperature); // convert voltage to pH with temperature compensation
Serial.print("pH:");
Serial.println(phValue, 4);
}
ph.calibration(voltage, temperature); // calibration process by Serail CMD
}
float readTemperature()
{
//add your code here to get the temperature from your temperature sensor
}
My problem is now that the code waits (to start the calibration)for a Serial Command.
From what i know, u can send Serial commands via nextion via print "command".
So i made a button that does that. So what i found out now.
When i push the button i see this in the Serialmonitor:[1073478928:11,6,b2]. Nothing happens.
BUT!
when i push the button fast enouth, sometimes!, the codes jumps into the calibrationmode and gives me that in my Serialmonitor: >>>Enter PH Calibration Mode<<<
>>>Please put the probe into the 4.0 or 7.0 standard buffer solution<<<. So exactly that what i would expected.
So what now? Does the Nextion sends the command to fast or to slow? i am kinda confuces.
What i found out. I looked around in the cpp file of the lib and found this:
boolean DFRobot_ESP_PH::cmdSerialDataAvailable()
{
char cmdReceivedChar;
static unsigned long cmdReceivedTimeOut = millis();
while (Serial2.available() > 0)
{
if (millis() - cmdReceivedTimeOut > 500U)
{
this->_cmdReceivedBufferIndex = 0;
memset(this->_cmdReceivedBuffer, 0, (ReceivedBufferLength));
}
cmdReceivedTimeOut = millis();
cmdReceivedChar = Serial2.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;
}
when i changes the 500U to something like 20U, it wasnt possible for me (even through pushing fast the button) to enter the calibration.
Anyone ideas?
Thank you