[mmc5603] enable AUTO_SR_en to compensate for temperature drift (#12556)

Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
pixelgrb
2025-12-18 20:13:36 -08:00
committed by GitHub
parent 7ae3a11d6b
commit f962497db1
4 changed files with 11 additions and 1 deletions

View File

@@ -83,6 +83,7 @@ void MMC5603Component::dump_config() {
ESP_LOGE(TAG, "The ID registers don't match - Is this really an MMC5603?");
}
LOG_UPDATE_INTERVAL(this);
ESP_LOGCONFIG(TAG, " Auto set/reset: %s", ONOFF(this->auto_set_reset_));
LOG_SENSOR(" ", "X Axis", this->x_sensor_);
LOG_SENSOR(" ", "Y Axis", this->y_sensor_);
@@ -93,7 +94,8 @@ void MMC5603Component::dump_config() {
float MMC5603Component::get_setup_priority() const { return setup_priority::DATA; }
void MMC5603Component::update() {
if (!this->write_byte(MMC56X3_CTRL0_REG, 0x01)) {
uint8_t ctrl0 = (this->auto_set_reset_) ? 0x21 : 0x01;
if (!this->write_byte(MMC56X3_CTRL0_REG, ctrl0)) {
this->status_set_warning();
return;
}

View File

@@ -25,6 +25,7 @@ class MMC5603Component : public PollingComponent, public i2c::I2CDevice {
void set_y_sensor(sensor::Sensor *y_sensor) { y_sensor_ = y_sensor; }
void set_z_sensor(sensor::Sensor *z_sensor) { z_sensor_ = z_sensor; }
void set_heading_sensor(sensor::Sensor *heading_sensor) { heading_sensor_ = heading_sensor; }
void set_auto_set_reset(bool auto_set_reset) { auto_set_reset_ = auto_set_reset; }
protected:
MMC5603Datarate datarate_;
@@ -32,6 +33,7 @@ class MMC5603Component : public PollingComponent, public i2c::I2CDevice {
sensor::Sensor *y_sensor_{nullptr};
sensor::Sensor *z_sensor_{nullptr};
sensor::Sensor *heading_sensor_{nullptr};
bool auto_set_reset_{true};
enum ErrorCode {
NONE = 0,
COMMUNICATION_FAILED,

View File

@@ -16,6 +16,8 @@ from esphome.const import (
UNIT_MICROTESLA,
)
CONF_AUTO_SET_RESET = "auto_set_reset"
DEPENDENCIES = ["i2c"]
mmc5603_ns = cg.esphome_ns.namespace("mmc5603")
@@ -54,6 +56,7 @@ CONFIG_SCHEMA = (
cv.Optional(CONF_FIELD_STRENGTH_Y): field_strength_schema,
cv.Optional(CONF_FIELD_STRENGTH_Z): field_strength_schema,
cv.Optional(CONF_HEADING): heading_schema,
cv.Optional(CONF_AUTO_SET_RESET, default=True): cv.boolean,
}
)
.extend(cv.polling_component_schema("60s"))
@@ -88,3 +91,5 @@ async def to_code(config):
if CONF_HEADING in config:
sens = await sensor.new_sensor(config[CONF_HEADING])
cg.add(var.set_heading_sensor(sens))
if CONF_AUTO_SET_RESET in config:
cg.add(var.set_auto_set_reset(config[CONF_AUTO_SET_RESET]))

View File

@@ -2,6 +2,7 @@ sensor:
- platform: mmc5603
i2c_id: i2c_bus
address: 0x30
auto_set_reset: true
field_strength_x:
name: HMC5883L Field Strength X
field_strength_y: