Schaltungsaufbau
Programmcode
Für externen BME280-Sensor.
import time
import board
from adafruit_bme280 import basic as adafruit_bme280
# Create sensor object, using the board's default I2C bus.
i2c = board.I2C() # uses board.SCL and board.SDA
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=118)
# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25
while True:
print("Temperature: {:.1f} C".format(bme280.temperature))
print("Humidity: {:.1f} %".format(bme280.humidity))
print("Barometric pressure: {:.1f} hPa".format(bme280.pressure))
print("Altitude: {:.2f} m".format(bme280.altitude))
time.sleep(2)
Für den BMP280-Sensor auf dem Feather Sense.
1import time
2import board
3import busio
4import adafruit_bmp280
5
6# Create the I2C interface.
7i2c = busio.I2C(board.SCL, board.SDA)
8bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
9# change this to match the location's pressure (hPa) at sea level
10bmp280.sea_level_pressure = 1013.25
11
12while True:
13 print("Temperature: {:.1f} C".format(bmp280.temperature))
14 print("Barometric pressure: {:.1f} hPa".format(bmp280.pressure))
15 print("Altitude: {:.2f} m".format(bmp280.altitude))
16 time.sleep(2)
Weiterführende Links
Du hast noch nicht genug vom Thema?
Hier findest du noch weitere passende Inhalte zum Thema: