Python Forum
reading raw data until condition is met, then stopping
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading raw data until condition is met, then stopping
#3
Do you want to clear the file (/home/pi/data_log.csv) every 5 seconds and start write to the same file ?

file = open("/home/pi/data_log.csv", "a") -> the second parameter is mode, try use w
'w' open for writing, truncating the file first


i=0 
 
while adcx.get_last_result() < 840:
    # Create a empty file
    file = open("/home/pi/data_log.csv", "w")
    file.write("Time,Sensor1,Sensor2,Sensor3,Sensor4\n")
    file.write(bytes(datetime.now())+"\n")
    print('Reading ADS1x15 channel 0 for 5 seconds...')
    start = time.time()
    # write for 5 seconds
    while (time.time() - start) <= 5.0:
        now = datetime.now()
        usec = "%02d%06d" % (now.second, now.microsecond)
        value = adcx.get_last_result()
        file.write(str(usec) + "," + "{0}".format(*value) + "\n")

    file.close() 
Reply


Messages In This Thread
RE: reading raw data until condition is met, then stopping - by ikejima - Sep-25-2018, 04:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading All The RAW Data Inside a PDF NBAComputerMan 4 1,412 Nov-30-2022, 10:54 PM
Last Post: Larz60+
  Reading Data from JSON tpolim008 2 1,134 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Help reading data from serial RS485 korenron 8 14,179 Nov-14-2021, 06:49 AM
Last Post: korenron
  How to map two data frames based on multiple condition SriRajesh 0 1,515 Oct-27-2021, 02:43 PM
Last Post: SriRajesh
  Help with WebSocket reading data from anoter function korenron 0 1,353 Sep-19-2021, 11:08 AM
Last Post: korenron
  Fastest Way of Writing/Reading Data JamesA 1 2,229 Jul-27-2021, 03:52 PM
Last Post: Larz60+
  Reading data to python: turn into list or dataframe hhchenfx 2 5,432 Jun-01-2021, 10:28 AM
Last Post: Larz60+
  Reading data from mysql. stsxbel 2 2,251 May-23-2021, 06:56 PM
Last Post: stsxbel
  reading canbus data as hex korenron 9 6,386 Dec-30-2020, 01:52 PM
Last Post: korenron
  Reading Serial data Moris526 6 5,461 Dec-26-2020, 04:04 PM
Last Post: Moris526

Forum Jump:

User Panel Messages

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