Open nekitoss opened 1 year ago
Another idea is to create startOneTimeMeasure()
, which will just start measure using already set (with validation) ONE_TIME mode, and, unlike conigure()
, it won't be waiting 10ms to sensor receive command (if i understood corretly that delay in case someone tries to do something just right after), which will allow non-blocking flow
I think this library will not get any further attention, maybe you should consider to fork and patch.
The sleep in general is not the problem, but most of the arduino devices doesn't restore their RAM. therefore the library needs to get initialized after every wakepup. However, the instance of this library stores the last value and no, there is no getter for this currently: https://github.com/claws/BH1750/blob/b6986b553faed246ee267801ca23ccaea038d7cc/src/BH1750.h#L81
this here: https://github.com/claws/BH1750/blob/b6986b553faed246ee267801ca23ccaea038d7cc/src/BH1750.cpp#L102 is because of the behavior of this chip, AFAIK it needs this time by itself. This value seems to work for most of the users, but feel free to look here: https://github.com/Starmbi/hp_BH1750/wiki/
As far as I remember you should be able to trigger a OneTime command, got to sleep the right amount of time and read then the sensor. The sensor itself stores the last measurement in the register until a new measurement is completed. (Need confirmation). A get function for the wait delay could be useful, but is unlikely to happen. On a battery driven design, you could sleep long enough to be sure that this chip is ready to deliver a new value (e.g. 500ms). If you want both, like maximum battery saving AND fastest refresh rate on hard timings, then this library is not useful.
Because at some point was removed this fix for auto-start one-time measurement (maybe because it sarted at reading moment) And because it is not clear from README.md (but still present in example), that you need to start one-time measurement again by calling
lightMeter.configure(BH1750::ONE_TIME_HIGH_RES_MODE);
(and not just usereadLightLevel()
)I suggest clarifiyng that in README.md:35
and in example BH1750onetime.ino
Also because my battery-powered device sleeps between the start and end of measurement - I cannot rely on
measurementReady()
function, because millis() are "paused" during sleep, if I remember correctly.So I suggest adding a function, that gives you back delay time, and reusing that function in the beginning of
measurementReady()
function. Here is quick sketch (sorry, if any bad function names or mistakes - i do not program on C++):I can make a PR if these changes are acceptable (or you can do it by yourself, if it is more comfortable).