我正在尝试编写一个简单的程序来从Arduino读取串行数据 . 在Arduino串行监视器窗口中,一切正常 . 在Python控制台中,每个数字都在一个单独的行上 . 在Pycharm中,它只显示 b' '
. 我不知道问题出在哪里 .
Arduino Serial Monitor :
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
Python 3 console :
1
2
3
4
5
6
7
8
9
0
Pycharm IDE :
b' '
b' '
b' '
b' '
b' '
b' '
b' '
b' '
b' '
b' '
这是我正在使用的Python 3代码:
import serial
from time import sleep
Ser = serial.Serial("COM3", 9600, timeout=0)
Counter = 1
while Counter <= 10:
data = Ser.readline()
print(data)
sleep(1)
Counter += 1
Ser.close()
Arduino代码:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(1234567890);
delay(1000);
}
1 回答
也许是
timeout=0
的副作用 . 我会试试这个: