Hi!
My device is working with an old version of ESPHome (I’m not sure which). I have this custom component/code to work with VEML6075 and it’s working, but I can’t compile with the latest version of ESPHome.
The code itself is OK, validated, no errors…but during compilating, PlatformIO is returning error that Wire.h is not found. This isn’t a common Arduino library? I’m not sure if PlatformIO would remove this lib.
This is the error from ESPHome:
INFO Reading configuration /config/esphome/sensor-uv.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing sensor-uv (board: nodemcu-32s; framework: arduino; platform: platformio/espressif32 @ 3.3.2)
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
Dependency Graph
|-- <AsyncTCP-esphome> 1.2.2
|-- <SparkFun VEML6075 Arduino Library> 1.1.4+sha.8cc6707
|-- <WiFi> 1.0
|-- <FS> 1.0
|-- <Update> 1.0
|-- <ESPAsyncWebServer-esphome> 2.1.0
| |-- <AsyncTCP-esphome> 1.2.2
|-- <DNSServer> 1.1.0
|-- <noise-c> 0.1.4
| |-- <libsodium> 1.10018.1
|-- <AsyncMqttClient-esphome> 0.8.6
| |-- <AsyncTCP-esphome> 1.2.2
|-- <Wire> 1.0.1
|-- <ArduinoJson-esphomelib> 5.13.3
|-- <ESPmDNS> 1.0
Compiling /data/sensor-uv/.pioenvs/sensor-uv/src/main.cpp.o
Archiving /data/sensor-uv/.pioenvs/sensor-uv/lib528/libAsyncTCP-esphome.a
Compiling /data/sensor-uv/.pioenvs/sensor-uv/libf28/SparkFun VEML6075 Arduino Library/SparkFun_VEML6075_Arduino_Library.cpp.o
Compiling /data/sensor-uv/.pioenvs/sensor-uv/lib64d/WiFi/ETH.cpp.o
Compiling /data/sensor-uv/.pioenvs/sensor-uv/lib64d/WiFi/WiFi.cpp.o
In file included from /data/sensor-uv/.piolibdeps/sensor-uv/SparkFun VEML6075 Arduino Library/src/SparkFun_VEML6075_Arduino_Library.cpp:26:0:
/data/sensor-uv/.piolibdeps/sensor-uv/SparkFun VEML6075 Arduino Library/src/SparkFun_VEML6075_Arduino_Library.h:36:18: fatal error: Wire.h: No such file or directory
**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:Wire.h"
* Web > https://platformio.org/lib/search?query=header:Wire.h
*
**************************************************************
compilation terminated.
*** [/data/sensor-uv/.pioenvs/sensor-uv/libf28/SparkFun VEML6075 Arduino Library/SparkFun_VEML6075_Arduino_Library.cpp.o] Error 1
========================= [FAILED] Took 12.24 seconds =========================
My device configuration:
substitutions:
device_name: sensor-uv
device_full_name: "Sensor UV"
device_ip: 192.168.22.44
device_use_ip: 192.168.22.44
packages:
wifi: !include common/wifi.yaml
web_server: !include common/web_server.yaml
esphome:
name: ${device_name}
platform: ESP32
board: nodemcu-32s
includes:
- VEML6075_Sparkfun.h
libraries:
- "https://github.com/sparkfun/SparkFun_VEML6075_Arduino_Library"
# Enable logging
logger:
level: VERY_VERBOSE
i2c:
- id: bus_a
sda: 21
scl: 22
scan: false
frequency: 200kHz
binary_sensor:
- platform: status
name: "${device_name} Status"
switch:
- platform: restart
name: "Restart ${device_name}"
sensor:
- platform: wifi_signal
name: "${device_name} Signal"
update_interval: 60s
- platform: adc
pin: A0
attenuation: 11db
name: "A0 Voltage"
# Sparkfun
- platform: custom
lambda: |-
auto veml6075_sparkfun = new VEML6075SparkFunSensor();
App.register_component(veml6075_sparkfun);
return {veml6075_sparkfun->uva_sensor, veml6075_sparkfun->uvb_sensor, veml6075_sparkfun->uvi_sensor, veml6075_sparkfun->uva_extra_sensor, veml6075_sparkfun->uvb_extra_sensor};
sensors:
- name: "VEML6075-UVA"
id: uva
unit_of_measurement: "steps"
accuracy_decimals: 0
- name: "VEML6075-UVB"
id: uvb
unit_of_measurement: "steps"
accuracy_decimals: 0
- name: "VEML6075-UVI"
id: uvi
accuracy_decimals: 0
- name: "VEML6075-UVA-Extra"
id: uva_extra
unit_of_measurement: "W/m²"
- name: "VEML6075-UVB-Extra"
id: uvb_extra
unit_of_measurement: "W/m²"
And VEML6075_Sparkfun.h file:
#include "esphome.h"
#include "SparkFun_VEML6075_Arduino_Library.h"
// Calibration constants:
// Four gain calibration constants -- alpha, beta, gamma, delta -- can be used to correct the output in
// reference to a GOLDEN sample. The golden sample should be calibrated under a solar simulator.
// Setting these to 1.0 essentialy eliminates the "golden"-sample calibration
const float CALIBRATION_ALPHA_VIS = 1.0; // UVA / UVAgolden
const float CALIBRATION_BETA_VIS = 1.0; // UVB / UVBgolden
const float CALIBRATION_GAMMA_IR = 1.0; // UVcomp1 / UVcomp1golden
const float CALIBRATION_DELTA_IR = 1.0; // UVcomp2 / UVcomp2golden
// Responsivity:
// Responsivity converts a raw 16-bit UVA/UVB reading to a relative irradiance (W/m^2).
// These values will need to be adjusted as either integration time or dynamic settings are modififed.
// These values are recommended by the "Designing the VEML6075 into an application" app note for 100ms IT
const float UVA_RESPONSIVITY = 0.00110; // UVAresponsivity
const float UVB_RESPONSIVITY = 0.00125; // UVBresponsivity
// UV coefficients:
// These coefficients
// These values are recommended by the "Designing the VEML6075 into an application" app note
const float UVA_VIS_COEF_A = 2.22; // a
const float UVA_IR_COEF_B = 1.33; // b
//const float UVA_IR_COEF_B = 1.17; // b
const float UVB_VIS_COEF_C = 2.95; // c
const float UVB_IR_COEF_D = 1.75; // d
//const float UVB_IR_COEF_D = 1.58; // d
class VEML6075SparkFunSensor : public PollingComponent, public Sensor {
public:
VEML6075 uv = VEML6075();
Sensor *uva_sensor = new Sensor();
Sensor *uvb_sensor = new Sensor();
Sensor *uvi_sensor = new Sensor();
Sensor *uva_extra_sensor = new Sensor();
Sensor *uvb_extra_sensor = new Sensor();
VEML6075SparkFunSensor() : PollingComponent(15000) {}
void setup() override {
Wire.begin();
uv.begin();
// Integration time and high-dynamic values will change the UVA/UVB sensitivity. That means
// new responsivity values will need to be measured for every combination of these settings.
uv.setIntegrationTime(VEML6075::IT_100MS);
uv.setHighDynamic(VEML6075::DYNAMIC_NORMAL);
//uv.setCoefficients(2.22, 1.33, 2.95, 1.74,0.001561, 0.002691);
//uv.setCoefficients(1.92, 0.55, 2.46, 0.63,0.001561, 0.002691);
}
void update() override {
uint16_t rawA, rawB, visibleComp, irComp;
float uviaCalc, uvibCalc, uvia, uvib, uvi;
// Read raw and compensation data from the sensor
rawA = uv.rawUva();
rawB = uv.rawUvb();
visibleComp = uv.visibleCompensation();
irComp = uv.irCompensation();
// Calculate the simple UVIA and UVIB. These are used to calculate the UVI signal.
uviaCalc = (float)rawA - ((UVA_VIS_COEF_A * CALIBRATION_ALPHA_VIS * visibleComp) / CALIBRATION_GAMMA_IR) - ((UVA_IR_COEF_B * CALIBRATION_ALPHA_VIS * irComp) / CALIBRATION_DELTA_IR);
uvibCalc = (float)rawB - ((UVB_VIS_COEF_C * CALIBRATION_BETA_VIS * visibleComp) / CALIBRATION_GAMMA_IR) - ((UVB_IR_COEF_D * CALIBRATION_BETA_VIS * irComp) / CALIBRATION_DELTA_IR);
// Convert raw UVIA and UVIB to values scaled by the sensor responsivity
uvia = uviaCalc * (1.0 / CALIBRATION_ALPHA_VIS) * UVA_RESPONSIVITY;
uvib = uvibCalc * (1.0 / CALIBRATION_BETA_VIS) * UVB_RESPONSIVITY;
// Use UVIA and UVIB to calculate the average UVI:
uvi = (uvia + uvib) / 2.0;
if (uvi < 0) {
uvi = 0;
}
//ESP_LOGD("custom", "The value of sensor uva is: %.0f", uviaCalc);
//ESP_LOGD("custom", "The value of sensor uvb is: %.0f", uvibCalc);
//ESP_LOGD("custom", "The value of sensor uvi is: %.0f", uvi);
publish_state(uviaCalc);
uva_sensor->publish_state(uviaCalc);
uvb_sensor->publish_state(uvibCalc);
uvi_sensor->publish_state(uvi);
uva_extra_sensor->publish_state(uvia);
uvb_extra_sensor->publish_state(uvib);
//uvb_sensor->publish_state(uvb);
//uvi_sensor->publish_state(uvi);
}
};