16 return LOG_STR(
"±125dps");
18 return LOG_STR(
"±250dps");
20 return LOG_STR(
"±500dps");
22 return LOG_STR(
"±1000dps");
24 return LOG_STR(
"±2000dps");
26 return LOG_STR(
"unknown");
32 case LSM6DS_WHO_AM_I_LSM6DS3:
33 return LOG_STR(
"LSM6DS3");
34 case LSM6DS_WHO_AM_I_LSM6DS3TR_C:
35 return LOG_STR(
"LSM6DS3TR-C");
36 case LSM6DS_WHO_AM_I_LSM6DSO:
37 return LOG_STR(
"LSM6DSO");
44 return who_am_i == LSM6DS_WHO_AM_I_LSM6DS3 ? 16 : 256;
48 MotionComponent::setup();
51 ESP_LOGE(TAG,
"Failed to read WHO_AM_I — check wiring and I2C address");
56 if (chip_name ==
nullptr) {
57 ESP_LOGE(TAG,
"Unknown WHO_AM_I: 0x%02X", who_am_i);
58 this->
mark_failed(LOG_STR(
"Unknown WHO_AM_I value"));
61 ESP_LOGD(TAG,
"Found %s (WHO_AM_I = 0x%02X)", LOG_STR_ARG(chip_name), who_am_i);
67 this->
mark_failed(LOG_STR(
"Software reset failed"));
76 uint8_t ctrl3 = CTRL3_C_IF_INC | CTRL3_C_BDU;
86 this->
mark_failed(LOG_STR(
"Failed to configure accelerometer"));
94 this->
mark_failed(LOG_STR(
"Failed to configure gyroscope"));
117 LOG_I2C_DEVICE(
this);
118 LOG_UPDATE_INTERVAL(
this);
123 " Accel range : %s\n"
124 " Accel data rate : %dHz\n"
126 " Gyro data rate : %dHz",
127 LOG_STR_ARG(AccelRangeStrings::get_log_str(this->
accel_range_, AccelRangeStrings::LAST_INDEX)),
128 accel_odr, LOG_STR_ARG(gyro_range_to_str(this->
gyro_range_)), gyro_odr);
142 uint8_t
raw[LSM6DS_BURST_LEN];
143 if (!this->
read_bytes(LSM6DS_REG_OUTX_L_G,
raw, LSM6DS_BURST_LEN)) {
152 static constexpr float GYRO_SCALE[] = {
170 data.angular_rate[motion::Y_AXIS] = (int16_t) ((
raw[3] << 8) |
raw[2]) * gyro_scale;
171 data.angular_rate[motion::Z_AXIS] = (int16_t) ((
raw[5] << 8) |
raw[4]) * gyro_scale;
177 static constexpr float ACCEL_SCALE[] = {
186 (int16_t) ((
raw[LSM6DS_ACCEL_OFFSET + 1] << 8) |
raw[LSM6DS_ACCEL_OFFSET + 0]) * accel_scale;
187 data.acceleration[motion::Y_AXIS] =
188 (int16_t) ((
raw[LSM6DS_ACCEL_OFFSET + 3] << 8) |
raw[LSM6DS_ACCEL_OFFSET + 2]) * accel_scale;
189 data.acceleration[motion::Z_AXIS] =
190 (int16_t) ((
raw[LSM6DS_ACCEL_OFFSET + 5] << 8) |
raw[LSM6DS_ACCEL_OFFSET + 4]) * accel_scale;
198 if (this->
read_bytes(LSM6DS_REG_OUT_TEMP_L, raw_t, 2)) {
199 int16_t temp_raw = (int16_t) ((raw_t[1] << 8) | raw_t[0]);
void mark_failed()
Mark this component as failed.
void status_clear_error()
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len) const
writes an array of bytes to a specific register in the I²C device
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
void dump_config() override
LazyCallbackManager< void(float)> temperature_callback_
LSM6DSAccelODR accel_odr_
uint16_t temperature_sensitivity_
bool update_data(motion::MotionData &data) override
LSM6DSGyroRange gyro_range_
LSM6DSAccelRange accel_range_
const LogString * chip_name_
@ ERROR_OK
No error found during execution of method.
uint16_t temperature_sensitivity_from_who_am_i(uint8_t who_am_i)
Temperature sensitivity in LSB/°C for a supported WHO_AM_I value, from the chip's datasheet.
ESPHOME_LOG_TAG(TAG, "lsm6ds")
const LogString * chip_name_from_who_am_i(uint8_t who_am_i)
Chip name for a WHO_AM_I value, or nullptr when the chip is not supported.
PROGMEM_STRING_TABLE(AccelRangeStrings, "±2g", "±16g", "±4g", "±8g")
void HOT delay(uint32_t ms)