为什么我的SDS011传感器不发送正确的字节?

发布于 2025-01-22 08:33:11 字数 838 浏览 1 评论 0原文

我尝试通过连接到Raspberry Pi的SDS011来测量空气质量。因此,我使用我在此处找到的脚本: https://forum-raspberrypi.de/forum/thread/32634-nova-pm2-5-pm2-5-pm10-feinstaub-sensor-sensor-sensor-sensor-sss011-am-am-am-pi-anschlie%c3% 9fen/

我将其更改为python3(ser.write(b.encode())而不是ser.write(b))。

脚本本身正在运行,但我想

def sensor_read():
    byte = 0
    while byte != "\xaa":
        byte = ser.read(size=1)
    d = ser.read(size=10)
    if d[0] == "\xc0":
        process_frame(byte + d)

创建了一个无限的循环,因为“字节”似乎从未成为“ \ xaa”。

我是否只需要等待更长的时间(大约几分钟),或者代码有问题?

非常感谢您的帮助!

I try to measure air quality with an sds011 connected to a raspberry Pi. Therefore I use a script I found here: https://forum-raspberrypi.de/forum/thread/32634-nova-pm2-5-pm10-feinstaub-sensor-sds011-am-pi-anschlie%C3%9Fen/

I changed it to python3 (ser.write(b.encode()) instead of ser.write(b)).

The script itself is running, but I guess

def sensor_read():
    byte = 0
    while byte != "\xaa":
        byte = ser.read(size=1)
    d = ser.read(size=10)
    if d[0] == "\xc0":
        process_frame(byte + d)

creates an infinite loop because "byte" never seems to become "\xaa".

Do I just have to wait even longer (about several minutes) or is something wrong with the code?

Thanks a lot for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文