Adafruit AS7341 Library
|
Class that stores state and functions for interacting with the AS7341 11-Channel Spectral Sensor. More...
#include <Adafruit_AS7341.h>
Public Member Functions | |
Adafruit_AS7341 () | |
Construct a new Adafruit_AS7341::Adafruit_AS7341 object. | |
~Adafruit_AS7341 () | |
Destroy the Adafruit_AS7341::Adafruit_AS7341 object. | |
bool | begin (uint8_t i2c_addr=AS7341_I2CADDR_DEFAULT, TwoWire *wire=&Wire, int32_t sensor_id=0) |
Sets up the hardware and initializes I2C. More... | |
bool | setASTEP (uint16_t astep_value) |
Sets the integration time step size. More... | |
bool | setATIME (uint8_t atime_value) |
Sets the integration time step count. More... | |
bool | setGain (as7341_gain_t gain_value) |
Sets the ADC gain multiplier. More... | |
uint16_t | getASTEP () |
Returns the integration time step size. More... | |
uint8_t | getATIME () |
Returns the integration time step count. More... | |
as7341_gain_t | getGain () |
Returns the ADC gain multiplier. More... | |
long | getTINT () |
Returns the integration time. More... | |
float | toBasicCounts (uint16_t raw) |
Converts raw ADC values to basic counts. More... | |
bool | readAllChannels (void) |
Take readings for F1-8, Clear and NIR and store them in a buffer. More... | |
bool | readAllChannels (uint16_t *readings_buffer) |
fills the provided buffer with the current measurements for Spectral channels F1-8, Clear and NIR More... | |
void | delayForData (int waitTime=0) |
Delay while waiting for data, with option to time out and recover. More... | |
uint16_t | readChannel (as7341_adc_channel_t channel) |
Returns the ADC data for a given channel. More... | |
uint16_t | getChannel (as7341_color_channel_t channel) |
Returns the reading data for the specified color channel. More... | |
bool | startReading (void) |
starts the process of getting readings from all channels without using delays More... | |
bool | checkReadingProgress () |
runs the process of getting readings from all channels without using delays. Should be called regularly (ie. in loop()) Need to call startReading() to initialise the process Need to call getAllChannels() to transfer the data into an external buffer More... | |
bool | getAllChannels (uint16_t *readings_buffer) |
transfer all the values from the private result buffer into one nominated More... | |
uint16_t | detectFlickerHz (void) |
Detect a flickering light. More... | |
void | setup_F1F4_Clear_NIR (void) |
Configure SMUX for sensors F1-4, Clear and NIR. | |
void | setup_F5F8_Clear_NIR (void) |
Configure SMUX for sensors F5-8, Clear and NIR. | |
void | powerEnable (bool enable_power) |
Sets the power state of the sensor. More... | |
bool | enableSpectralMeasurement (bool enable_measurement) |
Enables measurement of spectral data. More... | |
bool | setHighThreshold (uint16_t high_threshold) |
Sets the threshold above which spectral measurements will trigger interrupts when the APERS count is reached. More... | |
bool | setLowThreshold (uint16_t low_threshold) |
Sets the threshold below which spectral measurements will trigger interrupts when the APERS count is reached. More... | |
uint16_t | getHighThreshold (void) |
Returns the current high thighreshold for spectral measurements. More... | |
uint16_t | getLowThreshold (void) |
Returns the current low thighreshold for spectral measurements. More... | |
bool | enableSpectralInterrupt (bool enable_int) |
Enable Interrupts based on spectral measurements. More... | |
bool | enableSystemInterrupt (bool enable_int) |
Enabled system interrupts. More... | |
bool | setAPERS (as7341_int_cycle_count_t cycle_count) |
Sets the number of times an interrupt threshold must be exceeded before an interrupt is triggered. More... | |
bool | setSpectralThresholdChannel (as7341_adc_channel_t channel) |
Set the ADC channel to use for spectral thresholds including interrupts, automatic gain control, and persistance settings. More... | |
uint8_t | getInterruptStatus (void) |
Returns the current value of the Interupt status register. More... | |
bool | clearInterruptStatus (void) |
Clear the interrupt status register. More... | |
bool | spectralInterruptTriggered (void) |
Returns the status of the spectral measurement threshold interrupts. More... | |
uint8_t | spectralInterruptSource (void) |
The current state of the spectral measurement interrupt status register. More... | |
bool | spectralLowTriggered (void) |
The status of the low threshold interrupt. More... | |
bool | spectralHighTriggered (void) |
The status of the high threshold interrupt. More... | |
bool | enableLED (bool enable_led) |
Enable control of an attached LED on the LDR pin. More... | |
bool | setLEDCurrent (uint16_t led_current_ma) |
Set the current limit for the LED. More... | |
uint16_t | getLEDCurrent (void) |
Get the current limit for the LED. More... | |
void | disableAll (void) |
Disable Spectral reading, flicker detection, and power. | |
bool | getIsDataReady () |
bool | setBank (bool low) |
Sets the active register bank. More... | |
as7341_gpio_dir_t | getGPIODirection (void) |
Get the GPIO pin direction setting. More... | |
bool | setGPIODirection (as7341_gpio_dir_t gpio_direction) |
Set the GPIO pin to be used as an input or output. More... | |
bool | getGPIOInverted (void) |
Get the output inversion setting for the GPIO pin. More... | |
bool | setGPIOInverted (bool gpio_inverted) |
Invert the logic of then GPIO pin when used as an output. More... | |
bool | getGPIOValue (void) |
Read the digital level of the GPIO pin, high or low. More... | |
bool | setGPIOValue (bool) |
Set the digital level of the GPIO pin, high or low. More... | |
Protected Member Functions | |
virtual bool | _init (int32_t sensor_id) |
Initializer for post i2c/spi init. More... | |
Protected Attributes | |
uint8_t | last_spectral_int_source |
Adafruit_I2CDevice * | i2c_dev = NULL |
Pointer to I2C bus interface. | |
Class that stores state and functions for interacting with the AS7341 11-Channel Spectral Sensor.
bool Adafruit_AS7341::begin | ( | uint8_t | i2c_address = AS7341_I2CADDR_DEFAULT , |
TwoWire * | wire = &Wire , |
||
int32_t | sensor_id = 0 |
||
) |
Sets up the hardware and initializes I2C.
i2c_address | The I2C address to be used. |
wire | The Wire object to be used for I2C connections. |
sensor_id | The unique ID to differentiate the sensors from others |
bool Adafruit_AS7341::setASTEP | ( | uint16_t | astep_value | ) |
Sets the integration time step size.
astep_value | Integration time step size in 2.78 microsecon increments Step size is (astep_value+1) * 2.78 uS |
bool Adafruit_AS7341::setATIME | ( | uint8_t | atime_value | ) |
Sets the integration time step count.
Total integration time will be (ATIME + 1) * (ASTEP + 1) * 2.78µS
atime_value | The integration time step count |
bool Adafruit_AS7341::setGain | ( | as7341_gain_t | gain_value | ) |
Sets the ADC gain multiplier.
gain_value | The gain amount. must be an as7341_gain_t |
uint16_t Adafruit_AS7341::getASTEP | ( | ) |
Returns the integration time step size.
Step size is (astep_value+1) * 2.78 uS
uint8_t Adafruit_AS7341::getATIME | ( | ) |
Returns the integration time step count.
Total integration time will be (ATIME + 1) * (ASTEP + 1) * 2.78µS
as7341_gain_t Adafruit_AS7341::getGain | ( | ) |
Returns the ADC gain multiplier.
long Adafruit_AS7341::getTINT | ( | ) |
Returns the integration time.
The integration time is (ATIME + 1) * (ASTEP + 1) * 2.78µS
float Adafruit_AS7341::toBasicCounts | ( | uint16_t | raw | ) |
Converts raw ADC values to basic counts.
The basic counts are RAW/(GAIN * TINT)
raw | The raw ADC values to convert |
bool Adafruit_AS7341::readAllChannels | ( | void | ) |
Take readings for F1-8, Clear and NIR and store them in a buffer.
bool Adafruit_AS7341::readAllChannels | ( | uint16_t * | readings_buffer | ) |
fills the provided buffer with the current measurements for Spectral channels F1-8, Clear and NIR
readings_buffer | Pointer to a buffer of length 10 or more to fill with sensor data |
void Adafruit_AS7341::delayForData | ( | int | waitTime = 0 | ) |
Delay while waiting for data, with option to time out and recover.
waitTime | the maximum amount of time to wait |
uint16_t Adafruit_AS7341::readChannel | ( | as7341_adc_channel_t | channel | ) |
Returns the ADC data for a given channel.
channel | The ADC channel to read |
uint16_t Adafruit_AS7341::getChannel | ( | as7341_color_channel_t | channel | ) |
Returns the reading data for the specified color channel.
call readAllChannels
before reading to update the stored readings
channel | The color sensor channel to read |
bool Adafruit_AS7341::startReading | ( | void | ) |
starts the process of getting readings from all channels without using delays
bool Adafruit_AS7341::checkReadingProgress | ( | ) |
runs the process of getting readings from all channels without using delays. Should be called regularly (ie. in loop()) Need to call startReading() to initialise the process Need to call getAllChannels() to transfer the data into an external buffer
bool Adafruit_AS7341::getAllChannels | ( | uint16_t * | readings_buffer | ) |
transfer all the values from the private result buffer into one nominated
readings_buffer | Pointer to a buffer of length 12 (THERE IS NO ERROR CHECKING, YE BE WARNED!) |
uint16_t Adafruit_AS7341::detectFlickerHz | ( | void | ) |
Detect a flickering light.
void Adafruit_AS7341::powerEnable | ( | bool | enable_power | ) |
Sets the power state of the sensor.
enable_power | true: on false: off |
bool Adafruit_AS7341::enableSpectralMeasurement | ( | bool | enable_measurement | ) |
Enables measurement of spectral data.
enable_measurement | true: enabled false: disabled |
bool Adafruit_AS7341::setHighThreshold | ( | uint16_t | high_threshold | ) |
Sets the threshold above which spectral measurements will trigger interrupts when the APERS count is reached.
high_threshold |
bool Adafruit_AS7341::setLowThreshold | ( | uint16_t | low_threshold | ) |
Sets the threshold below which spectral measurements will trigger interrupts when the APERS count is reached.
low_threshold | the new threshold |
uint16_t Adafruit_AS7341::getHighThreshold | ( | void | ) |
Returns the current high thighreshold for spectral measurements.
uint16_t Adafruit_AS7341::getLowThreshold | ( | void | ) |
Returns the current low thighreshold for spectral measurements.
bool Adafruit_AS7341::enableSpectralInterrupt | ( | bool | enable_int | ) |
Enable Interrupts based on spectral measurements.
enable_int | true: enable false: disable |
bool Adafruit_AS7341::enableSystemInterrupt | ( | bool | enable_int | ) |
Enabled system interrupts.
enable_int | Set to true to enable system interrupts |
bool Adafruit_AS7341::setAPERS | ( | as7341_int_cycle_count_t | cycle_count | ) |
Sets the number of times an interrupt threshold must be exceeded before an interrupt is triggered.
cycle_count | The number of cycles to trigger an interrupt |
bool Adafruit_AS7341::setSpectralThresholdChannel | ( | as7341_adc_channel_t | channel | ) |
Set the ADC channel to use for spectral thresholds including interrupts, automatic gain control, and persistance settings.
channel | The channel to use for spectral thresholds. Must be a as7341_adc_channel_t except for AS7341_ADC_CHANNEL_5 |
uint8_t Adafruit_AS7341::getInterruptStatus | ( | void | ) |
Returns the current value of the Interupt status register.
bool Adafruit_AS7341::clearInterruptStatus | ( | void | ) |
Clear the interrupt status register.
bool Adafruit_AS7341::spectralInterruptTriggered | ( | void | ) |
Returns the status of the spectral measurement threshold interrupts.
uint8_t Adafruit_AS7341::spectralInterruptSource | ( | void | ) |
The current state of the spectral measurement interrupt status register.
bool Adafruit_AS7341::spectralLowTriggered | ( | void | ) |
The status of the low threshold interrupt.
bool Adafruit_AS7341::spectralHighTriggered | ( | void | ) |
The status of the high threshold interrupt.
bool Adafruit_AS7341::enableLED | ( | bool | enable_led | ) |
Enable control of an attached LED on the LDR pin.
enable_led | true: LED enabled false: LED disabled |
bool Adafruit_AS7341::setLEDCurrent | ( | uint16_t | led_current_ma | ) |
Set the current limit for the LED.
led_current_ma | the value to set in milliamps. With a minimum of 4. Any amount under 4 will be rounded up to 4 |
Range is 4mA to 258mA
uint16_t Adafruit_AS7341::getLEDCurrent | ( | void | ) |
Get the current limit for the LED.
Range is 4mA to 258mA
bool Adafruit_AS7341::getIsDataReady | ( | ) |
bool Adafruit_AS7341::setBank | ( | bool | low | ) |
Sets the active register bank.
The AS7341 uses banks to organize the register making it nescessary to set the correct bank to access a register.
low | true: false: Set the current bank to allow access to registers with addresses of 0x80 and above |
as7341_gpio_dir_t Adafruit_AS7341::getGPIODirection | ( | void | ) |
Get the GPIO pin direction setting.
AS7341_OUTPUT
or AS7341_INPUT
bool Adafruit_AS7341::setGPIODirection | ( | as7341_gpio_dir_t | gpio_direction | ) |
Set the GPIO pin to be used as an input or output.
gpio_direction | The IO direction to set |
bool Adafruit_AS7341::getGPIOInverted | ( | void | ) |
Get the output inversion setting for the GPIO pin.
bool Adafruit_AS7341::setGPIOInverted | ( | bool | gpio_inverted | ) |
Invert the logic of then GPIO pin when used as an output.
gpio_inverted | When true setting the gpio value to true will connect the GPIO pin to ground. When set to false, setting the GPIO pin value to true will disconnect the GPIO pin from ground |
bool Adafruit_AS7341::getGPIOValue | ( | void | ) |
Read the digital level of the GPIO pin, high or low.
bool Adafruit_AS7341::setGPIOValue | ( | bool | gpio_high | ) |
Set the digital level of the GPIO pin, high or low.
gpio_high | The GPIO level to set. Set to true to disconnect the pin from ground. Set to false to connect the gpio pin to ground. This can be used to connect the cathode of an LED to ground to turn it on. |
|
protectedvirtual |
Initializer for post i2c/spi init.
sensor_id | Optional unique ID for the sensor set |
|
protected |
The value of the last reading of the spectral interrupt source register