能否修改 Adafruit DHT22 库以支持 Raspberry Pi 4 模型 B (BCM2711)?

Can the Adafruit DHT22 library be modified to support Raspberry Pi 4 Model B (BCM2711)?

我找到了唯一一个 Python 数字输出相对湿度和温度库 sensor/module DHT22:https://github.com/adafruit/DHT-sensor-library

但考虑到 /usr/local/lib/python3.7/dist-packages/Adafruit_DHT/platform_detect.py 中的函数不支持最新的 Raspberry 处理器 (BCM2711):

def pi_version():
"""Detect the version of the Raspberry Pi.  Returns either 1, 2, 3 or
None depending on if it's a Raspberry Pi 1 (model A, B, A+, B+),
Raspberry Pi 2 (model B+), Raspberry Pi 3,Raspberry Pi 3 (model B+) or not $
"""
# Check /proc/cpuinfo for the Hardware field value.
# 2708 is pi 1
# 2709 is pi 2
# 2835 is pi 3
# 2837 is pi 3b+
# Anything else is not a pi.
with open('/proc/cpuinfo', 'r') as infile:
    cpuinfo = infile.read()
# Match a line like 'Hardware   : BCM2709'
match = re.search('^Hardware\s+:\s+(\w+)$', cpuinfo,
                  flags=re.MULTILINE | re.IGNORECASE)
if not match:
    # Couldn't find the hardware, assume it isn't a pi.
    return None
if match.group(1) == 'BCM2708':
    # Pi 1
    return 1
elif match.group(1) == 'BCM2709':
    # Pi 2
    return 2
elif match.group(1) == 'BCM2835':
    # Pi 3
    return 3
elif match.group(1) == 'BCM2837':
    # Pi 3b+
    return 3
else:
    # Something else, not a pi.
    return None

将此功能强制到 return“Pi 3(型号 B+)/BCM2837”是否安全?

否则我无法导入库:

Traceback:

File "/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/common.py", line 94, in read_retry
    humidity, temperature = read(sensor, pin, platform)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/common.py", line 80, in read
    platform = get_platform()
File "/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/common.py", line 60, in get_platform
    from . import Beaglebone_Black
File "/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/Beaglebone_Black.py", line 24, in <module>
    from . import Beaglebone_Black_Driver as driver
ImportError: cannot import name 'Beaglebone_Black_Driver' from 'Adafruit_DHT' (/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/__init__.py)

主持人: Raspberry Pi 4 B 型 2Gb 内存, Raspbian GNU/Linux 10 (克星), Python3.7

所有代的 Raspberry 开发板都兼容 GPIO(主要),所以修复这个库也许没什么大不了的?

我敢改上面的功能,居然成功了!但是,如果您使用针对不同电路板版本的不同输出,请务必小心。我用的是GPIO4.

...
elif match.group(1) == 'BCM2837':
    # Pi 3b+
    return 3
else:
    # Something else, PI 4 MODEL B
    return 3

@tconsta Raspberry pi 4b 使用 'BCM 2711' 所以我想我们可以添加下面的代码

...
elif match.group(1) == 'BCM2711':
    #Pi 4b
    return 3
else:
    return None