imu-lsm6ds3-read.ino
Demonstrates raw X, Y, Z axis reading from the IMU via the I2C bus.
Requires the STMicroelectronics LSM6DS3TR-C driver. The sensor is addressed at 0x6A on I2C1. Check the corresponding SCL/SDA pins on the XIAO. Data is raw (LSB), requiring conversion to g or dps based on configured sensitivity.
imu-lsm6ds3-read.ino
#include "stm32c5xx_hal.h"
#include "lsm6ds3tr_c_reg.h" // Driver ST standard
extern I2C_HandleTypeDef hi2c1;
uint8_t whoami;
int16_t acc_data[3], gyr_data[3];
void Read_IMU(void) {
uint8_t buf[6];
// Lire Accéléromètre (OUTX_L_XL)
HAL_I2C_Mem_Read(&hi2c1, 0x6A << 1, LSM6DS3TR_C_OUTX_L_XL, I2C_MEMADD_SIZE_8BIT, buf, 6, 100);
acc_data[0] = (int16_t)(buf[1] << 8 | buf[0]);
acc_data[1] = (int16_t)(buf[3] << 8 | buf[2]);
acc_data[2] = (int16_t)(buf[5] << 8 | buf[4]);
// Lire Gyroscope (OUTX_L_G)
HAL_I2C_Mem_Read(&hi2c1, 0x6A << 1, LSM6DS3TR_C_OUTX_L_G, I2C_MEMADD_SIZE_8BIT, buf, 6, 100);
gyr_data[0] = (int16_t)(buf[1] << 8 | buf[0]);
gyr_data[1] = (int16_t)(buf[3] << 8 | buf[2]);
gyr_data[2] = (int16_t)(buf[5] << 8 | buf[4]);
}
int main(void) {
HAL_Init();
// Init I2C1 (SCL/SDA sur XIAO)
while(1) {
Read_IMU();
HAL_Delay(100);
}
}