upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Types | Public Member Functions

API for the SI1145 UV Light Sensor. More...

Detailed Description

This module was tested with the Adafruit* UV Light Sensor

This device is capable of measuring IR and visible ambient light as well. It also supports the ability to use externally attached LEDs to perform proximity detection on 3 separate channels.

Currently, this class only supports the retrieving of the calculated UV index measured by the device, but enough infrastructure is provided to make it easy to enhance this driver in the future to support additional capabilities, including interrupt support.

si114x.jpg
// Instantiate a SI114x UV Sensor on I2C bus 0
upm::SI114X uvi(0);
// First initialize it
uvi.initialize();
cout << "UV Index Scale:" << endl;
cout << "---------------" << endl;
cout << "11+ Extreme" << endl;
cout << "8-10 Very High" << endl;
cout << "6-7 High" << endl;
cout << "3-5 Moderate" << endl;
cout << "0-2 Low" << endl;
cout << endl;
// update every second and print the currently measured UV Index
while (shouldRun) {
// update current value(s)
uvi.update();
// print detected value
cout << "UV Index: " << uvi.getUVIndex() << endl;
upm_delay(1);
}

Public Types

enum  SI114X_REG_T {
  REG_PART_ID = 0x00, REG_REV_ID = 0x01, REG_SEQ_ID = 0x02, REG_INT_CFG = 0x03,
  REG_IRQ_ENABLE = 0x04, REG_IRQ_MODE1 = 0x05, REG_IRQ_MODE2 = 0x06, REG_HW_KEY = 0x07,
  REG_MEAS_RATE0 = 0x08, REG_MEAS_RATE1 = 0x09, REG_PS_LED21 = 0x0f, REG_PS_LED3 = 0x10,
  REG_UCOEF0 = 0x13, REG_UCOEF1 = 0x14, REG_UCOEF2 = 0x15, REG_UCOEF3 = 0x16,
  REG_PARAM_WR = 0x17, REG_COMMAND = 0x18, REG_RESPONSE = 0x20, REG_IRQ_STATUS = 0x21,
  REG_ALS_VIS_DATA0 = 0x22, REG_ALS_VIS_DATA1 = 0x23, REG_ALS_IR_DATA0 = 0x24, REG_ALS_IR_DATA1 = 0x25,
  REG_PS1_DATA0 = 0x26, REG_PS1_DATA1 = 0x27, REG_PS2_DATA0 = 0x28, REG_PS2_DATA1 = 0x29,
  REG_PS3_DATA0 = 0x2a, REG_PS3_DATA1 = 0x2b, REG_AUX_UVINDEX0 = 0x2c, REG_AUX_UVINDEX1 = 0x2d,
  REG_PARAM_READ = 0x2e, REG_CHIP_STAT = 0x30, REG_ANA_IN_KEY0 = 0x3b, REG_ANA_IN_KEY1 = 0x3c,
  REG_ANA_IN_KEY2 = 0x3d, REG_ANA_IN_KEY3 = 0x3e
}
 
enum  SI114X_PARAM_T {
  PARAM_I2C_ADDDR = 0x00, PARAM_CHLIST = 0x01, PARAM_PSLED12_SEL = 0x02, PARAM_PSLED3_SEL = 0x03,
  PARAM_PS_ENCODING = 0x05, PARAM_ALS_ENCODING = 0x06, PARAM_PS1_ADCMUX = 0x07, PARAM_PS2_ADCMUX = 0x08,
  PARAM_PS3_ADCMUX = 0x09, PARAM_PS_ADC_COUNT = 0x0a, PARAM_PS_ADC_GAIN = 0x0b, PARAM_PS_ADC_MISC = 0x0c,
  PARAM_ALS_IR_ADCMUX = 0x0e, PARAM_AUX_ADCMUX = 0x0f, PARAM_ALS_VIS_ADC_COUNT = 0x10, PARAM_ALS_VIS_ADC_GAIN = 0x11,
  PARAM_ALS_VIS_ADC_MISC = 0x12, PARAM_LED_REC = 0x1c, PARAM_ALS_IR_ADC_COUNT = 0x1d, PARAM_ALS_IR_ADX_GAIN = 0x1e,
  PARAM_ALS_IR_ADC_MISC = 0x1f
}
 
enum  SI114X_CMD_T {
  CMD_NOOP = 0x00, CMD_RESET = 0x01, CMD_BUSADDR = 0x02, CMD_PS_FORCE = 0x05,
  CMD_GET_CAL = 0x12, CMD_ALS_FORCE = 0x06, CMD_PSALS_FORCE = 0x07, CMD_PS_PAUSE = 0x09,
  CMD_ALS_PAUSE = 0x0a, CMD_PSALS_PAUSE = 0x0b, CMD_PS_AUTO = 0x0d, CMD_ALS_AUTO = 0x0e,
  CMD_PSALS_AUTO = 0x0f, CMD_PARAM_QUERY = 0x80, CMD_PARAM_SET = 0xa0
}
 
enum  SI114X_CHLIST_BITS_T {
  CHLIST_EN_PS1 = 0x01, CHLIST_EN_PS2 = 0x02, CHLIST_EN_PS3 = 0x04, CHLIST_EN_ALS_VIS = 0x10,
  CHLIST_EN_ALS_IR = 0x20, CHLIST_EN_AUX = 0x40, CHLIST_EN_UV = 0x80
}
 
enum  SI114X_ERR_T {
  ERR_NONE = 0x00, ERR_INVALID_SET = 0x80, ERR_PS1_ADC_OVER = 0x88, ERR_PS2_ADC_OVER = 0x89,
  ERR_PS3_ADC_OVER = 0x8a, ERR_ALS_VIS_ADC_OVER = 0x8c, ERR_ALS_IR_ADC_OVER = 0x8d, ERR_AUX_ADC_OVER = 0x8e
}
 
enum  SI114X_IRQEN_BITS_T { IRQEN_ALS_IE = 0x01, IRQEN_PS1_IE = 0x04, IRQEN_PS2_IE = 0x08, IRQEN_PS3_IE = 0x10 }
 

Public Member Functions

 SI114X (int bus, uint8_t address=SI114X_DEFAULT_I2C_ADDR)
 
 ~SI114X ()
 
bool writeByte (uint8_t reg, uint8_t byte)
 
uint8_t readByte (uint8_t reg)
 
uint16_t readWord (uint8_t reg)
 
void reset ()
 
void setUVCalibration (uint8_t uvcoeff0, uint8_t uvcoeff1, uint8_t uvcoeff2, uint8_t uvcoeff3)
 
void writeParam (SI114X_PARAM_T param, uint8_t value)
 
uint8_t readParam (SI114X_PARAM_T param)
 
void initialize ()
 
void update ()
 
float getUVIndex ()
 

Member Enumeration Documentation

SI114X registers

Parameter memory (PARAM)

Commands (written to the REG_COMMAND register)

Channel list enable bits

Error codes from the RESPONSE register

Interrupt enable bits

Constructor & Destructor Documentation

SI114X ( int  bus,
uint8_t  address = SI114X_DEFAULT_I2C_ADDR 
)

SI114X constructor

Parameters
busI2C bus to use
addressAddress for this device
~SI114X ( )

SI114X destructor

Member Function Documentation

bool writeByte ( uint8_t  reg,
uint8_t  byte 
)

Writes a byte value into a register

Parameters
regRegister location to write into
byteByte to write
Returns
True if successful
uint8_t readByte ( uint8_t  reg)

Reads a byte value from a register

Parameters
regRegister location to read from
Returns
Value in a specified register
uint16_t readWord ( uint8_t  reg)

Reads a word value from a register

Parameters
regRegister location to read from
Returns
Value in a specified register
void reset ( )

Disables interrupts and auto-measuring, issues a device reset, and then sets the hardware key.

void setUVCalibration ( uint8_t  uvcoeff0,
uint8_t  uvcoeff1,
uint8_t  uvcoeff2,
uint8_t  uvcoeff3 
)

Sets UV calibration values. The constructor sets default values for you, so you only need this function if you need different values for your device and situation. If you set new values here, be sure to do so before calling initialize().

Parameters
uvcoeff0Coefficient for REG_UCOEF0
uvcoeff1Coefficient for REG_UCOEF1
uvcoeff2Coefficient for REG_UCOEF2
uvcoeff3Coefficient for REG_UCOEF3
void writeParam ( SI114X_PARAM_T  param,
uint8_t  value 
)

Writes a value to the parameter memory.

Parameters
paramSI114X_PARAM_T register to write
valueValue to write
uint8_t readParam ( SI114X_PARAM_T  param)

Reads a value from the parameter memory

Parameters
paramSI114X_PARAM_T register to read
Returns
Value
void initialize ( )

Resets and initializes the device and starts auto-sampling

void update ( void  )

Updates stored values. You should call this before calling getUVIndex()

float getUVIndex ( )
inline

Reads the currently measured UV index value

Returns
UV index value

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