python - pySerial works in one script but not another -
now getting output, yet wrong post modified reflect progress.
i have been reading documentation following links site. able find script works in reading data arduino serial output.
it follows:
import time import serial # configure serial connections (the parameters differs on device connecting to) ser = serial.serial( port='/dev/ttyacm0', baudrate=115200, parity=serial.parity_odd, stopbits=serial.stopbits_two, bytesize=serial.sevenbits ) ser.isopen() print 'enter commands below.\r\ninsert "exit" leave application.' input=1 while 1 : # keyboard input input = raw_input(">> ") # python 3 users # input = input(">> ") if input == 'exit': ser.close() exit() else: # send character device # (note happend \r\n carriage return , line feed characters - requested device) ser.write(input + '\r\n') out = '' # let's wait 1 second before reading output (let's give device time answer) time.sleep(1) while ser.inwaiting() > 0: out += ser.read(1) if out != '': print ">>" + out
the output window of python opens , code executed. able type 'exit' exit or 'read' , ton of lines arduino serial monitor populated in python output window.
what have output arduino populated in python output window. (later try plot data using matplotlib)
the code used attempt read arduinb such:
import time import serial # configure serial connections (the parameters differs on device connecting to) ser = serial.serial( port='/dev/ttyacm0', baudrate=115200, parity=serial.parity_odd, stopbits=serial.stopbits_two, bytesize=serial.sevenbits ) ser.isopen() input=1 while true: #first things first, lets wait data prior reading time.sleep(1) if (ser.inwaiting()>0): myarduinodata = ser.read() print myarduinodata
however, when use above code python execution hangs , no output serial monitor. this corrected above code , community help
the new problem output giving single digit value , not 2 3 digit value output arduino serial monitor.
thanks to @jalo i able values in question specifying byte value in inwaiting , ser.read statements. change follows:
(ser.inwaiting()>4): ser = ser.read(4)
thank you.
Comments
Post a Comment