parent
d8da243a07
commit
40b68af9aa
9
main.py
9
main.py
|
@ -8,6 +8,9 @@ try:
|
|||
import gpiozero
|
||||
global GPIO
|
||||
import RPi.GPIO as GPIO
|
||||
import board
|
||||
import busio
|
||||
import adafruit_bmp280
|
||||
except ImportError:
|
||||
print('Some modules are missing. Try to install them with "pip3 install -r requirements.txt"')
|
||||
print(ImportError)
|
||||
|
@ -77,5 +80,11 @@ def get_moisture():
|
|||
|
||||
return adc.readADCSingleEnded(0, gain, sps) / 1000 + adc.readADCSingleEnded(1, gain, sps) / 1000 + adc.readADCSingleEnded(2, gain, sps) / 1000 + adc.readADCSingleEnded(3, gain, sps) / 1000
|
||||
|
||||
#temperature
|
||||
def get_temperature():
|
||||
i2c = busio.I2C(board.SCL, board.SDA)
|
||||
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x03)
|
||||
return int(bmp280.temperature)
|
||||
|
||||
print(get_moisture())
|
||||
print(get_water_level())
|
60
test.py
60
test.py
|
@ -1,48 +1,30 @@
|
|||
import board
|
||||
import busio
|
||||
import adafruit_bmp280
|
||||
global GPIO
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
# def get_temperature():
|
||||
# i2c = busio.I2C(board.SCL, board.SDA)
|
||||
# bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x03)
|
||||
# return bmp280.temperature
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
|
||||
count = 2
|
||||
i2c = busio.I2C(board.SCL, board.SDA)
|
||||
while True:
|
||||
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76)
|
||||
print(int(bmp280.temperature))
|
||||
# print(get_temperature()
|
||||
GPIO_TRIGGER = 18
|
||||
GPIO_ECHO = 24
|
||||
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
|
||||
GPIO.setup(GPIO_ECHO, GPIO.IN)
|
||||
|
||||
|
||||
# global GPIO
|
||||
# import RPi.GPIO as GPIO
|
||||
# import time
|
||||
|
||||
# GPIO.setmode(GPIO.BCM)
|
||||
|
||||
# GPIO_TRIGGER = 18
|
||||
# GPIO_ECHO = 24
|
||||
# GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
|
||||
# GPIO.setup(GPIO_ECHO, GPIO.IN)
|
||||
|
||||
# def get_water_level():
|
||||
# GPIO.output(GPIO_TRIGGER, True)
|
||||
# time.sleep(0.00001)
|
||||
# GPIO.output(GPIO_TRIGGER, False)
|
||||
def get_water_level():
|
||||
GPIO.output(GPIO_TRIGGER, True)
|
||||
time.sleep(0.00001)
|
||||
GPIO.output(GPIO_TRIGGER, False)
|
||||
|
||||
# startTime = time.time()
|
||||
# StopTime = time.time()
|
||||
startTime = time.time()
|
||||
StopTime = time.time()
|
||||
|
||||
# while GPIO.input(GPIO_ECHO) == 0:
|
||||
# startTime = time.time()
|
||||
# while GPIO.input(GPIO_ECHO) == 1:
|
||||
# StopTime = time.time()
|
||||
while GPIO.input(GPIO_ECHO) == 0:
|
||||
startTime = time.time()
|
||||
while GPIO.input(GPIO_ECHO) == 1:
|
||||
StopTime = time.time()
|
||||
|
||||
# TimeElapsed = StopTime - startTime
|
||||
# distance = (TimeElapsed * 34300) / 2
|
||||
TimeElapsed = StopTime - startTime
|
||||
distance = (TimeElapsed * 34300) / 2
|
||||
|
||||
# return distance
|
||||
return distance
|
||||
|
||||
# print(get_water_level())
|
||||
print(get_water_level())
|
Loading…
Reference in New Issue