【发布时间】:2015-12-27 19:07:50
【问题描述】:
我正在尝试编写一个简单的程序来从 Arduino 读取串行数据。在 Arduino 串行监视器窗口中,一切正常。在 Python 控制台中,每个数字都位于单独的行中。在 Pycharm 中,它只显示b' '。不知道问题出在哪里。
Arduino 串口监视器:
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
Python 3 控制台:
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);
}
【问题讨论】: