Skip to content

adjust MTreg

Stefan Armborst edited this page Jan 27, 2020 · 16 revisions

Hacking the sensor...

...by adjusting the MTreg.

In the datasheet you will find the information that you can adjust the sensitivity and the range of brightness by MTreg.
The MTreg is proportional to the conversion time.

To calculate the conversion time in milliseconds you need a calibration , because the timing is chip-dependent an has differences up to 50%!

The range of MTreg is from 31 to 254 and typically corresponds to conversion times from 54 ms to 442 ms at high quality. For low quality you only need 7 ms to 59 ms.

If you want to measure very bright light conditions you has to use the lowest mode MTreg = 31.
Also if very short conversion times are important a low MTreg is needed.

So I asked myself, what would happen if I set the MTreg below 31?

Here the result:

Even at a MTreg = 1, I was able to measure reasonable values!
As you see, the raw data and the sampling time are proportional to the MTreg.

Also at low quality I measured valid values:

With MTreg 1 with low quality I was able to measure 1000 samples per second!
(ESP8266 with clock speed of wire at 400 kHz)

Each MTreg between 31 and 254 offers 65535 digits for raw data.
But is this also true for MTreg's below of 31?
With my brightest torch, I saturated the sensor and measured the maximum raw data at different MTreg's:

At quality BH1750_QUALITY_HIGH2 below of MTreg 5 the maximum value of 65535 decreases!
At quality BH1750_QUALITY_LOW and BH1750_QUALITY_HIGH, below of MTreg 10 the maximum value of 65535 decreases.

If we calculate the Lux values from this raw data we will obtain this diagram:

At quality BH1750_QUALITY_HIGH2 the maximum value you can measure is 383479 LUX at MTreg 5.
At quality BH1750_QUALITY_HIGH / BH1750_QUALITY_LOW the maximum value you can measure is 376826 LUX at MTreg 10.
That's at least three times more than the data sheet offers.

I suppose the reason for the limitation to MTreg 31, is the strong variation in quality of the chips.

So, with every individual sensor you will probably get other results or even wrong data!


Limitations of auto ranging

If you use the autor ranging function with this hack, you will not be able to get the lowest Mtreg's, because the library assumes that the highest raw data always will be 65535.
As each sensor quality is different, there is no fix for this.
To alleviate this problem, you should use adjustSettings with the parameter forcePreShot = true.

bool adjustSettings(byte percent = 50, bool forcePreShot = false);

Hacking guide

You do it on your own risk!

  • Please go to this library in your local library folder.
    Often the path is: "C:\Users\ <user name> \Documents\Arduino\libraries\hp_BH1750\src".

  • Create a backup copy of the File hp_BH1750.h.

  • Open the file hp_BH1750.h with a text editor and change the line:
    BH1750_MTREG_LOW = 31, to
    BH1750_MTREG_LOW = 1,.

  • Save the file and compile the sketch again.

  • Now you can check, up to which MTreg your sensor works correctly.
    For example try the sketch sweep_Mtreg.ino in the folder examples.
    (File -> examples -> hp_BH1750 -> sweep_Mtreg.ino)

  • It is quite unlikely that the sensor will be damaged, if it operates outside its specification. My sensors are working without any problems with MTreg's down to 1! :-)

  • To restore the original settings, change back to BH1750_MTREG_LOW = 31,", or restore the hp_BH1750.h with your backup copy.

  • You have to compile the sketch again.

Clone this wiki locally