Python Forum
Store variable data and display sum after 60 seconds
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Store variable data and display sum after 60 seconds
#5
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:

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))
Reply


Messages In This Thread
RE: Store variable data and display sum after 60 seconds - by the_dude - Dec-14-2021, 10:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 387 Apr-18-2024, 09:55 PM
Last Post: deanhystad
  How to display <IPython.core.display.HTML object>? pythopen 3 46,225 May-06-2023, 08:14 AM
Last Post: pramod08728
Video doing data treatment on a file import-parsing a variable EmBeck87 15 3,048 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Need help on how to include single quotes on data of variable string hani_hms 5 2,181 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  Problem with module time and leap seconds Pedroski55 3 1,297 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  USE string data as a variable NAME rokorps 1 1,010 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  store all variable values into list and insert to sql_summary table mg24 3 1,205 Sep-28-2022, 09:13 AM
Last Post: Larz60+
  Regex text file to store data in list TheSithSiggi 1 1,557 Dec-03-2020, 04:46 PM
Last Post: bowlofred
Information Unable to display joystick's value from Python onto display box MelfoyGray 2 2,293 Nov-11-2020, 02:23 AM
Last Post: MelfoyGray
  How to calculate time difference between each row of dataframe in seconds Mekala 1 2,636 Jul-16-2020, 12:57 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020