小编use*_*726的帖子

Python没有从arduino串行输出中读取正确的值

我正在尝试使用python从arduino中读取电位计值.但我的串行读取值很奇怪.

Python代码:

import serial

ser = serial.Serial('COM12')

print ( "connected to: " + ser.portstr )
count = 1                    

while True:
    for line in ser.read():
        print( str(count) + str( ': ' ) + str( line ) )
        count = count + 1


ser.close()
Run Code Online (Sandbox Code Playgroud)

Arduino代码:

int potpin = 0;  // analog pin used to connect the potentiometer
int val = 0;       // variable to store the value coming from the sensor
int oldVal = 0;   // used for updating the serial print …
Run Code Online (Sandbox Code Playgroud)

python arduino pyserial

11
推荐指数
1
解决办法
2725
查看次数

标签 统计

arduino ×1

pyserial ×1

python ×1