Driver for Vishay VEML6070 UV-A Sensor
VEML6070.h@2:14568f6891b3, 2017-06-21 (annotated)
- Committer:
- smatthew
- Date:
- Wed Jun 21 01:05:57 2017 +0000
- Revision:
- 2:14568f6891b3
- Parent:
- 0:820bf4c174e1
commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
smatthew | 0:820bf4c174e1 | 1 | /*************************************************** |
smatthew | 0:820bf4c174e1 | 2 | This is a library for the VEML6070 UV-A Sensor |
smatthew | 0:820bf4c174e1 | 3 | |
smatthew | 0:820bf4c174e1 | 4 | Works with the VEML6070 sensor from Adafruit |
smatthew | 0:820bf4c174e1 | 5 | ----> https://www.adafruit.com/products/2899 |
smatthew | 0:820bf4c174e1 | 6 | Or knock-off sensors from aliexpress |
smatthew | 0:820bf4c174e1 | 7 | |
smatthew | 0:820bf4c174e1 | 8 | These sensors use I2C to communicate, 2 pins are required to |
smatthew | 0:820bf4c174e1 | 9 | interface |
smatthew | 0:820bf4c174e1 | 10 | |
smatthew | 0:820bf4c174e1 | 11 | The VEML6070 is capable of alerting when UV levels rise past a pre-set level. |
smatthew | 2:14568f6891b3 | 12 | It uses a "ACK" pin, and the SMBus Alert Response Address must be read to |
smatthew | 2:14568f6891b3 | 13 | clear the alert. |
smatthew | 2:14568f6891b3 | 14 | If alert is turned on, you must clear the alert bit before you read/write the |
smatthew | 2:14568f6891b3 | 15 | sensor. |
smatthew | 0:820bf4c174e1 | 16 | |
smatthew | 0:820bf4c174e1 | 17 | 06/09/2017 - Initial mbed driver by Scott Roberts |
smatthew | 0:820bf4c174e1 | 18 | ****************************************************/ |
smatthew | 0:820bf4c174e1 | 19 | |
smatthew | 0:820bf4c174e1 | 20 | |
smatthew | 0:820bf4c174e1 | 21 | #ifndef VEML6070_H |
smatthew | 0:820bf4c174e1 | 22 | #define VEML6070_H |
smatthew | 0:820bf4c174e1 | 23 | |
smatthew | 0:820bf4c174e1 | 24 | #include "mbed.h" |
smatthew | 0:820bf4c174e1 | 25 | |
smatthew | 0:820bf4c174e1 | 26 | // really unusual way of getting data, your read from two different addrs! |
smatthew | 0:820bf4c174e1 | 27 | #define VEML6070_ADDR_H (0x39 << 1) |
smatthew | 0:820bf4c174e1 | 28 | #define VEML6070_ADDR_L (0x38 << 1) |
smatthew | 0:820bf4c174e1 | 29 | |
smatthew | 0:820bf4c174e1 | 30 | // three different integration times |
smatthew | 0:820bf4c174e1 | 31 | typedef enum veml6070_integrationtime { |
smatthew | 0:820bf4c174e1 | 32 | VEML6070_HALF_T, |
smatthew | 0:820bf4c174e1 | 33 | VEML6070_1_T, |
smatthew | 0:820bf4c174e1 | 34 | VEML6070_2_T, |
smatthew | 0:820bf4c174e1 | 35 | VEML6070_4_T, |
smatthew | 0:820bf4c174e1 | 36 | } veml6070_integrationtime_t; |
smatthew | 0:820bf4c174e1 | 37 | |
smatthew | 0:820bf4c174e1 | 38 | |
smatthew | 0:820bf4c174e1 | 39 | class VEML6070 |
smatthew | 0:820bf4c174e1 | 40 | { |
smatthew | 0:820bf4c174e1 | 41 | public: |
smatthew | 0:820bf4c174e1 | 42 | VEML6070(I2C& p_i2c); |
smatthew | 0:820bf4c174e1 | 43 | void begin(veml6070_integrationtime_t itime); |
smatthew | 0:820bf4c174e1 | 44 | uint16_t readUV(void); |
smatthew | 0:820bf4c174e1 | 45 | protected: |
smatthew | 0:820bf4c174e1 | 46 | I2C _i2c; |
smatthew | 0:820bf4c174e1 | 47 | private: |
smatthew | 0:820bf4c174e1 | 48 | char dt[2]; |
smatthew | 0:820bf4c174e1 | 49 | }; |
smatthew | 0:820bf4c174e1 | 50 | #endif |