Starmbi / hp_BH1750

hp_BH1750
MIT License
31 stars 10 forks source link

Occasional false positive returns from hasValue(true) (?) #2

Closed EKMallon closed 2 years ago

EKMallon commented 3 years ago

I've been doing some tests with your library and noticed that the following occasionally breaks out of the following loop before the sensor has had enough time to gather a reading:

bh1750.adjustSettings(90,true); bh1750.start(); do{ //...reading other non I2C sensors here & averaging.... } while(bh1750.hasValue(true) == false); float lux_T1red= bh1750.getLux();

If I take readings every minute, about 1-2 of them per hour will end up with zero in lux_T1red on a ProMini system running at 8mhz (default 100khz I2C bus). When I added a counter to the loop it's clear that the do-while is ending at seemingly random times 'before' the BH1750 has had enough time to gather its next reading. It's rare, but I've seen this behavior on 3 different systems with the same code, but different hardware & BH1750 sensor modules. The sensor modules are just cheap ones from eBay, so there is a possibility of that being a factor, rather than your library (?). Anyway just passing on the info.

Starmbi commented 3 years ago

I have recreated your program with the same parameters and made 10,000 measurements. All measurements were error-free. (Arduino nano at default 100khz I2C bus)

If the measurement is shorter than expected, the reason is probably really a communication issue.

This can be caused by the chip itself, the power supply, the wiring or interference from other devices. If the measurement shows "0 Lux", you can get the time with the function "getTime()". (https://github.com/Starmbi/hp_BH1750/wiki/getTime) If the result is "999", this indicates a communication issue.

Also most commands return a boolean value indicating whether the communication was successful or not.

EKMallon commented 3 years ago

When I run the same sensors with blocking reads (ie nothing in between .start and .getLux ) they produce no errors, so I'm going to assume those other sensors (a reverse bias LED light reading) must be causing a power blip affecting the I2C bus. I will do some checking with getTime. Cheers.

Starmbi commented 2 years ago

No answer, closed.