The best IDE for embedded development — Get temperature and humidity sensor data case

The best IDE for embedded development -- Get temperature and humidity sensor data case

Preparatory work


IDE: RT-Thread Studio



Temperature Humidity Sensor: SHT30

Communication module: ESP8266(WIFI)

Display module: 0.96’OLED(SSD1306)


  1. New RT-Thread Project

  1. Build Project

  1. Open the serial terminal

  1. Download

  1. Add I2C device

    5.1 Enable I2C Device Driver Framework

Double-click the RT-Thread Setting file on the left to open the RT-Thread graphical configuration tool. The software simulation I2C item is gray, indicating that it is not open. Click to open the software I2C driver framework, and the icon turns to color Means open

Right-click this option to open more configurations, such as viewing the dependency of the drive device, viewing the detailed configuration of the drive device, viewing the API document of the drive device, viewing online documents, etc.

Press Ctrl+S to save, the configuration will take effect, and the software will automatically add the I2C device driver framework to the project

5.2 Define Soft I2C Related Macros 

Define the related macros of soft I2C on the board.h file.

#define BSP_USING_I2C1 /* Use I2C1 Bus */

#define BSP_I2C1_SCL_PIN GET_PIN(C, 1) /* SCL -> PC1 */

#define BSP_I2C1_SDA_PIN GET_PIN(D, 6) /* SDA -> PD6 */

The above I2C bus related macros present that the SCL clock line of the I2C1 bus is connected to the PC1 pin and the SDA data cable is connected to the PD6 pin. If you need to use more than one I2C bus, please refer to the macro of I2C1 on the board.h file for more information about the relevant macro definition.

5.3 Use I2C Bus 

Compile and download the program, enter the list_devicecommand in the terminal you can observe that the I2C1 has been successfully registered in the system, as shown below:

  1. Add the SHT3x package

    6.1 Search add package

Next, press Ctrl+S to save the project, the software will automatically add the software package code to the project, where is the detailed documentation of the software package, you must read it before use

6.2 Test the package with commands 

Most software packages provide test commands, and the SHT3x software package is the same. The following commands are provided for testing

1- sht3x probe <i2c_dev_name> <pu/pd>-To mount SHT3x devices, you need to specify the i2c device name and the pull-up and pull-down method, the default pull-down

2- sht3x read--read SHT3x temperature and humidity

3- sht3x status--Read and view the status register value

4- sht3x reset--software reset SHT3x

5- sht3x heater <on/off>--Turn on/off heater

7. Obtain temperature and humidity sensor data

First mount the SHT30 temperature and humidity sensor to the previously registered I2C bus device:

After mounting, you can view the registers, read the temperature and humidity, reset, and turn on/off the heater, such as reading the temperature and humidity once:

  1. Obtain temperature and humidity sensor data

7.1 After successfully testing the device using the commands provided by the software package, create a thread to obtain SHT3x data using the API provided by the SHT3x software package.

Under the Applicaition group, create a new file sht30_ccollect.c to store the relevant code for SHT3x to obtain data, edit the following


* Copyright (c) 2006-2019, RT-Thread Development Team


* SPDX-License-Identifier: Apache-2.0


* Change Logs:

* Date Author Notes

* 2020-02-20 Mculover666 the first version


#include <rtthread.h>

#include <board.h>

#include <sht3x.h>




static rt_thread_ttid1 = RT_NULL;

/* Entry function*/

static void sht30_collect_thread_entry(void *parameter)

twenty three{

sht3x_device_t sht3x_device;

sht3x_device = sht3x_init(“i2c1”, 0x44);

while (1)




rt_kprintf(“sht30 humidity: %d.%d”, (int)sht3x_device->humidity, (int)(sht3x_device->humidity* 10)% 10);

rt_kprintf(“temperature:%d.%dn”, (int)sht3x_device->temperature, (int)(sht3x_device->temperature* 10)% 10);




rt_kprintf(“read sht3x fail.rn”);






/* Create thread*/

int sht30_collect(void)


/* Create thread*/

tid1 = rt_thread_create(“sht30_collect_thread”,

sht30_collect_thread_entry, RT_NULL,



/* If you get the thread control block, start this thread*/

if (tid1!= RT_NULL)


return 0;


Test the program in main.c:



It’s great, I completed this case almost without writing any code, Do you like it ?

You can get RT-Thread Studio from this address:

Btw, What IDE do you all use? Welcome to leave a message.

submitted by /u/Peter909098
[link] [comments]

Original article: The best IDE for embedded development — Get temperature and humidity sensor data case
Author: /u/Peter909098