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§
- Conversion
Time - The conversion time (configuration bit 11).
- Fault
Count - 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 numbers0to11select one of the fixed full-scale ranges;13to15are 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.