Manuel Caballero / BH1750
Embed: (wiki syntax)

« Back to documentation index

BH1750 Class Reference

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

Represents the different I2C address possibilities for the BH1750.

Enumerator:
BH1750_ADDR_L 

Addr pin = GND.

BH1750_ADDR_H 

Addr pin = VDD.

Definition at line 70 of file BH1750.h.

Enumerator:
BH1750_POWER_DOWN 

No active state

BH1750_POWER_ON 

Waiting for measurement command

BH1750_RESET 

Reset Data register value. Reset command is not acceptable in Power Down mode

BH1750_CONTINUOUSLY_H_RESOLUTION_MODE 

Start measurement at 1lx resolution. Measurement Time is typically 120ms

BH1750_CONTINUOUSLY_H_RESOLUTION_MODE2 

Start measurement at 0.5lx resolution. Measurement Time is typically 120ms

BH1750_CONTINUOUSLY_L_RESOLUTION_MODE 

Start measurement at 4lx resolution. Measurement Time is typically 16ms

BH1750_ONE_TIME_H_RESOLUTION_MODE 

Start measurement at 1lx resolution. Measurement Time is typically 120ms. It is automatically set to Power Down mode after measurement

BH1750_ONE_TIME_H_RESOLUTION_MODE2 

Start measurement at 0.5lx resolution. Measurement Time is typically 120ms. It is automatically set to Power Down mode after measurement

BH1750_ONE_TIME_L_RESOLUTION_MODE 

Start measurement at 4lx resolution. Measurement Time is typically 16ms. It is automatically set to Power Down mode after measurement

Definition at line 75 of file BH1750.h.

Enumerator:
BH1750_SUCCESS 

The communication was fine

BH1750_FAILURE 

Something went wrong

I2C_SUCCESS 

I2C communication was fine

Definition at line 92 of file BH1750.h.

Enumerator:
BH1750_SENSITIVITY_DEFAULT 

Measurement Time Register by default. This is for registration of measurement time

Definition at line 87 of file BH1750.h.


Constructor & Destructor Documentation

BH1750 ( PinName  sda,
PinName  scl,
uint32_t  addr,
uint32_t  freq 
)

Create an BH1750 object connected to the specified I2C pins.

BH1750.cpp.

Parameters:
sdaI2C data pin
sclI2C clock pin
addrI2C slave address
freqI2C frequency in Hz.

Digital 16-bit Serial Output Type Ambient Light Sensor IC. Functions file.

Returns:
NA
Author:
Manuel Caballero
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]Statusof BH1750_NewSensitivity.
Returns:
NA
Author:
Manuel Caballero
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]Statusof BH1750_PowerDown.
Returns:
NA
Author:
Manuel Caballero
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]Statusof BH1750_PowerOn.
Returns:
NA
Author:
Manuel Caballero
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:
myLuxLight value.

It turns the raw data into a Lux data.

Parameters:
[in]myLux,:Variable to store the Lux.
[out]Statusof BH1750_ReadLux.
Returns:
NA
Author:
Manuel Caballero
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:
myRawData2-Byte array.

Read a new raw temperature measurement.

Parameters:
[in]myRawData,:Variable to store the raw data.
[out]Statusof BH1750_ReadRawData.
Returns:
NA
Author:
Manuel Caballero
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]Statusof BH1750_ResetDataRegister.
Returns:
NA
Author:
Manuel Caballero
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:
modeOne-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]Statusof BH1750_TriggerMeasurement.
Returns:
NA
Author:
Manuel Caballero
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.