upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Member Functions | Protected Attributes

UPM C API for the DFRobot I2C BH1750 Light Sensor. More...

Detailed Description

This driver was developed with the DFRobot Light Sensor based on the BH1750. It has a sensitivity of .5 10 65535 Lux. It supports voltages from 3-5vdc and is connected via I2C.

// Instantiate a BH1750 sensor using defaults (I2C bus (0), using
// the default I2C address (0x23), and setting the mode to highest
// resolution, lowest power mode).
upm::BH1750 sensor;
// Every second, sample the BH1750 and output the measured lux value
while (shouldRun) {
cout << "Detected Light Level (lux): " << sensor.getLux() << endl;
upm_delay(1);
}

Public Member Functions

 BH1750 (int bus=BH1750_DEFAULT_I2C_BUS, int addr=BH1750_DEFAULT_I2C_ADDR, BH1750_OPMODES_T mode=BH1750_OPMODE_H2_ONCE)
 
 ~BH1750 ()
 
void reset ()
 
float getLux ()
 
void powerUp ()
 
void powerDown ()
 
void setOpmode (BH1750_OPMODES_T mode)
 

Protected Member Functions

void sendCommand (uint8_t cmd)
 
uint16_t readData ()
 

Protected Attributes

bh1750_context m_bh1750
 

Constructor & Destructor Documentation

BH1750 ( int  bus = BH1750_DEFAULT_I2C_BUS,
int  addr = BH1750_DEFAULT_I2C_ADDR,
BH1750_OPMODES_T  mode = BH1750_OPMODE_H2_ONCE 
)

BH1750 object constructor (Analog mode)

Parameters
busThe I2C bus to use
addrThe I2C address of the device
modeThe mode to start operation under. One of the BH1750_OPMODES_T values. The default is the highest precision, lowest power mode.
~BH1750 ( )

BH1750 object destructor

Here is the call graph for this function:

Member Function Documentation

void reset ( )

Reset the device. This doesn't really have much purpose. The device must be powered up for this command to work. In addition, this command will simply clear the measurement register to 0.

Here is the call graph for this function:

float getLux ( )

Get the measured light intensity in Lux.

Returns
The measured light intensity in Lux.

Here is the call graph for this function:

void powerUp ( )

Power up the device.

Here is the call graph for this function:

void powerDown ( )

Power down the device.

Here is the call graph for this function:

void setOpmode ( BH1750_OPMODES_T  mode)

Setup the device to match the selected operating mode.

Parameters
modeoperating mode, one of the BH1750_OPMODES_T values

Here is the call graph for this function:

void sendCommand ( uint8_t  cmd)
protected

Sends a command to the device via I2C.

Parameters
cmdThe command to write, one of the BH1750_CMD* values

Here is the call graph for this function:

uint16_t readData ( )
protected

Read the 2 result bytes from the device via I2C.

Returns
Data read in from the device as a uint16_t

Here is the call graph for this function:

Collaboration diagram for BH1750:
Collaboration graph
[legend]

The documentation for this class was generated from the following files: