[Tutor] truncated dictionary return
Wolfgang Maier
wolfgang.maier at biologie.uni-freiburg.de
Mon Dec 2 00:04:07 CET 2013
Hi again,
think I spotted the problem now:
you’re setting up your connection everytime you enter the function (with the
serial.Serial call), but I guess you’re calling that function repeatedly to
retrieve lines. That’s wrong and means you could loose data that was sent
while you weren’t listening.
You’ll have to open the connection once outside the sensorRead() function,
then pass it the arduino object like this:
def sensorRead (arduino):
line = arduino.readline().strip()
line = line.lstrip('{').rstrip('}').strip()
# rest of your code
# your main program:
arduino = serial.Serial('/dev/ttyACM0', 9600)
sleep(1)
while True:
reads = sensorRead(arduino)
# do something with the data
Hope that helps,
Wolfgang
More information about the Tutor
mailing list