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 3:f780ca9105bb, committed 2019-03-22
- Comitter:
- Steven Cooreman
- Date:
- Fri Mar 22 00:51:29 2019 +0100
- Parent:
- 2:1e2dd643afa8
- Commit message:
- remove VLA usage
Changed in this revision
Si1133.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 1e2dd643afa8 -r f780ca9105bb Si1133.cpp --- a/Si1133.cpp Sun Nov 12 20:18:04 2017 +0100 +++ b/Si1133.cpp Fri Mar 22 00:51:29 2019 +0100 @@ -222,10 +222,15 @@ ******************************************************************************/ uint32_t Si1133::write_register_block(enum Si1133::Register reg, uint8_t length, uint8_t *data) { - char buf[length+1]; + char buf[3]; buf[0] = (char)reg; + + if (length > 2) { + return SI1133_ERROR_I2C_TRANSACTION_FAILED; + } + memcpy(&buf[1], data, length); - + if (m_I2C.write(SI1133_I2C_ADDRESS, buf, length + 1)) { //Return failure return SI1133_ERROR_I2C_TRANSACTION_FAILED; @@ -528,7 +533,7 @@ if (count >= 5) { return SI1133_ERROR_I2C_TRANSACTION_FAILED; } - + return SI1133_OK; }