diff --git a/code/espurna/config/progmem.h b/code/espurna/config/progmem.h index 70fa8e1a..3fda6521 100644 --- a/code/espurna/config/progmem.h +++ b/code/espurna/config/progmem.h @@ -223,6 +223,9 @@ PROGMEM const char espurna_sensors[] = #if V9261F_SUPPORT "V9261F " #endif + #if VEML6075_SUPPORT + "VEML6075 " + #endif #if VL53L1X_SUPPORT "VL53L1X " #endif @@ -235,7 +238,9 @@ PROGMEM const unsigned char magnitude_decimals[] = { 3, 0, 0, 0, 0, 0, 0, 0, // Power decimals 0, 0, 0, // analog, digital, event 0, 0, 0, // PM - 0, 0, 3, 3, 0, + 0, 0, + 0, 0, 3, // UVA, UVB, UVI + 3, 0, 4, 4, // Geiger Counter decimals 0, 0, 0, 0 // NO2, CO, Ohms @@ -261,7 +266,9 @@ PROGMEM const char magnitude_pm2dot5_topic[] = "pm2dot5"; PROGMEM const char magnitude_pm10_topic[] = "pm10"; PROGMEM const char magnitude_co2_topic[] = "co2"; PROGMEM const char magnitude_lux_topic[] = "lux"; -PROGMEM const char magnitude_uv_topic[] = "uv"; +PROGMEM const char magnitude_uva_topic[] = "uva"; +PROGMEM const char magnitude_uvb_topic[] = "uvb"; +PROGMEM const char magnitude_uvi_topic[] = "uvi"; PROGMEM const char magnitude_distance_topic[] = "distance"; PROGMEM const char magnitude_hcho_topic[] = "hcho"; PROGMEM const char magnitude_geiger_cpm_topic[] = "ldr_cpm"; // local dose rate [Counts per minute] @@ -278,7 +285,8 @@ PROGMEM const char* const magnitude_topics[] = { magnitude_power_factor_topic, magnitude_energy_topic, magnitude_energy_delta_topic, magnitude_analog_topic, magnitude_digital_topic, magnitude_event_topic, magnitude_pm1dot0_topic, magnitude_pm2dot5_topic, magnitude_pm10_topic, - magnitude_co2_topic, magnitude_lux_topic, magnitude_uv_topic, + magnitude_co2_topic, magnitude_lux_topic, + magnitude_uva_topic, magnitude_uvb_topic, magnitude_uvi_topic, magnitude_distance_topic, magnitude_hcho_topic, magnitude_geiger_cpm_topic, magnitude_geiger_sv_topic, magnitude_count_topic, @@ -299,7 +307,6 @@ PROGMEM const char magnitude_kwh[] = "kWh"; PROGMEM const char magnitude_ugm3[] = "µg/m³"; PROGMEM const char magnitude_ppm[] = "ppm"; PROGMEM const char magnitude_lux[] = "lux"; -PROGMEM const char magnitude_uv[] = "uv"; PROGMEM const char magnitude_distance[] = "m"; PROGMEM const char magnitude_mgm3[] = "mg/m³"; PROGMEM const char magnitude_geiger_cpm[] = "cpm"; // Counts per Minute: Unit of local dose rate (Geiger counting) @@ -314,7 +321,8 @@ PROGMEM const char* const magnitude_units[] = { magnitude_percentage, magnitude_joules, magnitude_joules, magnitude_empty, magnitude_empty, magnitude_empty, magnitude_ugm3, magnitude_ugm3, magnitude_ugm3, - magnitude_ppm, magnitude_lux, magnitude_uv, + magnitude_ppm, magnitude_lux, + magnitude_empty, magnitude_empty, magnitude_empty, magnitude_distance, magnitude_mgm3, magnitude_geiger_cpm, magnitude_geiger_sv, // Geiger counter units magnitude_empty, // diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index 131d6760..8681194a 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -735,6 +735,25 @@ #define V9261F_POWER_FACTOR 153699.0 #define V9261F_RPOWER_FACTOR V9261F_CURRENT_FACTOR +//------------------------------------------------------------------------------ +// VEML6075 based power sensor +// Enable support by passing VEML6075_SUPPORT=1 build flag +//------------------------------------------------------------------------------ + +#ifndef VEML6075_SUPPORT +#define VEML6075_SUPPORT 0 +#endif + +#ifndef VEML6075_INTEGRATION_TIME +#define VEML6075_INTEGRATION_TIME VEML6075::IT_100MS // The time, in milliseconds, allocated for a single +#endif // measurement. A longer timing budget allows for more + // accurate results at the cost of power. + +#ifndef VEML6075_DYNAMIC_MODE +#define VEML6075_DYNAMIC_MODE VEML6075::DYNAMIC_NORMAL // The dynamic mode can either be normal or high. In high +#endif // dynamic mode, the resolution increases by about two + // times. + // ============================================================================= // Sensor helpers configuration - can't move to dependencies.h // ============================================================================= @@ -770,6 +789,7 @@ SONAR_SUPPORT || \ TMP3X_SUPPORT || \ V9261F_SUPPORT || \ + VEML6075_SUPPORT || \ VL53L1X_SUPPORT \ ) #endif @@ -928,6 +948,10 @@ #include "../sensors/V9261FSensor.h" #endif +#if VEML6075_SUPPORT + #include "../sensors/VEML6075Sensor.h" +#endif + #if VL53L1X_SUPPORT #include "../sensors/VL53L1XSensor.h" #endif diff --git a/code/espurna/config/types.h b/code/espurna/config/types.h index 45dfe7cc..8c258f83 100644 --- a/code/espurna/config/types.h +++ b/code/espurna/config/types.h @@ -279,7 +279,8 @@ #define SENSOR_SDS011_ID 0x27 #define SENSOR_MICS2710_ID 0x28 #define SENSOR_MICS5525_ID 0x29 -#define SENSOR_VL53L1X_ID 0x30 +#define SENSOR_VEML6075_ID 0x30 +#define SENSOR_VL53L1X_ID 0x31 //-------------------------------------------------------------------------------- // Magnitudes @@ -305,14 +306,16 @@ #define MAGNITUDE_PM10 17 #define MAGNITUDE_CO2 18 #define MAGNITUDE_LUX 19 -#define MAGNITUDE_UV 20 -#define MAGNITUDE_DISTANCE 21 -#define MAGNITUDE_HCHO 22 -#define MAGNITUDE_GEIGER_CPM 23 -#define MAGNITUDE_GEIGER_SIEVERT 24 -#define MAGNITUDE_COUNT 25 -#define MAGNITUDE_NO2 26 -#define MAGNITUDE_CO 27 -#define MAGNITUDE_RESISTANCE 28 - -#define MAGNITUDE_MAX 29 +#define MAGNITUDE_UVA 20 +#define MAGNITUDE_UVB 21 +#define MAGNITUDE_UVI 22 +#define MAGNITUDE_DISTANCE 23 +#define MAGNITUDE_HCHO 24 +#define MAGNITUDE_GEIGER_CPM 25 +#define MAGNITUDE_GEIGER_SIEVERT 26 +#define MAGNITUDE_COUNT 27 +#define MAGNITUDE_NO2 28 +#define MAGNITUDE_CO 29 +#define MAGNITUDE_RESISTANCE 30 + +#define MAGNITUDE_MAX 31 diff --git a/code/espurna/sensor.ino b/code/espurna/sensor.ino index 74ea3994..53e41df5 100644 --- a/code/espurna/sensor.ino +++ b/code/espurna/sensor.ino @@ -705,6 +705,15 @@ void _sensorLoad() { } #endif + #if VEML6075_SUPPORT + { + VEML6075Sensor * sensor = new VEML6075Sensor(); + sensor->setIntegrationTime(VEML6075_INTEGRATION_TIME); + sensor->setDynamicMode(VEML6075_DYNAMIC_MODE); + _sensors.push_back(sensor); + } + #endif + #if VL53L1X_SUPPORT { VL53L1XSensor * sensor = new VL53L1XSensor(); diff --git a/code/espurna/sensors/GUVAS12SDSensor.h b/code/espurna/sensors/GUVAS12SDSensor.h index f188b2b3..a4b65c54 100644 --- a/code/espurna/sensors/GUVAS12SDSensor.h +++ b/code/espurna/sensors/GUVAS12SDSensor.h @@ -104,7 +104,7 @@ class GUVAS12SDSensor : public BaseSensor { // Type for slot # index unsigned char type(unsigned char index) { - if (index == 0) return MAGNITUDE_UV; + if (index == 0) return MAGNITUDE_UVI; return MAGNITUDE_NONE; } diff --git a/code/espurna/sensors/VEML6075Sensor.h b/code/espurna/sensors/VEML6075Sensor.h new file mode 100644 index 00000000..60753401 --- /dev/null +++ b/code/espurna/sensors/VEML6075Sensor.h @@ -0,0 +1,96 @@ +// ----------------------------------------------------------------------------- +// VEML6075 Sensor over I2C +// Copyright (C) 2017-2018 by Xose Pérez +// ----------------------------------------------------------------------------- + +#if SENSOR_SUPPORT && VEML6075_SUPPORT + +#pragma once + +#undef I2C_SUPPORT +#define I2C_SUPPORT 1 // Explicitly request I2C support. + + +#include "Arduino.h" +#include "I2CSensor.h" +#include "SparkFun_VEML6075_Arduino_Library.h" + +class VEML6075Sensor : public I2CSensor { + + public: + + // --------------------------------------------------------------------- + // Public + // --------------------------------------------------------------------- + + VEML6075Sensor(): I2CSensor() { + _count = 3; + _sensor_id = SENSOR_VEML6075_ID; + _veml6075 = new VEML6075(); + } + + ~VEML6075Sensor() { + delete _veml6075; + } + + void begin() { + if (!_veml6075->begin()) { + return; + }; + + _ready = true; + } + + // --------------------------------------------------------------------- + // Sensor API + // --------------------------------------------------------------------- + + // Descriptive name of the sensor + String description() { + char buffer[25]; + snprintf(buffer, sizeof(buffer), "VEML6075 @ I2C (0x%02X)", _address); + return String(buffer); + } + + // Descriptive name of the slot # index + String slot(unsigned char index) { + return description(); + }; + + // Type for slot # index + unsigned char type(unsigned char index) { + if (index == 0) return MAGNITUDE_UVA; + if (index == 1) return MAGNITUDE_UVB; + if (index == 2) return MAGNITUDE_UVI; + return MAGNITUDE_NONE; + } + + // Pre-read hook (usually to populate registers with up-to-date data) + void pre() { + _error = SENSOR_ERROR_OK; + } + + // Current value for slot # index + double value(unsigned char index) { + if (index == 0) return _veml6075->a(); + if (index == 1) return _veml6075->b(); + if (index == 2) return _veml6075->index(); + + return 0; + } + + void setIntegrationTime(VEML6075::veml6075_uv_it_t integration_time) { + _veml6075->setIntegrationTime(integration_time); + } + + void setDynamicMode(VEML6075::veml6075_hd_t dynamic_mode) { + _veml6075->setHighDynamic(dynamic_mode); + } + + protected: + + VEML6075 * _veml6075 = NULL; + +}; + +#endif // SENSOR_SUPPORT && VEML6075_SUPPORT diff --git a/code/html/custom.js b/code/html/custom.js index 11910a99..3a9d6644 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -47,7 +47,7 @@ function sensorName(id) { "Events", "PMSX003", "BMX280", "MHZ19", "SI7021", "SHT3X I2C", "BH1750", "PZEM004T", "AM2320 I2C", "GUVAS12SD", "TMP3X", "Sonar", "SenseAir", "GeigerTicks", "GeigerCPM", - "NTC", "SDS011", "MICS2710", "MICS5525", "VL53L1X" + "NTC", "SDS011", "MICS2710", "MICS5525", "VL53L1X", "VEML6075" ]; if (1 <= id && id <= names.length) { return names[id - 1]; @@ -61,7 +61,7 @@ function magnitudeType(type) { "Current", "Voltage", "Active Power", "Apparent Power", "Reactive Power", "Power Factor", "Energy", "Energy (delta)", "Analog", "Digital", "Event", - "PM1.0", "PM2.5", "PM10", "CO2", "Lux", "UV", "Distance" , "HCHO", + "PM1.0", "PM2.5", "PM10", "CO2", "Lux", "UVA", "UVB", "UV Index", "Distance" , "HCHO", "Local Dose Rate", "Local Dose Rate", "Count", "NO2", "CO", "Resistance" diff --git a/code/platformio.ini b/code/platformio.ini index b5460970..4685ec2f 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -97,6 +97,7 @@ lib_deps = https://github.com/LowPowerLab/RFM69#1.1.3 https://github.com/xoseperez/Time NewPing + https://github.com/sparkfun/SparkFun_VEML6075_Arduino_Library#V_1.0.3 https://github.com/pololu/vl53l1x-arduino#1.0.1 lib_ignore =