[评测分享]
【更适合初学者的开发板ELF 1】+ AHT20温湿度传感器数据读取
#板卡评测
2006 人阅读
|
0 人回复
|
2023-12-12
TA的每日心情 | 开心 2025-9-22 14:25 |
|---|
签到天数: 1085 天 连续签到: 1 天 [LV.10]以坛为家III
版主
- 积分
- 20953
|
测试下AHT20温湿度传感器读取。
一、硬件部分
1.1、AHT20传感器部分电路图
1.2、MPU连接位置
1.3、使用i2c-tools软件检测下设备
在i2c-0总线上找到AHT20设备。
二、软件部分
2.1、AHT20设备驱动
开发板软件中已经做好AHT20设备驱动,查看下设备
2.2、驱动程序
elf1_cmd_aht20.c
- #include "stdio.h"
- #include "unistd.h"
- #include "sys/types.h"
- #include "sys/stat.h"
- #include "sys/ioctl.h"
- #include "fcntl.h"
- #include "stdlib.h"
- #include "string.h"
- #include <poll.h>
- #include <sys/select.h>
- #include <sys/time.h>
- #include <signal.h>
- #include <fcntl.h>
- #define AHT20_DEV "/dev/aht20"
- int main(int argc, char *argv[])
- {
- int fd;
- unsigned int databuf[2];
- int c1,t1;
- float hum,temp;
- int ret = 0;
-
- fd = open(AHT20_DEV, O_RDWR);
- if(fd < 0) {
- printf("can't open file %s\r\n", AHT20_DEV);
- return -1;
- }
-
- while (1) {
- ret = read(fd, databuf, sizeof(databuf));
- if(ret == 0) { /* ?????? */
-
- c1 = databuf[0]*1000/1024/1024; //
- t1 = databuf[1] *200*10/1024/1024-500;
- hum = (float)c1/10.0;
- temp = (float)t1/10.0;
- printf("hum = %0.2f temp = %0.2f \r\n",hum,temp);
- usleep(500000);
- }
- }
- close(fd);
- return 0;
- }
复制代码
2.3、使能编译工具
2.4、编译应用程序
2.5、复制程序到开发板
执行命令:scp elf1_cmd_aht20 root@192.168.1.107:/mnt
三、测试
在开发板上运行./elf1_cmd_aht20
在AHT20附近放置高温热源,检测到的温度数据发生较大变化。
|
|
|
|
|
|
|
|
|