gpt4 book ai didi

c++ - 什么是 MaxDetect 1-wire 总线?

转载 作者:行者123 更新时间:2023-11-28 07:59:34 26 4
gpt4 key购买 nike

我买了这个传感器:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com