Communicate an Arduino with python -
i trying communicate arduino using python. able connect using serial
module. code:
import serial while true: print "opening port" arduinodata = serial.serial("com7", 9600) print "the port open" while (arduinodata.inwaiting()==0): #i wait data print "there no data" print "reading data" arduinostring = arduinodata.readline() print arduinostring
it seems hanging when want read data, in line says arduinostring = arduino.readline()
.
what problem?
instead using while loop inside of main while loop can use if else statement. also, read data can use read function arduinodata.inwaiting() paramater : arduinodata.read(arduinodata.inwaiting())
. hope code you:
arduinodata = serial.serial("com7", 9600) while true: if arduinodata.inwaiting() > 0: # check if there data available print "reading data" arduinostring = arduinodata.read(arduinodata.inwaiting()) '''read , decode data''' print arduinostring else: print "there no data"
Comments
Post a Comment