57 lines
1.2 KiB
Python
57 lines
1.2 KiB
Python
import board
|
|
import busio
|
|
import adafruit_bmp280
|
|
import time
|
|
|
|
# def get_temperature():
|
|
# i2c = busio.I2C(board.SCL, board.SDA)
|
|
# bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x03)
|
|
# return bmp280.temperature
|
|
|
|
count = 2
|
|
i2c = busio.I2C(board.SCL, board.SDA)
|
|
while True:
|
|
count += 1
|
|
if count != 77:
|
|
print(hex(count))
|
|
try:
|
|
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=hex(count))
|
|
print(bmp280.temperature)
|
|
exit()
|
|
except:
|
|
pass
|
|
else:
|
|
exit()
|
|
# print(get_temperature()
|
|
|
|
|
|
# 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)
|
|
|
|
# startTime = time.time()
|
|
# 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
|
|
|
|
# return distance
|
|
|
|
# print(get_water_level()) |