首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Serial.serial不起作用,所以:模块‘串行’没有属性'serial‘

Serial.serial不起作用,所以:模块‘串行’没有属性'serial‘
EN

Stack Overflow用户
提问于 2022-08-12 08:51:37
回答 1查看 113关注 0票数 0

我刚开始使用Ardunino、Python和RPI与Ardunio之间的串行通信(使用Thonny)。我查看了一些教程(例如https://roboticsbackend.com/raspberry-pi-arduino-serial-communication/)来运行我的代码。但即使是标准代码也没有运行。

这是我的代码:

代码语言:javascript
复制
if __name__ == '__main__':
    ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
    ser.reset_input_buffer()
    while True:
        if ser.in_waiting > 0:
            line = ser.readline().decode('utf-8').rstrip()
            print(line)```

This error keeps occuring: *AttributeError: module 'serial' has no attribute 'Serial'*

Your program tries to call method Serial of an object of type serial, but this type does not have such method. 

I have installed the library serial, the name of my file is : *Comm_testb.py*. 

I have tried also to do some other codes, which I found on stackoverflow ;). But either I failed to adapt them or there is something wrong. I also can not figure out other causes. So, I hope you can help me :).
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-12 08:59:10

你确定你下载了正确的库吗?在python中,有‘串行’和'pyserial‘,要与Arduino通信,您需要后者。

您最好卸载“串行”库,因为导入pyserial的行是:

代码语言:javascript
复制
import serial

请告诉我这是否有效

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73331587

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档