public
anonymous / arduinoReaderTest.py
Created

  • Download Gist
arduinoReaderTest.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
import serial
import random
import time
import string
 
# Change timeout so we can quickly see what's wrong
arduino = serial.Serial(port='/dev/cu.usbserial-A600egLQ', baudrate=115200, timeout=0.1)
 
print "Connected:", arduino.isOpen()
 
testList = []
c = 0
while (c < 10):
a = random.randint(50,150)
testList.append(a)
c+=1
 
# Length will be 9 always (c<10 determines how many items we have)
length = len(testList)
points = 20
writeString = str(length) + str(testList) + str(points)
 
print "Writing this string:", writeString
 
arduino.write(writeString)
d = 0
dataList = []
while (d < points):
readIn = arduino.readline()
# Print the actual string we get - maybe we don't get \r\n at the end
print repr(readIn)
point = string.translate(readIn, None, deletions='\r\n')
 
print point
dataList.append(point)
d+=1
 
arduino.close()
maximum = max(dataList)
print 'The Maximum point returned is:', maximum

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.