Skip to content

Instantly share code, notes, and snippets.

Created February 12, 2013 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4760624 to your computer and use it in GitHub Desktop.
Save anonymous/4760624 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment