当前位置:网站首页>RT based_ Distributed wireless temperature monitoring system of thread (I)
RT based_ Distributed wireless temperature monitoring system of thread (I)
2022-07-28 04:53:00 【The endeavor】
today , Teach you how to pass RT_thread studio Transplant code to realize temperature data acquisition
The first step is to create a project
I'm using STM32ZET6 Development board ( In fact, any development board is the same ) Just support BSP Development That is to say ;
Mode configuration 
Set configuration , And save “Ctrl+S”
The second step is code migration
Open from RT_thread in github Downloaded routines . If you can't find it , You can download... From here
be based on RT_thread Distributed temperature acquisition system
After downloading , Find these two files 
Then copy the file to the newly created RT_thread studio Created Demo in
Notice here , Put two files in driver In the folder of 
I haven't tried other directories , however , I put it in this directory according to the routine ;
Click sync inside the project :
In this folder , Right click , Click on Sync scons Configure this item You can add the just two folders to the project ;
Third code addition
stay main Add this code to complete the code work of the first week ;
/* * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2022-05-30 RT-Thread first version */
#include <rtthread.h>
#include "board.h"
#include <stdlib.h>
#include <rtdevice.h>
#include <sensor.h>
#include "sensor_dallas_ds18b20.h"
#include <rtdbg.h>
#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
//#define LED0_PIN GET_PIN(F, 0)
#define DS18B20_DATA_PIN GET_PIN(G, 9)
static void read_temp_entry(void *parameter)
{
rt_device_t dev = RT_NULL;
struct rt_sensor_data sensor_data;
rt_size_t res;
dev = rt_device_find(parameter);
if (dev == RT_NULL)
{
rt_kprintf("Can't find device:%s\n", parameter);
return;
}
if (rt_device_open(dev, RT_DEVICE_FLAG_RDWR) != RT_EOK)
{
rt_kprintf("open device failed!\n");
return;
}
rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)100);
while (1)
{
res = rt_device_read(dev, 0, &sensor_data, 1);
if (res != 1)
{
rt_kprintf("read data failed!size is %d\n", res);
rt_device_close(dev);
return;
}
else
{
if (sensor_data.data.temp > 0)
{
rt_kprintf("temp:%3d.%dC, timestamp:%5d\n",
sensor_data.data.temp / 10,
sensor_data.data.temp % 10,
sensor_data.timestamp);
}
else
{
rt_kprintf("temp:-%2d.%dC, timestamp:%5d\n",
abs(sensor_data.data.temp) / 10,
abs(sensor_data.data.temp) % 10,
sensor_data.timestamp);
}
}
rt_thread_mdelay(100);
}
}
int main(void)
{
rt_thread_t ds18b20_thread;
ds18b20_thread = rt_thread_create("18b20tem", read_temp_entry, "temp_ds18b20",
640, RT_THREAD_PRIORITY_MAX / 2, 20);
if (ds18b20_thread != RT_NULL)
{
rt_thread_startup(ds18b20_thread);
}
return RT_EOK;
}
static int rt_hw_ds18b20_port(void)
{
struct rt_sensor_config cfg;
cfg.intf.user_data = (void *)DS18B20_DATA_PIN;
rt_hw_ds18b20_init("ds18b20", &cfg);
return RT_EOK;
}
INIT_ENV_EXPORT(rt_hw_ds18b20_port);
Fourth Compile and debug download

5、 ... and 、 Result demonstration


This is the whole process of this routine , I write while reading , So we need to understand ha !
边栏推荐
- gerrit操作-回退掉某个patch_set
- Special topic of APP performance design and Optimization - poor implementation affecting performance
- Rendering process, how the code becomes a page (2)
- Basic knowledge of network security - password (I)
- (clone virtual machine steps)
- 【sylar】框架篇-Chapter20-守护进程模块
- Artificial intelligence and RPA technology application (I) -rpa Hongji product introduction, designer interface function explanation
- 01 node express system framework construction (express generator)
- 解析智能扫地机器人中蕴含的情感元素
- Use animatedbuilder to separate components and animation, and realize dynamic reuse
猜你喜欢

CPU and memory usage are too high. How to modify RTSP round robin detection parameters to reduce server consumption?

Testcafe provides automatic waiting mechanism and live operation mode

动态sql和分页

excel实战应用案例100讲(十一)-Excel插入图片小技巧

Destructor of member function

How to quickly locate bugs? How to write test cases?

Mac installs mysql5.7 through brew

What SaaS architecture design do you need to know?
![[每日一氵]上古年代的 Visual Studio2015 安装](/img/b1/066ed0b9e93b8f378c89ee974163e5.png)
[每日一氵]上古年代的 Visual Studio2015 安装

Is low code the future of development? On low code platform
随机推荐
Phpstorm2022 connect to the database
Take out system file upload
网络安全基本知识——密码(一)
If mongoose exists, it will be updated; if it does not exist, it will be added
Leetcode 15. sum of three numbers
启发国内学子学习少儿机器人编程教育
Look at the experience of n-year software testing summarized by people who came over the test
物联网工业串口转WiFi模块 无线路由WiFi模块的选型
What is the reason why the easycvr national standard protocol access equipment is online but the channel is not online?
Jupyter Notebook安装代码提示功能
Improving the readability of UI layer test with puppeter
Geely AI interview question [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
scipy.stats.chi2
猿辅导技术进化论:助力教与学 构想未来学校
Blooming old trees -- quickly build a map bed application with imageprocessor
pytorch打包exe出现WARNING: file already exists but should not: C:\Users\workAI\AppData\Local\Temp\_MEI13
What should testers know about login security?
Leetcode 454. Adding four numbers II
X Book Keyword Search
Observable time series data downsampling practice in Prometheus