Major restructure to follow ESPHome conventions for multi-interface components: Component Structure Changes: - Renamed lsm6ds/ to lsm6ds_base/ to follow _base naming convention - Created lsm6ds_i2c/ for I2C interface implementation - Created lsm6ds_spi/ for SPI interface implementation - Both interfaces use AUTO_LOAD to automatically include base component - Updated C++ namespaces to match component folder names (lsm6ds_base, lsm6ds_i2c, lsm6ds_spi) Features: - Support for LSM6DSOX, LSM6DS3TR-C, LSM6DSO32 variants - Full 3-axis accelerometer and gyroscope support - Temperature sensor support - Configurable ranges: Accel (2G-16G), Gyro (125-2000 DPS) - Configurable output data rate (12.5Hz - 6.66kHz) - Two usage patterns: all-in-one and hub+sensor platform Implementation Details: - Base component (lsm6ds_base) contains shared code and abstract LSM6DSComponent class - I2C variant implements LSM6DSI2CDevice with I2C read/write methods - SPI variant implements LSM6DSSPIDevice with SPI read/write methods (MSB-based protocol) - Both variants support optional sensor.py for hub+sensor pattern - Added README_EXAMPLE.md files with usage examples for both interfaces - Added component test files for validation Documentation: - Added COMPONENT_STRUCTURE.md explaining architecture and usage patterns - Included example configurations for both I2C and SPI - Documented all configuration options and sensor variants
2.1 KiB
2.1 KiB
LSM6DS SPI Example Configuration
This component supports LSM6DS family IMU sensors (accelerometer + gyroscope) via SPI interface.
Supported Sensors
- LSM6DSOX (WHO_AM_I: 0x6C)
- LSM6DS3TR-C (WHO_AM_I: 0x6A)
- LSM6DSO32 (WHO_AM_I: 0x69)
Example 1: All-in-one Pattern
Configure the sensor with all outputs in the component block:
spi:
- id: spi_bus
clk_pin: GPIO12
mosi_pin: GPIO11
miso_pin: GPIO13
lsm6ds_spi:
id: imu_sensor
spi_id: spi_bus
cs_pin: GPIO10
accel_range: 4G
gyro_range: 500DPS
accel_odr: 104HZ
gyro_odr: 104HZ
update_interval: 50ms
accel_x:
name: "Accel X"
accel_y:
name: "Accel Y"
accel_z:
name: "Accel Z"
gyro_x:
name: "Gyro X"
gyro_y:
name: "Gyro Y"
gyro_z:
name: "Gyro Z"
temperature:
name: "IMU Temperature"
Example 2: Hub + Sensor Platform Pattern
Configure the hub separately, then add sensor outputs under the sensor platform:
spi:
- id: spi_bus
clk_pin: GPIO12
mosi_pin: GPIO11
miso_pin: GPIO13
lsm6ds_spi:
id: imu_hub
spi_id: spi_bus
cs_pin: GPIO10
accel_range: 4G
gyro_range: 500DPS
accel_odr: 104HZ
gyro_odr: 104HZ
update_interval: 50ms
sensor:
- platform: lsm6ds_spi
lsm6ds_id: imu_hub
accel_x:
name: "Accel X"
accel_y:
name: "Accel Y"
accel_z:
name: "Accel Z"
gyro_x:
name: "Gyro X"
gyro_y:
name: "Gyro Y"
gyro_z:
name: "Gyro Z"
temperature:
name: "IMU Temperature"
Configuration Options
Accelerometer Range
2G(default)4G8G16G
Gyroscope Range
125DPS250DPS(default)500DPS1000DPS2000DPS
Output Data Rate (ODR)
12.5HZ26HZ52HZ104HZ(default)208HZ416HZ833HZ1660HZ3330HZ6660HZ
SPI Configuration
The LSM6DS SPI implementation uses:
- Mode 0 or Mode 3 (CPOL=0, CPHA=0 or CPOL=1, CPHA=1)
- MSB first
- Read bit: MSB set to 1 (reg | 0x80)
- Write bit: MSB set to 0 (reg & 0x7F)
- Max speed: 10 MHz
The component handles the SPI protocol automatically.