ESPHome can't find Wire.h - VEML6075

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);
  }
};

Add Wire to the libraries key (before the SparkFun one).

4 Likes

Tks! Working again!

Thanks. It helps.

I’m having a similar issue:

substitutions:
  devicename: "louder-esparagus"
  long_devicename: "Speakers office"
  pcb_version: "02/24 REV G"

esphome:
  name: "${devicename}"
  name_add_mac_suffix: false
  comment: "${long_devicename} Louder ESP32 ${pcb_version}"
  libraries:
  - "Wire"
  includes:
    - louderesparagus.h

esp32:
  board: esp-wrover-kit
  framework:
    type: esp-idf

wifi:
  ssid: !secret esphome_wifi_ssid
  password: !secret esphome_wifi_password
  ap:
    ssid: "$devicename Hotspot"
    password: !secret esphome_ap_password

captive_portal:

logger:
  level: DEBUG

api:
  encryption:
    key: !secret esphome_api_key

ota:
  password: !secret esphome_ota_password

psram:
  mode: octal
  speed: 80MHz

switch:
  - platform: custom
    lambda: |-
      auto tas5805 = new TAS5805();
      App.register_component(tas5805);
      return {tas5805};
    switches:
      name: "Enable Amp"
      id: amp
      on_turn_on:
        then:
          - light.turn_on: 
              id: led
              brightness: 30%
              red: 0%
              green: 100%
              blue: 0%
      on_turn_off:
        then:
          - light.turn_on: 
              id: led
              brightness: 40%
              red: 100%
              green: 0%
              blue: 0%
  - platform: gpio
    name: PD support
    id: pd_on_off
    pin:
      number: GPIO13

binary_sensor:
  - platform: gpio
    name: PD Available
    id: pd_avail
    pin:
      number: GPIO36

i2c:
  sda: GPIO21
  scl: GPIO27
  scan: True
  id: i2c_component

i2s_audio:
  i2s_lrclk_pin: GPIO25
  i2s_bclk_pin: GPIO26

....

Custom component:

#include "esphome.h"
#include <Wire.h>
#define DEVICE_CTRL_2_REGISTER 0x03
#define PWDN_PIN 33
#define I2C_ADDR 0x2D
class TAS5805 : public Component, public Switch  {
  public:
    void setup() override {
      pinMode(PWDN_PIN, OUTPUT);
      digitalWrite(PWDN_PIN, LOW);
      delay(200);
      digitalWrite(PWDN_PIN, HIGH);
      Wire.begin();
      Wire.beginTransmission(I2C_ADDR);
      if (Wire.endTransmission() != 0) {
        ESP_LOGE("TAS5805", "TAS5805 not found at address 0x2D");
        return;
      }
      Wire.beginTransmission(I2C_ADDR);
      Wire.write(DEVICE_CTRL_2_REGISTER);
      Wire.write(0x02);
      Wire.endTransmission();
      delay(50);
      Wire.beginTransmission(I2C_ADDR);
      Wire.write(DEVICE_CTRL_2_REGISTER);
      Wire.write(0x03);
      Wire.endTransmission();
      ESP_LOGI("TAS5805", "TAS5805 initialized.");
    }
    void write_state(bool state) override {
      uint8_t value = state ? 0x03 : 0x00;
      Wire.beginTransmission(I2C_ADDR);
      Wire.write(DEVICE_CTRL_2_REGISTER);
      Wire.write(value);
      Wire.endTransmission();
      publish_state(state);
    }
};

log:

...
Dependency Graph
|-- noise-c @ 0.1.4
Compiling .pioenvs/louder-esparagus/src/main.o
Compiling .pioenvs/louder-esparagus/app_trace/app_trace_util.o
Compiling .pioenvs/louder-esparagus/app_trace/host_file_io.o
Compiling .pioenvs/louder-esparagus/app_trace/gcov/gcov_rtio.o
Compiling .pioenvs/louder-esparagus/app_update/esp_ota_ops.o
Archiving .pioenvs/louder-esparagus/esp-idf/app_trace/libapp_trace.a
Compiling .pioenvs/louder-esparagus/app_update/esp_app_desc.o
In file included from src/main.cpp:69:
src/louderesparagus.h:7:10: 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://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

 #include <Wire.h>
          ^~~~~~~~
compilation terminated.
Compiling .pioenvs/louder-esparagus/asio/asio/asio/src/asio.o
*** [.pioenvs/louder-esparagus/src/main.o] Error 1
========================== [FAILED] Took 5.97 seconds ==========================

Tried all platformio options as mentioned in other github issues, and topis. but no luck.