ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
veml3235.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
7
8namespace esphome::veml3235 {
9
10// Register IDs/locations
11//
12static const uint8_t CONFIG_REG = 0x00;
13static const uint8_t W_REG = 0x04;
14static const uint8_t ALS_REG = 0x05;
15static const uint8_t ID_REG = 0x09;
16
17// Bit offsets within CONFIG_REG
18//
19static const uint8_t CONFIG_REG_IT_BIT = 12;
20static const uint8_t CONFIG_REG_DG_BIT = 5;
21static const uint8_t CONFIG_REG_G_BIT = 3;
22
23// Other important constants
24//
25static const uint8_t DEVICE_ID = 0x35;
26static const uint16_t SHUTDOWN_BITS = 0x0018;
27
28// Base multiplier value for lux computation
29//
30static const float LUX_MULTIPLIER_BASE = 0.00213;
31
32// Enum for conversion/integration time settings for the VEML3235.
33//
34// Specific values of the enum constants are register values taken from the VEML3235 datasheet.
35// Longer times mean more accurate results, but will take more energy/more time.
36//
44
45// Enum for digital gain settings for the VEML3235.
46// Higher values are better for low light situations, but can increase noise.
47//
52
53// Enum for gain settings for the VEML3235.
54// Higher values are better for low light situations, but can increase noise.
55//
61
63 public:
64 void setup() override;
65 void dump_config() override;
66 void update() override { this->publish_state(this->read_lx_()); }
67
68 // Used by ESPHome framework. Does NOT actually set the value on the device.
76 void set_power_on(bool power_on) { this->power_on_ = power_on; }
82
83 bool auto_gain() { return this->auto_gain_; }
87 VEML3235ComponentGain gain() { return this->gain_; }
89
90 // Updates the configuration register on the device
91 bool refresh_config_reg(bool force_on = false);
92
93 protected:
94 float read_lx_();
95 void adjust_gain_(uint16_t als_raw_value);
96
97 bool auto_gain_{true};
98 bool power_on_{true};
104};
105
106} // namespace esphome::veml3235
This class simplifies creating components that periodically check a state.
Definition component.h:585
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:132
Base-class for all sensors.
Definition sensor.h:47
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
VEML3235ComponentIntegrationTime integration_time_
Definition veml3235.h:103
void set_digital_gain(VEML3235ComponentDigitalGain digital_gain)
Definition veml3235.h:77
VEML3235ComponentGain gain()
Definition veml3235.h:87
void set_power_on(bool power_on)
Definition veml3235.h:76
void adjust_gain_(uint16_t als_raw_value)
Definition veml3235.cpp:108
void set_integration_time(VEML3235ComponentIntegrationTime integration_time)
Definition veml3235.h:79
void set_auto_gain(bool auto_gain)
Definition veml3235.h:69
void set_auto_gain_threshold_high(float auto_gain_threshold_high)
Definition veml3235.h:70
VEML3235ComponentIntegrationTime integration_time()
Definition veml3235.h:88
void set_gain(VEML3235ComponentGain gain)
Definition veml3235.h:78
VEML3235ComponentGain gain_
Definition veml3235.h:102
void set_auto_gain_threshold_low(float auto_gain_threshold_low)
Definition veml3235.h:73
VEML3235ComponentDigitalGain digital_gain()
Definition veml3235.h:86
VEML3235ComponentDigitalGain digital_gain_
Definition veml3235.h:101
bool refresh_config_reg(bool force_on=false)
Definition veml3235.cpp:25
const uint8_t CONFIG_REG
Definition pca9554.cpp:10
VEML3235ComponentIntegrationTime
Definition veml3235.h:37
@ VEML3235_INTEGRATION_TIME_100MS
Definition veml3235.h:39
@ VEML3235_INTEGRATION_TIME_200MS
Definition veml3235.h:40
@ VEML3235_INTEGRATION_TIME_50MS
Definition veml3235.h:38
@ VEML3235_INTEGRATION_TIME_800MS
Definition veml3235.h:42
@ VEML3235_INTEGRATION_TIME_400MS
Definition veml3235.h:41