Skip to main content

Module opt3001

Module opt3001 

Source
Expand description

Texas Instruments OPT3001 ambient light sensor.

The OPT3001 is a single-chip lux meter with an optical filter matched to the photopic response of the human eye. It reports illuminance as a 16-bit word holding a 4-bit exponent and a 12-bit mantissa, across twelve binary-weighted full-scale ranges the part can select on its own; the low- and high-limit registers that drive its interrupt pin share that encoding. This module decodes the word, encodes a lux threshold back into it, and builds and parses the configuration register field by field, following the datasheet’s register tables and its table of worked decoding examples.

Illuminance is returned in integer milli-lux, which holds every register value exactly since the smallest LSB is 0.01 lux; an f32 lux convenience sits beside it.

Modules§

register
The OPT3001 register addresses. Every register is 16 bits, sent most significant byte first.

Structs§

Configuration
A decoded OPT3001 configuration register.

Enums§

ConversionTime
The conversion time (configuration bit 11).
FaultCount
The number of consecutive fault events that trigger a report (configuration bits 1:0).
Latch
The interrupt reporting style, the latch field (configuration bit 4).
Mode
The mode of conversion operation (configuration bits 10:9).
Polarity
The INT pin polarity (configuration bit 3).

Constants§

CONFIGURATION_RESET
The power-on value of the configuration register (0xC810): automatic full-scale range, 800 ms conversion time, shutdown mode, latched window-style comparison, an active-low INT pin, the exponent not masked, and a fault count of one.
DEVICE_ID
The value the device ID register returns for an OPT3001.
HIGH_LIMIT_RESET
The power-on value of the high-limit register: exponent 11, mantissa 0xFFF, the largest encodable threshold of 83865.60 lux.
I2C_ADDRESS_GND
The I2C address with the ADDR pin tied to GND.
I2C_ADDRESS_SCL
The I2C address with the ADDR pin tied to SCL.
I2C_ADDRESS_SDA
The I2C address with the ADDR pin tied to SDA.
I2C_ADDRESS_VDD
The I2C address with the ADDR pin tied to VDD.
LOW_LIMIT_END_OF_CONVERSION
The low-limit register value that selects end-of-conversion mode, where the INT pin and the flags report every completed conversion: the exponent’s two most significant bits set to 11b.
LOW_LIMIT_RESET
The power-on value of the low-limit register: exponent 0, mantissa 0, or 0 lux.
MANUFACTURER_ID
The value the manufacturer ID register returns: 0x5449, the ASCII bytes “TI”.
RANGE_AUTOMATIC
The range number that selects automatic full-scale setting, 1100b. Range numbers 0 to 11 select one of the fixed full-scale ranges; 13 to 15 are reserved.
RANGE_MAX
The largest range number that selects a fixed full-scale range.

Functions§

full_scale_milli_lux
Returns the full-scale illuminance, in milli-lux, of a range number.
lsb_milli_lux
Returns the LSB size, in milli-lux, of a result or limit register at an exponent.
lux
Decodes a result or limit register word to lux.
milli_lux
Decodes a result or limit register word to milli-lux.
raw_from_milli_lux
Encodes an illuminance into the result and limit registers’ exponent-and-mantissa word, at the smallest exponent that holds the value.
word_from_bytes
Assembles a register word from the two bytes the part sends, most significant byte first.
word_to_bytes
Splits a register word into the two bytes written to the part, most significant byte first.