![]() |
SparkFun Spectral Sensor - AS7343
v1.0.0-4-gd418547
Library for the SparkFun SpectralSensor - AS7343
|
#include <sfDevAS7343.h>
Public Member Functions | |
| sfDevAS7343 () | |
| bool | begin (sfTkIBus *theBus=nullptr) |
| This method is called to initialize the AS7343 device through the specified bus. More... | |
| uint8_t | getDeviceID (void) |
| Requests the device ID from the sensor. More... | |
| void | setCommunicationBus (sfTkIBus *theBus) |
| Sets the communication bus to the specified bus. More... | |
| bool | setRegisterBank (sfe_as7343_reg_bank_t regBank) |
| Set the register bank. In order to access registers from 0x58 to 0x66, bit REG_BANK in register CFG0 (0xBF) needs to be set to “1”. For register access of registers 0x80 and above bit REG_BANK needs to be set to “0” More... | |
| bool | powerOn (bool power=true) |
| Power on or off the device. More... | |
| bool | powerOff (void) |
| Power off the device. More... | |
| bool | enableSpectralMeasurement (bool enable=true) |
| Enable or Disable the Spectral Measurement. More... | |
| bool | disableSpectralMeasurement (void) |
| Spectral Measurement Disable. More... | |
| bool | readSpectraDataFromSensor (void) |
| Read all Spectral Data Registers. More... | |
| uint8_t | getData (uint16_t *data, size_t size) |
| Get data from the sensor using a pointer to an array and the desired data length. More... | |
| uint8_t | getData (uint16_t data[ksfAS7343NumChannels]) |
| bool | setAutoSmux (sfe_as7343_auto_smux_channel_t auto_smux) |
| Set automatic channel read-out. More... | |
| bool | ledOn (bool ledOn=true) |
| Turn on or off the LED. More... | |
| bool | ledOff (void) |
| Turn off the LED. More... | |
| bool | setLedDrive (uint8_t ledDrive) |
| Set the LED drive current. More... | |
| uint16_t | getRed (void) |
| Get Red spectrum data. (aka channel F7, 690nm) More... | |
| uint16_t | getGreen (void) |
| Get Green spectrum data. (aka channel F5, 550nm) More... | |
| uint16_t | getBlue (void) |
| Get Blue spectrum data. (aka channel FZ, 450nm) More... | |
| uint16_t | getNIR (void) |
| Get NIR spectrum data. (aka channel NIR, 855nm) More... | |
| uint16_t | getChannelData (sfe_as7343_channel_t channel) |
| Get Specific Channel of Spectrum Data. More... | |
| bool | setSpectralIntThresholdHigh (uint16_t spThH) |
| Set the spectral interrupt threshold high. More... | |
| bool | setSpectralIntThresholdLow (uint16_t spThL) |
| Set the spectral interrupt threshold low. More... | |
| bool | enableSpectralInterrupt (bool enable=true) |
| Enable or Disable the spectral interrupt. More... | |
| bool | disableSpectralInterrupt (void) |
| Disable the spectral interrupt. More... | |
| bool | setSpectralThresholdChannel (sfe_as7343_spectral_threshold_channel_t spThCh) |
| Set the spectral threshold channel. More... | |
| bool | getSystemInterruptStatus (void) |
| Get the System Interrupt Status. More... | |
| bool | getSpectralChannelInterruptStatus (void) |
| Get the Spectral Channel Interrupt Status. More... | |
| bool | clearSpectralChannelInterrupt (void) |
| Clear Spectral Channel Interrupt bit (AINT). More... | |
| bool | getSpectralInterruptHighStatus (void) |
| Get the Spectral Interrupt High Status. More... | |
| bool | getSpectralTriggerErrorStatus (void) |
| Get the Spectral Trigger Error Status. More... | |
| bool | setWaitTime (uint8_t wTime) |
| Set the Spectral Measurement Wait Time. More... | |
| uint8_t | getWaitTime (void) |
| Get the Spectral Measurement Wait Time. More... | |
| bool | enableWaitTime (bool enable=true) |
| Enable or Disable Wait Time. More... | |
| bool | disableWaitTime (void) |
| Disable Wait Time. More... | |
| bool | getSpectralValidStatus (void) |
| Get the Spectral Valid Status. More... | |
| uint8_t | readIntEnableReg (void) |
| Read the register INT Enable. More... | |
| bool | setGPIOMode (sfe_as7343_gpio_mode_t gpioMode) |
| Set the GPIO pin mode. More... | |
| bool | getGPIOInputStatus (void) |
| Get the GPIO input status. More... | |
| bool | setGPIOOutput (sfe_as7343_gpio_output_t gpioOut) |
| Set the GPIO output. More... | |
| bool | reset (void) |
| Reset the device. More... | |
| bool | setSpectralIntPersistence (uint8_t apers) |
| Set the Spectral Interrupt Persistence. More... | |
| bool | readRegisterBank (uint8_t reg, uint8_t &data) |
| Read a register from the device. More... | |
| bool | setAgain (sfe_as7343_again_t again) |
| bool | enableFlickerDetection (bool enable=true) |
| Enable or Disable the Flicker Detection. More... | |
| bool | disableFlickerDetection (void) |
| Disable Flicker Detection. More... | |
| bool | isFlickerDetectionValid (void) |
| Get the Flicker Detection Measurement Valid Status. More... | |
| bool | isFlickerDetectionSaturated (void) |
| Get the Flicker Detection Saturation Detected Status. More... | |
| uint8_t | getFlickerDetectionFrequency (void) |
| Get the Flicker Detection Frequency Detected. More... | |
|
inline |
| bool sfDevAS7343::begin | ( | sfTkIBus * | theBus = nullptr | ) |
This method is called to initialize the AS7343 device through the specified bus.
| theBus | Pointer to the bus object. |
| bool sfDevAS7343::clearSpectralChannelInterrupt | ( | void | ) |
Clear Spectral Channel Interrupt bit (AINT).
This method clears the spectral channel interrupt bit by writing a 1 to the AINT bit in the STATUS register (ksfAS7343RegStatus).
| bool sfDevAS7343::disableFlickerDetection | ( | void | ) |
Disable Flicker Detection.
This method disables flicker detection by calling the enableFlickerDetection method with false.
| bool sfDevAS7343::disableSpectralInterrupt | ( | void | ) |
Disable the spectral interrupt.
This method disables the spectral interrupt by calling the enableSpectralInterrupt method with false.
| bool sfDevAS7343::disableSpectralMeasurement | ( | void | ) |
Spectral Measurement Disable.
This method disables the spectral measurement by calling the enableSpectralMeasurement method with false.
| bool sfDevAS7343::disableWaitTime | ( | void | ) |
Disable Wait Time.
This method disables the wait time by calling the enableWaitTime method with false.
| bool sfDevAS7343::enableFlickerDetection | ( | bool | enable = true | ) |
Enable or Disable the Flicker Detection.
This method enables or disables the flicker detection by setting or clearing the FD_EN bit in the ENABLE register (ksfAS7343RegEnable).
| enable | True to enable the flicker detection, false to disable. |
| bool sfDevAS7343::enableSpectralInterrupt | ( | bool | enable = true | ) |
Enable or Disable the spectral interrupt.
This method enables or disables the spectral interrupt by setting or clearing the SP_IEN bit in the INT_ENAB register (ksfAS7343RegIntEnab).
| enable | True to enable the spectral interrupt, false to disable. |
| bool sfDevAS7343::enableSpectralMeasurement | ( | bool | enable = true | ) |
Enable or Disable the Spectral Measurement.
This method enables or disables the spectral measurement by setting or clearing the SP_EN bit in the Enable register (ksfAS7343RegEnable).
| enable | True to enable the spectral measurement, false to disable. |
| bool sfDevAS7343::enableWaitTime | ( | bool | enable = true | ) |
Enable or Disable Wait Time.
This method enables or disables the wait time by setting or clearing the WEN bit in the Enable register (ksfAS7343RegEnable).
| enable | True to enable the wait time, false to disable. |
| uint16_t sfDevAS7343::getBlue | ( | void | ) |
Get Blue spectrum data. (aka channel FZ, 450nm)
| uint16_t sfDevAS7343::getChannelData | ( | sfe_as7343_channel_t | channel | ) |
Get Specific Channel of Spectrum Data.
| channel | The channel to get the data from. (sfe_as7343_channel_t) |
Options: CH_BLUE_FZ_450NM, CH_GREEN_FY_555NM, CH_ORANGE_FXL_600NM, CH_NIR_855NM, CH_VIS_1, CH_FD_1, CH_DARK_BLUE_F2_425NM, CH_LIGHT_BLUE_F3_475NM, CH_BLUE_F4_515NM, CH_BROWN_F6_640NM, CH_VIS_2, CH_FD_2, CH_PURPLE_F1_405NM, CH_RED_F7_690NM, CH_DARK_RED_F8_745NM, CH_GREEN_F5_550NM, CH_VIS_3, CH_FD_3.
| uint8_t sfDevAS7343::getData | ( | uint16_t * | data, |
| size_t | size | ||
| ) |
Get data from the sensor using a pointer to an array and the desired data length.
You must call the readSpectraDataFromSensor() method before calling this method to get the most recent data from the specified channel.
| data | Pointer to the array to store the data. |
| size | Size of the array. |
|
inline |
| uint8_t sfDevAS7343::getDeviceID | ( | void | ) |
Requests the device ID from the sensor.
| uint8_t sfDevAS7343::getFlickerDetectionFrequency | ( | void | ) |
Get the Flicker Detection Frequency Detected.
This method gets the flicker detection frequency detected by reading the FD_100HZ_DET and FD_120HZ_DET bits in the FD_STATUS register (ksfAS7343RegFdStatus).
| bool sfDevAS7343::getGPIOInputStatus | ( | void | ) |
Get the GPIO input status.
This method gets the GPIO input status by reading the GPIO_IN bit in the GPIO register (ksfAS7343RegGpio).
| uint16_t sfDevAS7343::getGreen | ( | void | ) |
Get Green spectrum data. (aka channel F5, 550nm)
| uint16_t sfDevAS7343::getNIR | ( | void | ) |
Get NIR spectrum data. (aka channel NIR, 855nm)
| uint16_t sfDevAS7343::getRed | ( | void | ) |
Get Red spectrum data. (aka channel F7, 690nm)
| bool sfDevAS7343::getSpectralChannelInterruptStatus | ( | void | ) |
Get the Spectral Channel Interrupt Status.
This method gets the spectral channel interrupt status by reading the AINT bit in the STATUS register (ksfAS7343RegStatus).
| bool sfDevAS7343::getSpectralInterruptHighStatus | ( | void | ) |
Get the Spectral Interrupt High Status.
This method gets the spectral interrupt high status by reading the INT_PS_H bit in the STATUS3 register (ksfAS7343RegStatus3).
| bool sfDevAS7343::getSpectralTriggerErrorStatus | ( | void | ) |
Get the Spectral Trigger Error Status.
This method gets the spectral trigger error status by reading the SP_TRIG bit in the STATUS4 register (ksfAS7343RegStatus4).
| bool sfDevAS7343::getSpectralValidStatus | ( | void | ) |
Get the Spectral Valid Status.
This method gets the spectral valid status by reading the AVALID bit in the STATUS2 register (ksfAS7343RegStatus2).
| bool sfDevAS7343::getSystemInterruptStatus | ( | void | ) |
Get the System Interrupt Status.
This method gets the system interrupt status by reading the SINT bit in the STATUS register (ksfAS7343RegStatus).
| uint8_t sfDevAS7343::getWaitTime | ( | void | ) |
Get the Spectral Measurement Wait Time.
This method gets the spectral measurement wait time by reading the WTIME register (ksfAS7343RegWTime).
The value is in units of 2.78ms. The default value is 0x00.
| bool sfDevAS7343::isFlickerDetectionSaturated | ( | void | ) |
Get the Flicker Detection Saturation Detected Status.
This method gets the flicker detection saturation detected status by reading the FD_SATURATION bit in the FD_STATUS register (ksfAS7343RegFdStatus).
| bool sfDevAS7343::isFlickerDetectionValid | ( | void | ) |
Get the Flicker Detection Measurement Valid Status.
This method gets the flicker detection measurement valid status by reading the FD_MEAS_VALID bit in the FD_STATUS register (ksfAS7343RegFdStatus).
| bool sfDevAS7343::ledOff | ( | void | ) |
Turn off the LED.
This method turns off the LED by calling the ledOn method with false.
| bool sfDevAS7343::ledOn | ( | bool | ledOn = true | ) |
Turn on or off the LED.
This method turns on or off the LED by setting or clearing the LED_ACT bit in the LED register (ksfAS7343RegLed).
| ledOn | True to turn on the LED, false to turn off. |
| bool sfDevAS7343::powerOff | ( | void | ) |
Power off the device.
This method powers off the device by clearing the PON bit in the Enable register (ksfAS7343RegEnable).
| bool sfDevAS7343::powerOn | ( | bool | power = true | ) |
Power on or off the device.
This method powers on or off the device by setting or clearing the PON bit in the Enable register (ksfAS7343RegEnable).
| power | True to power on the device, false to power off. |
| uint8_t sfDevAS7343::readIntEnableReg | ( | void | ) |
Read the register INT Enable.
This method reads the INT Enable register (ksfAS7343RegIntEnab).
The INT Enable register is a bit field that enables or disables the spectral interrupt, FIFO interrupt, and AGC interrupt.
| bool sfDevAS7343::readRegisterBank | ( | uint8_t | reg, |
| uint8_t & | data | ||
| ) |
Read a register from the device.
This method reads a register from the device
| reg | The register to read. |
| data | Pointer to the register data to read into. |
| bool sfDevAS7343::readSpectraDataFromSensor | ( | void | ) |
Read all Spectral Data Registers.
This method reads all the spectral data registers from the AS7343 device. The data is stored in this drivers private struct variables.
The data is stored in the _data array in the class. You can access the data using the getData() method, which returns the data from the specified channel. Another option is to use the getRed(), getGreen(), getBlue(), and getNIR() methods to get only those channels.
| bool sfDevAS7343::reset | ( | void | ) |
Reset the device.
This method resets the device by writing to the SW_RESET bit in the CONTROL register (ksfAS7343RegControl).
| bool sfDevAS7343::setAgain | ( | sfe_as7343_again_t | again | ) |
Brief Set AGAIN value
This method sets the AGAIN value by writing to the AGAIN bits in the CFG1 register (ksfAS7343RegCfg1).
| again | The AGAIN value to set. |
Options: AGAIN_0_5X (default), AGAIN_1X, AGAIN_2X, AGAIN_4X, AGAIN_8X, AGAIN_16X, AGAIN_32X, AGAIN_64X.
| bool sfDevAS7343::setAutoSmux | ( | sfe_as7343_auto_smux_channel_t | auto_smux | ) |
Set automatic channel read-out.
This method sets the automatic channel read-out mode. The auto_smux setting in the CFG20 register (0xD6) can be set to 6, 12, or 18 channels. The default is 6 channels.
| auto_smux | The automatic channel read-out setting. |
Options: AUTOSMUX_6_CH (default), AUTOSMUX_12_CH, AUTOSMUX_18_CHANNELS.
| void sfDevAS7343::setCommunicationBus | ( | sfTkIBus * | theBus | ) |
Sets the communication bus to the specified bus.
| theBus | Bus to set as the communication device. |
| bool sfDevAS7343::setGPIOMode | ( | sfe_as7343_gpio_mode_t | gpioMode | ) |
Set the GPIO pin mode.
This method sets the GPIO pin mode by writing to the GPIO_IN_EN and GPIO_OUT bits in the GPIO register (ksfAS7343RegGpio).
| gpioMode | The GPIO pin mode to set. |
Options: AS7343_GPIO_MODE_INPUT (default), AS7343_GPIO_MODE_OUTPUT.
| bool sfDevAS7343::setGPIOOutput | ( | sfe_as7343_gpio_output_t | gpioOut | ) |
Set the GPIO output.
This method sets the GPIO output by writing to the GPIO_OUT bit in the GPIO register (ksfAS7343RegGpio).
| gpioOut | The GPIO output to set. |
Options: AS7343_GPIO_OUTPUT_LOW (default), AS7343_GPIO_OUTPUT_HIGH.
| bool sfDevAS7343::setLedDrive | ( | uint8_t | ledDrive | ) |
Set the LED drive current.
This method sets the LED drive current by writing to the LED register (ksfAS7343RegLed). The LED drive current is set by writing to the LED_DRIVE bits in the LED register.
| ledDrive | The LED drive current to set. |
Options: 0-127. (4-258mA) The drive current can be set to values of 0-127 (0-258 mA). 0 = 4mA, 1 = 6mA, 2 = 8mA, ... 127 = 258mA. default is 12mA.
| bool sfDevAS7343::setRegisterBank | ( | sfe_as7343_reg_bank_t | regBank | ) |
Set the register bank. In order to access registers from 0x58 to 0x66, bit REG_BANK in register CFG0 (0xBF) needs to be set to “1”. For register access of registers 0x80 and above bit REG_BANK needs to be set to “0”
| regBank | The register bank to set. |
Options: REG_BANK_0 (default), REG_BANK_1.
| bool sfDevAS7343::setSpectralIntPersistence | ( | uint8_t | apers | ) |
Set the Spectral Interrupt Persistence.
This method sets the spectral interrupt persistence by writing to the PERS bits in the PERS register (ksfAS7343RegPers).
| apers | The spectral interrupt persistence to set. |
Options: 0 = Every spectral cycle generates an interrupt. 1 = 1 2 = 2 3 = 3 4 = 5 5 = 10 ... 5*(APERS - 3) 14 = 55 15 = 60
The default value is 0x00.
| bool sfDevAS7343::setSpectralIntThresholdHigh | ( | uint16_t | spThH | ) |
Set the spectral interrupt threshold high.
This method sets the spectral threshold high by writing to the SP_TH_H register (ksfAS7343RegSpThH). The spectral threshold high is set by writing to the SP_TH_H_LSB Register and SP_TH_H_MSB Register.
| spThH | The spectral threshold high to set. |
| bool sfDevAS7343::setSpectralIntThresholdLow | ( | uint16_t | spThL | ) |
Set the spectral interrupt threshold low.
This method sets the spectral threshold low by writing to the SP_TH_L register (ksfAS7343RegSpThL). The spectral threshold low is set by writing to the SP_TH_L_LSB Register and SP_TH_L_MSB Register.
| spThL | The spectral threshold low to set. |
| bool sfDevAS7343::setSpectralThresholdChannel | ( | sfe_as7343_spectral_threshold_channel_t | spThCh | ) |
Set the spectral threshold channel.
This method sets the spectral threshold channel by writing to the SP_TH_CH bits [2:0] in the CFG12 register, ksfAS7343RegCfg12 (0x66).
| spThCh | The spectral threshold channel to set. |
Options: SPECTRAL_THRESHOLD_CHANNEL_0 (default), SPECTRAL_THRESHOLD_CHANNEL_1, SPECTRAL_THRESHOLD_CHANNEL_2, SPECTRAL_THRESHOLD_CHANNEL_3, SPECTRAL_THRESHOLD_CHANNEL_4, SPECTRAL_THRESHOLD_CHANNEL_5.
| bool sfDevAS7343::setWaitTime | ( | uint8_t | wTime | ) |
Set the Spectral Measurement Wait Time.
This method sets the spectral measurement wait time by writing to the WTIME register (ksfAS7343RegWTime).
| wTime | The spectral measurement wait time to set. |
8-bit value to specify the delay between two consecutive spectral measurements. The value is in units of 2.78ms. The default value is 0x00.