OrangePi PC2 H5 驱动GPIO利用DTH11获取温湿度
发布日期:2021-08-22 06:43:27
浏览次数:2
分类:技术文章
本文共 5259 字,大约阅读时间需要 17 分钟。
- 去OrangePi官网寻找了一会还是没找到H5 GPIO(PC2)驱动的方法,但是在Armbian一位朋友帮忙编译最新的4.10 pc2 系统的时候发现了H5 的GPIO选项,我在GitHub寻找了一会发现还是H3的GPIO启动很多,没找到H5的GPIO驱动,但是目前解决了驱动,但是支持C语言的支持,还没有找到GPIO for python的版本,估计不久就会有大神移植了。
编译GPIO的H5的驱动
git clone https://github.com/kazukioishi/WiringOP.git -b h5cd WiringOPchmod +x ./buildsudo ./build
GPIO 打印信息
# gpio -vgpio version: 2.20Copyright (c) 2012-2014 Gordon HendersonThis is free software with ABSOLUTELY NO WARRANTY.For details type: gpio -warrantyBanana Pro Details: Type: Banana Pro, Revision: 1.2, Memory: 1024MB, Maker: LeMaker
显示
[hang@PC2]$ gpio readall +-----+-----+----------+------+---+-Orange Pi+---+---+------+---------+-----+--+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+ | | | 3.3v | | | 1 || 2 | | | 5v | | | | 12 | 8 | SDA.0 | ALT5 | 0 | 3 || 4 | | | 5V | | | | 11 | 9 | SCL.0 | ALT5 | 0 | 5 || 6 | | | 0v | | | | 6 | 7 | GPIO.7 | ALT3 | 0 | 7 || 8 | 0 | ALT5 | TxD3 | 15 | 13 | | | | 0v | | | 9 || 10 | 0 | ALT5 | RxD3 | 16 | 14 | | 1 | 0 | RxD2 | ALT5 | 0 | 11 || 12 | 0 | ALT3 | GPIO.1 | 1 | 110 | | 0 | 2 | TxD2 | ALT5 | 0 | 13 || 14 | | | 0v | | | | 3 | 3 | CTS2 | ALT5 | 0 | 15 || 16 | 0 | ALT3 | GPIO.4 | 4 | 68 | | | | 3.3v | | | 17 || 18 | 0 | ALT3 | GPIO.5 | 5 | 71 | | 64 | 12 | MOSI | ALT4 | 0 | 19 || 20 | | | 0v | | | | 65 | 13 | MISO | ALT0 | 0 | 21 || 22 | 0 | ALT5 | RTS2 | 6 | 2 | | 66 | 14 | SCLK | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE0 | 10 | 67 | | | | 0v | | | 25 || 26 | 0 | ALT3 | GPIO.11 | 11 | 21 | | 19 | 30 | SDA.1 | ALT4 | 0 | 27 || 28 | 0 | ALT4 | SCL.1 | 31 | 18 | | 7 | 21 | GPIO.21 | ALT3 | 0 | 29 || 30 | | | 0v | | | | 8 | 22 | GPIO.22 | ALT3 | 0 | 31 || 32 | 0 | ALT5 | RTS1 | 26 | 200 | | 9 | 23 | GPIO.23 | ALT3 | 0 | 33 || 34 | | | 0v | | | | 10 | 24 | GPIO.24 | ALT3 | 0 | 35 || 36 | 0 | ALT5 | CTS1 | 27 | 201 | | 20 | 25 | GPIO.25 | OUT | 1 | 37 || 38 | 0 | ALT5 | TxD1 | 28 | 198 | | | | 0v | | | 39 || 40 | 0 | ALT5 | RxD1 | 29 | 199 | +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+----------+------+---+-Orange Pi+---+------+----------+-----+-----+
DTH11 代码
/* * dht11.c: * Simple test program to test the wiringPi functions * DHT11 test */#include#include #include #include #define MAXTIMINGS 85#define DHTPIN 7int dht11_dat[5] = { 0, 0, 0, 0, 0 };void read_dht11_dat() { uint8_t laststate = HIGH; uint8_t counter = 0; uint8_t j = 0, i; float f; /* fahrenheit */ dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = 0; /* pull pin down for 18 milliseconds */ pinMode( DHTPIN, OUTPUT ); digitalWrite( DHTPIN, LOW ); delay( 18 ); /* then pull it up for 40 microseconds */ digitalWrite( DHTPIN, HIGH ); delayMicroseconds( 40 ); /* prepare to read the pin */ pinMode( DHTPIN, INPUT ); /* detect change and read data */ for ( i = 0; i < MAXTIMINGS; i++ ) { counter = 0; while ( digitalRead( DHTPIN ) == laststate ) { counter++; delayMicroseconds( 1 ); if ( counter == 255 ) { break; } } laststate = digitalRead( DHTPIN ); if ( counter == 255 ) break; /* ignore first 3 transitions */ if ( (i >= 4) && (i % 2 == 0) ) { /* shove each bit into the storage bytes */ dht11_dat[j / 8] <<= 1; if ( counter > 16 ) dht11_dat[j / 8] |= 1; j++; } } /* * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte * print it out if data is good */ if ( (j >= 40) && (dht11_dat[4] == ( (dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF) ) ) { f = dht11_dat[2] * 9. / 5. + 32; printf( "Humidity = %d.%d %% Temperature = %d.%d *C (%.1f *F)\n", dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3], f ); } else { printf( "Data not good, skip\n" ); }}int main( void ) { printf( "Raspberry Pi wiringPi DHT11 Temperature test program\n" ); if ( wiringPiSetup() == -1 ) exit( 1 ); while ( 1 ) { read_dht11_dat(); delay( 1000 ); /* wait 1sec to refresh */ } return(0);}
编译并设置环境变量
# 编译 dth11.cgcc -Wall -o dht11 dht11.c -lwiringPi -lpthread# 设置环境变量export WIRINGPI_DEBUG=TRUEunset WIRINGPI_DEBUG
运行结果
Raspberry Pi wiringPi DHT11 Temperature test programData not good, skipHumidity = 22.0 % Temperature = 23.0 *C (73.4 *F)Humidity = 22.0 % Temperature = 23.0 *C (73.4 *F)Data not good, skipData not good, skipHumidity = 22.0 % Temperature = 23.0 *C (73.4 *F)
转载地址:https://blog.csdn.net/weixin_33738555/article/details/89648657 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月07日 10时46分52秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【Leetcode刷题篇】leetcode4 寻找两个正序数组的中位数
2019-04-26
【Leetcode刷题篇】leetcode316 去除重复字母
2019-04-26
【Leetcode刷题篇】leetcode1081 不同字符的最小子序列
2019-04-26
【面试篇】Java网络编程与IO流体系
2019-04-26
【Leetcode刷题篇】leetcode84 柱状图中最大的矩形
2019-04-26
【Leetcode刷题篇】leetcode85 最大矩形
2019-04-26
【Leetcode刷题篇】leetcode124 二叉树中的最大路径和
2019-04-26
【Leetcode刷题篇】leetcode297 二叉树的序列化与反序列化
2019-04-26
【Leetcode刷题篇】leetcode301 删除无效的括号
2019-04-26
【Leetcode刷题篇】leetcode239 滑动窗口最大值
2019-04-26
【Leetcode刷题篇】leetcode76 最小覆盖子串
2019-04-26
【Leetcode刷题篇】leetcode10 正则表达式匹配
2019-04-26
【Leetcode刷题篇】leetcode32 最长有效括号
2019-04-26
【Leetcode刷题篇】leetcode128 最长连续序列
2019-04-26
【Leetcode刷题篇】leetcode72 编辑距离
2019-04-26
【Leetcode刷题篇】leetcode312 戳气球
2019-04-26
前后端分离如何使用spring boot处理跨域请求
2019-04-26
【Leetcode刷题篇】leetcode283 移动零
2019-04-26
【Leetcode刷题篇】leetcode611 有效三角形的个数
2021-06-29
【Leetcode刷题篇】leetcode26 删除排序数组中的重复项
2021-06-29