bh1750 - Driver for BH1750 light sensor

group bh1750

ESP-IDF driver for BH1750 light sensor.

Datasheet: ROHM Semiconductor bh1750fvi-e.pdf

Ported from esp-open-rtos

Copyright (C) 2017 Andrej Krutak dev@andree.sk

Copyright (C) 2018 Ruslan V. Uss

unclerus@gmail.com

BSD Licensed as described in the file LICENSE

Defines

BH1750_ADDR_LO

I2C address when ADDR pin floating/low.

BH1750_ADDR_HI

I2C address when ADDR pin high.

Enums

enum bh1750_mode_t

Measurement mode.

Values:

enumerator BH1750_MODE_ONE_TIME

One time measurement.

enumerator BH1750_MODE_CONTINUOUS

Continuous measurement.

enum bh1750_resolution_t

Measurement resolution.

Values:

enumerator BH1750_RES_LOW

4 lx resolution, measurement time is usually 16 ms

enumerator BH1750_RES_HIGH

1 lx resolution, measurement time is usually 120 ms

enumerator BH1750_RES_HIGH2

0.5 lx resolution, measurement time is usually 120 ms

Functions

esp_err_t bh1750_init_desc(i2c_dev_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptor.

Parameters
  • [out] dev – Device descriptor

  • [in] addr – I2C address, BH1750_ADDR_LO or BH1750_ADDR_HI

  • [in] port – I2C port number

  • [in] sda_gpio – GPIO pin number for SDA

  • [in] scl_gpio – GPIO pin number for SCL

Returns

ESP_OK on success

esp_err_t bh1750_free_desc(i2c_dev_t *dev)

Free device descriptor.

Parameters

dev – Pointer to device descriptor

Returns

ESP_OK on success

esp_err_t bh1750_power_down(i2c_dev_t *dev)

Power down device.

Parameters

dev – Pointer to device descriptor

Returns

ESP_OK on success

esp_err_t bh1750_power_on(i2c_dev_t *dev)

Power on device.

Parameters

dev – Pointer to device descriptor

Returns

ESP_OK on success

esp_err_t bh1750_setup(i2c_dev_t *dev, bh1750_mode_t mode, bh1750_resolution_t resolution)

Setup device parameters.

Parameters
  • dev – Pointer to device descriptor

  • mode – Measurement mode

  • resolution – Measurement resolution

Returns

ESP_OK on success

esp_err_t bh1750_set_measurement_time(i2c_dev_t *dev, uint8_t time)

Set measurement time.

Parameters
  • dev – Pointer to device descriptor

  • time – Measurement time (see datasheet)

Returns

ESP_OK on success

esp_err_t bh1750_read(i2c_dev_t *dev, uint16_t *level)

Read LUX value from the device.

Parameters
  • dev – Pointer to device descriptor

  • [out] level – read value in lux units

Returns

ESP_OK on success