|
Envorimental Monitoring
|
Driver interface for the BH1750 ambient light sensor. More...
#include "stdint.h"#include "stddef.h"Go to the source code of this file.
Data Structures | |
| struct | BH1750_HandleTypeDef |
| BH1750 driver handle. More... | |
Macros | |
| #define | BH1750_ADDRESS_GND (0x23 << 1) |
| #define | BH1750_ADDRESS_VCC (0x5C << 1) |
| #define | BH1750_ADDRESS BH1750_ADDRESS_GND |
| #define | BH1750_CONTINIOUS_H_RES_MODE 0x10 |
| #define | BH1750_CONTINIOUS_H_RES_MODE2 0x11 |
| #define | BH1750_CONTINIOUS_L_RES_MODE 0x13 |
| #define | BH1750_ONE_TIME_H_RES_MODE 0x20 |
| #define | BH1750_ONE_TIME_H_RES_MODE2 0x21 |
| #define | BH1750_ONE_TIME_L_RES_MODE 0x23 |
| #define | BH1750_PWR_DOWN 0x00 |
| #define | BH1750_PWR_ON 0x01 |
| #define | BH1750_RST 0x07 |
| #define | MEASUREMENT_TIME_H_RES_MODE 120 |
| #define | MEASUREMENT_TIME_H_RES_MODE2 120 |
| #define | MEASUREMENT_TIME_L_RES_MODE 16 |
| #define | BH1750_LUX_COEFF 1.2f |
| Lux conversion coefficient: raw / BH1750_LUX_COEFF = lux. | |
Functions | |
| int8_t | BH1750_Init (BH1750_HandleTypeDef *dev) |
| Powers on the BH1750 and sends the initial measurement mode command. | |
| int8_t | BH1750_Read (BH1750_HandleTypeDef *dev) |
| Reads the latest illuminance measurement from the BH1750. | |
Driver interface for the BH1750 ambient light sensor.
The BH1750 is a 16-bit I2C ambient light sensor with a configurable measurement mode. This driver supports all six modes defined in the datasheet and is platform-independent through injected function pointers.
Typical usage:
| #define BH1750_ADDRESS BH1750_ADDRESS_GND |
Default address alias.
| #define BH1750_ADDRESS_GND (0x23 << 1) |
I2C address when ADDR pin = GND.
| #define BH1750_ADDRESS_VCC (0x5C << 1) |
I2C address when ADDR pin = VCC.
| #define BH1750_CONTINIOUS_H_RES_MODE 0x10 |
Continuous high-res mode (1 lx, ~120 ms).
| #define BH1750_CONTINIOUS_H_RES_MODE2 0x11 |
Continuous high-res mode2 (0.5 lx, ~120 ms).
| #define BH1750_CONTINIOUS_L_RES_MODE 0x13 |
Continuous low-res mode (4 lx, ~16 ms).
| #define BH1750_ONE_TIME_H_RES_MODE 0x20 |
One-time high-res mode (1 lx, ~120 ms).
| #define BH1750_ONE_TIME_H_RES_MODE2 0x21 |
One-time high-res mode2 (0.5 lx, ~120 ms).
| #define BH1750_ONE_TIME_L_RES_MODE 0x23 |
One-time low-res mode (4 lx, ~16 ms).
| #define BH1750_PWR_DOWN 0x00 |
Power-down command.
| #define BH1750_PWR_ON 0x01 |
Power-on command.
| #define BH1750_RST 0x07 |
Reset data register command.
| #define MEASUREMENT_TIME_H_RES_MODE 120 |
Typical conversion time for H-res modes.
| #define MEASUREMENT_TIME_H_RES_MODE2 120 |
Typical conversion time for H-res2 mode.
| #define MEASUREMENT_TIME_L_RES_MODE 16 |
Typical conversion time for L-res mode.
| int8_t BH1750_Init | ( | BH1750_HandleTypeDef * | dev | ) |
Powers on the BH1750 and sends the initial measurement mode command.
| [in,out] | dev | Pointer to a BH1750_HandleTypeDef with all fields set. |
| int8_t BH1750_Read | ( | BH1750_HandleTypeDef * | dev | ) |
Reads the latest illuminance measurement from the BH1750.
For one-time modes the function re-sends the mode command and waits for conversion before reading. For continuous modes it reads immediately. The result is stored in dev->lux.
| [in,out] | dev | Pointer to an initialised BH1750_HandleTypeDef. |