Driver for Vishay VEML6070 UV-A Sensor

Dependents:   FTHR_SensorHub

Committer:
smatthew
Date:
Wed Jun 21 01:05:57 2017 +0000
Revision:
2:14568f6891b3
Parent:
1:06d6e31c903e
commit;

Who changed what in which revision?

UserRevisionLine numberNew 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 06/09/2017 - Initial mbed driver by Scott Roberts
smatthew 0:820bf4c174e1 12 ****************************************************/
smatthew 0:820bf4c174e1 13
smatthew 1:06d6e31c903e 14 #include "VEML6070.h"
smatthew 1:06d6e31c903e 15 VEML6070::VEML6070 (I2C& p_i2c) : _i2c(p_i2c)
smatthew 0:820bf4c174e1 16 {
smatthew 0:820bf4c174e1 17
smatthew 0:820bf4c174e1 18 }
smatthew 0:820bf4c174e1 19
smatthew 1:06d6e31c903e 20 void VEML6070::begin(veml6070_integrationtime_t itime)
smatthew 0:820bf4c174e1 21 {
smatthew 0:820bf4c174e1 22 _i2c.read((int)0x18,dt,1,false);
smatthew 0:820bf4c174e1 23 dt[0]=((itime << 2) | 0x02);
smatthew 0:820bf4c174e1 24 _i2c.write((int)VEML6070_ADDR_L,dt,2,false);
smatthew 0:820bf4c174e1 25 Thread::wait(500);
smatthew 0:820bf4c174e1 26 }
smatthew 0:820bf4c174e1 27
smatthew 1:06d6e31c903e 28 uint16_t VEML6070::readUV()
smatthew 0:820bf4c174e1 29 {
smatthew 0:820bf4c174e1 30 uint16_t uvi;
smatthew 0:820bf4c174e1 31 _i2c.read(VEML6070_ADDR_H, dt,1);
smatthew 0:820bf4c174e1 32 uvi = dt[0]<<8;
smatthew 0:820bf4c174e1 33 _i2c.read(VEML6070_ADDR_L, dt,1,false);
smatthew 0:820bf4c174e1 34 uvi |= dt[0];
smatthew 0:820bf4c174e1 35
smatthew 0:820bf4c174e1 36 return uvi;
smatthew 0:820bf4c174e1 37 }
smatthew 0:820bf4c174e1 38