Driver for the Texas Instruments OPT3001 sensor. More...

Detailed Description

Driver for the Texas Instruments OPT3001 sensor.

The TI OPT3001 (Ambient Light Sensor) measures the intensity of visible light with a spectal response comparable to the human eye, with simultaneous rejection of infrared light. The conversion time, mode of conversion and the interrupt reporting mechanism mode can be set by the sensor initialization. After initialization the raw sensor values can be read. The ambient light can be calculated as follows:

Result register translation into lux:

\begin{eqnarray*} Lux &=& LSB\_Size \cdot R[11:0] \end{eqnarray*}

Where LSB_Size:

\begin{eqnarray*} LSB\_Size &=& 0.01 \cdot 2^{E[3:0]} \end{eqnarray*}

The calculation is wrapped from TI OPT3001 Ambient Light Sensor (ALS) datasheet (Rev. C).

This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities.

Files

file  opt3001.h
 Interface definition for the OPT3001 sensor driver.
 
file  opt3001_params.h
 Default configuration for OPT3001 devices.
 
file  opt3001_regs.h
 Register definitions for OPT3001 devices.
 

Data Structures

struct  opt3001_params_t
 Parameters needed for device initialization. More...
 
struct  opt3001_t
 Device descriptor for OPT3001 sensors. More...
 

Macros

#define OPT3001_I2C_ADDRESS   (0x45)
 OPT3001 Default Address. More...
 
#define OPT3001_CONVERSION_TIME   OPT3001_CONVERSION_TIME_800_MS
 OPT3001 Default conversion time. More...
 

Enumerations

enum  { OPT3001_OK, OPT3001_ERROR_BUS, OPT3001_ERROR_DEV, OPT3001_ERROR }
 OPT3001 specific return values. More...
 

Functions

int opt3001_init (opt3001_t *dev, const opt3001_params_t *params)
 Initialize the OPT3001 sensor driver. More...
 
int opt3001_reset (const opt3001_t *dev)
 Reset the OPT3001 sensor while simultaneous deactivating measurements. More...
 
int opt3001_set_active (const opt3001_t *dev)
 Set active mode, this enables periodic measurements. More...
 
int opt3001_read_lux (const opt3001_t *dev, uint32_t *convl)
 Read sensor's raw data and convert it to milliLux. More...
 

Conversion time

#define OPT3001_CONVERSION_TIME_100_MS   (0x0000)
 Conversion time of 100ms.
 
#define OPT3001_CONVERSION_TIME_800_MS   (0x0800)
 Conversion time of 800ms.
 

Macro Definition Documentation

◆ OPT3001_CONVERSION_TIME

#define OPT3001_CONVERSION_TIME   OPT3001_CONVERSION_TIME_800_MS

OPT3001 Default conversion time.

If set to 0x0000, the conversion time will be 100ms. If set to 0x0800, the conversion time will be 800ms

Definition at line 76 of file opt3001.h.

◆ OPT3001_I2C_ADDRESS

#define OPT3001_I2C_ADDRESS   (0x45)

OPT3001 Default Address.

If set to 0x44 the corresponding ADDR PIN is GND.

Definition at line 58 of file opt3001.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

OPT3001 specific return values.

Enumerator
OPT3001_OK 

Success, no error.

OPT3001_ERROR_BUS 

I2C bus error.

OPT3001_ERROR_DEV 

Internal device error.

OPT3001_ERROR 

General error.

Definition at line 97 of file opt3001.h.

Function Documentation

◆ opt3001_init()

int opt3001_init ( opt3001_t dev,
const opt3001_params_t params 
)

Initialize the OPT3001 sensor driver.

Parameters
[out]devdevice descriptor of sensor to initialize
[in]paramsconfiguration parameters
Returns
0 on success
-OPT3001_ERROR_BUS on I2C bus error
-OPT3001_ERROR_DEV if sensor test failed

◆ opt3001_read_lux()

int opt3001_read_lux ( const opt3001_t dev,
uint32_t *  convl 
)

Read sensor's raw data and convert it to milliLux.

Parameters
[in]devdevice descriptor of sensor
[out]convlambient light in milliLux
Returns
0 on success
-1 on error

◆ opt3001_reset()

int opt3001_reset ( const opt3001_t dev)

Reset the OPT3001 sensor while simultaneous deactivating measurements.

Afterwards the sensor should be idle.

Parameters
[out]devdevice descriptor of sensor
Returns
0 on success
-1 on error

◆ opt3001_set_active()

int opt3001_set_active ( const opt3001_t dev)

Set active mode, this enables periodic measurements.

Parameters
[in]devdevice descriptor of sensor
Returns
0 on success
-1 on error