How are you Please help me with my sketch,… My build: ESP32, BLYNK IOT, Gravity PH meter V2.0
Everything works on the serial monitor, but do I need to calibrate in the Blynk IOT - Terminal widget? or something like that.I see only the actual PHValue. My vision is that if I type this (as in the serial monitor) ENTERPH, CALPH, EXITPH, it will work as it should.
/*
* 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
*
*/
// Replace/ Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#include "BlynkEdgent.h"
#include "DFRobot_ESP_PH.h"
#include "EEPROM.h"
#include <SimpleTimer.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;
static unsigned long timepoint = millis();
void phsonda()
{
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);
Blynk.virtualWrite(V78,phValue);
ph.calibration(voltage, temperature); // calibration process by Serail CMD
delay(4000);
}
float readTemperature()
{
//add your code here to get the temperature from your temperature sensor
}
void setup()
{
Serial.begin(115200);
BlynkEdgent.begin();//(115200);
EEPROM.begin(32);//needed to permit storage of calibration value in eeprom
ph.begin();
delay(2000);
timer.setInterval(1000L, phsonda);
}
void loop()
{
timer.run();
BlynkEdgent.run();
}
@nesvi Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Copy and paste these if you can’t find the correct symbol on your keyboard.
This statement implies that you already have code in your sketch that looks for input of these key words, presumably followed by values, and takes the appropriate action.
I don’t see this code in the sketch you’ve posted.
To be honest, using the serial monitor or the terminal widget in this way is a very clunky approach.
You’d be far better having a tab within your mobile dashboard that allows calibration values to be entered via appropriate widgets (numeric input I would expect).
I used the Atlas Scientific ph probe. To calibrate it uses cmd commands. I eventually managed to get it working where I push a buttons on my interface to issue the calibration states which in turn call a cmd command without the need for serial. I attach my code it might be useful to you.
void pHFunction()
{
if (input_string_complete == true)
{
Serial3.print(inputstring);
Serial3.print('\r');
inputstring = "";
input_string_complete = false;
}
if (sensor_string_complete == true)
{
if (isdigit(sensorstring[0]))
{
pH = sensorstring.toFloat();
//Serial.println(pH);
}
}
sensorstring = "";
sensor_string_complete = false;
if (CAL7 == true)
{
Serial3.print("cal,mid,7\r\n");
}
if (CAL4 == true)
{
Serial3.print("cal,low,4\r\n");
}
if (CAL10 == true)
{
Serial3.print("cal,high,10\r\n");
}
}
I don’t write code for other people. I have given you the pH function which you should be able to adapt. Remember though I used the Atlas Scientic probe and shield. Maybe you should look at their website where they have examples of code, and then you will be able to see how I have come by my code