2022-07-10 23:27:51 +00:00
|
|
|
import board
|
|
|
|
import busio
|
|
|
|
import adafruit_bmp280
|
|
|
|
import time
|
2022-07-10 23:17:29 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
def get_temperature():
|
|
|
|
i2c = busio.I2C(board.SCL, board.SDA)
|
2022-07-10 23:28:26 +00:00
|
|
|
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x01)
|
2022-07-10 23:27:51 +00:00
|
|
|
return bmp280.temperature
|
2022-07-10 23:17:29 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
while True:
|
|
|
|
print(get_temperature())
|
|
|
|
time.sleep(1)
|
2022-07-10 23:17:29 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
# global GPIO
|
|
|
|
# import RPi.GPIO as GPIO
|
|
|
|
# import time
|
2022-07-06 16:34:46 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
# GPIO.setmode(GPIO.BCM)
|
2022-07-10 23:18:12 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
# GPIO_TRIGGER = 18
|
|
|
|
# GPIO_ECHO = 24
|
|
|
|
# GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
|
|
|
|
# GPIO.setup(GPIO_ECHO, GPIO.IN)
|
2022-07-10 23:17:29 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
# def get_water_level():
|
|
|
|
# GPIO.output(GPIO_TRIGGER, True)
|
|
|
|
# time.sleep(0.00001)
|
|
|
|
# GPIO.output(GPIO_TRIGGER, False)
|
2022-07-10 23:17:29 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
# startTime = time.time()
|
|
|
|
# StopTime = time.time()
|
2022-07-10 23:17:29 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
# while GPIO.input(GPIO_ECHO) == 0:
|
|
|
|
# startTime = time.time()
|
|
|
|
# while GPIO.input(GPIO_ECHO) == 1:
|
|
|
|
# StopTime = time.time()
|
2022-07-10 23:17:29 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
# TimeElapsed = StopTime - startTime
|
|
|
|
# distance = (TimeElapsed * 34300) / 2
|
2022-07-10 23:17:29 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
# return distance
|
2022-07-09 22:24:32 +00:00
|
|
|
|
2022-07-10 23:27:51 +00:00
|
|
|
# print(get_water_level())
|