claws / BH1750

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

Reading light level fails if using the ONETIME modes #17

Closed gerritv closed 7 years ago

gerritv commented 7 years ago

These modes power down the chip after the level is read. The present code does not wake up the chip when reading the value in those modes.

I added a save of mode and changed the code in readLightLevel:

uint16_t BH1750::readLightLevel(void) {

    ...

    // Start transmission to sensor
    Wire.beginTransmission(BH1750_I2CADDR);
    switch (MODE) {
        case BH1750_ONE_TIME_HIGH_RES_MODE:
        case BH1750_ONE_TIME_HIGH_RES_MODE_2:
        case BH1750_ONE_TIME_LOW_RES_MODE:
        __wire_write((uint8_t)MODE);
        break;
    }
    // Read two bytes from sensor
    Wire.requestFrom(BH1750_I2CADDR, 2);

    ...
}
gerritv commented 7 years ago

Awesome, thank you!!!

coelner commented 7 years ago

Please add the right delay time for the one-time measurement (datasheet page 7 and page 5 )

claws commented 7 years ago

@coelner, if you know what to do you are welcome to submit a merge request with the proposed change.