Hi, python interpreter show an ImportError: No module named 'bme280' but this has worked for me fine before and now that I'm trying it again after some time, this happens. I haven't changed my code but I did update the MicroPython firmware to latest v1.23.0 although when I saw the problem I tried with older firmware versions but with no luck.
RPI Pico W firmware
I'm using a Raspberry Pi Pico W board here and this is the code:
import machine
from time import sleep
import math
import bme280
i2c = machine.I2C(1, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
print(i2c)
devices = i2c.scan()
print("I2C devices found:", devices)
last_altitude = 0.
def calculate_altitude(pressure, temperature):
pressure_at_sea_level = float(1013.25)
temperature_at_sea_level = float(288.15)
earth_molar_mass = float(0.029)
gravity = float(9.8062)
gas_constant = float(8.314)
lapse_rate = float(-0.0065)
exponent = (gas_constant*lapse_rate)/(gravity*earth_molar_mass)
altitude = temperature_at_sea_level/lapse_rate*(1-(pressure/pressure_at_sea_level)**exponent)
return altitude
def ewma_filter(current_value, last_value):
filtered_value = last_value + 0.4*(current_value - last_value);
last_value = filtered_value;
return filtered_value, last_value
while True:
bme = bme280.BME280(i2c=i2c)
temperature_str, pressure_str, humidity_str = bme.values
temperature = float(temperature_str[:-1])
pressure = float(pressure_str[:-3])
humidity = float(humidity_str[:-1])
altitude = calculate_altitude(pressure, temperature)
filtered_altitude, last_altitude = ewma_filter(altitude, last_altitude)
print(filtered_altitude)
sleep(0.005)
I also noticed that the on board LED isn't working after updating to the latest frimware version and on any other after that but the code does compile. I went through the documentation of the latest released FW but I haven't found anything. Could you tell if there is something wrong with the BME280 library or the FW in general?
On board LED code:
from machine import Pin
import time
led = Pin("LED", Pin.OUT)
i = True
while i:
led.on()
time.sleep(0.2)
led.off()
time.sleep(0.2)