当前位置:网站首页>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 !
边栏推荐
- Alibaba interview question [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
- Installing MySQL under Linux
- If mongoose exists, it will be updated; if it does not exist, it will be added
- Geely AI interview question [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
- 【sylar】框架篇-Chapter7-IO 协程调度模块
- Redux basic syntax
- Improve the core quality of steam education among students
- Program life | how to switch to software testing? (software testing learning roadmap attached)
- bubble sort
- Attempt method in laravel user authentication
猜你喜欢

could only be written to 0 of the 1 minReplication nodes. There are 0 datanode(s) running and 0 node

Interview fraud: there are companies that make money from interviews

031 log4j log framework

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

Use animatedbuilder to separate components and animation, and realize dynamic reuse

Service object creation and use

Automated test tool playwright (quick start)

Mysql database -- first knowledge database

What is the core value of testing?

Redux basic syntax
随机推荐
数据库故障容错之系统时钟故障
Depth traversal and breadth traversal of tree structure in JS
Take out system file upload
Redis type
excel实战应用案例100讲(十一)-Excel插入图片小技巧
Is low code the future of development? On low code platform
The go zero singleton service uses generics to simplify the registration of handler routes
Introduction to testcafe
Chuangyuan will join hands with 50+ cloud native enterprises to explore new models to cross the digital divide
Analyze the emotional elements contained in intelligent sweeping robot
Select sorting method
NAT基本原理与私有IP
Nat fundamentals and private IP
(2.4) [service Trojan -slimftp] introduction and use
你必需要了解的saas架构设计?
Cmake usage base summary
[II. Mobile web page development] 2D & 3D conversion and animation, mobile terminal layout, responsive layout
[function document] torch Histc and paddle Histogram and numpy.histogram
Redux basic syntax
阿里巴巴面试题【杭州多测师】【杭州多测师_王sir】