commit dbd015f3b89365ccbfe964e2dd1e030f95818651 Author: Christian Mantha Date: Wed May 20 15:33:38 2026 -0400 start diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d63057 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# raspool diff --git a/Raspool b/Raspool new file mode 160000 index 0000000..e2a93c9 --- /dev/null +++ b/Raspool @@ -0,0 +1 @@ +Subproject commit e2a93c9ffc999dd001916c69827639200ab313af diff --git a/WiringPi b/WiringPi new file mode 160000 index 0000000..b2af17e --- /dev/null +++ b/WiringPi @@ -0,0 +1 @@ +Subproject commit b2af17eea92238fa99dae5bf174b3cdf81b78656 diff --git a/__pycache__/main.cpython-311.pyc b/__pycache__/main.cpython-311.pyc new file mode 100644 index 0000000..c74d362 Binary files /dev/null and b/__pycache__/main.cpython-311.pyc differ diff --git a/api.py b/api.py new file mode 100644 index 0000000..090f9ad --- /dev/null +++ b/api.py @@ -0,0 +1,16 @@ +from fastapi import FastAPI +from main import read_temp_water +#from main import read_ph +import uvicorn +app = FastAPI() + +@app.get("/get_water_temp") +async def read_root(): + return {"Message": read_temp_water()} + +#@app.get("/get_ph") +#async def read_root(): +# return {"Message": read_ph()} + +if(__name__ == "__main__"): + uvicorn.run(app, host='0.0.0.0', port=8000) diff --git a/calibrate.py b/calibrate.py new file mode 100644 index 0000000..2a36a9f --- /dev/null +++ b/calibrate.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +''' Raspberry Pi, ADS1115, PH4502C Calibration ''' +import board +import busio +import time +import sys + +import adafruit_ads1x15.ads1115 as ADS +from adafruit_ads1x15.analog_in import AnalogIn + +# Setup +i2c = busio.I2C(board.SCL, board.SDA) +ads = ADS.ADS1115(i2c) + +def read_voltage(channel): + while True: + buf = list() + + for i in range(10): # Take 10 samples + buf.append(channel.voltage) + buf.sort() # Sort samples and discard highest and lowest + buf = buf[2:-2] + avg = (sum(map(float,buf))/6) # Get average value from remaining 6 + + print(round(avg,2),'V') + time.sleep(2) + +if __name__ == '__main__': + print('\n\n\n') + print('---- RPi-ADS115-PH4502 Calibration ----') + input('Press Enter once you have grounded the BNC connector...') + channel = None + while channel not in [0,1,2,3]: + try: + channel = int(input('ADS1115 channel 0-3: ')) # ADS.P0, ADS.P1, ADS.P2, ADS.P3 + except: + print('Not a valid option. Try again.') + if channel == 0: + channel = AnalogIn(ads, ADS.P0) + elif channel == 1: + channel = AnalogIn(ads, ADS.P1) + elif channel == 2: + channel = AnalogIn(ads, ADS.P1) + elif channel == 3: + channel = AnalogIn(ads, ADS.P1) + else: + sys.exit('Error selecting an ADS1115 pin.') + print('Adjust potentiometer nearest to BNC socket to ~2.50V') + print('Starting readings. Press CTRL+C to stop...') + try: + read_voltage(channel) + except KeyboardInterrupt: + pass diff --git a/main.py b/main.py new file mode 100644 index 0000000..82e977f --- /dev/null +++ b/main.py @@ -0,0 +1,31 @@ +import os, glob, time + +os.system('modprobe w1-gpio') +os.system('modprobe w1-therm') + +base_dir = '/sys/bus/w1/devices/' +device_folder = glob.glob(base_dir + '28*')[0] +print(device_folder) +#device_file = device_folder + "/"+ 'w1_bus_master1' +#device_file = "/sys/bus/w1/devices/w1_bus_master1/28-000000bbd852" + + +def read_temp_raw(): + f = open(device_file, 'r') + lines = f.readlines() + f.close() + return lines + +def read_temp_water(): + lines = read_temp_raw() + while lines[0].strip()[-3:] != 'YES': + time.sleep(0.2) + lines = read_temp_raw() + equals_pos = lines[1].find('t=') + if equals_pos != -1: + temp_string = lines[1][equals_pos+2:] + temp_c = float(temp_string) / 1000.0 + return temp_c + +print(read_temp_water()) + diff --git a/test.py b/test.py new file mode 100644 index 0000000..fde8d8c --- /dev/null +++ b/test.py @@ -0,0 +1,18 @@ +import time +import board +import busio +import adafruit_ads1x15.ads1115 as ADS +from adafruit_ads1x15.analog_in import AnalogIn + + +i2c = busio.I2C(board.SCL, board.SDA) + +# Create the ADS object and specify the gain +ads = ADS.ADS1115(i2c) +ads.gain = 1 +chan = AnalogIn(ads, ADS.P0) + +# Continuously print the values +while True: + print(f"MQ-135 Voltage: {chan.voltage}V") + time.sleep(1)