Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
ART-Pi
LittlevGL_LVGL
AHT10
Art_Pi学习笔记8:使用AHT10温湿度模块
发布于 2021-02-04 15:48:52 浏览:3650
订阅该版
开发环境: rt-thread studio 开发板: Art-Pi 参考链接: RT-Thread Studio入门(6)— 采集温湿度数据_Willliam_william的博客-CSDN博客 https://blog.csdn.net/qq_38113006/article/details/105349975 基于潘多拉开发使用rt-thread studio 开发使用软件包AHT10遇到.... - RT-Thread问答社区 https://club.rt-thread.org/ask/question/424593.html AHT10 - 立创EDA开源硬件平台 https://oshwhub.com/chenzhy/AHT10 Art-Pi上没有温湿度监控的传感器,需要自己添加,于是近日从某宝上购得AHT10温湿度模块,于是乎接到Art-Pi上体验一番,无奈中间还是有少许曲折。经过摸索,最终还是能成功驱动,再此记录一贴,方便小伙伴们查阅。 硬件连接上,借用了多媒体扩展版的触摸接口I2C2。为什么选用这个I2C接口呢,一方面因为自从有了RGB屏之后,多媒体扩展屏就一直吃灰状态,这个接口暂时不需要使用到;另一方面是这个接口之前在调试多媒体扩展屏的时候使用过,知根知底。说到底,就是懒。   由于使用的是AHT10模块,而不是芯片,模块上集成了3.3V的LDO,因此供电上从5V拉电过来用,而不是从3.3V拉电过来用。如果是没有LDO的情况下,则必须从3.3V拉电,因为AHT10的最大供电电压是3.6V。 完成了硬件连接之后就是软件配置了。这里参考了上面大佬的文章之后,自己做了一番摸索。配置如下: 首先是添加AHT10的软件包,使能模拟I2C组件。  详细的配置如下: 这里的aht10配置上我选用最新版本的软件包,而且没有使能软件滤波功能。  硬件上使能I2C2,并且配置引脚,这里保持默认配置不改动  组件上使能I2C设备驱动  保存配置,退出settings,然后编译下载。 在调试终端中list_device命令,可以看到i2c1和i2c2已经注册成功了。  接下来参考大佬的贴子,为程序添加aht10的使用代码。 首先是端口初始化  然后是温度采集线程入口函数  接下来是创建线程  完成之后编译通过烧录到art-pi上,居然不行!  明明是已经初始化成功了啊,怎么会读取不到数据呢?再次用list_device查看一下设备。确实是有注册到设备啊,百思不得其解。  通过仔细检查一番,原来是SDA和SCL引脚接错了。把线调整好,重新上电,搞定,走你!  然后再把数据显示到lvgl上,perfect!   下面是代码,第一次在贴子中贴代码。 // 使用AHT10范例 #include "sensor_asair_aht10.h" #define AHT10_I2C_BUS "i2c2" // AHT10端口初始化 int rt_hw_aht10_port(void) { struct rt_sensor_config cfg; cfg.intf.dev_name = AHT10_I2C_BUS; cfg.intf.user_data = (void *)AHT10_I2C_ADDR; rt_hw_aht10_init("aht10", &cfg); return RT_EOK; } // AHT10温湿度采集 #include "aht10.h" /* 定义一个温湿度采集线程句柄结构体指针 */ static rt_thread_t aht10_thread = RT_NULL; float humidity, temperature; /* 温湿度采集线程入口函数*/ static void aht10_thread_entry(void *parameter) { rt_err_t res; aht10_device_t dev; rt_hw_aht10_port(); dev = aht10_init(AHT10_I2C_BUS); if (dev == RT_NULL) { rt_kprintf(" The sensor initializes failure"); return 0; } else { rt_kprintf(" The sensor initializes ok!"); } while (1) { /* read humidity 采集湿度 */ humidity = aht10_read_humidity(dev); rt_kprintf("humidity : %d.%d %%\n", (int)humidity, (int) (humidity * 10) % 10); /* former is integer and behind is decimal */ /* read temperature 采集温度 */ temperature = aht10_read_temperature(dev); rt_kprintf("temperature: %d.%d \n", (int)temperature, (int)(temperature * 10) % 10); /* former is integer and behind is decimal */ rt_thread_mdelay(60000); } } static int app_aht10_init(void) { rt_err_t rt_err; /* 创建温湿度采集线程*/ aht10_thread = rt_thread_create("aht10 thread", /* 线程的名称 */ aht10_thread_entry, /* 线程入口函数 */ RT_NULL, /* 线程入口函数的参数 */ 1024, /* 线程栈大小,单位是字节 */ 25, /* 线程的优先级,数值越小优先级越高*/ 10); /* 线程的时间片大小 */ /* 如果获得线程控制块,启动这个线程 */ if (aht10_thread != RT_NULL) rt_err = rt_thread_startup(aht10_thread); else rt_kprintf("aht10 thread create failure !!! \n"); /* 判断线程是否创建成功 */ if( rt_err != RT_EOK) rt_kprintf("aht10 thread startup err. \n"); return RT_EOK; } INIT_APP_EXPORT(app_aht10_init);
6
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
adaphoto
这家伙很懒,什么也没写!
文章
25
回答
44
被采纳
5
关注TA
发私信
相关文章
1
LittlevGL + DMA2D 显示图案扭曲
2
LittleVGL2RTT软件包还有在维护吗,测试遇到一些问题求解
3
使用littlevgl2rtt软件包实例运行不成功,emwin正常
4
关于littlevgl2rtt软件包刷频慢的解决方案?
5
移植了littlevGUI之后,用动态 线程去跑例程会卡死
6
lvgl的字体、图片文件如何升级?
7
qemu-vexpress-a9bsp下的littvgl工程可以实现触屏操作吗?
8
LVGL控件刷新死机问题
9
在lvgl上设置一个时间显示的label,一段时间后所有控件消失。
10
littlevgl2rtt和littlevgl的pc模拟器源码不兼容吗?
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
I2C_IIC
UART
ESP8266
cubemx
WIZnet_W5500
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
编译报错
socket
中断
Debug
rt_mq_消息队列_msg_queue
keil_MDK
ulog
SFUD
msh
C++_cpp
MicroPython
本月问答贡献
RTT_逍遥
10
个答案
3
次被采纳
xiaorui
3
个答案
3
次被采纳
踩姑娘的小蘑菇
6
个答案
2
次被采纳
winfeng
2
个答案
2
次被采纳
三世执戟
8
个答案
1
次被采纳
本月文章贡献
catcatbing
3
篇文章
5
次点赞
lizimu
2
篇文章
9
次点赞
jinchanchan
2
篇文章
2
次点赞
alight
1
篇文章
5
次点赞
swet123
1
篇文章
4
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部