当前位置:网站首页>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 !
边栏推荐
- CPU and memory usage are too high. How to modify RTSP round robin detection parameters to reduce server consumption?
- [function document] torch Histc and paddle Histogram and numpy.histogram
- Rendering process, how the code becomes a page (I)
- pytorch打包exe出现WARNING: file already exists but should not: C:\Users\workAI\AppData\Local\Temp\_MEI13
- Use and expansion of fault tolerance and fusing
- NAT基本原理与私有IP
- 猿辅导技术进化论:助力教与学 构想未来学校
- MySQL partition table transformation
- How to upgrade a pair of 12.2 RAC(primary) and a pair of 12.2 RAC(dataguard) to 19c
- 【sylar】框架篇-Chapter6-协程调度模块
猜你喜欢

After easycvr is connected to the national standard equipment, how to solve the problem that the equipment video cannot be played completely?

With a monthly salary of 15.5K, he failed to start a business and was heavily in debt. How did he reverse the trend through software testing?

The go zero singleton service uses generics to simplify the registration of handler routes

How to upgrade a pair of 12.2 RAC(primary) and a pair of 12.2 RAC(dataguard) to 19c

go-zero单体服务使用泛型简化注册Handler路由

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

MySQL数据库————初识数据库

字符串0123456789abcdef,子串(非空且非同串本身)的个数是多少【杭州多测师】【杭州多测师_王sir】...

(克隆虚拟机步骤)

Jupyter notebook installation code prompt function
随机推荐
【sylar】框架篇-Chapter7-IO 协程调度模块
Histogram of pyplot module of Matplotlib (hist(): basic parameter, return value)
set与list性能对比
[Sylar] framework -chapter15 stream module
Destructor of member function
Constructor of member function
Rendering process, how the code becomes a page (I)
Attempt method in laravel user authentication
pytorch打包exe出现WARNING: file already exists but should not: C:\Users\workAI\AppData\Local\Temp\_MEI13
Introduction to this pointer
提升学生群体中的STEAM教育核心素养
机器人教育在STEM课程中的设计研究
[每日一氵]上古年代的 Visual Studio2015 安装
Special topic of APP performance design and Optimization - poor implementation affecting performance
Real intelligence has been certified by two of the world's top market research institutions and has entered the global camp of excellence
字符串0123456789abcdef,子串(非空且非同串本身)的个数是多少【杭州多测师】【杭州多测师_王sir】...
Research on the design of robot education in stem course
Jupyter Notebook安装代码提示功能
(clone virtual machine steps)
低代码是开发的未来吗?浅谈低代码平台