I was hoping to get some help with my TDS sensor I have tried everything in the comments thus far TDS is plugged into A0
#!/usr/bin/env python3
import math
import sys
import time
from grove.i2c import Bus
from grove.adc import ADC
class GroveTDS:
def __init__(self, channel):
self.channel = channel
self.adc = ADC()
@property
def TDS(self):
value = self.adc.read(self.channel)
if value != 0:
voltage = value*5/1024.0
tdsValue = (133.42/voltage*voltage*voltage-255.86*voltage*voltage+857.39*voltage)*0.5
return tdsValue
else:
return 0
Grove = GroveTDS
def main():
if len(sys.argv) < 2:
print(‘Usage: {} adc_channel’.format(sys.argv[0]))
sys.exit(1)
#else:
# print(sys.argv)
sensor = GroveTDS(int(sys.argv[1]))
print('Detecting TDS on port A{}...'.format(sys.argv[1]))
while True:
try:
print('TDS Value: {}'.format(sensor.TDS))
time.sleep(1)
except:
print('Not found')
time.sleep(1)
if name == ‘main’:
main()
Thanks!