The OS I have loaded currently is Openhabian (A flavor of Raspberian). I have the GrovePi library loaded there as well. I can read other GrovePi sensors just fine, just not the pH meter.
When I run the script, I get no output at all. The cursur flashes for a bit than goes completely solid. I"ve let it run for several minutes before I kill it with CNTRL C.
I heard back from Support and Dexter never was able to get this sensor to work. This particular sensor is made by SEEED studio. Also, for those looking, at this time their is not a working script available for that sensor to work with the Raspberry Pi. It is compatible but would require the user to write their own python script in order to get it to work.
The sensor in question here is the Grove - PH Sensor Kit (E-201C-Blue ) from SEEED studio.
Unfortunately, the link in our code above now goes to a ‘Not Found’ page on SEEED’s site, so I’m not sure where this stands even with the black pH sensor.
One thing I don’t lack is perseverance. I did much thinking and came up with code (used another sensors script as donor code) that reads the sensor. Problem is, I don’t know how to interpret the values. I tried plugging a pH formula from another sensor but my values are screwy.
When I run it to get the raw value from the sensor, I am getting numbers like 534 or 535. If I run it with the formula that is in the code below I get values like 37.28… The known pH of this solution is 7.6. I just don’t know how to get from where I am at to where I need to be with some regularity. The good news, is I AM able to read the dang sensor.
I’ll keep chugging away. If by chance i get it, I’ll post results here.
So without further ado, here is my code:
GNU nano 3.2 ph_sensor.py Modified
import math
import sys
import time
from grove.adc import ADC
class GrovePH:
Vref = 4.95
def __init__(self, channel):
self.channel = channel
self.adc = ADC()
@property
def PH(self):
value = self.adc.read(self.channel)
if value != 0:
voltage = value*3.3/1024.0
PHValue = (7-1000*(voltage-372)*4.95/59.16/1023)
return PHValue
else:
return 0
Grove = GrovePH
def main():
if len(sys.argv) < 2:
print(‘Usage: {} adc_channel’.format(sys.argv[0]))
sys.exit(1)
Weird that the grovepi documentation does not specify the vref nor the precision. I expect it is 5volts and 12-bits. So voltage = reading * 5/4096. Your code says Vref is 4.95 volts so perhaps use that.
This is very weird to be subtracting 372 from a number between 0 and 5 volts. Maybe the voltage in the formula is in millivolts so the voltage computed in the line above needs to be multiplied by 1000?
**Note:** If the measured value you get maintains higher or smaller than it should be, the reason could be a inappropriate Vref value. Vref is the working voltage of Arduino.
The relationship between PH value and the output voltage: E=59.16(mV/PH)
Here is their original C program:
#define Vref 4.95
void setup()
{
Serial.begin(9600);
}
void loop()
{
int sensorValue;
int m;
long sensorSum;
for(m=0;m<50;m++)
{
sensorValue=analogRead(A0);//Connect the PH Sensor to A0 port
sensorSum += sensorValue;
}
sensorValue = sensorSum/50;
Serial.print(" the PH value is");
Serial.println(7-1000*(sensorValue-372)*Vref/59.16/1023);
So the calibration step finds the voltage for ph(7)
If we start with a wild guess of vref/2.0
Vref=5
VcalInMV= 2500
VreadingInMV = reading * Vref/4096 * 1000
phPerMV = 1.0/59.6
Guess not: EPA guidelines state that the pH of tap water should be between 6.5 and 8.5. Still, tap water in the U.S. tends to fall below that – in the 4.3 to 5.3 range – depending on where you live.
If I adjust the millivolts I can bring the pH in to a more appropriate value. I tried it in my other code with known sample but my values for my well water were off. I’m going to try it again with your code and see where we are.
I made my adjustments and it’s still off. Let me know your thoughts! I can check and verify millivolts and such if need be. Just give me a little direction as I don’t know where to start.
@cyclicalobsessive SEEED sent me over this code. They also said they were getting false readings as well and did not know why… So… We are doing something right. I couldn’t get his code to work. It kept bombing out.
Thanks again for all of your help! I’d love to know why it’s sending false readings…
import time,sys,math
from grove.adc import ADC
__all__ = ["GrovePhSensor"]
class GrovePhSensor(object):
def __init__(self, channel):
self.channel = channel
self.adc = ADC()
@property
def value(self):
return self.adc.read(self.channel)
def main():
#Connect the Grove PH Sensor to analog port A0
# SIG,NC,VCC,GND
sensor = GrovePhSensor(0)
# Reference voltage of ADC is 4.95v
Vref = 4.95
while True:
try:
# Read sensor value
# sensor_value = grove.analogRead(sensor)
# Calculate PH
# 7 means the neutral PH value,372 means the Reference value of ADC measured under neutral pH
# 59.16=Conversion method to convert the output voltage value to PH value.
ph = 7 - 1000 * (GrovePhSensor.value-372) * Vref / 59.16 / 1023
print("sensor_value =", GrovePhSensor.value, " ph =", ph)
except IOError:
print ("Error")
if __name__ == '__main__':
main()