Scott Roberts / VEML6070

Dependents:   FTHR_SensorHub

Files at this revision

API Documentation at this revision

Comitter:
smatthew
Date:
Mon Jun 19 21:43:48 2017 +0000
Child:
1:06d6e31c903e
Commit message:
Initial Commit

Changed in this revision

VEML6070.cpp Show annotated file Show diff for this revision Revisions of this file
VEML6070.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VEML6070.cpp	Mon Jun 19 21:43:48 2017 +0000
@@ -0,0 +1,38 @@
+/***************************************************
+  This is a library for the VEML6070 UV-A Sensor
+
+  Works with the VEML6070 sensor from Adafruit
+  ----> https://www.adafruit.com/products/2899
+  Or knock-off sensors from aliexpress
+
+  These sensors use I2C to communicate, 2 pins are required to
+  interface
+
+  06/09/2017 - Initial mbed driver by Scott Roberts
+ ****************************************************/
+
+#include "Adafruit_VEML6070.h"
+Adafruit_VEML6070::Adafruit_VEML6070 (I2C& p_i2c) : _i2c(p_i2c)
+{
+
+}
+
+void Adafruit_VEML6070::begin(veml6070_integrationtime_t itime)
+{
+    _i2c.read((int)0x18,dt,1,false);
+    dt[0]=((itime << 2) | 0x02);
+    _i2c.write((int)VEML6070_ADDR_L,dt,2,false);
+    Thread::wait(500);
+}
+
+uint16_t Adafruit_VEML6070::readUV()
+{
+    uint16_t uvi;
+    _i2c.read(VEML6070_ADDR_H, dt,1);
+    uvi = dt[0]<<8;
+    _i2c.read(VEML6070_ADDR_L, dt,1,false);
+    uvi |= dt[0];
+
+    return uvi;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VEML6070.h	Mon Jun 19 21:43:48 2017 +0000
@@ -0,0 +1,48 @@
+/***************************************************
+  This is a library for the VEML6070 UV-A Sensor
+
+  Works with the VEML6070 sensor from Adafruit
+  ----> https://www.adafruit.com/products/2899
+  Or knock-off sensors from aliexpress
+
+  These sensors use I2C to communicate, 2 pins are required to
+  interface
+
+  The VEML6070 is capable of alerting when UV levels rise past a pre-set level.
+  It uses a "ACK" pin, and the SMBus Alert Response Address must be read to clear the alert.
+  If alert is turned on, you must clear the alert bit before you read/write the sensor.
+
+  06/09/2017 - Initial mbed driver by Scott Roberts
+ ****************************************************/
+
+
+#ifndef VEML6070_H
+#define VEML6070_H
+
+#include "mbed.h"
+
+// really unusual way of getting data, your read from two different addrs!
+#define VEML6070_ADDR_H (0x39 << 1)
+#define VEML6070_ADDR_L (0x38 << 1)
+
+// three different integration times
+typedef enum veml6070_integrationtime {
+    VEML6070_HALF_T,
+    VEML6070_1_T,
+    VEML6070_2_T,
+    VEML6070_4_T,
+} veml6070_integrationtime_t;
+
+
+class VEML6070
+{
+public:
+    VEML6070(I2C& p_i2c);
+    void begin(veml6070_integrationtime_t itime);
+    uint16_t readUV(void);
+protected:
+    I2C  _i2c;
+private:
+    char dt[2];
+};
+#endif