![]() |
SparkFun Spectral UV Sensor - AS7331
v2.1.2-21-g3e22fb4
Library for the SparkFun Spectral UV Sensor - AS7331
|
Arduino I2C implementation for the AS7331 UV sensor. More...
#include <SparkFun_AS7331.h>
Public Member Functions | |
SfeAS7331ArdI2C () | |
bool | begin (const uint8_t &address=kDefaultAS7331Addr, TwoWire &wirePort=Wire) |
Initializes the AS7331 UV sensor with I2C communication. More... | |
bool | isConnected (void) |
Checks if the AS7331 UV sensor is connected and responding. More... | |
bool | setDeviceAddress (const uint8_t &deviceAddress) |
Sets the I2C address for communicating with the AS7331 sensor. More... | |
uint8_t | getDeviceAddress (void) |
Gets the currently configured I2C address of the AS7331 sensor. More... | |
bool | begin (sfTkIBus *theBus=nullptr) |
This method is called to initialize the AS7331 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 | runDefaultSetup (const bool &runSoftReset=false) |
Helper class that sets up the sensor and state in the POR configuration. More... | |
bool | prepareMeasurement (const as7331_meas_mode_t &measMode=MEAS_MODE_CONT, const bool &startMeasure=false) |
Puts the sensor in the specified measurement mode. More... | |
bool | reset (void) |
Performs a soft reset of the sensor. More... | |
sfTkError_t | readTemp (void) |
Reads the sensor's temperature, converts it to a usable form, and saves it to the internal temperature variable. More... | |
sfTkError_t | readUVA (void) |
Reads the sensor's UVA register, converts it to a usable form, and saves it to the internal UVA variable. More... | |
sfTkError_t | readUVB (void) |
Reads the sensor's UVB register, converts it to a usable form, and saves it to the internal UVB variable. More... | |
sfTkError_t | readUVC (void) |
Reads the sensor's UVC register, converts it to a usable form, and saves it to the internal UVC variable. More... | |
sfTkError_t | readAllUV (void) |
Read's all three UV registers, converts them to a usable form, then saves them to their respective internal variable. More... | |
sfTkError_t | readAll (void) |
Read the sensor's temperature, UV, and external time conversion clock counts, converts them, and then saves them to their respective internal variable. More... | |
sfTkError_t | readOutConv (void) |
Read the conversion clock counts register and saves it to the internal output conversion time variable. More... | |
float | getUVA (void) |
Returns the last valid UVA reading. More... | |
float | getUVB (void) |
Returns the last valid UVB reading. More... | |
float | getUVC (void) |
Returns the last valid UVC reading. More... | |
float | getTemp (void) |
Returns the last valid Temperature reading. More... | |
uint32_t | getOutConv (void) |
Returns the last valid output conversion. More... | |
as7331_gain_t | getGainRaw (void) |
Getter for the currently configured gain. More... | |
uint16_t | getGainValue (void) |
Getter for the currently configured gain. More... | |
sfTkError_t | setGain (const as7331_gain_t &gain) |
Sets the UV sensor's gain. More... | |
as7331_conv_clk_freq_t | getCClkRaw (void) |
Getter for the currently configured conversion clock. More... | |
uint16_t | getCClkKHz (void) |
Getter for the currently configured conversion clock. More... | |
sfTkError_t | setCClk (const as7331_conv_clk_freq_t &cclk) |
Set the sensor's internal clock speed. More... | |
as7331_conv_time_t | getConversionTimeRaw (void) |
Getter for the currently configured conversion time. More... | |
uint16_t | getConversionTimeMillis (void) |
Getter for the currently configured conversion time. More... | |
sfTkError_t | setConversionTime (const as7331_conv_time_t &convTime) |
Sets the conversion time that the sensor will run to. More... | |
bool | getReadyPinMode (void) |
Getter for the currently configured pin mode. More... | |
sfTkError_t | setReadyPinMode (const bool &pinMode) |
Sets the ready pin type to push-pull or open-drain. More... | |
bool | getDigitalDividerEnabled (void) |
Getter for the currently configured divider status. More... | |
sfTkError_t | setDigitalDividerEnabled (const bool &isEnabled) |
Enables or disables the internal UV result divider. More... | |
as7331_divider_val_t | getDigitalDividerRange (void) |
Getter for the currently configured divider range. More... | |
sfTkError_t | setDigitalDividerRange (const as7331_divider_val_t ÷r, const bool &enableDiv=true) |
Sets the value of the internal UV result divider. More... | |
bool | getSyndTempConversionEnabled (void) |
Getter for the SYND temperature conversion status. More... | |
sfTkError_t | setSyndTempConversionEnabled (const bool &isEnabled) |
Enables or disables temperature conversion when in SYND mode. More... | |
bool | getIndexMode (void) |
Getter for the currently configured I2C compatibility mode. More... | |
sfTkError_t | setIndexMode (const bool &indexMode) |
Set the index mode for compatibility with I2C controllers that don't support repeated start. More... | |
uint8_t | getBreakTime (void) |
Getter for the currently configured minimum break time in CONT, CMD, SYNS modes. More... | |
sfTkError_t | setBreakTime (const uint8_t &breakTime) |
Set the minimum time between measurements in CONT, SYNS, SYND modes. More... | |
uint8_t | getNumEdges (void) |
Getter for the currently configured minimum number of edges to end conversion when in SYND mode. More... | |
sfTkError_t | setNumEdges (const uint8_t &numEdges) |
Set the minimum number of falling edges required at the SYN input until the conversion is terminated. Only operational in SYND mode. More... | |
bool | getPowerDownState (void) |
Getter for the current power state. More... | |
sfTkError_t | setPowerDownState (const bool &pd) |
Sets the power state of the sensor. More... | |
as7331_dev_op_state_t | getOperationMode (void) |
Getter for the current operational state. More... | |
sfTkError_t | setOperationMode (const as7331_dev_op_state_t &opMode) |
Set the sensor's operating mode. More... | |
as7331_meas_mode_t | getMeasurementMode (void) |
Getter for the current measurement state. More... | |
sfTkError_t | setMeasurementMode (const as7331_meas_mode_t &measMode) |
Sets the sensor's measurement mode. More... | |
bool | getStandbyState (void) |
Getter for the current standby state. More... | |
sfTkError_t | setStandbyState (const bool &standby) |
Sets the sensor's standby mode. More... | |
bool | getStartState (void) |
Getter for the current start state. More... | |
sfTkError_t | setStartState (const bool &startState) |
Sets the sensor's start state. This begins measurement. More... | |
sfTkError_t | getStatus (sfe_as7331_reg_meas_osr_status_t &statusReg) |
Gets the sensor's status when in measurement operation mode. More... | |
sfTkError_t | getOSR (sfe_as7331_reg_cfg_osr_t &osrReg) |
Gets the operational state register when in configuration operation mode. More... | |
sfTkError_t | setOSR (const sfe_as7331_reg_cfg_osr_t &osrReg) |
Sets the operational state register when in configuration operation mode. More... | |
sfTkError_t | getCReg1 (sfe_as7331_reg_cfg_creg1_t &creg1) |
Gets the configuration register #1 when in configuration operation mode. More... | |
sfTkError_t | setCReg1 (const sfe_as7331_reg_cfg_creg1_t &creg1) |
Sets the configuration register #1 when in configuration operation mode. More... | |
sfTkError_t | getCReg2 (sfe_as7331_reg_cfg_creg2_t &creg2) |
Gets the configuration register #2 when in configuration operation mode. More... | |
sfTkError_t | setCReg2 (const sfe_as7331_reg_cfg_creg2_t &creg2) |
Sets the configuration register #2 when in configuration operation mode. More... | |
sfTkError_t | getCReg3 (sfe_as7331_reg_cfg_creg3_t &creg3) |
Gets the configuration register #3 when in configuration operation mode. More... | |
sfTkError_t | setCReg3 (const sfe_as7331_reg_cfg_creg3_t &creg3) |
Sets the configuration register #3 when in configuration operation mode. More... | |
sfTkError_t | getBreak (uint8_t &breakReg) |
Gets the break register when in configuration operation mode. More... | |
sfTkError_t | setBreak (const uint8_t &breakReg) |
Sets the break register when in configuration operation mode. More... | |
sfTkError_t | getEdges (uint8_t &edgesReg) |
Gets the edges register when in configuration operation mode. More... | |
sfTkError_t | setEdges (const uint8_t &edgesReg) |
Sets the edges register when in configuration operation mode. More... | |
sfTkError_t | getOptIndex (sfe_as7331_reg_cfg_optreg_t &optReg) |
Gets the option register when in configuration operation mode. More... | |
sfTkError_t | setOptIndex (const sfe_as7331_reg_cfg_optreg_t &optReg) |
Sets the option register when in configuration operation mode. More... | |
Arduino I2C implementation for the AS7331 UV sensor.
This class provides Arduino-specific I2C communication implementation for the AS7331 UV sensor. It inherits from the base driver class and implements the I2C interface using Arduino's Wire library. The class manages device addressing and connection verification.
Example usage:
|
inline |
|
inline |
Initializes the AS7331 UV sensor with I2C communication.
This method performs the following initialization steps:
address | I2C address of the device (default: kDefaultAS7331Addr) |
wirePort | TwoWire instance to use for I2C communication (default: Wire) |
Example:
|
inherited |
This method is called to initialize the AS7331 device through the specified bus.
theBus | Pointer to the bus object. |
|
inherited |
Gets the break register when in configuration operation mode.
breakReg | Pointer to a register struct to store the sensor's current break register. |
|
inherited |
Getter for the currently configured minimum break time in CONT, CMD, SYNS modes.
|
inherited |
Getter for the currently configured conversion clock.
|
inherited |
Getter for the currently configured conversion clock.
|
inherited |
Getter for the currently configured conversion time.
|
inherited |
Getter for the currently configured conversion time.
|
inherited |
Gets the configuration register #1 when in configuration operation mode.
creg1 | Pointer to a register struct to store the sensor's current creg1 register. |
|
inherited |
Gets the configuration register #2 when in configuration operation mode.
creg2 | Pointer to a register struct to store the sensor's current creg2 register. |
|
inherited |
Gets the configuration register #3 when in configuration operation mode.
creg3 | Pointer to a register struct to store the sensor's current creg3 register. |
|
inline |
Gets the currently configured I2C address of the AS7331 sensor.
Returns the I2C address currently being used to communicate with the sensor. The address will be one of:
Example:
|
inherited |
Requests the device ID from the sensor.
|
inherited |
Getter for the currently configured divider status.
|
inherited |
Getter for the currently configured divider range.
|
inherited |
Gets the edges register when in configuration operation mode.
edgesReg | Pointer to a register struct to store the sensor's current edges register. |
|
inherited |
Getter for the currently configured gain.
|
inherited |
Getter for the currently configured gain.
|
inherited |
Getter for the currently configured I2C compatibility mode.
|
inherited |
Getter for the current measurement state.
|
inherited |
Getter for the currently configured minimum number of edges to end conversion when in SYND mode.
|
inherited |
Getter for the current operational state.
|
inherited |
Gets the option register when in configuration operation mode.
optReg | Pointer to a register struct to store the sensor's current option register. |
|
inherited |
Gets the operational state register when in configuration operation mode.
osrReg | Pointer to a register struct to store the sensor's current OSR register. |
|
inherited |
Returns the last valid output conversion.
|
inherited |
Getter for the current power state.
|
inherited |
Getter for the currently configured pin mode.
|
inherited |
Getter for the current standby state.
|
inherited |
Getter for the current start state.
|
inherited |
Gets the sensor's status when in measurement operation mode.
statusReg | Pointer to a register struct to store the sensor's current status. |
|
inherited |
Getter for the SYND temperature conversion status.
|
inherited |
Returns the last valid Temperature reading.
|
inherited |
Returns the last valid UVA reading.
|
inherited |
Returns the last valid UVB reading.
|
inherited |
Returns the last valid UVC reading.
|
inline |
Checks if the AS7331 UV sensor is connected and responding.
This method performs two checks:
Example:
|
inherited |
Puts the sensor in the specified measurement mode.
measMode | Measurement mode to enter. |
startMeasure | Flag to start measuring immediately if set. |
|
inherited |
Read the sensor's temperature, UV, and external time conversion clock counts, converts them, and then saves them to their respective internal variable.
|
inherited |
Read's all three UV registers, converts them to a usable form, then saves them to their respective internal variable.
|
inherited |
Read the conversion clock counts register and saves it to the internal output conversion time variable.
|
inherited |
Reads the sensor's temperature, converts it to a usable form, and saves it to the internal temperature variable.
|
inherited |
Reads the sensor's UVA register, converts it to a usable form, and saves it to the internal UVA variable.
|
inherited |
Reads the sensor's UVB register, converts it to a usable form, and saves it to the internal UVB variable.
|
inherited |
Reads the sensor's UVC register, converts it to a usable form, and saves it to the internal UVC variable.
|
inherited |
Performs a soft reset of the sensor.
|
inherited |
Helper class that sets up the sensor and state in the POR configuration.
runSoftReset | Flag that runs the soft reset function to reset the device. |
|
inherited |
Sets the break register when in configuration operation mode.
breakReg | Pointer to a register struct that has the new register configuration. |
|
inherited |
Set the minimum time between measurements in CONT, SYNS, SYND modes.
breakTime | Time between measurements, 8us step time, max 2048us. A 0 value is a minimum of 3 cclk cycles. |
|
inherited |
Set the sensor's internal clock speed.
cclk | Clock speed to set on the sensor. |
|
inherited |
Sets the communication bus to the specified bus.
theBus | Bus to set as the communication device. |
|
inherited |
Sets the conversion time that the sensor will run to.
convTime | Conversion time to set the sensor to. |
|
inherited |
Sets the configuration register #1 when in configuration operation mode.
creg1 | Pointer to a register struct that has the new register configuration. |
|
inherited |
Sets the configuration register #2 when in configuration operation mode.
creg2 | Pointer to a register struct that has the new register configuration. |
|
inherited |
Sets the configuration register #3 when in configuration operation mode.
creg3 | Pointer to a register struct that has the new register configuration. |
|
inline |
Sets the I2C address for communicating with the AS7331 sensor.
This method validates and sets the I2C address for the sensor. Only specific addresses are allowed:
deviceAddress | The I2C address to set |
Example:
|
inherited |
Enables or disables the internal UV result divider.
isEnabled | Enable or disable the divder. |
|
inherited |
Sets the value of the internal UV result divider.
divider | Divider value to set. |
setEnableDiv | Option to turn on the divider if desired. |
|
inherited |
Sets the edges register when in configuration operation mode.
edgesReg | Pointer to a register struct that has the new register configuration. |
|
inherited |
Sets the UV sensor's gain.
gain | The gain to set the sensor to. |
|
inherited |
Set the index mode for compatibility with I2C controllers that don't support repeated start.
indexMode | Simple or standard I2C addressing mode. |
|
inherited |
Sets the sensor's measurement mode.
measMode | Measurement mode to set. |
|
inherited |
Set the minimum number of falling edges required at the SYN input until the conversion is terminated. Only operational in SYND mode.
numEdges | Number of edges prior to terminating conversion in SYND mode. 0 is not allowed, 1 is the minimum. |
|
inherited |
Set the sensor's operating mode.
opMode | Operating mode to set. |
|
inherited |
Sets the option register when in configuration operation mode.
optReg | Pointer to a register struct that has the new register configuration. |
|
inherited |
Sets the operational state register when in configuration operation mode.
osrReg | Pointer to a register struct that has the new register configuration. |
|
inherited |
Sets the power state of the sensor.
pd | Power state to set. |
|
inherited |
Sets the ready pin type to push-pull or open-drain.
pinMode | Mode to set the ready pin to. |
|
inherited |
Sets the sensor's standby mode.
standby | State to set. |
|
inherited |
Sets the sensor's start state. This begins measurement.
startState | Start state to set. |
|
inherited |
Enables or disables temperature conversion when in SYND mode.
isEnabled | Enable or disable the feature. |