SparkFun Spectral Sensor - AS7343  v1.0.0-4-gd418547
Library for the SparkFun SpectralSensor - AS7343
Loading...
Searching...
No Matches
sfDevAS7343 Class Reference

#include <sfDevAS7343.h>

Inheritance diagram for sfDevAS7343:

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...
 

Constructor & Destructor Documentation

◆ sfDevAS7343()

sfDevAS7343::sfDevAS7343 ( )
inline

Member Function Documentation

◆ begin()

bool sfDevAS7343::begin ( sfTkIBus *  theBus = nullptr)

This method is called to initialize the AS7343 device through the specified bus.

Parameters
theBusPointer to the bus object.
Returns
True if successful, false if it fails.

◆ clearSpectralChannelInterrupt()

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).

Returns
True if successful, false if it fails.

◆ disableFlickerDetection()

bool sfDevAS7343::disableFlickerDetection ( void  )

Disable Flicker Detection.

This method disables flicker detection by calling the enableFlickerDetection method with false.

Returns
True if successful, false if it fails.

◆ disableSpectralInterrupt()

bool sfDevAS7343::disableSpectralInterrupt ( void  )

Disable the spectral interrupt.

This method disables the spectral interrupt by calling the enableSpectralInterrupt method with false.

Returns
True if successful, false if it fails.

◆ disableSpectralMeasurement()

bool sfDevAS7343::disableSpectralMeasurement ( void  )

Spectral Measurement Disable.

This method disables the spectral measurement by calling the enableSpectralMeasurement method with false.

Returns
True if successful, false if it fails.

◆ disableWaitTime()

bool sfDevAS7343::disableWaitTime ( void  )

Disable Wait Time.

This method disables the wait time by calling the enableWaitTime method with false.

Returns
True if successful, false if it fails.

◆ enableFlickerDetection()

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).

Parameters
enableTrue to enable the flicker detection, false to disable.
Returns
True if successful, false if it fails.

◆ enableSpectralInterrupt()

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).

Parameters
enableTrue to enable the spectral interrupt, false to disable.
Returns
True if successful, false if it fails.

◆ enableSpectralMeasurement()

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).

Parameters
enableTrue to enable the spectral measurement, false to disable.
Returns
True if successful, false if it fails.

◆ enableWaitTime()

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).

Parameters
enableTrue to enable the wait time, false to disable.
Returns
True if successful, false if it fails.

◆ getBlue()

uint16_t sfDevAS7343::getBlue ( void  )

Get Blue spectrum data. (aka channel FZ, 450nm)

Returns
The blue spectrum data.

◆ getChannelData()

uint16_t sfDevAS7343::getChannelData ( sfe_as7343_channel_t  channel)

Get Specific Channel of Spectrum Data.

Parameters
channelThe 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.

Returns
The data from the specified channel. Returns 0 on error or if the channel is invalid.

◆ getData() [1/2]

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.

Parameters
dataPointer to the array to store the data.
sizeSize of the array.
See also
readSpectraDataFromSensor()
getChannelData()
Returns
The number of channel data bytes written to the desired array pointer

◆ getData() [2/2]

uint8_t sfDevAS7343::getData ( uint16_t  data[ksfAS7343NumChannels])
inline

◆ getDeviceID()

uint8_t sfDevAS7343::getDeviceID ( void  )

Requests the device ID from the sensor.

Returns
The device ID of the sensor.

◆ getFlickerDetectionFrequency()

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).

Returns
The flicker detection frequency detected (100 or 120) or 0 if no frequency is detected.

◆ getGPIOInputStatus()

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).

Returns
True if the GPIO input is reading HIGH, false if it is reading LOW.

◆ getGreen()

uint16_t sfDevAS7343::getGreen ( void  )

Get Green spectrum data. (aka channel F5, 550nm)

Returns
The green spectrum data.

◆ getNIR()

uint16_t sfDevAS7343::getNIR ( void  )

Get NIR spectrum data. (aka channel NIR, 855nm)

Returns
The NIR spectrum data.

◆ getRed()

uint16_t sfDevAS7343::getRed ( void  )

Get Red spectrum data. (aka channel F7, 690nm)

Returns
The red spectrum data.

◆ getSpectralChannelInterruptStatus()

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).

Returns
True if the spectral channel interrupt is set, false if it is not set.

◆ getSpectralInterruptHighStatus()

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).

Returns
True if the spectral interrupt high is set, false if it is not set.

◆ getSpectralTriggerErrorStatus()

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).

Returns
True if the spectral trigger error is set, false if it is not set.

◆ getSpectralValidStatus()

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).

Returns
True if the spectral valid status is set, false if it is not set.

◆ getSystemInterruptStatus()

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).

Returns
True if the system interrupt is set, false if it is not set.

◆ getWaitTime()

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).

Returns
The spectral measurement wait time.

The value is in units of 2.78ms. The default value is 0x00.

◆ isFlickerDetectionSaturated()

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).

Returns
True if the flicker detection saturation is detected, false if it is not detected.

◆ isFlickerDetectionValid()

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).

Returns
True if the flicker detection measurement is valid, false if it is not valid.

◆ ledOff()

bool sfDevAS7343::ledOff ( void  )

Turn off the LED.

This method turns off the LED by calling the ledOn method with false.

Returns
True if successful, false if it fails.

◆ ledOn()

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).

Parameters
ledOnTrue to turn on the LED, false to turn off.
Returns
True if successful, false if it fails.

◆ powerOff()

bool sfDevAS7343::powerOff ( void  )

Power off the device.

This method powers off the device by clearing the PON bit in the Enable register (ksfAS7343RegEnable).

Returns
True if successful, false if it fails.

◆ powerOn()

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).

Parameters
powerTrue to power on the device, false to power off.
Returns
True if successful, false if it fails.

◆ readIntEnableReg()

uint8_t sfDevAS7343::readIntEnableReg ( void  )

Read the register INT Enable.

This method reads the INT Enable register (ksfAS7343RegIntEnab).

Returns
The INT Enable register value.

The INT Enable register is a bit field that enables or disables the spectral interrupt, FIFO interrupt, and AGC interrupt.

Returns
The INT Enable register value.

◆ readRegisterBank()

bool sfDevAS7343::readRegisterBank ( uint8_t  reg,
uint8_t &  data 
)

Read a register from the device.

This method reads a register from the device

Parameters
regThe register to read.
dataPointer to the register data to read into.
Returns
True if successful, false if it fails.

◆ readSpectraDataFromSensor()

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.

Returns
True if successful, false if it fails.

◆ reset()

bool sfDevAS7343::reset ( void  )

Reset the device.

This method resets the device by writing to the SW_RESET bit in the CONTROL register (ksfAS7343RegControl).

Returns
True if successful, false if it fails.

◆ setAgain()

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).

Parameters
againThe AGAIN value to set.

Options: AGAIN_0_5X (default), AGAIN_1X, AGAIN_2X, AGAIN_4X, AGAIN_8X, AGAIN_16X, AGAIN_32X, AGAIN_64X.

Returns
True if successful, false if it fails.

◆ setAutoSmux()

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.

Parameters
auto_smuxThe automatic channel read-out setting.

Options: AUTOSMUX_6_CH (default), AUTOSMUX_12_CH, AUTOSMUX_18_CHANNELS.

Returns
True if successful, false if it fails.

◆ setCommunicationBus()

void sfDevAS7343::setCommunicationBus ( sfTkIBus *  theBus)

Sets the communication bus to the specified bus.

Parameters
theBusBus to set as the communication device.

◆ setGPIOMode()

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).

Parameters
gpioModeThe GPIO pin mode to set.

Options: AS7343_GPIO_MODE_INPUT (default), AS7343_GPIO_MODE_OUTPUT.

Returns
True if successful, false if it fails.

◆ setGPIOOutput()

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).

Parameters
gpioOutThe GPIO output to set.

Options: AS7343_GPIO_OUTPUT_LOW (default), AS7343_GPIO_OUTPUT_HIGH.

Returns
True if successful, false if it fails.

◆ setLedDrive()

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.

Parameters
ledDriveThe 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.

Returns
True if successful, false if it fails.

◆ setRegisterBank()

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”

Parameters
regBankThe register bank to set.

Options: REG_BANK_0 (default), REG_BANK_1.

Returns
True if successful, false if it fails.

◆ setSpectralIntPersistence()

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).

Parameters
apersThe 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.

Returns
True if successful, false if it fails.

◆ setSpectralIntThresholdHigh()

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.

Parameters
spThHThe spectral threshold high to set.
Returns
True if successful, false if it fails.

◆ setSpectralIntThresholdLow()

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.

Parameters
spThLThe spectral threshold low to set.
Returns
True if successful, false if it fails.

◆ setSpectralThresholdChannel()

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).

Parameters
spThChThe 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.

Returns
True if successful, false if it fails.

◆ setWaitTime()

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).

Parameters
wTimeThe 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.

Returns
True if successful, false if it fails.

The documentation for this class was generated from the following files: