python-2.7 - DHT 11 温度传感器的 Python GPIO 代码在 PI 2 中失败

标签 python-2.7 raspberry-pi raspberry-pi2

我在使用 Python2.7 GPIO 0.5.11 在 PI 2 中运行 DHT 11 温度传感器时遇到问题。我指的是http://www.uugear.com/portfolio/dht11-humidity-temperature-sensor-module/示例代码。

相同的代码在 PI 1 B+ 上运行良好。在 PI 2 中,我得到“ERR_RANGE”作为错误。我尝试调试问题似乎需要增加@ GPIO pin 4 读取的数据。

将数据读取值增加到2000后,返回的温湿度值一直是255。有没有人遇到过这个问题,帮我解决一下。

谢谢,
巴拉德瓦伊

最佳答案

您还可以查看以下小型库。它仅取决于 GPIO 模块:

https://github.com/szazo/DHT11_Python

例子:

import RPi.GPIO as GPIO
import dht11

# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

# read data using pin 14
instance = dht11.DHT11(pin = 14)
result = instance.read()

if result.is_valid():
    print("Temperature: %d C" % result.temperature)
    print("Humidity: %d %%" % result.humidity)
else:
    print("Error: %d" % result.error_code)

关于python-2.7 - DHT 11 温度传感器的 Python GPIO 代码在 PI 2 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28913592/

相关文章:

python - Python 2 和 Python 3 中 type() 函数的区别

javascript - 如何在 ODOO v8 中对特定字段使用 JQ 或 JavaScript?

linux - 如何保持蓝牙音箱连接树莓派不休眠

arduino - 其他设备伪装SD卡或两台设备共享一张SD卡

google-chrome - 《树莓派 2》 Netflix

android - 如何在我的 android 应用程序中访问 raspberry.local?

python - 模式后面不再有数字正则表达式 python

linux - 将 BlueZ 堆栈用作外围设备时的有效载荷错误

python - ffmpeg编译错误

python-2.7 - 使用 pip 和 python 2.7 在 Windows 7 上安装 lxml