Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # should send 'foobar~' to the arduino over serial. The corresponding arduino code will echo all the characters back, # this program will then reconstitute them as characters, then stop listening and print the joined result on
- # receiving '#'
- import serial
- import io
- from time import sleep
- ser = serial.Serial("/dev/ttyACM0", 9600, timeout=1)
- sleep(2)
- print ser.portstr
- ser.write("foobar~")
- value = None
- rawVal = ''
- chrValue = ''
- received = ''
- esc = False
- while esc == False:
- rawVal = ser.readline()
- print "raw data received: ", rawVal
- try:
- value = int(float(rawVal))
- chrValue = chr(value)
- except ValueError:
- chrValue = rawVal
- received = received + chrValue
- valBuf = chrValue.rstrip('\n')
- valBuf = valBuf.rstrip('\r')
- valBuf = valBuf.rstrip(' ')
- if valBuf == '~':
- print "escape character detected"
- esc = True
- print "joined data: ", received
- ser.close()
Advertisement
Add Comment
Please, Sign In to add comment