DFRobot / DFRobot_PH

Arduino library for Gravity: Analog pH Sensor / Meter Kit V2, SKU: SEN0161-V2
MIT License
73 stars 46 forks source link

ESP32 support #8

Open ayavilevich opened 2 years ago

ayavilevich commented 2 years ago

The main readme mentions that the library will "Work Wrong" on the ESP32. Can you provide more details? What is the issue? What would be required to support this sensor on the ESP32?

Thanks.

igorkorneichuk commented 8 months ago

@ayavilevich did you manage to make it work? As I understand, the problem is that ESP32 (M5Stack Core2 for me) returns incorrect voltage values for analog output.

ayavilevich commented 8 months ago

@ayavilevich did you manage to make it work? As I understand, the problem is that ESP32 (M5Stack Core2 for me) returns incorrect voltage values for analog output.

I wrote custom code and used an external ADC IC. I didn't use this library in the end. The built-in ADC of the ESP32 is not very accurate. Not sure what is "Wrong" with this library and ESP32 but likely the ADC or the EEPROM part.

akermania commented 5 months ago

Can you please share the code ? I've changed the EEPROM part, everything is working but I guess the readings are a bit off.

Changed from 1024 to 4096, but I'm not sure what the '5000' stands for (maybe voltage then it needs to be 3380..?) voltage = analogRead(PH_PIN)/4096.0*5000;

Also in the library the auto detection of 7.0 vs 4.0 solution : if((this->_voltage>1322)&&(this->_voltage<1678)){ //buffer solution:7.0 else if((this->_voltage>1854)&&(this->_voltage<2210)){ //buffer solution:4.0

I changed it to some reading but again not sure ....

igorkorneichuk commented 5 months ago

@akermania

float acid_voltage = 1920;
float neutral_voltage = 1405;
float ph = 0;

float ph_sensor_voltage = analogRead(PH_PIN) / 4095.0 * 3300;
float slope = (7.0 - 4.0) / ((neutral_voltage - 1500) / 3.0 - (acid_voltage - 1500) / 3.0); 
float intercept = 7.0 - slope * (neutral_voltage - 1500) / 3.0;
ph = slope * (ph_sensor_voltage - 1500) / 3.0 + intercept;

It gave correct values for buffers from the box and it has worked well since April in a real environment :) The sensor is always inside the aquarium (the manufacturer doesn’t recommend this, but it works anyway). I also had a problem while turning the device on. The voltage was incorrect on the first try, so the screen displayed strange values. I solved this by simply using if (ph < 0) { ph = 0; }.

akermania commented 5 months ago

@igorkorneichuk Thanks! 3300 that what I was missing

I also found that the ESP32 ADC is funky, I'll try attaching an external ADC to see if it helps with the readings.

igorkorneichuk commented 5 months ago

@akermania Yeah, I came here after figured out that problem with ESP32 ADC, but I did it on M5Stack Core2 and really didn't want to attach external ADC.

photo_2024-06-23_22-56-55