38 ESP_LOGV(TAG,
" Setting up Power Management");
46 ESP_LOGV(TAG,
" Setting up Gyroscope Config");
52 ESP_LOGV(TAG,
" Setting up Accelerometer Config");
57void MPU6886Component::dump_config() {
58 ESP_LOGCONFIG(TAG,
"MPU6886:");
60 LOG_UPDATE_INTERVAL(
this);
61 LOG_SENSOR(
" ",
"Acceleration X", this->accel_x_sensor_);
62 LOG_SENSOR(
" ",
"Acceleration Y", this->accel_y_sensor_);
63 LOG_SENSOR(
" ",
"Acceleration Z", this->accel_z_sensor_);
64 LOG_SENSOR(
" ",
"Gyro X", this->gyro_x_sensor_);
65 LOG_SENSOR(
" ",
"Gyro Y", this->gyro_y_sensor_);
66 LOG_SENSOR(
" ",
"Gyro Z", this->gyro_z_sensor_);
67 LOG_SENSOR(
" ",
"Temperature", this->temperature_sensor_);
70void MPU6886Component::update() {
71 ESP_LOGV(TAG,
" Updating");
73 if (!this->
read_bytes_16(MPU6886_REGISTER_ACCEL_XOUT_H, raw_data, 7)) {
77 auto *data =
reinterpret_cast<int16_t *
>(raw_data);
90 "Got accel={x=%.3f m/s², y=%.3f m/s², z=%.3f m/s²}, "
91 "gyro={x=%.3f °/s, y=%.3f °/s, z=%.3f °/s}, temp=%.3f°C",
92 accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z,
temperature);
94 PUBLISH_STATE(this->accel_x_sensor_, accel_x);
95 PUBLISH_STATE(this->accel_y_sensor_, accel_y);
96 PUBLISH_STATE(this->accel_z_sensor_, accel_z);
98 PUBLISH_STATE(this->temperature_sensor_,
temperature);
100 PUBLISH_STATE(this->gyro_x_sensor_, gyro_x);
101 PUBLISH_STATE(this->gyro_y_sensor_, gyro_y);
102 PUBLISH_STATE(this->gyro_z_sensor_, gyro_z);
void mark_failed()
Mark this component as failed.
virtual void setup()
Where the component's initialization should happen.
void status_set_warning()
void status_clear_warning()
bool read_byte(uint8_t a_register, uint8_t *data)
bool read_bytes_16(uint8_t a_register, uint16_t *data, uint8_t len)
bool update_register(uint8_t a_register, uint8_t mask, uint8_t value)
Read a register, replace the bits in mask with those of value and write it back.
bool setup_registers_()
Configure the sensor; false on an I2C failure.
const uint8_t MPU6886_REGISTER_WHO_AM_I
const float TEMPERATURE_OFFSET
const uint8_t MPU6886_BIT_TEMPERATURE_DISABLED
ESPHOME_LOG_TAG(TAG, "mpu6886")
const uint8_t MPU6886_REGISTER_ACCEL_XOUT_H
const uint8_t MPU6886_REGISTER_GYRO_CONFIG
const float MPU6886_RANGE_PER_DIGIT_2G
const uint8_t MPU6886_RANGE_2G
const float MPU6886_SCALE_DPS_PER_DIGIT_2000
const float TEMPERATURE_SENSITIVITY
const uint8_t MPU6886_WHO_AM_I_IDENTIFIER
const uint8_t MPU6886_BIT_SLEEP_ENABLED
const uint8_t MPU6886_REGISTER_POWER_MANAGEMENT_1
const uint8_t MPU6886_CLOCK_SOURCE_X_GYRO
const uint8_t MPU6886_SCALE_2000_DPS
const float GRAVITY_EARTH
const uint8_t MPU6886_REGISTER_ACCEL_CONFIG