This commit is contained in:
2026-05-20 15:33:38 -04:00
commit dbd015f3b8
8 changed files with 121 additions and 0 deletions

1
README.md Normal file
View File

@@ -0,0 +1 @@
# raspool

1
Raspool Submodule

Submodule Raspool added at e2a93c9ffc

1
WiringPi Submodule

Submodule WiringPi added at b2af17eea9

Binary file not shown.

16
api.py Normal file
View File

@@ -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)

53
calibrate.py Normal file
View File

@@ -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

31
main.py Normal file
View File

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

18
test.py Normal file
View File

@@ -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)