Driver for the Silicon Labs Si1133 Visible Light/UV sensor

Dependents:   TBSense2_Sensor_Demo mbed-BLE-coragem-teste Pulga_BLE_GPS pulga-mbed-lorawan-gps ... more

Sample library for use with the Silicon Labs Si1133 sensor for visible light intensity (lux) and UV index measurements.

Information

All examples in this repo are considered EXPERIMENTAL QUALITY, meaning this code has been created as one-off proof-of-concept and is suitable as a demonstration for experimental purposes only. This code will not be regularly maintained by Silicon Labs and there is no guarantee that these projects will work across all environments, SDK versions and hardware.

Datasheet

https://www.silabs.com/documents/public/data-sheets/Si1133.pdf

Usage

#include "mbed.h"
#include "Si1133.h"
//Create an Si1133 object
Si1133 sensor(PC4, PC5);
int main()
{
    //Try to open the Si1133
    if (sensor.open()) {
        printf("Device detected!\n");
        while (1) {
            //Print the current light level
            printf("Lux = %.3f\n", (float)sensor.get_light_level());
            //Print the current UV index
            printf("UV index = %.3f\n", (float)sensor.get_uv_index());
            //Sleep for 0.5 seconds
            wait(0.5);
        }
    } else {
        error("Device not detected!\n");
    }
}
Revision:
2:1e2dd643afa8
Parent:
1:410f61a3900b
Child:
3:f780ca9105bb
--- a/Si1133.cpp	Sun Nov 12 16:42:03 2017 +0100
+++ b/Si1133.cpp	Sun Nov 12 20:18:04 2017 +0100
@@ -121,7 +121,7 @@
 float Si1133::get_light_level()
 {
     float lux, uvi;
-    measureLuxUvi(&lux, &uvi);
+    measure_lux_uv(&lux, &uvi);
     return lux;
 }
 
@@ -132,13 +132,13 @@
 float Si1133::get_uv_index()
 {
     float lux, uvi;
-    measureLuxUvi(&lux, &uvi);
+    measure_lux_uv(&lux, &uvi);
     return uvi;
 }
 
 bool Si1133::get_light_and_uv(float *light_level, float *uv_index)
 {
-    if(measureLuxUvi(light_level, uv_index)) {
+    if(measure_lux_uv(light_level, uv_index)) {
         return false;
     }
     return true;
@@ -626,7 +626,7 @@
  * @return
  *    Returns zero on OK, non-zero otherwise
  ******************************************************************************/
-uint32_t Si1133::measurementGet (Si1133::Samples_t *samples)
+uint32_t Si1133::measure (Si1133::Samples_t *samples)
 {
     uint8_t buffer[13];
     uint32_t retval;
@@ -757,7 +757,7 @@
  * @return
  *    UV index scaled by UV_OUPTUT_FRACTION
  ******************************************************************************/
-int32_t Si1133::getUv (int32_t uv)
+int32_t Si1133::get_uv (int32_t uv)
 {
     int32_t uvi;
 
@@ -785,7 +785,7 @@
  * @return
  *    Lux value scaled by LUX_OUPTUT_FRACTION
  ******************************************************************************/
-int32_t Si1133::getLux (int32_t vis_high, int32_t vis_low, int32_t ir)
+int32_t Si1133::get_lux (int32_t vis_high, int32_t vis_low, int32_t ir)
 {
     int32_t lux;
 
@@ -821,7 +821,7 @@
  * @return
  *    Returns zero on OK, non-zero otherwise
  ******************************************************************************/
-uint32_t Si1133::measureLuxUvi (float *lux, float *uvi)
+uint32_t Si1133::measure_lux_uv (float *lux, float *uvi)
 {
     Si1133::Samples_t samples;
     uint32_t retval;
@@ -841,14 +841,14 @@
     }
 
     /* Get the results */
-    measurementGet(&samples);
+    measure(&samples);
 
     /* Convert the readings to lux */
-    *lux = (float) getLux(samples.ch1, samples.ch3, samples.ch2);
+    *lux = (float) get_lux(samples.ch1, samples.ch3, samples.ch2);
     *lux = *lux / (1 << LUX_OUTPUT_FRACTION);
 
     /* Convert the readings to UV index */
-    *uvi = (float) getUv(samples.ch0);
+    *uvi = (float) get_uv(samples.ch0);
     *uvi = *uvi / (1 << UV_OUTPUT_FRACTION);
 
     return retval;
@@ -864,11 +864,11 @@
  * @return
  *    Returns zero on OK, non-zero otherwise
  ******************************************************************************/
-uint32_t Si1133::getHardwareID (uint8_t *hardwareID)
+uint32_t Si1133::get_hardware_id (uint8_t *hardware_id)
 {
     uint32_t retval;
 
-    retval = read_register(REG_PART_ID, hardwareID);
+    retval = read_register(REG_PART_ID, hardware_id);
 
     return retval;
 }
@@ -887,20 +887,20 @@
  * @return
  *    Returns zero on OK, non-zero otherwise
  ******************************************************************************/
-uint32_t Si1133::getMeasurement (float *lux, float *uvi)
+uint32_t Si1133::get_measurement (float *lux, float *uvi)
 {
     Si1133::Samples_t samples;
     uint32_t retval;
 
     /* Get the results */
-    retval = measurementGet(&samples);
+    retval = measure(&samples);
 
     /* Convert the readings to lux */
-    *lux = (float) getLux(samples.ch1, samples.ch3, samples.ch2);
+    *lux = (float) get_lux(samples.ch1, samples.ch3, samples.ch2);
     *lux = *lux / (1 << LUX_OUTPUT_FRACTION);
 
     /* Convert the readings to UV index */
-    *uvi = (float) getUv(samples.ch0);
+    *uvi = (float) get_uv(samples.ch0);
     *uvi = *uvi / (1 << UV_OUTPUT_FRACTION);
 
     return retval;