Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ void calibration(float voltage, float temperature, char* cmd);

## Compatibility

MCU | Work Well | Work Wrong | Untested | Remarks
------------------ | :----------: | :----------: | :---------: | -----
Arduino Uno | √ | | |
Leonardo | √ | | |
Meag2560 | √ | | |
MCU | Work Well | Work Wrong | Untested | Remarks
-------------------- | :----------: | :----------: | :----------: | ------------
Arduino Uno | √ | | |
Leonardo | √ | | |
Meag2560 | √ | | |
Raspberry Pi Pico WH | √ | | | Micropython
ESP32 | √ | | √ | Micropython

## History

Expand Down
2 changes: 2 additions & 0 deletions RaspberryPi/Micropython/example/ecdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kvalueLow=1.0
kvalueHigh=1.0
16 changes: 16 additions & 0 deletions RaspberryPi/Micropython/example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from machine import Pin, ADC
import utime
from uDFRobot_EC import DFRobot_EC

ec = DFRobot_EC()
ec.begin()

adc = ADC(Pin(28, Pin.IN)) # Read Analog Value from a ADC Pin GPIO28

while True:
temperature = 25 # Need to read the water temperature in Celsius
adc_value_16bit = adc.read_u16()
adc_value_12bit = adc_value_16bit >> 4 # Convert to 12-bit by shifting right 4 bits
EC = ec.readEC(adc_value_12bit,temperature)
print("Temperature:%.1f EC:%.2f ms/cm"%(temperature,EC))
utime.sleep(0.5)
19 changes: 19 additions & 0 deletions RaspberryPi/Micropython/example/uDFRobot_EC_Calibration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from machine import Pin, ADC
import utime
from uDFRobot_EC import DFRobot_EC

ec = DFRobot_EC()
ec.begin()

adc = ADC(Pin(28, Pin.IN)) # Read Analog Value from a ADC Pin GPIO28

while True:
temperature = 25 # Specify the conductivity solution temperature in Celsius

adc_value_16bit = adc.read_u16()
adc_value_12bit = adc_value_16bit >> 4 # Convert to 12-bit by shifting right 4 bits

print("12-bit ADC: ", adc_value_12bit)

#Calibrate the calibration data
ec.calibration(adc_value_12bit,temperature)
4 changes: 4 additions & 0 deletions RaspberryPi/Micropython/example/uDFRobot_EC_Reset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from uDFRobot_EC import DFRobot_EC

ec = DFRobot_EC()
ec.reset()
88 changes: 88 additions & 0 deletions RaspberryPi/Micropython/uDFRobot_EC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import machine

_kvalue = 1.0
_kvalueLow = 1.0
_kvalueHigh = 1.0

class DFRobot_EC():
def begin(self):
global _kvalueLow
global _kvalueHigh
try:
with open('ecdata.py','r') as f:
kvalueLowLine = f.readline()
kvalueLowLine = kvalueLowLine.strip('kvalueLow=')
_kvalueLow = float(kvalueLowLine)
kvalueHighLine = f.readline()
kvalueHighLine = kvalueHighLine.strip('kvalueHigh=')
_kvalueHigh = float(kvalueHighLine)
except:
print("ecdata.py ERROR ! Reset to default parameters")
self.reset()
def readEC(self,voltage,temperature):
global _kvalueLow
global _kvalueHigh
global _kvalue
rawEC = 1000*voltage/820.0/200.0
valueTemp = rawEC * _kvalue
if(valueTemp > 2.5):
_kvalue = _kvalueHigh
elif(valueTemp < 2.0):
_kvalue = _kvalueLow
value = rawEC * _kvalue
value = value / (1.0+0.0185*(temperature-25.0))
return value
def calibration(self,voltage,temperature):
rawEC = 1000*voltage/820.0/200.0
print(rawEC, voltage, temperature)
if (rawEC>0.9 and rawEC<1.9):
compECsolution = 1.413*(1.0+0.0185*(temperature-25.0))
KValueTemp = 820.0*200.0*compECsolution/1000.0/voltage
round(KValueTemp,2)
print(">>>Buffer Solution:1.413us/cm")
f=open('ecdata.py','r')
flist=f.readlines()
flist[0]='kvalueLow='+ str(KValueTemp) + '\n'
f=open('ecdata.py','w')
f.write(''.join(flist))
f.close()
print(">>>EC:1.413us/cm Calibration completed,Please enter Ctrl+C exit calibration in 5 seconds")
machine.reset()
elif (rawEC>9 and rawEC<16.8):
compECsolution = 12.88*(1.0+0.0185*(temperature-25.0))
KValueTemp = 820.0*200.0*compECsolution/1000.0/voltage
print(">>>Buffer Solution:12.88ms/cm")
f=open('ecdata.py','r')
flist=f.readlines()
flist[1]='kvalueHigh='+ str(KValueTemp) + '\n'
f=open('ecdata.py','w')
f.write(''.join(flist))
f.close()
print(">>>EC:12.88ms/cm Calibration completed,Please enter Ctrl+C exit calibration in 5 seconds")
machine.reset()
else:
print(">>>Buffer Solution Error Try Again<<<")
machine.reset()
def reset(self):
_kvalueLow = 1.0;
_kvalueHigh = 1.0;
try:
f=open('ecdata.py','r')
flist=f.readlines()
flist[0]='kvalueLow=' + str(_kvalueLow) + '\n'
flist[1]='kvalueHigh='+ str(_kvalueHigh) + '\n'
f=open('ecdata.py','w')
f.write(flist)
f.close()
print(">>>Reset to default parameters<<<")
machine.reset()
except:
f=open('ecdata.py','r')
flist=f.readlines()
flist ='kvalueLow=' + str(_kvalueLow) + '\n'
flist +='kvalueHigh='+ str(_kvalueHigh) + '\n'
f=open('ecdata.py','w')
f.write(''.join(flist))
f.close()
print(">>>Reset to default parameters<<<")
machine.reset()