# hello_imu_mag Reads the on-board LSM6DSO IMU (accelerometer, gyroscope, temperature) and the LIS3MDL magnetometer at about 10 Hz and shows the values live on an LVGL dark-theme screen and on the console. ## Features - **Accelerometer** (g): X/Y/Z values with a bar graph for each axis - **Gyroscope** (dps): X/Y/Z values - **Magnetometer** (gauss): X/Y/Z values - **Temperature** from the IMU, in °C - **Sensor detection**: logs the `WHO_AM_I` register of each sensor at start-up; a sensor that is missing is reported and skipped - **Console fallback**: when LVGL is disabled the same data is printed to the console - **Independent sensors**: the IMU and magnetometer parts are compiled only when `CONFIG_CUBE32_IMU_ENABLED` / `CONFIG_CUBE32_MAG_ENABLED` are set ## Hardware - CUBE32 board (ESP32-S3) with a supported display - LSM6DSO IMU and LIS3MDL magnetometer (on the board) ## Configuration `sdkconfig.defaults` of the release example already has what the demo needs: | Setting | Why | |---------|-----| | `CONFIG_CUBE32_LVGL_ENABLED=y` | LVGL display driver | | `CONFIG_CUBE32_TOUCH_ENABLED=y` | Touch input (standard LVGL setup of the examples) | | `CONFIG_CUBE32_IMU_ENABLED=y` | Accelerometer, gyroscope, temperature | | `CONFIG_CUBE32_MAG_ENABLED=y` | Magnetometer | | `CONFIG_LV_FONT_MONTSERRAT_14=y` | Axis labels | | `CONFIG_LV_FONT_MONTSERRAT_10/20/24=y` | Required by the BLE OTA UI whenever LVGL is on | In the BSP dev project select the demo with `idf.py menuconfig` → `CUBE32 Application Selection` → `Hello IMU/MAG Example` (it is listed when the IMU or the magnetometer is enabled). ## Build and run ```bash idf.py set-target esp32s3 idf.py build idf.py -p <port> flash monitor ``` Run `idf.py set-target esp32s3` again after deleting `sdkconfig`; otherwise the target falls back to `esp32`. ## Usage 1. Flash the example; the screen shows **CUBE32 IMU / MAG** with three sections: `Accel (g)`, `Gyro (dps)` and `Mag (gauss)`, and the temperature at the bottom. 2. Tilt the board: the accelerometer values and bars change; at rest the total is about 1 g. 3. Rotate the board: the gyroscope values change while it moves and return to about 0 at rest. 4. Move the board near a magnet or a piece of iron: the magnetometer values change. The Earth's field is about 0.25 – 0.65 gauss. ## Console output ``` I (xxxx) hello_imu_mag: ======================================== I (xxxx) hello_imu_mag: CUBE32 Hello IMU/MAG Example I (xxxx) hello_imu_mag: ======================================== I (xxxx) hello_imu_mag: IMU: LSM6DSO ready (WHO_AM_I = 0x6C) I (xxxx) hello_imu_mag: MAG: LIS3MDL ready (WHO_AM_I = 0x3D) I (xxxx) hello_imu_mag: LVGL display ready (240x320) I (xxxx) hello_imu_mag: Starting sensor polling at ~10 Hz... IMU | Accel(g): X= +0.012 Y= -0.034 Z= +0.998 | Gyro(dps): X= +0.12 Y= -0.05 Z= +0.01 | T=27.5°C MAG | Field(gauss): X= +0.123 Y= -0.241 Z= +0.402 ```
To create a project from this example, run:
idf.py create-project-from-example "cube32esp/cube32_bsp=0.0.17:hello_imu_mag"