Sep-25-2018, 04:51 PM
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
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()