Hello everyone. I'm working with a ph probe from DFRobot.
DFRobot code comes with a calibration option that is triggered, when an user inputs a command thru the monitor serial text box. An user needs to write enterph and press enter or send button in order to enter into calibration mode.
I have my arduino connected to a raspberry pi, where I have the main program running in python and when a user presses a button in there, I want to access it calibration mode in the arduino code.
So far I have my arduino reading and detecting thru serial when the button is pressed, but I can't figure out how to "simulate" the user writing the command in the text box from arduino serial monitor.
So basically, I would like the user to press calibrate ph button in my raspberry pi and that will trigger the "enterph" command in my arduino.
I tried different Serial.print but nothing seems to make arduino trigger that command.
I've been trying to find similar problems to mine and almost found it but they were talking about a different board instead of the raspberry and the commands wouldn't work for me.
This is the code I have so far in my arduino.
Thanks in advance and hopefully I was clear enough with my expplanation.
//
//
//
//
//
#include "DFRobot_PH.h"
#include <GravityTDS.h> // For EC sensor
#include <OneWire.h> // For water temp sensor DS18B20
#include <DallasTemperature.h> // For water temp sensor DS18B20
const int TdsSensorPin = A0; // TDS sensor analog pin
const int watempsensor = 10; // Water temperature sensor digital pin
// PH sensor
#define PH_PIN A1
float voltage,phValue;
DFRobot_PH ph;
// Ph sensor
// Water temp sensor begin
OneWire oneWire(watempsensor);
DallasTemperature wasensor(&oneWire);
float Celcius = 0;
//float Fahrenheit=0;
// Water temp sensor end
GravityTDS gravityTds;
float temperature = 0, ppm500 = 0, ec = 0, ppm700 = 0;
String r = "test";
int tempindexserial = 0;
void setup() {
Serial.begin(115200);
ph.begin();
gravityTds.setPin(TdsSensorPin);
gravityTds.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds.begin(); //initialization
wasensor.begin();
}
void loop() {
ecphread();
}
void ecphread() {
float actualec = 0, actualph = 0;
if (tempindexserial == 0){
if(Serial.available()){ //From RPi to Arduino
char tempchar = Serial.read();
delay(50);
//tempchar = Serial.read();
r = "enterph\n";
Serial.print(r);
tempindexserial = 1;
delay(50);
}
}
wasensor.requestTemperatures();
Celcius = wasensor.getTempCByIndex(0);
//Fahrenheit=wasensor.toFahrenheit(Celcius);
temperature = Celcius; //add your temperature sensor and read it chnage to Fahrenheit if prefer F
gravityTds.setTemperature(temperature); // set the temperature and execute temperature compensation
gravityTds.update(); //sample and calculate
ppm500 = gravityTds.getTdsValue(); // then get the value
ec = gravityTds.getTdsValue() / 500; // ec value
ppm700 = ec * 700; // ppm700 value
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
}
ph.calibration(voltage,temperature); // calibration process by Serail CMD
actualec = ec;
actualph = phValue;
Serial.print("E");
Serial.println(actualec);
Serial.print("P");
Serial.println(actualph);
Serial.print("W");
Serial.println(temperature);
}
