APDS-9301 Sensor Hookup Guide

Pages
Contributors: SFUptownMaker
Favorited Favorite 0

Library Overview

Here's a list of the most critical functions supported by the library.

  • begin(address) - enables the IC, sets the gain and integration times to minimum (i.e., lowest sensitivity), and disables the interrupt.

  • setGain(gainLevel) - there are two possible parameters to pass to this function: APDS9301::LOW_GAIN and APDS9301::HIGH_GAIN. High gain is 16x more sensitive than low gain.

  • gain getGain() - returns one of the two values specified in setGain() above. This function actually reads the gain from the sensor and returns the true value currently being used.

  • setIntegrationTime(integrationTime) - there are three possible parameters to pass to this function: APDS9301::INT_TIME_13_7_MS, APDS9301::INT_TIME_101_MS, and APDS9301::INT_TIME_402_MS. Sensitivity to light increases with integration time, and the rate at which new data is generated by the sensor is also determined by integration time. By default, the integration time is set to the lowest value (13.7ms).

  • intTime getIntegrationTime() - returns one of the three values specfied in setIntegrationTime() above. This function actually reads the gain from the sensor and returns the true value currently being used.

  • enableInterrupt(intMode) - pass either APDS9301::INT_ON or APDS9301::INT_OFF to this function to enable or disable the interrupt functionality. By default, the interrupt is disabled. If enabled, the following three functions will determine the circumstances under which an interrupt will be issued and the INT pin will be set high.

  • setCyclesForInterrupt(cycles) - sets number of ADC cycles values must be in interrupt range for an interrupt to occur. Pass 0 to interrupt on every ADC cycle (ADC cycle time is defined by integration time as discussed above). Pass 1 to interrupt if the reading is ever above the high threshold or below the low threshold (see next two functions for information regarding threshold settings). Pass 2 through 15 to require that many cycles above or below the respective threshold before issuing an interrupt.

  • setLowThreshold(threshold) - pass an unsigned int to this function between 0 and 65535. Readings on CH0 of the sensor (which detects both visible and IR light) below this threshold for the time set by the setCyclesForInterrupt() will trigger an interrupt on the INT pin. To disable the low threshold, simply write 0 to this function.

  • unsigned int getLowThreshold() - returns the current low threshold setting, read from the sensor directly.

  • setHighThreshold(threshold) - pass an unsigned int to this function between 0 and 65535. Readings on CH0 of the sensor (which detects both visible and IR light) above this threshold for the time set by the setCyclesForInterrupt() will trigger an interrupt on the INT pin. To disable the high threshold, simply write 65535 to this function.

  • unsigned int getHighThreshold() - returns the current low threshold setting, read from the sensor directly.

  • float readLuxLevel() - returns a floating point number representing the current light level in lux. Note that due to inherent inaccuracy in the sensor, this value is only accurate to within 35%-40% of the actual absolute lux value.