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

Software

IDE: RT-Thread Studio

https://preview.redd.it/uq71j38ry2761.png?width=599&format=png&auto=webp&s=9749da11807c9b033d10dd4c3f28ec3e3610a2da

Hardware

DSP: STM32L431RCT6

Temperature Humidity Sensor: SHT30

Communication module: ESP8266(WIFI)

Display module: 0.96’OLED(SSD1306)

Steps

  1. New RT-Thread Project

https://preview.redd.it/38bp6sdsy2761.png?width=612&format=png&auto=webp&s=caf0c87df99ef385b62f770cf4b7ce284d11360d

  1. Build Project

https://preview.redd.it/4zdj4rfty2761.png?width=434&format=png&auto=webp&s=0bd35da6b78aa2b0de59f61e30bb552de5826c5a

  1. Open the serial terminal

https://preview.redd.it/a7j2zhyty2761.png?width=548&format=png&auto=webp&s=9ced45c6c40757f8fb2c563c9997baf6777dad7b

https://preview.redd.it/yvaw9t6vy2761.png?width=881&format=png&auto=webp&s=806b839fded69ffb6b9eed7a9e0b9f0fd181a8d9

  1. Download

https://preview.redd.it/q6puh0mxy2761.png?width=442&format=png&auto=webp&s=aab7a7807ffadca25816bdb3c57f0a61f94d7fa0

  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

https://preview.redd.it/9zfw73ryy2761.png?width=1218&format=png&auto=webp&s=f182f72a52495614e92f2875c2c03c5db8210433

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.

https://preview.redd.it/tudr1zkzy2761.png?width=1283&format=png&auto=webp&s=53f893af1c3ee46565970282345840f1f66daf92

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:

https://preview.redd.it/hdhhoic2z2761.png?width=713&format=png&auto=webp&s=76b0566aa39c0c3d6f1597032f9014cae35750de

  1. Add the SHT3x package

    6.1 Search add package

https://preview.redd.it/dtnnaaj3z2761.png?width=1036&format=png&auto=webp&s=c3e27ea11561415ed95f1a3fce98cb046cbe7df4

https://preview.redd.it/nmtvt694z2761.png?width=1446&format=png&auto=webp&s=c1e7f708fc6fb6a485ac06dc0ce25c1a6975c0e7

https://preview.redd.it/rkg79qd5z2761.png?width=703&format=png&auto=webp&s=f3626b9e3dacbd8059e43d7b89b7ea4b6e0f6bf4

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

https://preview.redd.it/6wj0w0a6z2761.png?width=325&format=png&auto=webp&s=51719f721a1acb2aed6eed15515b399fe4a2699c

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:

https://preview.redd.it/ziyrua4az2761.png?width=399&format=png&auto=webp&s=854e62310770abb32a48dd8fcebf969976fe1077

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:

https://preview.redd.it/1nklmoraz2761.png?width=470&format=png&auto=webp&s=1a2cd2c1fa463ccae7a673d27d8ad2433cc5d900

  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>

#define THREAD_PRIORITY 25

#define THREAD_STACK_SIZE 512

#define THREAD_TIMESLICE 5

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)

{

if(RT_EOK==sht3x_read_singleshot(sht3x_device))

{

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);

}

else

{

rt_kprintf(“read sht3x fail.rn”);

break;

}

rt_thread_mdelay(2000);

}

}

/* Create thread*/

int sht30_collect(void)

{

/* Create thread*/

tid1 = rt_thread_create(“sht30_collect_thread”,

sht30_collect_thread_entry, RT_NULL,

THREAD_STACK_SIZE,

THREAD_PRIORITY, THREAD_TIMESLICE);

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

if (tid1!= RT_NULL)

rt_thread_startup(tid1);

return 0;

}

Test the program in main.c:

https://preview.redd.it/ghg0s4sbz2761.png?width=412&format=png&auto=webp&s=04e6bcc55956065bb2d68234c75ea950f8326358

result

End

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: https://www.rt-thread.io/download.html?download=Studio

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