-
Notifications
You must be signed in to change notification settings - Fork 0
/
bme680_sample.py
41 lines (33 loc) · 1.28 KB
/
bme680_sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
"""BME680 Sensor
reads Temperature, Humidity, Pressure and Gas of a BME680 sensor
you need to download first bme680.py from:
* https://raw.githubusercontent.com/alaub81/rpi_pico_scripts/main/lib/bme680.py
and upload it to the lib or root folder of your pico
"""
from bme680 import *
from machine import I2C, Pin
from time import sleep
# Initialize I2C-Pins
i2c_sda = Pin(20)
i2c_scl = Pin(21)
# change this to match the location's pressure (hPa) at sea level
sealevelpressure = 1013.25
# Initialize BME680 Sensor
bme680 = BME680_I2C(I2C(0, sda=i2c_sda,scl=i2c_scl))
# You will usually have to add an offset to account for the temperature of
# the sensor. This is usually around 5 degrees but varies by use. Use a
# separate temperature sensor to calibrate this one.
temperature_offset = -2
# set sealevel if it is conffigured
if 'sealevelpressure' in locals():
bme680.sea_level_pressure = sealevelpressure
# degree symbol decleration
degreecels = '\u00B0' + "C"
while True:
print("\nTemperature: %0.1f " % (bme680.temperature + temperature_offset) + degreecels)
print("Gas: %d ohm" % bme680.gas)
print("Humidity: %0.1f %%" % bme680.humidity)
print("Pressure: %0.3f hPa" % bme680.pressure)
print("Altitude = %0.2f meters" % bme680.altitude)
sleep(3)