-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bmp/bme280 first read #1994
Comments
I can confirm that. Just ran into this yesterday. |
What is returned by |
My test bed is really simple (snippet from our examples). Note that I'm on the 1.5.4 branch while the OP tests against https://github.com/nodemcu/nodemcu-firmware/tree/22e1adc4b06c931797539b986c85e229e5942a5f i.e. doesn't have your #1887 changes yet. print(bme280.init(6, 7))
H, T = bme280.humi()
print(string.format("T=%d.%02d", T / 100, T % 100))
print(string.format("humidity=%d.%03d%%", H / 1000, H % 1000)) Run for the 1st time right after power up this yields
NOT running |
Maybe you hit the initial measurement phase with the read commands. |
A delay of even 10ms fixes this for me: print(bme280.init(6, 7))
tmr.create():alarm(10, tmr.ALARM_SINGLE, function()
local H, T = bme280.humi()
print(string.format("T=%d.%02d", T / 100, T % 100))
print(string.format("humidity=%d.%03d%%", H / 1000, H % 1000))
end) Is there a sensible way for the module to correct this internally or do we just need to document this behavior? |
The delay depends on the selected oversampling rates (ref. chapter 9.1 in the BME280 datasheet) and varies between some tens to hundreds of milliseconds. |
I expect that the correct way to handle this is to check the status register (0xF3) for zero after a forced read or after a cold start. |
So, "universal" code looks like this? alt=217 -- altitude of the measurement place
mode = nil
mode = bme280.init(5, 4)
tmr.create():alarm(200, tmr.ALARM_SINGLE, function()
if mode == 1 then
print("bmp280")
T, P, H, QNH = bme280.read(alt)
local Tsgn = (T < 0 and -1 or 1); T = Tsgn*T
print(string.format("T=%s%d.%02d", Tsgn<0 and "-" or "", T/100, T%100))
print(string.format("QFE=%d.%03d", P/1000, P%1000))
print(string.format("QNH=%d.%03d", QNH/1000, QNH%1000))
MHG = P / 133,3
print(string.format("pressure = %d.%02d", MHG/10 , MHG%10))
-- altimeter function - calculate altitude based on current sea level pressure (QNH) and measure pressure
P = bme280.baro()
curAlt = bme280.altitude(P, QNH)
local curAltsgn = (curAlt < 0 and -1 or 1); curAlt = curAltsgn*curAlt
print(string.format("altitude=%s%d.%02d", curAltsgn<0 and "-" or "", curAlt/100, curAlt%100))
elseif mode == 2 then
print("bme280")
T, P, H, QNH = bme280.read(alt)
local Tsgn = (T < 0 and -1 or 1); T = Tsgn*T
print(string.format("T=%s%d.%02d", Tsgn<0 and "-" or "", T/100, T%100))
print(string.format("QFE=%d.%03d", P/1000, P%1000))
print(string.format("QNH=%d.%03d", QNH/1000, QNH%1000))
MHG = P / 133,3
print(string.format("pressure = %d.%02d", MHG/10 , MHG%10))
print(string.format("humidity=%d.%03d%%", H/1000, H%1000))
D = bme280.dewpoint(H, T)
local Dsgn = (D < 0 and -1 or 1); D = Dsgn*D
print(string.format("dew_point=%s%d.%02d", Dsgn<0 and "-" or "", D/100, D%100))
-- altimeter function - calculate altitude based on current sea level pressure (QNH) and measure pressure
P = bme280.baro()
curAlt = bme280.altitude(P, QNH)
local curAltsgn = (curAlt < 0 and -1 or 1); curAlt = curAltsgn*curAlt
print(string.format("altitude=%s%d.%02d", curAltsgn<0 and "-" or "", curAlt/100, curAlt%100))
else
print("no device")
end
end) |
i don't know why panic happend paste.ubuntu.com/24891211 sensors.lua |
A delay is required between `setup` and reading from sensor. Fixes #1994.
I have to replace bme280.init(bmeSdaPin, bmeSclPin) to i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
bme280.setup() ? this work in master or i need dev firmware? |
The documentation for the respective branch has the authoritative answers. So either -> |
the log http://pastebin.ubuntu.com/25376531/ i need new firmware? |
Yes, we only support current versions (atm 2.1).
You could use |
need help sorry, wrong version. Need float
|
We gotta stop this, GitHub ain't a support forum, see #1010 |
A delay is required between `setup` and reading from sensor. Fixes nodemcu#1994.
hi @johndoe71rus , I am getting the same nil response after calling bme.setup(), how did you fix it? |
@ccunarro |
First read data bmp/bme280 get error
all next readings correct.
I have bme280 and bmp280, check booth.
Code http://paste.ubuntu.com/24710875/
logs http://paste.ubuntu.com/24711075/
i can wait long time to start script. Problem only with the first reading. After power up
The text was updated successfully, but these errors were encountered: