Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BH1750 Class Reference
Example: More...
#include <BH1750.h>
Public Types | |
| enum | BH1750_ADDRESS { BH1750_ADDR_L = ( 0x23 << 1 ), BH1750_ADDR_H = ( 0x5C << 1 ) } |
Represents the different I2C address possibilities for the BH1750. More... | |
| enum | BH1750_COMMANDS { BH1750_POWER_DOWN = 0x00, BH1750_POWER_ON = 0x01, BH1750_RESET = 0x07, BH1750_CONTINUOUSLY_H_RESOLUTION_MODE = 0x10, BH1750_CONTINUOUSLY_H_RESOLUTION_MODE2 = 0x11, BH1750_CONTINUOUSLY_L_RESOLUTION_MODE = 0x13, BH1750_ONE_TIME_H_RESOLUTION_MODE = 0x20, BH1750_ONE_TIME_H_RESOLUTION_MODE2 = 0x21, BH1750_ONE_TIME_L_RESOLUTION_MODE = 0x23 } |
| enum | BH1750_SENSITIVITY { BH1750_SENSITIVITY_DEFAULT = 0x45 } |
| enum | BH1750_CONSTANT { BH1750_SUCCESS = 0x00, BH1750_FAILURE = 0x01, I2C_SUCCESS = 0x00 } |
Public Member Functions | |
| BH1750 (PinName sda, PinName scl, uint32_t addr, uint32_t freq) | |
| Create an BH1750 object connected to the specified I2C pins. | |
| ~BH1750 () | |
| Delete BH1750 object. | |
| uint32_t | BH1750_PowerDown (void) |
| It put the BH1750 sensor in the lowest power mode. | |
| uint32_t | BH1750_PowerOn (void) |
| It turns on the BH1750 sensor. | |
| uint32_t | BH1750_ResetDataRegister (void) |
| It clears the Data register. | |
| uint32_t | BH1750_TriggerMeasurement (BH1750_COMMANDS mode) |
| Create an BH1750 object connected to the specified I2C pins. | |
| uint32_t | BH1750_NewSensitivity (uint8_t newSensitivity) |
| It configures a new sensitivity. | |
| uint32_t | BH1750_ReadRawData (char *myRawData) |
| It reads the raw data from the BH1750 sensor. | |
| uint32_t | BH1750_ReadLux (float *myLux) |
| It reads a converted data from the BH1750 sensor. | |
Detailed Description
Example:
include "mbed.h" include "BH1750.h"
BH1750 myLightSensor ( I2C_SDA, I2C_SCL, BH1750::BH1750_ADDR_L, 400000 ); //[todo] Serial pc ( USBTX, USBRX ); // tx, rx
Ticker serial;
DigitalOut myled(LED1);
void sendDATA ( void ) { float myLux = 0;
myled = 0;
myLightSensor.BH1750_TriggerMeasurement ( BH1750::BH1750_ONE_TIME_H_RESOLUTION_MODE ); wait ( 1 ); myLightSensor.BH1750_ReadLux ( &myLux );
pc.printf( "Lux: %0.1f\r\n", myLux );
myled = 1;
}
int main() { pc.baud ( 115200 ); serial.attach( &sendDATA, 3 ); // the address of the function to be attached ( sendDATA ) and the interval ( 3s )
Let the callbacks take care of everything while(1) sleep(); }
Library for the BH1750 Digital 16-bit Serial Output Type Ambient Light Sensor IC.
Definition at line 65 of file BH1750.h.
Member Enumeration Documentation
| enum BH1750_ADDRESS |
| enum BH1750_COMMANDS |
- Enumerator:
| enum BH1750_CONSTANT |
| enum BH1750_SENSITIVITY |
Constructor & Destructor Documentation
| BH1750 | ( | PinName | sda, |
| PinName | scl, | ||
| uint32_t | addr, | ||
| uint32_t | freq | ||
| ) |
Create an BH1750 object connected to the specified I2C pins.
- Parameters:
-
sda I2C data pin scl I2C clock pin addr I2C slave address freq I2C frequency in Hz.
Digital 16-bit Serial Output Type Ambient Light Sensor IC. Functions file.
- Returns:
- NA
- Date:
- 10/August/2017
- Version:
- 10/August/2017 The ORIGIN
- Precondition:
- NaN
- Warning:
- NaN
- Precondition:
- This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ).
Definition at line 21 of file BH1750.cpp.
| ~BH1750 | ( | ) |
Delete BH1750 object.
Definition at line 29 of file BH1750.cpp.
Member Function Documentation
| uint32_t BH1750_NewSensitivity | ( | uint8_t | newSensitivity ) |
It configures a new sensitivity.
uint32_t BH1750_NewSensitivity ( uint8_t )
It configures the new sensitivity of the sensor. The sensitivity depends on which resolution mode is used:
H-reslution mode : Illuminance per 1 count ( lx / count ) = 1 / 1.2 *( 69 / X ) H-reslution mode2 : Illuminance per 1 count ( lx / count ) = 1 / 1.2 *( 69 / X ) / 2
So, by the default:
H-reslution mode : Sensitivity = 1 / 1.2 *( 69 / 69 ) ~ 0.83 H-reslution mode2 : Sensitivity = 1 / 1.2 *( 69 / 69 ) / 2 ~ 1.67
Example ( H-reslution mode ):
Minimum Sensitivity = 1 / 1.2 *( 69 / 31 ) ~ 0.37 Maximum Sensitivity = 1 / 1.2 *( 69 / 254 ) ~ 3.07
- Parameters:
-
[in] newSensitivity,: New sensitivity value. [out] Status of BH1750_NewSensitivity.
- Returns:
- NA
- Date:
- 10/August/2017
- Version:
- 10/August/2017 The ORIGIN
- Precondition:
- NaN
- Warning:
- newSensitivity can ONLY be from 31 to 254.
Definition at line 203 of file BH1750.cpp.
| uint32_t BH1750_PowerDown | ( | void | ) |
It put the BH1750 sensor in the lowest power mode.
uint32_t BH1750_PowerDown ( void )
BH1750 in low power mode.
- Parameters:
-
[in] NaN [out] Status of BH1750_PowerDown.
- Returns:
- NA
- Date:
- 10/August/2017
- Version:
- 10/August/2017 The ORIGIN
- Precondition:
- NaN
- Warning:
- NaN.
Definition at line 84 of file BH1750.cpp.
| uint32_t BH1750_PowerOn | ( | void | ) |
It turns on the BH1750 sensor.
uint32_t BH1750_PowerOn ( void )
BH1750 is on and waiting for measurement command.
- Parameters:
-
[in] NaN [out] Status of BH1750_PowerOn.
- Returns:
- NA
- Date:
- 10/August/2017
- Version:
- 10/August/2017 The ORIGIN
- Precondition:
- NaN
- Warning:
- NaN.
Definition at line 117 of file BH1750.cpp.
| uint32_t BH1750_ReadLux | ( | float * | myLux ) |
It reads a converted data from the BH1750 sensor.
BH1750_ReadLux ( float* )
- Parameters:
-
myLux Light value.
It turns the raw data into a Lux data.
- Parameters:
-
[in] myLux,: Variable to store the Lux. [out] Status of BH1750_ReadLux.
- Returns:
- NA
- Date:
- 10/August/2017
- Version:
- 10/August/2017 The ORIGIN
- Precondition:
- NaN
- Warning:
- BH1750_TriggerMeasurement MUST be call before.
Definition at line 278 of file BH1750.cpp.
| uint32_t BH1750_ReadRawData | ( | char * | myRawData ) |
It reads the raw data from the BH1750 sensor.
uint32_t BH1750_ReadRawData ( uint32_t* )
- Parameters:
-
myRawData 2-Byte array.
Read a new raw temperature measurement.
- Parameters:
-
[in] myRawData,: Variable to store the raw data. [out] Status of BH1750_ReadRawData.
- Returns:
- NA
- Date:
- 10/August/2017
- Version:
- 10/August/2017 The ORIGIN
- Precondition:
- NaN
- Warning:
- BH1750_TriggerMeasurement MUST be call before.
Definition at line 246 of file BH1750.cpp.
| uint32_t BH1750_ResetDataRegister | ( | void | ) |
It clears the Data register.
uint32_t BH1750_ResetDataRegister ( void )
Reseting the data register value.
- Parameters:
-
[in] NaN. [out] Status of BH1750_ResetDataRegister.
- Returns:
- NA
- Date:
- 10/August/2017
- Version:
- 10/August/2017 The ORIGIN
- Precondition:
- NaN
- Warning:
- Reset command is not acceptable in Power Down mode.
Definition at line 51 of file BH1750.cpp.
| uint32_t BH1750_TriggerMeasurement | ( | BH1750_COMMANDS | mode ) |
Create an BH1750 object connected to the specified I2C pins.
uint32_t BH1750_TriggerMeasurement ( uint32_t )
- Parameters:
-
mode One-shot/Continuous mode in High, High2 or Low resolution.
Trigger a new temperature measurement.
- Parameters:
-
[in] mode,: ONE-SHOT or CONTINUOUSLY measurement ( Normal Mode or Mode2 ). [out] Status of BH1750_TriggerMeasurement.
- Returns:
- NA
- Date:
- 10/August/2017
- Version:
- 10/August/2017 The ORIGIN
- Precondition:
- NaN
- Warning:
- The measuring time depends on the chosen resolution ( MODE ). The user must take this into account.
Definition at line 151 of file BH1750.cpp.
Generated on Sat Jul 16 2022 06:05:46 by
1.7.2