Main Content

Read Data from I2C-Based Sensors on STM32L475VG Discovery Board

This example shows how to use the Embedded Coder® Support Package for STMicroelectronics® STM32 Processors to configure and read data from these sensors on the STM32L475VG Discovery (B-L475E-IOT01A) board:

  • LPS22HB MEMS nano pressure sensor.

  • LSM6DSL 3D accelerometer and 3D gyroscope.

  • LIS3MDL digital output magnetic sensor.

  • HTS221 capacitive digital sensor for relative humidity and temperature.

The sensors are interfaced with the STM32L475VG Discovery (B-L475E-IOT01A) board using an I2C bus (module 2).

This example shows how to program the STM32L475VG Discovery (B-L475E-IOT01A) board to read data from these sensors and display the data using external mode.

Available Models

The example includes these target models:

These models are pre-configured for the STMicroelectronics® STM32L475VG Discovery (B-L475E-IOT01A) board.

Prerequisites

Complete the Getting Started with Embedded Coder Support Package for STMicroelectronics Discovery Boards example.

Required Hardware

To run this example you need the following hardware:

  • USB cable

Configure Models to Read Sensor Data from Blocks

In this task, you will configure the target models to read data from the sensors on the STM32L475VG Discovery (B-L475E-IOT01A) board.

Configure LPS22HB MEMS Nano Pressure Sensor

1. Open the stm32l475vg_pressure_sensor target model.

2. Configure the LPS22HB Pressure Sensor block done for this model. Double-click on the block to open block parameter configurations.

For more details, see the LPS22HB and B-L475E-IOT01A datasheets.

Configure LSM6DSL 3D accelerometer and 3D gyroscope

1. Open the stm32l475vg_accel_gyro_sensor target model.

2. Configure the LSM6DSL IMU Sensor block done for this model. Double-click on the block to open block parameter configurations.

For more details, see the LSM6DSL and B-L475E-IOT01A datasheets.

Configure LIS3MDL digital output magnetic sensor

1. Open the stm32l475vg_magnetometer_sensor target model.

2. Configure the LIS3MDL Magnetometer Sensor block done for this model. Double-click on the block to open block parameter configurations.

For more details, see the LIS3MDL and B-L475E-IOT01A datasheets.

Configure HTS221 capacitive digital sensor for relative humidity and temperature

1. Open the stm32l475vg_humidity_temperature_sensor target model.

2. Configure the LIS3MDL Magnetometer Sensor block done for this model. Double-click on the block to open block parameter configurations.

For more details, see the HTS221 and B-L475E-IOT01A datasheets.

Configure Hardware and Model for Monitoring and Tuning

In this task, you will configure the hardware and monitor the sensor data obtained by the target model.

1. In the Modeling tab, click Model Settings or press Ctrl+E to open the Configuration Parameters dialog box.

2. Navigate to Hardware Implementation > Target hardware resources > External mode > COM Port and enter the COM port of the serial interface on Windows.

3. Open the Hardware tab and click Monitor & Tune.

4. The Display blocks in the target model display the sensor output.

5. Click the Stop button in the Hardware tab to end the Monitor and Tune execution.

See Also

Exchanging WiFi Data and Using ThingSpeak with STM32L475VG Discovery Board