完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
回帖奖励 +1 分积分
看在没有积分奖励的份上发你一个吧。
# -*- coding: utf-8 -*- """ Created on Sun Jan 26 14:24:43 2014 @author: pi """ import RPi.GPIO as gpio import time gpio.setwarnings(False) gpio.setmode(gpio.BOARD) time.sleep(1) data=[] def delay(i): #20*i usdelay a=0 for j in range(i): a+1 j=0 #start work gpio.setup(12,gpio.OUT) #gpio.output(12,gpio.HIGH) #delay(10) gpio.output(12,gpio.LOW) time.sleep(0.02) gpio.output(12,gpio.HIGH) i=1 i=1 #wait to response gpio.setup(12,gpio.IN) while gpio.input(12)==1: continue while gpio.input(12)==0: continue while gpio.input(12)==1: continue #get data while j<40: k=0 while gpio.input(12)==0: continue while gpio.input(12)==1: k+=1 if k>100:break if k<3: data.append(0) else: data.append(1) j+=1 print "Sensor is working" #get temperature humidity_bit=data[0:8] humidity_point_bit=data[8:16] temperature_bit=data[16:24] temperature_point_bit=data[24:32] check_bit=data[32:40] humidity=0 humidity_point=0 temperature=0 temperature_point=0 check=0 for i in range(8): humidity+=humidity_bit[i]*2**(7-i) humidity_point+=humidity_point_bit[i]*2**(7-i) temperature+=temperature_bit[i]*2**(7-i) temperature_point+=temperature_point_bit[i]*2**(7-i) check+=check_bit[i]*2**(7-i) tmp=humidity+humidity_point+temperature+temperature_point if check==tmp: print "temperature is ", temperature,"wet is ",humidity,"%" else: print "something is worong the humidity,humidity_point,temperature,temperature_point,check is",humidity,humidity_point,temperature,temperature_point,check |
|
|
|
回帖奖励 +1 分积分
LCD Arduino
PIN1 = GND PIN2 = 5V RS(CS) = 8; RW(SID)= 9; EN(CLK) = 3; PIN15 PSB = GND; */ #include #include #include #define ONE_WIRE_BUS 2 #include "LCD12864RSPI.h" #define AR_SIZE( a ) sizeof( a ) / sizeof( a[0] ) OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); char str[4]; //定义温度值存储数组,4位,其中3位为数字,1位为小数点 double temp =0; //定义中间变量,用于将获取的float型温度值转变为unsigned char数组 unsigned char show[]={ 0xB5,0xB1,0xC7,0xB0,0xBB,0xB7,0xBE,0xB3,0xCE,0xC2,0xB6,0xC8};//当前环境温度 int numberOfDevices; void setup() { Serial.begin(9600); sensors.begin(); //传感器初始化 numberOfDevices = sensors.getDeviceCount(); LCDA.Initialise(); // 屏幕初始化 LCDA.DisplayString(0,0,show,AR_SIZE(show));//第一行第1格开始,显示文字“当前环境温度” } void loop() { sensors.requestTemperatures(); //获取温度值 for(int i=0;i temp=sensors.getTempCByIndex(i); //使用索引序号获得摄氏度数值 dtostrf(temp,4,2,str); //将获取的数值转换为字符型数组 if (i<=2) { LCDA.DisplayString(1,i*3,(unsigned char *)str,sizeof(str)); } //自第2行第1列开始显示温度值 else { if(i>2&&i<=5) { LCDA.DisplayString(2,(i-3)*3,(unsigned char *)str,sizeof(str)); } else { LCDA.DisplayString(3,(i-6)*3,(unsigned char *)str,sizeof(str)); } } } } |
|
|
|
LCD Arduino
PIN1 = GND PIN2 = 5V RS(CS) = 8; RW(SID)= 9; EN(CLK) = 3; PIN15 PSB = GND; */ #include #include #include #define ONE_WIRE_BUS 2 #include "LCD12864RSPI.h" #define AR_SIZE( a ) sizeof( a ) / sizeof( a[0] ) OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); char str[4]; //定义温度值存储数组,4位,其中3位为数字,1位为小数点 double temp =0; //定义中间变量,用于将获取的float型温度值转变为unsigned char数组 unsigned char show[]={ 0xB5,0xB1,0xC7,0xB0,0xBB,0xB7,0xBE,0xB3,0xCE,0xC2,0xB6,0xC8};//当前环境温度 int numberOfDevices; void setup() { Serial.begin(9600); sensors.begin(); //传感器初始化 numberOfDevices = sensors.getDeviceCount(); LCDA.Initialise(); // 屏幕初始化 LCDA.DisplayString(0,0,show,AR_SIZE(show));//第一行第1格开始,显示文字“当前环境温度” } void loop() { sensors.requestTemperatures(); //获取温度值 for(int i=0;i temp=sensors.getTempCByIndex(i); //使用索引序号获得摄氏度数值 dtostrf(temp,4,2,str); //将获取的数值转换为字符型数组 if (i<=2) { LCDA.DisplayString(1,i*3,(unsigned char *)str,sizeof(str)); } //自第2行第1列开始显示温度值 else { if(i>2&&i<=5) { LCDA.DisplayString(2,(i-3)*3,(unsigned char *)str,sizeof(str)); } else { LCDA.DisplayString(3,(i-6)*3,(unsigned char *)str,sizeof(str)); } } }按上述程序即可,我已经通过测试。 |
|
|
|
只有小组成员才能发言,加入小组>>
WIO Terminal +MCP2515 实现车辆OBD的速度监控
10420 浏览 0 评论
60659 浏览 77 评论
6003 浏览 3 评论
一块扩展板完成Arduino的10类37项实验(代码+图形+仿真)
36962 浏览 219 评论
10059 浏览 0 评论
535浏览 1评论
请教:esp32中用u8g2显示shtc3传感器数据到i2c液晶屏,显示不稳定的问题
1310浏览 1评论
1452浏览 1评论
654浏览 0评论
575浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 02:46 , Processed in 0.573142 second(s), Total 82, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号