我正在尝试使用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)