catdog2 / mpy_bme280_esp8266

Driver for the Bosch BME280 for use with MicroPython on ESP8266 boards
73 stars 41 forks source link

Bad readings every 16th reading #8

Open OndrejBakan opened 6 years ago

OndrejBakan commented 6 years ago

Hi! First of all thanks for your work!

I was measuring temperature with one minute interval and I noticed that every +- 16 minutes I got false readings. Temperature is 20.5°C and than it suddenly drops to 16 - 18°C for one reading. Same goes for pressure, 975 hPa and then drop to about 967. False values are not same everytime.

Here is my code:

import machine
import network
from lib import bme280
from lib import urequests as requests

i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
bmp = bme280.BME280(i2c=i2c)

def connect():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        wlan.connect('*', '*')
        while not wlan.isconnected():
            pass

def get_data(timer=None):
    api_key = '*'
    temperature, pressure, humidity = bmp.read_compensated_data()

    temperature = (temperature / 100) - 2
    pressure = (pressure / 256) / 100

    url = 'https://api.thingspeak.com/update?api_key={}&field1={}&field2={}' . format(api_key, temperature, pressure)
    r = requests.get(url)

connect()

get_data()

timer = machine.Timer(-1)
timer.init(period=60000, mode=machine.Timer.PERIODIC, callback=get_data)
OndrejBakan commented 6 years ago

I just noticed it's not every 16 minutes, but every 16th reading.