Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. VEML6070 and VEML6075 UV sensors

VEML6070 and VEML6075 UV sensors

Scheduled Pinned Locked Moved Hardware
52 Posts 6 Posters 16.1k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • scalzS Offline
    scalzS Offline
    scalz
    Hardware Contributor
    wrote on last edited by scalz
    #15

    @korttoma what do you need exactly?? I can share some example, but there is nothing fancy for veml6075. On my side i'm using this lib for the moment https://github.com/schizobovine/VEML6075 , not digged much yet but it's working with MySensors of course. You simply need the same cooking in your sketch, as usual ;)

    1 Reply Last reply
    0
    • korttomaK Offline
      korttomaK Offline
      korttoma
      Hero Member
      wrote on last edited by korttoma
      #16

      Well, I'm looking to replace my Oregon Scientific UV Sensor UVN800 (that finally stopped reporting any values) by using a VEML6075 and a Sensebender Micro.

      I can probably work out the code for the sketch myself but I'm not a fan of reinventing the wheel so if someone already created a sketch it would simply save me the time.

      I would expect the sensor to report a UV Index value between 0 and 10 like the Oregon sensor did according to this -> https://www.epa.gov/sunsafety/uv-index-scale-1

      The example in the Lib you mentioned @scalz seems to have the UV Index posibility

      • Tomas
      alexsh1A 1 Reply Last reply
      0
      • korttomaK korttoma

        Well, I'm looking to replace my Oregon Scientific UV Sensor UVN800 (that finally stopped reporting any values) by using a VEML6075 and a Sensebender Micro.

        I can probably work out the code for the sketch myself but I'm not a fan of reinventing the wheel so if someone already created a sketch it would simply save me the time.

        I would expect the sensor to report a UV Index value between 0 and 10 like the Oregon sensor did according to this -> https://www.epa.gov/sunsafety/uv-index-scale-1

        The example in the Lib you mentioned @scalz seems to have the UV Index posibility

        alexsh1A Offline
        alexsh1A Offline
        alexsh1
        wrote on last edited by
        #17

        @korttoma this thread is about VEML6075 :-)
        However, VEML6075 is more complex - it does report uv-a and uv-b. I do not think you'd get UVI from this sensor straight away, you'd need to do it in the sketch.

        I can share the sketch after I get the sensor, write a code and convert it into MySensors

        1 Reply Last reply
        0
        • scalzS Offline
          scalzS Offline
          scalz
          Hardware Contributor
          wrote on last edited by scalz
          #18

          @korttoma oki, i agree with you about reinventing the wheel, but for big job. I think it's always better to know how to use the lib, so that's not a waste imho ;)

          No time for the moment to check my bigger sketch and extract everything.

          But in case you would like to try your new sensor, here a quick 5-10min conversion and mix of the lib example to mysensors uv. I wouldn't release it like this, not optimized, and untested version. But it's compiling, it should work :)

          // Enable debug prints to serial monitor
          #define MY_DEBUG
          
          // Enable and select radio type attached
          #define MY_RADIO_NRF24
          //#define MY_RADIO_RFM69
          
          //#define MY_NODE_ID 10
          
          #include <MySensors.h>
          
          #include <VEML6075.h>
          
          
          VEML6075 veml6075 = VEML6075();
          bool sensorFound = false;
          
          #define CHILD_ID_UVI 0
          #define CHILD_ID_UVA 0
          #define CHILD_ID_UVB 0
          
          uint32_t SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)
          
          MyMessage uviMsg(CHILD_ID_UVI, V_UV);
          MyMessage uvaMsg(CHILD_ID_UVA, V_UV);
          MyMessage uvbMsg(CHILD_ID_UVB, V_UV);
          
          
          void presentation()
          {
              // Send the sketch version information to the gateway and Controller
              sendSketchInfo("UV Sensor", "1.3");
          
              // Register all sensors to gateway (they will be created as child devices)
              present(CHILD_ID_UVI, S_UV);
              present(CHILD_ID_UVA, S_UV);
              present(CHILD_ID_UVB, S_UV);
          }
          
          void setup()
          {
            if (!veml6075.begin()) {
              Serial.println(F("VEML6075 not found!"));
            } else 
              sensorFound = true;
          
          }
          
          void loop()
          {
            if (sensorFound) {
              unsigned long lastSend =0;
              float uvi;
              float uva;
              float uvb;
              static float uviOld = -1;
              static float uvaOld = -1;
              static float uvbOld = -1;
          
              // Poll sensor
              veml6075.poll();
          
              uva = veml6075.getUVA();
              Serial.print(F("UVA = "));
              Serial.println(uva, 2);
          
              uvb = veml6075.getUVB();
              Serial.print(F("UVB = "));
              Serial.println(uvb, 2);
          
              uvi = veml6075.getUVIndex();
              Serial.print(F("UV Index = "));
              Serial.println(uvi, 1);
          
              uint16_t devid = veml6075.getDevID();
              Serial.print(F("Device ID = "));
              Serial.println(devid, HEX);
          
              Serial.println(F("----------------"));
              
              if (uvi != uviOld) {
                  send(uviMsg.set(uvi,2));
                  uviOld = uvi;
              }
              if (uva != uvaOld) {
                  send(uvaMsg.set(uva,2));
                  uvaOld = uva;
              }
              if (uvb != uvbOld) {
                  send(uvbMsg.set(uvb,2));
                  uvbOld = uvb;
              }    
            }
          
            sleep(SLEEP_TIME);
          }
          

          It simply read sensor, send messages, and sleep.

          As you can see, it's possible to get the three values from the lib.

          korttomaK 1 Reply Last reply
          0
          • scalzS scalz

            @korttoma oki, i agree with you about reinventing the wheel, but for big job. I think it's always better to know how to use the lib, so that's not a waste imho ;)

            No time for the moment to check my bigger sketch and extract everything.

            But in case you would like to try your new sensor, here a quick 5-10min conversion and mix of the lib example to mysensors uv. I wouldn't release it like this, not optimized, and untested version. But it's compiling, it should work :)

            // Enable debug prints to serial monitor
            #define MY_DEBUG
            
            // Enable and select radio type attached
            #define MY_RADIO_NRF24
            //#define MY_RADIO_RFM69
            
            //#define MY_NODE_ID 10
            
            #include <MySensors.h>
            
            #include <VEML6075.h>
            
            
            VEML6075 veml6075 = VEML6075();
            bool sensorFound = false;
            
            #define CHILD_ID_UVI 0
            #define CHILD_ID_UVA 0
            #define CHILD_ID_UVB 0
            
            uint32_t SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)
            
            MyMessage uviMsg(CHILD_ID_UVI, V_UV);
            MyMessage uvaMsg(CHILD_ID_UVA, V_UV);
            MyMessage uvbMsg(CHILD_ID_UVB, V_UV);
            
            
            void presentation()
            {
                // Send the sketch version information to the gateway and Controller
                sendSketchInfo("UV Sensor", "1.3");
            
                // Register all sensors to gateway (they will be created as child devices)
                present(CHILD_ID_UVI, S_UV);
                present(CHILD_ID_UVA, S_UV);
                present(CHILD_ID_UVB, S_UV);
            }
            
            void setup()
            {
              if (!veml6075.begin()) {
                Serial.println(F("VEML6075 not found!"));
              } else 
                sensorFound = true;
            
            }
            
            void loop()
            {
              if (sensorFound) {
                unsigned long lastSend =0;
                float uvi;
                float uva;
                float uvb;
                static float uviOld = -1;
                static float uvaOld = -1;
                static float uvbOld = -1;
            
                // Poll sensor
                veml6075.poll();
            
                uva = veml6075.getUVA();
                Serial.print(F("UVA = "));
                Serial.println(uva, 2);
            
                uvb = veml6075.getUVB();
                Serial.print(F("UVB = "));
                Serial.println(uvb, 2);
            
                uvi = veml6075.getUVIndex();
                Serial.print(F("UV Index = "));
                Serial.println(uvi, 1);
            
                uint16_t devid = veml6075.getDevID();
                Serial.print(F("Device ID = "));
                Serial.println(devid, HEX);
            
                Serial.println(F("----------------"));
                
                if (uvi != uviOld) {
                    send(uviMsg.set(uvi,2));
                    uviOld = uvi;
                }
                if (uva != uvaOld) {
                    send(uvaMsg.set(uva,2));
                    uvaOld = uva;
                }
                if (uvb != uvbOld) {
                    send(uvbMsg.set(uvb,2));
                    uvbOld = uvb;
                }    
              }
            
              sleep(SLEEP_TIME);
            }
            

            It simply read sensor, send messages, and sleep.

            As you can see, it's possible to get the three values from the lib.

            korttomaK Offline
            korttomaK Offline
            korttoma
            Hero Member
            wrote on last edited by korttoma
            #19

            Thanks for the sketch @scalz , I made an attempt at it myself also. I was not avare that V_UV and S_UV could be used so I had V/S_LIGHT_LEVEL but I changed it now. Seems to compile just fine. Just need to get it tested.

            SensebenderMicroWithUVIndex:

            /**
             * The MySensors Arduino library handles the wireless radio link and protocol
             * between your home built sensors/actuators and HA controller of choice.
             * The sensors forms a self healing radio network with optional repeaters. Each
             * repeater and gateway builds a routing tables in EEPROM which keeps track of the
             * network topology allowing messages to be routed to nodes.
             *
             * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
             * Copyright (C) 2013-2015 Sensnology AB
             * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
             *
             * Documentation: http://www.mysensors.org
             * Support Forum: http://forum.mysensors.org
             *
             * This program is free software; you can redistribute it and/or
             * modify it under the terms of the GNU General Public License
             * version 2 as published by the Free Software Foundation.
             *
             *******************************
             *
             * REVISION HISTORY
             * Version 1.0 - Thomas Bowman Mørch
             * 
             * DESCRIPTION
             * Default sensor sketch for Sensebender Micro module
             * Act as a temperature / humidity sensor by default.
             *
             * If A0 is held low while powering on, it will enter testmode, which verifies all on-board peripherals
             *  
             * Battery voltage is as battery percentage (Internal message), and optionally as a sensor value (See defines below)
             *
             *
             * Version 1.3 - Thomas Bowman Mørch
             * Improved transmission logic, eliminating spurious transmissions (when temperatuere / humidity fluctuates 1 up and down between measurements) 
             * Added OTA boot mode, need to hold A1 low while applying power. (uses slightly more power as it's waiting for bootloader messages)
             * 
             * Version 1.4 - Thomas Bowman Mørch
             * 
             * Corrected division in the code deciding whether to transmit or not, that resulted in generating an integer. Now it's generating floats as expected.
             * Simplified detection for OTA bootloader, now detecting if MY_OTA_FIRMWARE_FEATURE is defined. If this is defined sensebender automaticly waits 300mS after each transmission
             * Moved Battery status messages, so they are transmitted together with normal sensor updates (but only every 60th minute)
             * 
             */
            
            // Enable debug prints to serial monitor
            //#define MY_DEBUG 
            
            // Define a static node address, remove if you want auto address assignment
            #define MY_NODE_ID 27
            
            // Enable and select radio type attached
            #define MY_RADIO_NRF24
            //#define MY_RADIO_RFM69
            
            // Enable to support OTA for this node (needs DualOptiBoot boot-loader to fully work)
            //#define MY_OTA_FIRMWARE_FEATURE
            
            #include <SPI.h>
            #include <MySensors.h>
            #include <Wire.h>
            #include <SI7021.h>
            #ifndef MY_OTA_FIRMWARE_FEATURE
            #include "drivers/SPIFlash/SPIFlash.cpp"
            #endif
            #include <EEPROM.h>  
            #include <sha204_lib_return_codes.h>
            #include <sha204_library.h>
            #include <RunningAverage.h>
            #include <VEML6075.h>
            //#include <avr/power.h>
            
            // Uncomment the line below, to transmit battery voltage as a normal sensor value
            //#define BATT_SENSOR    199
            
            #define RELEASE "1.4"
            
            #define AVERAGES 2
            
            // Child sensor ID's
            #define CHILD_ID_UVI    1
            #define CHILD_ID_TEMP   2
            #define CHILD_ID_HUM    3
            
            // How many milli seconds between each measurement
            #define MEASURE_INTERVAL 60000
            
            // How many milli seconds should we wait for OTA?
            #define OTA_WAIT_PERIOD 300
            
            // FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller
            #define FORCE_TRANSMIT_INTERVAL 30 
            
            // When MEASURE_INTERVAL is 60000 and FORCE_TRANSMIT_INTERVAL is 30, we force a transmission every 30 minutes.
            // Between the forced transmissions a tranmission will only occur if the measured value differs from the previous measurement
            
            // HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with
            // TEMP_TRANSMIT_THRESHOLD for temperature threshold.
            #define HUMI_TRANSMIT_THRESHOLD 0.5
            #define TEMP_TRANSMIT_THRESHOLD 0.5
            #define UVI_TRANSMIT_THRESHOLD 0.1
            
            // Pin definitions
            #define TEST_PIN       A0
            #define LED_PIN        A2
            #define ATSHA204_PIN   17 // A3
            
            VEML6075 veml6075 = VEML6075();
            
            const int sha204Pin = ATSHA204_PIN;
            atsha204Class sha204(sha204Pin);
            
            SI7021 humiditySensor;
            SPIFlash flash(8, 0x1F65);
            
            // Sensor messages
            MyMessage msgHum(CHILD_ID_HUM, V_HUM);
            MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
            MyMessage msgUVI(CHILD_ID_UVI, V_UV);
            
            #ifdef BATT_SENSOR
            MyMessage msgBatt(BATT_SENSOR, V_VOLTAGE);
            #endif
            
            // Global settings
            int measureCount = 0;
            int sendBattery = 0;
            boolean isMetric = true;
            boolean highfreq = true;
            boolean transmission_occured = false;
            
            // Storage of old measurements
            float lastTemperature = -100;
            int lastHumidity = -100;
            long lastBattery = -100;
            int lastUVI = -100;
            
            RunningAverage raHum(AVERAGES);
            
            /****************************************************
             *
             * Setup code 
             *
             ****************************************************/
            void setup() {
              
              pinMode(LED_PIN, OUTPUT);
              digitalWrite(LED_PIN, LOW);
            
              //Serial.begin(115200);
              //Serial.print(F("Sensebender Micro FW "));
              //Serial.print(RELEASE);
              //Serial.flush();
            
              // First check if we should boot into test mode
            
              pinMode(TEST_PIN,INPUT);
              digitalWrite(TEST_PIN, HIGH); // Enable pullup
              if (!digitalRead(TEST_PIN)) testMode();
            
              // Make sure that ATSHA204 is not floating
              pinMode(ATSHA204_PIN, INPUT);
              digitalWrite(ATSHA204_PIN, HIGH);
              
              digitalWrite(TEST_PIN,LOW);
              
              digitalWrite(LED_PIN, HIGH); 
            
              humiditySensor.begin();
            
              veml6075.begin();
              
              digitalWrite(LED_PIN, LOW);
            
              //Serial.flush();
              //Serial.println(F(" - Online!"));
              
              isMetric = getControllerConfig().isMetric;
              //Serial.print(F("isMetric: ")); Serial.println(isMetric);
              raHum.clear();
              sendTempHumidityMeasurements(false);
              sendBattLevel(false);
              
            #ifdef MY_OTA_FIRMWARE_FEATURE  
              //Serial.println("OTA FW update enabled");
            #endif
            
            }
            
            void presentation()  {
              sendSketchInfo("Sensebender Micro", RELEASE);
            
              present(CHILD_ID_UVI,S_UV);
              present(CHILD_ID_TEMP,S_TEMP);
              present(CHILD_ID_HUM,S_HUM);
                
            #ifdef BATT_SENSOR
              present(BATT_SENSOR, S_POWER);
            #endif
            }
            
            
            /***********************************************
             *
             *  Main loop function
             *
             ***********************************************/
            void loop() {
              
              measureCount ++;
              sendBattery ++;
              bool forceTransmit = false;
              transmission_occured = false;
            #ifndef MY_OTA_FIRMWARE_FEATURE
              if ((measureCount == 5) && highfreq) 
              {
                clock_prescale_set(clock_div_8); // Switch to 1Mhz for the reminder of the sketch, save power.
                highfreq = false;
              } 
            #endif
              
              if (measureCount > FORCE_TRANSMIT_INTERVAL) { // force a transmission
                forceTransmit = true; 
                measureCount = 0;
              }
                
              sendTempHumidityMeasurements(forceTransmit);
            /*  if (sendBattery > 60) 
              {
                 sendBattLevel(forceTransmit); // Not needed to send battery info that often
                 sendBattery = 0;
              }*/
            #ifdef MY_OTA_FIRMWARE_FEATURE
              if (transmission_occured) {
                  wait(OTA_WAIT_PERIOD);
              }
            #endif
            
              sleep(MEASURE_INTERVAL);  
            }
            
            
            /*********************************************
             *
             * Sends temperature and humidity from Si7021 sensor
             *
             * Parameters
             * - force : Forces transmission of a value (even if it's the same as previous measurement)
             *
             *********************************************/
            void sendTempHumidityMeasurements(bool force)
            {
              bool tx = force;
            
              si7021_env data = humiditySensor.getHumidityAndTemperature();
            
              veml6075.poll();
            
                float UVA = veml6075.getUVA();
                //Serial.print(F("UVA = "));
                //Serial.println(UVA, 2);
            
                float UVB = veml6075.getUVB();
                //Serial.print(F("UVB = "));
                //Serial.println(UVB, 2);
            
                float UVI = veml6075.getUVIndex();
                //Serial.print(F("UV Index = "));
                //Serial.println(UVI, 1);
              
              
              
              raHum.addValue(data.humidityPercent);
              
              float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0);
              float diffHum = abs(lastHumidity - raHum.getAverage());
            
              float diffUVI = abs(lastUVI - UVI);
            
              //Serial.print(F("TempDiff :"));Serial.println(diffTemp);
              //Serial.print(F("HumDiff  :"));Serial.println(diffHum); 
              //Serial.print(F("UVIDiff  :"));Serial.println(diffUVI); 
              
              if (isnan(diffHum)) tx = true; 
              if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true;
              if (diffHum > HUMI_TRANSMIT_THRESHOLD) tx = true;
              if (diffUVI > UVI_TRANSMIT_THRESHOLD) tx = true;
            
              
              if (tx) {
                measureCount = 0;
                float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0;
                 
                int humidity = data.humidityPercent;
                //Serial.print("T: ");Serial.println(temperature);
                //Serial.print("H: ");Serial.println(humidity);
                
                send(msgTemp.set(temperature,1));
                send(msgHum.set(humidity));
                send(msgUVI.set(UVI,2));
                lastTemperature = temperature;
                lastHumidity = humidity;
                lastUVI = UVI;
                transmission_occured = true;
                if (sendBattery > 60) {
                 sendBattLevel(true); // Not needed to send battery info that often
                 sendBattery = 0;
                }
              }
            }
            
            /********************************************
             *
             * Sends battery information (battery percentage)
             *
             * Parameters
             * - force : Forces transmission of a value
             *
             *******************************************/
            void sendBattLevel(bool force)
            {
              if (force) lastBattery = -1;
              long vcc = readVcc();
              if (vcc != lastBattery) {
                lastBattery = vcc;
            
            #ifdef BATT_SENSOR
                float send_voltage = float(vcc)/1000.0f;
                send(msgBatt.set(send_voltage,3));
            #endif
            
                // Calculate percentage
            
                vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at
                
                long percent = vcc / 14.0;
                sendBatteryLevel(percent);
                transmission_occured = true;
              }
            }
            
            /*******************************************
             *
             * Internal battery ADC measuring 
             *
             *******************************************/
            long readVcc() {
              // Read 1.1V reference against AVcc
              // set the reference to Vcc and the measurement to the internal 1.1V reference
              #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
                ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
              #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
                ADMUX = _BV(MUX5) | _BV(MUX0);
              #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
                ADcdMUX = _BV(MUX3) | _BV(MUX2);
              #else
                ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
              #endif  
             
              delay(2); // Wait for Vref to settle
              ADCSRA |= _BV(ADSC); // Start conversion
              while (bit_is_set(ADCSRA,ADSC)); // measuring
             
              uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
              uint8_t high = ADCH; // unlocks both
             
              long result = (high<<8) | low;
             
              result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
              return result; // Vcc in millivolts
             
            }
            
            /****************************************************
             *
             * Verify all peripherals, and signal via the LED if any problems.
             *
             ****************************************************/
            void testMode()
            {
              uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
              uint8_t ret_code;
              byte tests = 0;
              
              digitalWrite(LED_PIN, HIGH); // Turn on LED.
              //Serial.println(F(" - TestMode"));
              //Serial.println(F("Testing peripherals!"));
              //Serial.flush();
              //Serial.print(F("-> SI7021 : ")); 
              //Serial.flush();
              
              if (humiditySensor.begin()) 
              {
                //Serial.println(F("ok!"));
                tests ++;
              }
              else
              {
                //Serial.println(F("failed!"));
              }
              //Serial.flush();
            
              //Serial.print(F("-> Flash : "));
              //Serial.flush();
              if (flash.initialize())
              {
                //Serial.println(F("ok!"));
                tests ++;
              }
              else
              {
                //Serial.println(F("failed!"));
              }
              //Serial.flush();
            
              
              //Serial.print(F("-> SHA204 : "));
              ret_code = sha204.sha204c_wakeup(rx_buffer);
              //Serial.flush();
              if (ret_code != SHA204_SUCCESS)
              {
                //Serial.print(F("Failed to wake device. Response: ")); Serial.println(ret_code, HEX);
              }
              //Serial.flush();
              if (ret_code == SHA204_SUCCESS)
              {
                ret_code = sha204.getSerialNumber(rx_buffer);
                if (ret_code != SHA204_SUCCESS)
                {
                  //Serial.print(F("Failed to obtain device serial number. Response: ")); Serial.println(ret_code, HEX);
                }
                else
                {
                  //Serial.print(F("Ok (serial : "));
                  for (int i=0; i<9; i++)
                  {
                    if (rx_buffer[i] < 0x10)
                    {
                      //Serial.print('0'); // Because Serial.print does not 0-pad HEX
                    }
                    //Serial.print(rx_buffer[i], HEX);
                  }
                  //Serial.println(")");
                  tests ++;
                }
            
              }
              //Serial.flush();
            
              //Serial.println(F("Test finished"));
              
              if (tests == 3) 
              {
                //Serial.println(F("Selftest ok!"));
                while (1) // Blink OK pattern!
                {
                  digitalWrite(LED_PIN, HIGH);
                  delay(200);
                  digitalWrite(LED_PIN, LOW);
                  delay(200);
                }
              }
              else 
              {
                //Serial.println(F("----> Selftest failed!"));
                while (1) // Blink FAILED pattern! Rappidly blinking..
                {
                }
              }  
            }
            
            • Tomas
            alexsh1A 1 Reply Last reply
            1
            • korttomaK korttoma

              Thanks for the sketch @scalz , I made an attempt at it myself also. I was not avare that V_UV and S_UV could be used so I had V/S_LIGHT_LEVEL but I changed it now. Seems to compile just fine. Just need to get it tested.

              SensebenderMicroWithUVIndex:

              /**
               * The MySensors Arduino library handles the wireless radio link and protocol
               * between your home built sensors/actuators and HA controller of choice.
               * The sensors forms a self healing radio network with optional repeaters. Each
               * repeater and gateway builds a routing tables in EEPROM which keeps track of the
               * network topology allowing messages to be routed to nodes.
               *
               * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
               * Copyright (C) 2013-2015 Sensnology AB
               * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
               *
               * Documentation: http://www.mysensors.org
               * Support Forum: http://forum.mysensors.org
               *
               * This program is free software; you can redistribute it and/or
               * modify it under the terms of the GNU General Public License
               * version 2 as published by the Free Software Foundation.
               *
               *******************************
               *
               * REVISION HISTORY
               * Version 1.0 - Thomas Bowman Mørch
               * 
               * DESCRIPTION
               * Default sensor sketch for Sensebender Micro module
               * Act as a temperature / humidity sensor by default.
               *
               * If A0 is held low while powering on, it will enter testmode, which verifies all on-board peripherals
               *  
               * Battery voltage is as battery percentage (Internal message), and optionally as a sensor value (See defines below)
               *
               *
               * Version 1.3 - Thomas Bowman Mørch
               * Improved transmission logic, eliminating spurious transmissions (when temperatuere / humidity fluctuates 1 up and down between measurements) 
               * Added OTA boot mode, need to hold A1 low while applying power. (uses slightly more power as it's waiting for bootloader messages)
               * 
               * Version 1.4 - Thomas Bowman Mørch
               * 
               * Corrected division in the code deciding whether to transmit or not, that resulted in generating an integer. Now it's generating floats as expected.
               * Simplified detection for OTA bootloader, now detecting if MY_OTA_FIRMWARE_FEATURE is defined. If this is defined sensebender automaticly waits 300mS after each transmission
               * Moved Battery status messages, so they are transmitted together with normal sensor updates (but only every 60th minute)
               * 
               */
              
              // Enable debug prints to serial monitor
              //#define MY_DEBUG 
              
              // Define a static node address, remove if you want auto address assignment
              #define MY_NODE_ID 27
              
              // Enable and select radio type attached
              #define MY_RADIO_NRF24
              //#define MY_RADIO_RFM69
              
              // Enable to support OTA for this node (needs DualOptiBoot boot-loader to fully work)
              //#define MY_OTA_FIRMWARE_FEATURE
              
              #include <SPI.h>
              #include <MySensors.h>
              #include <Wire.h>
              #include <SI7021.h>
              #ifndef MY_OTA_FIRMWARE_FEATURE
              #include "drivers/SPIFlash/SPIFlash.cpp"
              #endif
              #include <EEPROM.h>  
              #include <sha204_lib_return_codes.h>
              #include <sha204_library.h>
              #include <RunningAverage.h>
              #include <VEML6075.h>
              //#include <avr/power.h>
              
              // Uncomment the line below, to transmit battery voltage as a normal sensor value
              //#define BATT_SENSOR    199
              
              #define RELEASE "1.4"
              
              #define AVERAGES 2
              
              // Child sensor ID's
              #define CHILD_ID_UVI    1
              #define CHILD_ID_TEMP   2
              #define CHILD_ID_HUM    3
              
              // How many milli seconds between each measurement
              #define MEASURE_INTERVAL 60000
              
              // How many milli seconds should we wait for OTA?
              #define OTA_WAIT_PERIOD 300
              
              // FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller
              #define FORCE_TRANSMIT_INTERVAL 30 
              
              // When MEASURE_INTERVAL is 60000 and FORCE_TRANSMIT_INTERVAL is 30, we force a transmission every 30 minutes.
              // Between the forced transmissions a tranmission will only occur if the measured value differs from the previous measurement
              
              // HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with
              // TEMP_TRANSMIT_THRESHOLD for temperature threshold.
              #define HUMI_TRANSMIT_THRESHOLD 0.5
              #define TEMP_TRANSMIT_THRESHOLD 0.5
              #define UVI_TRANSMIT_THRESHOLD 0.1
              
              // Pin definitions
              #define TEST_PIN       A0
              #define LED_PIN        A2
              #define ATSHA204_PIN   17 // A3
              
              VEML6075 veml6075 = VEML6075();
              
              const int sha204Pin = ATSHA204_PIN;
              atsha204Class sha204(sha204Pin);
              
              SI7021 humiditySensor;
              SPIFlash flash(8, 0x1F65);
              
              // Sensor messages
              MyMessage msgHum(CHILD_ID_HUM, V_HUM);
              MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
              MyMessage msgUVI(CHILD_ID_UVI, V_UV);
              
              #ifdef BATT_SENSOR
              MyMessage msgBatt(BATT_SENSOR, V_VOLTAGE);
              #endif
              
              // Global settings
              int measureCount = 0;
              int sendBattery = 0;
              boolean isMetric = true;
              boolean highfreq = true;
              boolean transmission_occured = false;
              
              // Storage of old measurements
              float lastTemperature = -100;
              int lastHumidity = -100;
              long lastBattery = -100;
              int lastUVI = -100;
              
              RunningAverage raHum(AVERAGES);
              
              /****************************************************
               *
               * Setup code 
               *
               ****************************************************/
              void setup() {
                
                pinMode(LED_PIN, OUTPUT);
                digitalWrite(LED_PIN, LOW);
              
                //Serial.begin(115200);
                //Serial.print(F("Sensebender Micro FW "));
                //Serial.print(RELEASE);
                //Serial.flush();
              
                // First check if we should boot into test mode
              
                pinMode(TEST_PIN,INPUT);
                digitalWrite(TEST_PIN, HIGH); // Enable pullup
                if (!digitalRead(TEST_PIN)) testMode();
              
                // Make sure that ATSHA204 is not floating
                pinMode(ATSHA204_PIN, INPUT);
                digitalWrite(ATSHA204_PIN, HIGH);
                
                digitalWrite(TEST_PIN,LOW);
                
                digitalWrite(LED_PIN, HIGH); 
              
                humiditySensor.begin();
              
                veml6075.begin();
                
                digitalWrite(LED_PIN, LOW);
              
                //Serial.flush();
                //Serial.println(F(" - Online!"));
                
                isMetric = getControllerConfig().isMetric;
                //Serial.print(F("isMetric: ")); Serial.println(isMetric);
                raHum.clear();
                sendTempHumidityMeasurements(false);
                sendBattLevel(false);
                
              #ifdef MY_OTA_FIRMWARE_FEATURE  
                //Serial.println("OTA FW update enabled");
              #endif
              
              }
              
              void presentation()  {
                sendSketchInfo("Sensebender Micro", RELEASE);
              
                present(CHILD_ID_UVI,S_UV);
                present(CHILD_ID_TEMP,S_TEMP);
                present(CHILD_ID_HUM,S_HUM);
                  
              #ifdef BATT_SENSOR
                present(BATT_SENSOR, S_POWER);
              #endif
              }
              
              
              /***********************************************
               *
               *  Main loop function
               *
               ***********************************************/
              void loop() {
                
                measureCount ++;
                sendBattery ++;
                bool forceTransmit = false;
                transmission_occured = false;
              #ifndef MY_OTA_FIRMWARE_FEATURE
                if ((measureCount == 5) && highfreq) 
                {
                  clock_prescale_set(clock_div_8); // Switch to 1Mhz for the reminder of the sketch, save power.
                  highfreq = false;
                } 
              #endif
                
                if (measureCount > FORCE_TRANSMIT_INTERVAL) { // force a transmission
                  forceTransmit = true; 
                  measureCount = 0;
                }
                  
                sendTempHumidityMeasurements(forceTransmit);
              /*  if (sendBattery > 60) 
                {
                   sendBattLevel(forceTransmit); // Not needed to send battery info that often
                   sendBattery = 0;
                }*/
              #ifdef MY_OTA_FIRMWARE_FEATURE
                if (transmission_occured) {
                    wait(OTA_WAIT_PERIOD);
                }
              #endif
              
                sleep(MEASURE_INTERVAL);  
              }
              
              
              /*********************************************
               *
               * Sends temperature and humidity from Si7021 sensor
               *
               * Parameters
               * - force : Forces transmission of a value (even if it's the same as previous measurement)
               *
               *********************************************/
              void sendTempHumidityMeasurements(bool force)
              {
                bool tx = force;
              
                si7021_env data = humiditySensor.getHumidityAndTemperature();
              
                veml6075.poll();
              
                  float UVA = veml6075.getUVA();
                  //Serial.print(F("UVA = "));
                  //Serial.println(UVA, 2);
              
                  float UVB = veml6075.getUVB();
                  //Serial.print(F("UVB = "));
                  //Serial.println(UVB, 2);
              
                  float UVI = veml6075.getUVIndex();
                  //Serial.print(F("UV Index = "));
                  //Serial.println(UVI, 1);
                
                
                
                raHum.addValue(data.humidityPercent);
                
                float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0);
                float diffHum = abs(lastHumidity - raHum.getAverage());
              
                float diffUVI = abs(lastUVI - UVI);
              
                //Serial.print(F("TempDiff :"));Serial.println(diffTemp);
                //Serial.print(F("HumDiff  :"));Serial.println(diffHum); 
                //Serial.print(F("UVIDiff  :"));Serial.println(diffUVI); 
                
                if (isnan(diffHum)) tx = true; 
                if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true;
                if (diffHum > HUMI_TRANSMIT_THRESHOLD) tx = true;
                if (diffUVI > UVI_TRANSMIT_THRESHOLD) tx = true;
              
                
                if (tx) {
                  measureCount = 0;
                  float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0;
                   
                  int humidity = data.humidityPercent;
                  //Serial.print("T: ");Serial.println(temperature);
                  //Serial.print("H: ");Serial.println(humidity);
                  
                  send(msgTemp.set(temperature,1));
                  send(msgHum.set(humidity));
                  send(msgUVI.set(UVI,2));
                  lastTemperature = temperature;
                  lastHumidity = humidity;
                  lastUVI = UVI;
                  transmission_occured = true;
                  if (sendBattery > 60) {
                   sendBattLevel(true); // Not needed to send battery info that often
                   sendBattery = 0;
                  }
                }
              }
              
              /********************************************
               *
               * Sends battery information (battery percentage)
               *
               * Parameters
               * - force : Forces transmission of a value
               *
               *******************************************/
              void sendBattLevel(bool force)
              {
                if (force) lastBattery = -1;
                long vcc = readVcc();
                if (vcc != lastBattery) {
                  lastBattery = vcc;
              
              #ifdef BATT_SENSOR
                  float send_voltage = float(vcc)/1000.0f;
                  send(msgBatt.set(send_voltage,3));
              #endif
              
                  // Calculate percentage
              
                  vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at
                  
                  long percent = vcc / 14.0;
                  sendBatteryLevel(percent);
                  transmission_occured = true;
                }
              }
              
              /*******************************************
               *
               * Internal battery ADC measuring 
               *
               *******************************************/
              long readVcc() {
                // Read 1.1V reference against AVcc
                // set the reference to Vcc and the measurement to the internal 1.1V reference
                #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
                  ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
                #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
                  ADMUX = _BV(MUX5) | _BV(MUX0);
                #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
                  ADcdMUX = _BV(MUX3) | _BV(MUX2);
                #else
                  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
                #endif  
               
                delay(2); // Wait for Vref to settle
                ADCSRA |= _BV(ADSC); // Start conversion
                while (bit_is_set(ADCSRA,ADSC)); // measuring
               
                uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
                uint8_t high = ADCH; // unlocks both
               
                long result = (high<<8) | low;
               
                result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
                return result; // Vcc in millivolts
               
              }
              
              /****************************************************
               *
               * Verify all peripherals, and signal via the LED if any problems.
               *
               ****************************************************/
              void testMode()
              {
                uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
                uint8_t ret_code;
                byte tests = 0;
                
                digitalWrite(LED_PIN, HIGH); // Turn on LED.
                //Serial.println(F(" - TestMode"));
                //Serial.println(F("Testing peripherals!"));
                //Serial.flush();
                //Serial.print(F("-> SI7021 : ")); 
                //Serial.flush();
                
                if (humiditySensor.begin()) 
                {
                  //Serial.println(F("ok!"));
                  tests ++;
                }
                else
                {
                  //Serial.println(F("failed!"));
                }
                //Serial.flush();
              
                //Serial.print(F("-> Flash : "));
                //Serial.flush();
                if (flash.initialize())
                {
                  //Serial.println(F("ok!"));
                  tests ++;
                }
                else
                {
                  //Serial.println(F("failed!"));
                }
                //Serial.flush();
              
                
                //Serial.print(F("-> SHA204 : "));
                ret_code = sha204.sha204c_wakeup(rx_buffer);
                //Serial.flush();
                if (ret_code != SHA204_SUCCESS)
                {
                  //Serial.print(F("Failed to wake device. Response: ")); Serial.println(ret_code, HEX);
                }
                //Serial.flush();
                if (ret_code == SHA204_SUCCESS)
                {
                  ret_code = sha204.getSerialNumber(rx_buffer);
                  if (ret_code != SHA204_SUCCESS)
                  {
                    //Serial.print(F("Failed to obtain device serial number. Response: ")); Serial.println(ret_code, HEX);
                  }
                  else
                  {
                    //Serial.print(F("Ok (serial : "));
                    for (int i=0; i<9; i++)
                    {
                      if (rx_buffer[i] < 0x10)
                      {
                        //Serial.print('0'); // Because Serial.print does not 0-pad HEX
                      }
                      //Serial.print(rx_buffer[i], HEX);
                    }
                    //Serial.println(")");
                    tests ++;
                  }
              
                }
                //Serial.flush();
              
                //Serial.println(F("Test finished"));
                
                if (tests == 3) 
                {
                  //Serial.println(F("Selftest ok!"));
                  while (1) // Blink OK pattern!
                  {
                    digitalWrite(LED_PIN, HIGH);
                    delay(200);
                    digitalWrite(LED_PIN, LOW);
                    delay(200);
                  }
                }
                else 
                {
                  //Serial.println(F("----> Selftest failed!"));
                  while (1) // Blink FAILED pattern! Rappidly blinking..
                  {
                  }
                }  
              }
              
              alexsh1A Offline
              alexsh1A Offline
              alexsh1
              wrote on last edited by alexsh1
              #20

              This is the VEML6070 UV Index graph. The last day, I placed the sensor outside rather than behind my window. There is a huge difference :

              0_1498067711576_Screenshot (33).png

              1 Reply Last reply
              1
              • alexsh1A Offline
                alexsh1A Offline
                alexsh1
                wrote on last edited by alexsh1
                #21

                I finally received VEML6075 and comparing it with VEML6070 side y side
                _____UVI__UVA__UVB
                6070 0.9

                6075 1.2 1036.53 1005.31

                Not sure why there is a difference in UVI

                1 Reply Last reply
                0
                • korttomaK Offline
                  korttomaK Offline
                  korttoma
                  Hero Member
                  wrote on last edited by
                  #22

                  Did anyone measure the current consumption of these VEML chips?
                  I just compared a Sensebender Micro with the VEML6075 to a standalone Sensebender Micro and the standalone one measured 28uA and the one with the VEML6075 measured 740uA.

                  I just checked the VEML6075 documentation and typical consumption is 480uA but it should also be possible to shut it down and then it should only draw 800nA.

                  I need to check the Lib if there is some function to shut it down and wake it up. Or else I will try to change the setup so I can power the VEML6075 from an output pin so I can turn it completely off.

                  • Tomas
                  scalzS 1 Reply Last reply
                  0
                  • korttomaK korttoma

                    Did anyone measure the current consumption of these VEML chips?
                    I just compared a Sensebender Micro with the VEML6075 to a standalone Sensebender Micro and the standalone one measured 28uA and the one with the VEML6075 measured 740uA.

                    I just checked the VEML6075 documentation and typical consumption is 480uA but it should also be possible to shut it down and then it should only draw 800nA.

                    I need to check the Lib if there is some function to shut it down and wake it up. Or else I will try to change the setup so I can power the VEML6075 from an output pin so I can turn it completely off.

                    scalzS Offline
                    scalzS Offline
                    scalz
                    Hardware Contributor
                    wrote on last edited by
                    #23

                    @korttoma
                    if i remember, sleep is not implemented in the veml6075 lib above. I added a sleep function and set the corresponding CONF register. not a big thing ;)

                    korttomaK 1 Reply Last reply
                    0
                    • scalzS scalz

                      @korttoma
                      if i remember, sleep is not implemented in the veml6075 lib above. I added a sleep function and set the corresponding CONF register. not a big thing ;)

                      korttomaK Offline
                      korttomaK Offline
                      korttoma
                      Hero Member
                      wrote on last edited by korttoma
                      #24

                      @scalz please share your sleep function implementation :D it is quite a "big thing" for a non programmer.

                      • Tomas
                      1 Reply Last reply
                      0
                      • scalzS Offline
                        scalzS Offline
                        scalz
                        Hardware Contributor
                        wrote on last edited by scalz
                        #25

                        @korttoma you can try this, and you'll see it's not a big thing :smile:

                        in your .h, in the public section, add this:

                        void sleep(bool mode);
                        

                        then in the .cpp, add this:

                        void VEML6075::sleep(bool mode) {
                        
                        	if (mode) 
                        		this->config |= 1; // Go to sleep			
                        	else 
                        		this->config &= 254; // Wake up
                        	
                        	this->write16(VEML6075_REG_CONF, this->config);
                        	
                        }
                        

                        In your sketch, just do this:

                        veml6075.sleep(true); // power down veml6075
                        

                        Note: i added this because i noticed it wasn't implemented, but i've not checked the power consumption yet. So if you can tell me if it's ok, please!

                        Enjoy ;)

                        korttomaK alexsh1A 2 Replies Last reply
                        1
                        • scalzS scalz

                          @korttoma you can try this, and you'll see it's not a big thing :smile:

                          in your .h, in the public section, add this:

                          void sleep(bool mode);
                          

                          then in the .cpp, add this:

                          void VEML6075::sleep(bool mode) {
                          
                          	if (mode) 
                          		this->config |= 1; // Go to sleep			
                          	else 
                          		this->config &= 254; // Wake up
                          	
                          	this->write16(VEML6075_REG_CONF, this->config);
                          	
                          }
                          

                          In your sketch, just do this:

                          veml6075.sleep(true); // power down veml6075
                          

                          Note: i added this because i noticed it wasn't implemented, but i've not checked the power consumption yet. So if you can tell me if it's ok, please!

                          Enjoy ;)

                          korttomaK Offline
                          korttomaK Offline
                          korttoma
                          Hero Member
                          wrote on last edited by
                          #26

                          @scalz thanks for the sleep function! The current consumption is now down to 85uA but the problem is that onece it sleeps I cant get it to wake up.

                          Tried with:

                          veml6075.sleep(false);
                          

                          Tried allso adding a 500ms sleep after the wakeup to give it time to setle.
                          But do I need to do something more?

                          • Tomas
                          scalzS 1 Reply Last reply
                          0
                          • korttomaK korttoma

                            @scalz thanks for the sleep function! The current consumption is now down to 85uA but the problem is that onece it sleeps I cant get it to wake up.

                            Tried with:

                            veml6075.sleep(false);
                            

                            Tried allso adding a 500ms sleep after the wakeup to give it time to setle.
                            But do I need to do something more?

                            scalzS Offline
                            scalzS Offline
                            scalz
                            Hardware Contributor
                            wrote on last edited by scalz
                            #27

                            @korttoma sorry for the copy/paste mistake :) you can try again, i've updated above. maybe someday i'll measure power consuption of a sensebender, weird that you get 28uA for the standalone..

                            korttomaK 1 Reply Last reply
                            0
                            • scalzS scalz

                              @korttoma sorry for the copy/paste mistake :) you can try again, i've updated above. maybe someday i'll measure power consuption of a sensebender, weird that you get 28uA for the standalone..

                              korttomaK Offline
                              korttomaK Offline
                              korttoma
                              Hero Member
                              wrote on last edited by korttoma
                              #28

                              @scalz seems to be working now :D don´t take my current consumtion figures to sareously since Im using the Micro (nano) ampere meter and I realy have nothing good to calibrate it against.

                              0_1498719943898_20170628_071528.jpg

                              • Tomas
                              1 Reply Last reply
                              1
                              • alexsh1A Offline
                                alexsh1A Offline
                                alexsh1
                                wrote on last edited by
                                #29

                                I have a strange problem. VEML6070 is showing UV Index 6, which is more or less in line with other online sources. VEML6075 is showing UV index 10.5, which is wrong. I'll double check the sketch once more but cannot understand where this error comes from

                                1 Reply Last reply
                                0
                                • korttomaK Offline
                                  korttomaK Offline
                                  korttoma
                                  Hero Member
                                  wrote on last edited by korttoma
                                  #30

                                  I mounted the Sensebender Micro VEML6075 inside my old broken UVN800 and set it in the roof. Here are graphs of the values I received the last 3 days. Unfortunately I do not have anything to compare with but the values seem reasonable.

                                  0_1499540455956_UVIndex.jpg

                                  • Tomas
                                  1 Reply Last reply
                                  0
                                  • scalzS scalz

                                    @korttoma you can try this, and you'll see it's not a big thing :smile:

                                    in your .h, in the public section, add this:

                                    void sleep(bool mode);
                                    

                                    then in the .cpp, add this:

                                    void VEML6075::sleep(bool mode) {
                                    
                                    	if (mode) 
                                    		this->config |= 1; // Go to sleep			
                                    	else 
                                    		this->config &= 254; // Wake up
                                    	
                                    	this->write16(VEML6075_REG_CONF, this->config);
                                    	
                                    }
                                    

                                    In your sketch, just do this:

                                    veml6075.sleep(true); // power down veml6075
                                    

                                    Note: i added this because i noticed it wasn't implemented, but i've not checked the power consumption yet. So if you can tell me if it's ok, please!

                                    Enjoy ;)

                                    alexsh1A Offline
                                    alexsh1A Offline
                                    alexsh1
                                    wrote on last edited by
                                    #31

                                    @scalz FYG, I am using VEML6075 without sleep and it works now for nearly a year on 2xAA. I am still puzzled though by Index difference 6070 and 6075

                                    1 Reply Last reply
                                    0
                                    • korttomaK Offline
                                      korttomaK Offline
                                      korttoma
                                      Hero Member
                                      wrote on last edited by
                                      #32

                                      Yeah, my 6075 device is also still working fine on the 2xAA batteries I put in it a year ago.

                                      • Tomas
                                      alexsh1A 1 Reply Last reply
                                      0
                                      • alexsh1A Offline
                                        alexsh1A Offline
                                        alexsh1
                                        wrote on last edited by
                                        #33

                                        OK, I think found what the issue is. VEML 6070 is not providing accurate UV Index. Adafruit is stating the following:

                                        Note that this is not UV index, its just UV light intensity!
                                        

                                        This is how it can be converted into sort of UV Index according to the datasheet:

                                        RISK_LEVEL convert_to_risk_level(WORD uvs_step)
                                        {
                                        WORD risk_level_mapping_table[4] = {2241, 4482, 5976, 8217};
                                        }
                                        
                                        WORD read_uvs_step(void)
                                        {
                                        BYTE lsb, msb;
                                        WORD data;
                                        VEML6070_read_byte(VEML6070_ADDR_DATA_MSB, &msb);
                                        VEML6070_read_byte(VEML6070_ADDR_DATA_LSB, &lsb);
                                        data = ((WORD)msb << 8) | (WORD)lsb;
                                        return data;
                                        }
                                        
                                        
                                        LEVEL* UV Index 
                                        ===== ======== 
                                        LOW 0-2 
                                        MODERATE 3-5 
                                        HIGH 6-7 
                                        VERY HIGH 8-10 
                                        EXTREME >=11
                                        
                                        1 Reply Last reply
                                        1
                                        • korttomaK korttoma

                                          Yeah, my 6075 device is also still working fine on the 2xAA batteries I put in it a year ago.

                                          alexsh1A Offline
                                          alexsh1A Offline
                                          alexsh1
                                          wrote on last edited by alexsh1
                                          #34

                                          @korttoma @scalz FYG I got a new DMM from Dave Jones 121GW and decided to measure a sleep current for VEML6075 and to my surprise:

                                          0_1530957108991_0F29A8F8-3AD9-4235-AAF9-5756384C7B79.jpeg

                                          Quickly reading the datasheet I discovered my mistake:

                                          • current supply - 480uA
                                          • shutdown current - 800nA

                                          Therefore, the sensor has to be put to sleep properly.
                                          One can modify the existing lib:

                                          uint8_t VEML6075::Shutdown() {  //Places device in shutdown low power mode
                                          
                                          	Config = ReadByte(CONF_CMD, 0); //Update global config value
                                          
                                          	return WriteConfig(Config | 0x01); //Set shutdown bit
                                          
                                          }
                                          
                                          
                                          
                                          uint8_t VEML6075::PowerOn() {  //Turns device on from shutdown mode
                                          
                                          	Config = ReadByte(CONF_CMD, 0); //Update global config value
                                          
                                          	return WriteConfig(Config & 0xFE); //Clear shutdown bit
                                          
                                          }
                                          
                                          Make sure you define #define CONF_CMD 0x00
                                          
                                          

                                          PS Now I understand why I did not change batteries - they are rechargeable. Charing and putting them back made me think that batteries lasted for a long time. :relaxed:

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          13

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular