-->
Page 1 of 1

bmp/bme280 first read

PostPosted: Wed Aug 23, 2017 11:22 pm
by johndoe71rus
i have issue read bmp/bme280 first time after power on. This is https://github.com/nodemcu/nodemcu-firmware/issues/1994 more info.

Code: Select allNodeMCU custom build by frightanic.com
   branch: master
   commit: b62fae918b3627209fe434950cffb2506cee9a31
   SSL: false
   modules: bme280,file,gpio,i2c,net,node,ow,spi,tmr,uart,wifi
 build    built on: 2017-08-23 16:50
 powered by Lua 5.1.4 on SDK 2.1.0(116b762)
lua: cannot open init.lua
> dofile("initsens.lua")
> Status = 5 (Got IP)
I'm connected to my last network. Launching my real task.
1
fail read alt
fail baro
PANIC: unprotected error in call to Lua API (sensors.lua:36: attempt to perform arithmetic on global 'P' (a nil value))

after panic and reset all read is ok.

sensors.lua http://pastebin.ubuntu.com/25376535/
I need advice on how to get around this problem

Re: bmp/bme280 first read

PostPosted: Sun Aug 27, 2017 2:56 pm
by darethehair
I am a newbie, but having the same problem with the BME280, I eventually read up on an (imperfect) suggestion to just introduce a delay before accessing the 'humi' part of the sensor -- but since many of the other calculations depend on it, I have *all* the I/O of the BME280 within the delay section:

Code: Select all   tmr.create():alarm(1000, tmr.ALARM_SINGLE, function()
      H, T = bme280.humi()
   ... (other BME280 I/O as well)...
   end)


Is this what you meant?

Re: bmp/bme280 first read

PostPosted: Sun Aug 27, 2017 11:01 pm
by johndoe71rus
so you think

Code: Select allfunction initSensors()
    i2c.setup(0, bmeSdaPin, bmeSclPin, i2c.SLOW) -- call i2c.setup() only once
    mode = bme280.setup()
    print(mode)
    tmr.delay(200)
end
...

200ms not enough

Re: bmp/bme280 first read

PostPosted: Mon Sep 04, 2017 12:58 pm
by darethehair
johndoe71rus wrote:so you think

Code: Select allfunction initSensors()
    i2c.setup(0, bmeSdaPin, bmeSclPin, i2c.SLOW) -- call i2c.setup() only once
    mode = bme280.setup()
    print(mode)
    tmr.delay(200)
end
...

200ms not enough


Sorry, I am not enough of an expert to really comment on this -- just that the delay that I found and used seems to work fine. Also, according to the docs, using 'tmr.delay' is not a recommended approach (I even found a thread on this forum that mentions the same thing). My suggestion is this: try 1000ms in your code, and if that doesn't work then try the code style that I used -- and report back your findings :)