Browse Source

Merge pull request #1112 from ruimarinho/sensor/veml6075

Add support for VEML6075
alexa
Xose Pérez 6 years ago
committed by GitHub
parent
commit
2f156c2e46
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 161 additions and 20 deletions
  1. +13
    -5
      code/espurna/config/progmem.h
  2. +24
    -0
      code/espurna/config/sensors.h
  3. +15
    -12
      code/espurna/config/types.h
  4. +9
    -0
      code/espurna/sensor.ino
  5. +1
    -1
      code/espurna/sensors/GUVAS12SDSensor.h
  6. +96
    -0
      code/espurna/sensors/VEML6075Sensor.h
  7. +2
    -2
      code/html/custom.js
  8. +1
    -0
      code/platformio.ini

+ 13
- 5
code/espurna/config/progmem.h View File

@ -223,6 +223,9 @@ PROGMEM const char espurna_sensors[] =
#if V9261F_SUPPORT #if V9261F_SUPPORT
"V9261F " "V9261F "
#endif #endif
#if VEML6075_SUPPORT
"VEML6075 "
#endif
#if VL53L1X_SUPPORT #if VL53L1X_SUPPORT
"VL53L1X " "VL53L1X "
#endif #endif
@ -235,7 +238,9 @@ PROGMEM const unsigned char magnitude_decimals[] = {
3, 0, 0, 0, 0, 0, 0, 0, // Power decimals 3, 0, 0, 0, 0, 0, 0, 0, // Power decimals
0, 0, 0, // analog, digital, event 0, 0, 0, // analog, digital, event
0, 0, 0, // PM 0, 0, 0, // PM
0, 0, 3, 3, 0,
0, 0,
0, 0, 3, // UVA, UVB, UVI
3, 0,
4, 4, // Geiger Counter decimals 4, 4, // Geiger Counter decimals
0, 0,
0, 0, 0 // NO2, CO, Ohms 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_pm10_topic[] = "pm10";
PROGMEM const char magnitude_co2_topic[] = "co2"; PROGMEM const char magnitude_co2_topic[] = "co2";
PROGMEM const char magnitude_lux_topic[] = "lux"; 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_distance_topic[] = "distance";
PROGMEM const char magnitude_hcho_topic[] = "hcho"; PROGMEM const char magnitude_hcho_topic[] = "hcho";
PROGMEM const char magnitude_geiger_cpm_topic[] = "ldr_cpm"; // local dose rate [Counts per minute] 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_power_factor_topic, magnitude_energy_topic, magnitude_energy_delta_topic,
magnitude_analog_topic, magnitude_digital_topic, magnitude_event_topic, magnitude_analog_topic, magnitude_digital_topic, magnitude_event_topic,
magnitude_pm1dot0_topic, magnitude_pm2dot5_topic, magnitude_pm10_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_distance_topic, magnitude_hcho_topic,
magnitude_geiger_cpm_topic, magnitude_geiger_sv_topic, magnitude_geiger_cpm_topic, magnitude_geiger_sv_topic,
magnitude_count_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_ugm3[] = "µg/m³";
PROGMEM const char magnitude_ppm[] = "ppm"; PROGMEM const char magnitude_ppm[] = "ppm";
PROGMEM const char magnitude_lux[] = "lux"; PROGMEM const char magnitude_lux[] = "lux";
PROGMEM const char magnitude_uv[] = "uv";
PROGMEM const char magnitude_distance[] = "m"; PROGMEM const char magnitude_distance[] = "m";
PROGMEM const char magnitude_mgm3[] = "mg/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) 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_percentage, magnitude_joules, magnitude_joules,
magnitude_empty, magnitude_empty, magnitude_empty, magnitude_empty, magnitude_empty, magnitude_empty,
magnitude_ugm3, magnitude_ugm3, magnitude_ugm3, 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_distance, magnitude_mgm3,
magnitude_geiger_cpm, magnitude_geiger_sv, // Geiger counter units magnitude_geiger_cpm, magnitude_geiger_sv, // Geiger counter units
magnitude_empty, // magnitude_empty, //


+ 24
- 0
code/espurna/config/sensors.h View File

@ -735,6 +735,25 @@
#define V9261F_POWER_FACTOR 153699.0 #define V9261F_POWER_FACTOR 153699.0
#define V9261F_RPOWER_FACTOR V9261F_CURRENT_FACTOR #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 // Sensor helpers configuration - can't move to dependencies.h
// ============================================================================= // =============================================================================
@ -770,6 +789,7 @@
SONAR_SUPPORT || \ SONAR_SUPPORT || \
TMP3X_SUPPORT || \ TMP3X_SUPPORT || \
V9261F_SUPPORT || \ V9261F_SUPPORT || \
VEML6075_SUPPORT || \
VL53L1X_SUPPORT \ VL53L1X_SUPPORT \
) )
#endif #endif
@ -928,6 +948,10 @@
#include "../sensors/V9261FSensor.h" #include "../sensors/V9261FSensor.h"
#endif #endif
#if VEML6075_SUPPORT
#include "../sensors/VEML6075Sensor.h"
#endif
#if VL53L1X_SUPPORT #if VL53L1X_SUPPORT
#include "../sensors/VL53L1XSensor.h" #include "../sensors/VL53L1XSensor.h"
#endif #endif


+ 15
- 12
code/espurna/config/types.h View File

@ -279,7 +279,8 @@
#define SENSOR_SDS011_ID 0x27 #define SENSOR_SDS011_ID 0x27
#define SENSOR_MICS2710_ID 0x28 #define SENSOR_MICS2710_ID 0x28
#define SENSOR_MICS5525_ID 0x29 #define SENSOR_MICS5525_ID 0x29
#define SENSOR_VL53L1X_ID 0x30
#define SENSOR_VEML6075_ID 0x30
#define SENSOR_VL53L1X_ID 0x31
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Magnitudes // Magnitudes
@ -305,14 +306,16 @@
#define MAGNITUDE_PM10 17 #define MAGNITUDE_PM10 17
#define MAGNITUDE_CO2 18 #define MAGNITUDE_CO2 18
#define MAGNITUDE_LUX 19 #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

+ 9
- 0
code/espurna/sensor.ino View File

@ -705,6 +705,15 @@ void _sensorLoad() {
} }
#endif #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 #if VL53L1X_SUPPORT
{ {
VL53L1XSensor * sensor = new VL53L1XSensor(); VL53L1XSensor * sensor = new VL53L1XSensor();


+ 1
- 1
code/espurna/sensors/GUVAS12SDSensor.h View File

@ -104,7 +104,7 @@ class GUVAS12SDSensor : public BaseSensor {
// Type for slot # index // Type for slot # index
unsigned char type(unsigned char index) { unsigned char type(unsigned char index) {
if (index == 0) return MAGNITUDE_UV;
if (index == 0) return MAGNITUDE_UVI;
return MAGNITUDE_NONE; return MAGNITUDE_NONE;
} }


+ 96
- 0
code/espurna/sensors/VEML6075Sensor.h View File

@ -0,0 +1,96 @@
// -----------------------------------------------------------------------------
// VEML6075 Sensor over I2C
// Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
// -----------------------------------------------------------------------------
#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

+ 2
- 2
code/html/custom.js View File

@ -47,7 +47,7 @@ function sensorName(id) {
"Events", "PMSX003", "BMX280", "MHZ19", "SI7021", "Events", "PMSX003", "BMX280", "MHZ19", "SI7021",
"SHT3X I2C", "BH1750", "PZEM004T", "AM2320 I2C", "GUVAS12SD", "SHT3X I2C", "BH1750", "PZEM004T", "AM2320 I2C", "GUVAS12SD",
"TMP3X", "Sonar", "SenseAir", "GeigerTicks", "GeigerCPM", "TMP3X", "Sonar", "SenseAir", "GeigerTicks", "GeigerCPM",
"NTC", "SDS011", "MICS2710", "MICS5525", "VL53L1X"
"NTC", "SDS011", "MICS2710", "MICS5525", "VL53L1X", "VEML6075"
]; ];
if (1 <= id && id <= names.length) { if (1 <= id && id <= names.length) {
return names[id - 1]; return names[id - 1];
@ -61,7 +61,7 @@ function magnitudeType(type) {
"Current", "Voltage", "Active Power", "Apparent Power", "Current", "Voltage", "Active Power", "Apparent Power",
"Reactive Power", "Power Factor", "Energy", "Energy (delta)", "Reactive Power", "Power Factor", "Energy", "Energy (delta)",
"Analog", "Digital", "Event", "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", "Local Dose Rate", "Local Dose Rate",
"Count", "Count",
"NO2", "CO", "Resistance" "NO2", "CO", "Resistance"


+ 1
- 0
code/platformio.ini View File

@ -97,6 +97,7 @@ lib_deps =
https://github.com/LowPowerLab/RFM69#1.1.3 https://github.com/LowPowerLab/RFM69#1.1.3
https://github.com/xoseperez/Time https://github.com/xoseperez/Time
NewPing NewPing
https://github.com/sparkfun/SparkFun_VEML6075_Arduino_Library#V_1.0.3
https://github.com/pololu/vl53l1x-arduino#1.0.1 https://github.com/pololu/vl53l1x-arduino#1.0.1
lib_ignore = lib_ignore =


Loading…
Cancel
Save