[英]Serial.serial is not working, thonny: module 'serial' has no attribute 'Serial'
I just started with Ardunino, Python and a serial Communication between RPI and Ardunio (using Thonny).我刚开始使用 Ardunino、Python 以及 RPI 和 Ardunio 之间的串行通信(使用 Thonny)。 I checked out some tutorials (eg https://roboticsbackend.com/raspberry-pi-arduino-serial-communication/ ) to get my code run.
我查看了一些教程(例如https://roboticsbackend.com/raspberry-pi-arduino-serial-communication/ )来运行我的代码。 But not even the standard code is running.
但即使是标准代码也没有运行。
That is my code:那是我的代码:
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 :).
Are you sure you downloaded the right library?你确定你下载了正确的库吗? In python there are both 'serial' and 'pyserial' and to communicate with Arduino you need the latter.
在 python 中既有“串行”又有“pyserial”,要与 Arduino 通信,您需要后者。
You better uninstall 'serial' library, because the line for importing pyserial is:你最好卸载 'serial' 库,因为导入 pyserial 的行是:
import serial
Pls, let me know if this works请让我知道这是否有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.