from temperature import TemperatureSensor # importerer Temperatur dokumentet
import time
from machine import Pin, ADC
pin = 25
t = TemperatureSensor(pin) # her kalder vi klassen. funktioner kan kaldes via t.funktion
R1 = 1000
Ra = 25 #Resistance of powering Pins
ECPin = ADC(Pin(32, Pin.IN))
ECGround = Pin(27, Pin.OUT)
ECPower = Pin(14, Pin.OUT)
Hana [USA] PPMconverion: 0.5
Eutech [EU] PPMconversion: 0.64
#Tranchen [Australia] PPMconversion: 0.7
Why didnt anyone standardise this?
PPMconversion=0.64
#*************Compensating for temperature ************************************#
#The value below will change depending on what chemical solution we are measuring
#0.019 is generaly considered the standard for plant nutrients [google "Temperature compensation EC" for more info
TemperatureCoef = 0.019 #this changes depending on what chemical we are measuring
#********************** Cell Constant For Ec Measurements *********************#
#Mine was around 2.9 with plugs being a standard size they should all be around the same
#But If you get bad readings you can use the calibration script and fluid to get a better estimate for K
K=2.88
##***************************** END Of Recomended User Inputs *****************************************************************#
#OneWire oneWire(ONE_WIRE_BUS) # Setup a oneWire instance to communicate with any OneWire devices
#DallasTemperature sensors(&oneWire) # Pass our oneWire reference to Dallas Temperature.
Temperature = None
rawEC = ECPin.read()
Vin = 3.3
Vdrop = 0
R1=(R1+Ra)
Rc = 0
EC = 0
EC25 = 0
ppm = 0
buffer = 0
ECGround.value(0)
time.sleep_ms(1000)
def GetEC():
Temperature = t.read_temp()
#************Estimates Resistance of Liquid ****************
ECPower.value(1)
rawEC = ECPin.read()
rawEC = ECPin.read()
ECPower.value(0)
#***************** Converts to EC **************************
Vdrop = (VinrawEC)/1024.0
Rc = (VdropR1)/(Vin-Vdrop)
Rc = Rc-Ra #acounting for Digital Pin Resitance
EC = 1000/(Rc*K)
#Compensating For Temperaure*******
EC25 = EC/ (1 + TemperatureCoef*(Temperature-25.0))
ppm = (EC25)(PPMconversion1000)
def PrintReadings():
print("rawEC: {}".format(rawEC))
print("Rc: {}".format(Rc))
#print(Rc)
#print(" EC: ")
#print(EC25)
print("EC: {} Simens ".format(EC25))
#print(ppm)
print("{} ppm ".format(ppm))
#print(Temperature)
print("{} *C ".format(Temperature))
print('')
"""
Usued for debugging
print("Vdrop: ");
print(Vdrop);
print("Rc: ");
print(Rc);
print(EC);
print("Siemens");
#********** end of Debugging Prints *********
"""
while True:
Temperature = t.read_temp()
GetEC()
PrintReadings()
"""
ECPower.value(1)
rawEC = ECPin.read()
rawEC = ECPin.read()
ECPower.value(0)
print(rawEC)
"""
time.sleep_ms(2000)