29 if (!this->
read_byte(MPU6050_REGISTER_WHO_AM_I, &who_am_i) ||
30 (who_am_i != 0x68 && who_am_i != 0x70 && who_am_i != 0x98)) {
34 ESP_LOGV(TAG,
" Setting up Power Management");
42 ESP_LOGV(TAG,
" Setting up Gyro Config");
48 ESP_LOGV(TAG,
" Setting up Accel Config");
52void MPU6050Component::dump_config() {
53 ESP_LOGCONFIG(TAG,
"MPU6050:");
55 LOG_UPDATE_INTERVAL(
this);
56 LOG_SENSOR(
" ",
"Acceleration X", this->accel_x_sensor_);
57 LOG_SENSOR(
" ",
"Acceleration Y", this->accel_y_sensor_);
58 LOG_SENSOR(
" ",
"Acceleration Z", this->accel_z_sensor_);
59 LOG_SENSOR(
" ",
"Gyro X", this->gyro_x_sensor_);
60 LOG_SENSOR(
" ",
"Gyro Y", this->gyro_y_sensor_);
61 LOG_SENSOR(
" ",
"Gyro Z", this->gyro_z_sensor_);
62 LOG_SENSOR(
" ",
"Temperature", this->temperature_sensor_);
65void MPU6050Component::update() {
66 ESP_LOGV(TAG,
"Updating");
68 if (!this->
read_bytes_16(MPU6050_REGISTER_ACCEL_XOUT_H, raw_data, 7)) {
72 auto *data =
reinterpret_cast<int16_t *
>(raw_data);
85 "Got accel={x=%.3f m/s², y=%.3f m/s², z=%.3f m/s²}, "
86 "gyro={x=%.3f °/s, y=%.3f °/s, z=%.3f °/s}, temp=%.3f°C",
87 accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z,
temperature);
89 PUBLISH_STATE(this->accel_x_sensor_, accel_x);
90 PUBLISH_STATE(this->accel_y_sensor_, accel_y);
91 PUBLISH_STATE(this->accel_z_sensor_, accel_z);
93 PUBLISH_STATE(this->temperature_sensor_,
temperature);
95 PUBLISH_STATE(this->gyro_x_sensor_, gyro_x);
96 PUBLISH_STATE(this->gyro_y_sensor_, gyro_y);
97 PUBLISH_STATE(this->gyro_z_sensor_, gyro_z);
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.