Grove - PH Sensor Kit (E-201C-Blue) Raspberry pi Zero

Hello!

I recently purchased a GrovePi Zero and a pH Sensor Kit (Blue). I am having problems reading the sensor using the python script found on https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_ph_sensor.py.

The script runs but does not output anything.

Do you have any suggestions?

1 Like

Also send your question (with what OS you loaded) to support@modrobotics.com

Do you mean it prints an unchanging sensor_value and Ph= value,
or

Error
Error
...

or it runs without printing anything to the command line, period?

1 Like

Thanks for the reply!

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.

Thanks!

2 Likes

I thought I would update this.

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.

Thanks for the feedback!

3 Likes

Thanks for sharing @mountbaldybrewing!

Dexter Industries once supported the Industrial-Grade pH Sensor (https://www.seeedstudio.com/RS485-pH-Sensor-S-pH-01A-p-4632.html).

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.

2 Likes

One thing I don’t lack is perseverance. :smile: I did much thinking and came up with code (used another sensors script as donor code) that reads the sensor. :smiley: 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. :smiley:

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)

sensor = GrovePH(int(sys.argv[1]))
print('Detecting PH...')

while True:
    print('PH Value: {0}'.format(sensor.PH))
    time.sleep(1)

if name == ‘main’:
main()

3 Likes

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.

1 Like

I used the Vref data from Seeed’s old code for their old pH sensor.

I’ll try changing my code and see what happens. Progress is being made though. :slight_smile:

https://wiki.seeedstudio.com/Grove-PH_Sensor/

1 Like

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?

1 Like

Could be!

Also I just stumbled across this:

**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);

}

1 Like

Also, the Voltage variable in this code I stole from another working sensor. (TDS Sensor)

1 Like

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

PH = 7 - ((VreadingInMV - VcalInMV) * phPerMV)

1 Like

I’ll have to look at this later when I have some pH 7 solution handy. That looks like a great starting point.

Thanks for your input!!

1 Like

I would guess tap water to be close, no?

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.

1 Like

Our pH here runs at 7.6 - 7.8. Very high in TDS as well.

I ran that code on my water sample at work and I am getting 38.02 as my reading and I know that’s way off.

When I run the code without any constraints to see what the sensor is returning RAW, I get 535.

1 Like

Can you give this a try?

#!/usr/bin/env python3

import math
import sys
import time
from grove.adc import ADC

# CONSTANTS
Vref = 4.95   # volts
Vcal_mv = 646  # milli-volts (using raw value 535 * 4.95/4096 * 1000)
mv_per_ph = 59.6
ph_per_mv = 1.0 / mv_per_ph


class GrovePH:

    def __init__(self, channel):
        self.channel = channel
        self.adc = ADC()


    @property
    def PH(self):
        value = self.adc.read(self.channel)
        if value != 0:
            voltage_mv = value * Vref / 4096.0 * 1000
            PHValue = 7 - ((voltage_mv - Vcal_mv) * ph_per_mv)
            return PHValue
        else:
            return 0



def main():

    if len(sys.argv) < 2:
        print(‘Usage: {} adc_channel’.format(sys.argv[0]))
        sys.exit(1)

    sensor = GrovePH(int(sys.argv[1]))

    print('Detecting PH...')

    while True:
        try:
            print('PH Value: {:2.1f}'.format(sensor.PH))
            time.sleep(1)
        except KeyboardInterrupt:
            print("\nExiting...")
            sys.exit(0)

if __name__ == ‘__main__’:
    main()
1 Like

Thanks for the help!

I tried that code. This is the result:

[18:57:06] pi@openhab:~/GrovePi/Software/Python$ sudo python3 ph_sensor_2.py 4
Detecting PH…
PH Value: 38.1
PH Value: 38.1
PH Value: 38.1
PH Value: 38.1
PH Value: 38.1
PH Value: 38.1
PH Value: 38.1
PH Value: 38.1
PH Value: 38.1
PH Value: 38.1
^C
Exiting…

1 Like

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.

We’re really really close though!!

2 Likes

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.

Thanks!!!

1 Like

@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()
1 Like