作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我买了这个传感器:
http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf
输出为“MaxDetect 1-wire bus”,这是什么意思以及如何使用它?我试图将它连接到 arduino 并对其进行编程,但它无法正常工作,我不断收到 1 位的数据。我想我的代码是错误的。我需要为 arduino 使用 Wire-1 库吗?
int SensorVccPin = 8;
int datapin = 6;
int bitcheck1;
int bitcheck2;
int temp[16];
int humidity[16];
int sensorcheck[8];
void setup()
{
pinMode(SensorVccPin, OUTPUT);
pinMode(datapin, INPUT);
Serial.begin(9600);
}
void loop()
{
// This is the STEP #1
digitalWrite(SensorVccPin, HIGH);
delay(5000);
digitalWrite(SensorVccPin, LOW);
delay(15);
digitalWrite(SensorVccPin, HIGH);
delayMicroseconds(30);
digitalWrite(SensorVccPin, LOW);
while(digitalRead(datapin) == 0){
delayMicroseconds(2); }
while(digitalRead(datapin) == HIGH)
{
delayMicroseconds(2); }
// STEP #2
for (int i = 0; i<16; i++)
{
while(digitalRead(datapin) == LOW)
{
delayMicroseconds(2); }
delayMicroseconds(10);
bitcheck1 = digitalRead(datapin); // maybe store as an array
delayMicroseconds(17); // 50 sec pause // 27us = 0 bit, 70us is 1 bit data
delayMicroseconds(15);
bitcheck2 = digitalRead(datapin);
if (bitcheck1==bitcheck2)
{temp[i]=1;
delayMicroseconds(28);
}
else
{temp[i]=0;
}
}
for (int i = 0; i<16; i++)
{
while(digitalRead(datapin) == LOW)
{
delayMicroseconds(2); }
delayMicroseconds(10);
bitcheck1 = digitalRead(datapin); // maybe store as an array
delayMicroseconds(17); // 50 sec pause // 27us = 0 bit, 70us is 1 bit data
delayMicroseconds(15);
bitcheck2 = digitalRead(datapin);
if (bitcheck1==bitcheck2)
{humidity[i]=1;
delayMicroseconds(28);
}
else
{humidity[i]=0;
}
}
for (int i = 0; i<8; i++)
{
while(digitalRead(datapin) == LOW)
{
delayMicroseconds(2); }
delayMicroseconds(10);
bitcheck1 = digitalRead(datapin); // maybe store as an array
delayMicroseconds(17); // 50 sec pause // 27us = 0 bit, 70us is 1 bit data
delayMicroseconds(15);
bitcheck2 = digitalRead(datapin);
if (bitcheck1==bitcheck2)
{sensorcheck[i]=1;
delayMicroseconds(28);
}
else
{sensorcheck[i]=0;
}
delayMicroseconds(80);
for(int i=0; i<16; i++)
{
Serial.print(temp[i]);
}
Serial.print(" temp ");
for(int i=0; i<16; i++)
{
Serial.print(humidity[i]);
}
Serial.print(" hum ");
for(int i=0; i<8; i++)
{
Serial.print(sensorcheck[i]);
}
Serial.print(" check ");
}
}
最佳答案
您应该始终将 VCC 引脚(引脚 1)保持在高电平。事实上,理想情况下,它应该连接到电源。它是您应该拉高和拉低以与传感器通信的数据引脚(引脚2),它是您应该读取的数据引脚。您必须在输入和输出模式之间切换数据引脚。确保数据引脚上有一个上拉电阻,因为传感器只能将其拉低。
关于c++ - 什么是 MaxDetect 1-wire 总线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11856699/
我买了这个传感器: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf 输出为“MaxDetect 1-w
我是一名优秀的程序员,十分优秀!