Skip to content

stm32-hotspot/stm32cubemx2_sht40ad1b_datalog_i2c

Repository files navigation

Example: sht40ad1b_datalog_i2c

How to use part SHT40AD1B API. It illustrates it by getting the values of the temperature (in celsius) and humidity (in %) and displaying them on a terminal.

1. Detailed scenario

Initialization phase: At the beginning of the main() function, the mx_system_init() function is called to initialize the peripherals.

The application executes the following example steps:

Step 1: Initializes and enables temperature and humidity features of SHT40AD1B

Step 2: Gets the values of the temperature (in celsius) and the humidity (in %) and displays them on a terminal

End of example: It is an endless example that loops infinitely on step 2

You can follow these execution steps in the terminal logs:

[INFO] Step 1: SHT40AD1B sensor init completed
[INFO] Step 2: TEMP 31 degC
[INFO] Step 2: HUM 46 %
[INFO] Step 2: TEMP 31 degC
[INFO] Step 2: HUM 46 %

2. Example configuration

This example demonstrates the following driver:

  • Part sht40ad1b.c/.h
  • Part sht40ad1b/interfaces/i2c/sht40ad1b_io.c/.h

In this example, the SHT40AD1B component is configured through the I2C IO operations defined under the folder "interfaces/i2c." Once the I2C is initialized, the SHT40AD1B can be initialized too through the call of sht40ad1b_drv_init() API. After this step, the MEMS sensor will be ready to provide the values of the temperature and humidity.

3. Hardware environment and setup

3.1. Generic Setup

This section describes the hardware setup principles that apply to any board.

3.2. Specific board setups

On STM32C5 series. On board NUCLEO-C562RE.
Board connector MCU pin Signal name ARDUINO
connector pin
CN5-10 PB6 I2C1_SCL ARDUINO CONNECTOR - D15
CN5-9 PB7 I2C1_SDA ARDUINO CONNECTOR - D14

4. Software setup

To create a functional project, complete the following steps:

  • Select the appropriate IoC2 file based on the combination of NUCLEO and X-NUCLEO boards. For example, use c562re_iks4a1_sht40ad1b_datalog_i2c.ioc2 for NUCLEO-C562RE and X-NUCLEO-IKS4A1.

  • Open the IoC2 file with STM32CubeMX2.

  • Select the preferred toolchain and generate the source code.

  • Copy the main.c, main.h, example.c, and example.h files into the project folder of the generated code.

  • Open the Integrated Development Environment (IDE), add the example.c and example.h files to the project.

  • Add the USE_TRACE=1 to the global variables of the project.

  • Compile the project.

5. Troubleshooting

No specific debug tips.

6. See Also

More information about SHT40AD1B part driver can be found in the SHT40AD1B Part Driver

More information about the STM32 ecosystem can be found in the STM32 MCU Developer Zone.

7. License

Copyright (c) 2026 STMicroelectronics.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

About

Example of usage of ST components and middlewares with STM32CubeMX2

Resources

License

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages