-
Notifications
You must be signed in to change notification settings - Fork 10
begin
This function sets the address to this Sensor and resets the timing values according to the datasheet to the most pessimistic values. This will ensure, that you always get valid results.
bool begin(byte address, TwoWire *myWire = &Wire);
true if a device found at the address.
For the BH1750 there a two available addresses: 0x23 and 0x5C.
To choose 0x23, you have to connect the address pin to ground.
For 0x5C, you have to connect the address pin to VCC.
With the breakout boards GY-30
and GY-302
, you can connect this pin to 5V or to 3.3V.
To make it easier, to choose the right address, the library provides a enum:
enum BH1750Address
{
toGround = 0x23,
BH1750_TO_VCC = 0x5C
};
So just call:
bool avail = BH1750_1.begin(BH1750_TO_VCC);
bool avail = BH1750_2.begin(BH1750_TO_GROUND);
No check for correct address.
Optional parameter.
If not set, the standard wire object is used.
For ESP32, you can use one of the two wire objects, so you are able to work with up to 4 sensors.
For ESP8266, you may use different pin than the standard pins.
If you have a compatible software library for wire, you can pass this object to TwoWire
, without changing this library.
You can drive this device in fast wire mode with wire.setClock(400000);
, instead of standard (100000);.
You may even switch this, while running your code.
The timing parameters are not stored in the chip itself.
So, if you do not get valid results, because on heavy manipulations to the timings, you can call begin
again, to reset the sensor or, more easy, just press the reset button on your MCU.