claws / BH1750

An Arduino library for the digital light sensor breakout boards containing the BH1750FVI IC
MIT License
248 stars 107 forks source link

Usage information MTreg #53

Closed coelner closed 3 years ago

coelner commented 5 years ago

As you can see, I used the MTreg value to capture outdoor light. bildschirmfoto von 2018-10-11 09-16-16

It reveals an error. The esp8266 is in deep sleep, therefore it restart completely and the saved MTreg value in the library get lost. But the sensor itself uses another MTreg value. I have no idea how to solve the problem in a nice way, but some thoughts:

  1. include in begin() some resetting to the default MTreg
  2. get/set method to manipulate the saved MTreg in the library space
  3. inform the user to take care of this behavior
  4. (find a hidden possibility to get the current MTreg from the sensor itself)
bjarnebuchmann commented 4 years ago

I can confirm this issue. The problem is that the BH1750 library does not always write the default MTreg to the device upon begin(). Rather, it assumes (sometimes falsely so) that the device uses the default MTreg on start. That is not true, if the program is reset (eg waking from deep sleep or rebooting) without giving a full power interrupt, which could reset MTreg on the BH1750. The solution seems straight forward: setup() should always call

setMTreg( (byte) BH1750_MTreg ) or alt setMTreg( (byte)BH1750_DEFAULT_MTREG )

to ensure that MTreg on device (BH1750) and object (library) mathches.

/Bjarne

bjarnebuchmann commented 4 years ago

As a work-around, I will suggest to manually call setMTreg() right after begin(), as per:

setup(){
...
  lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE);
  lightMeter.setMTreg((byte) BH1750_DEFAULT_MTREG);
...
}
coelner commented 3 years ago

https://github.com/claws/BH1750/blob/38e9f378e07f0740f80a9a7700377ecdddcc7836/src/BH1750.cpp#L79 @claws what about this? return (configure(mode) && setMTreg((byte) BH1750_DEFAULT_MTREG))