Hi @menator01 Your code has really helped me out. I can take readings until the 60 second mark but then it throws me this error-
Traceback (most recent call last):
File "****.py", line 19, in <module>
print(sum(mynums))
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Any idea what might be causing that? I've tried converting runtime to a float with all types of different formatting but that hasn't worked.
Updated code below:
Traceback (most recent call last):
File "****.py", line 19, in <module>
print(sum(mynums))
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Any idea what might be causing that? I've tried converting runtime to a float with all types of different formatting but that hasn't worked.
Updated code below:
import serial import os import time mynums = [] if __name__ == '__main__': ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1) ser.flush() while True: if ser.in_waiting > 0: t_end = time.time() + 10 while time.time() < t_end: value = ser.readline().decode('utf-8').rstrip() #reading from serial. It's a float 0.00 (second.milliseconds) runTime = (value) #convert variable to float. print(value) #prints variable result. mynums.append(runTime) print(sum(mynums))
(Dec-14-2021, 08:43 PM)menator01 Wrote: I'm not familiar with using serial but, you may be able to do something like
mynums = [] while True: # Code ......... mynums.append(runTime) print(sum(mynums))