# Example of logging data to a CSV file import time import random # Open the file for writing f = open("data.csv", "a") # Write the CSV header (the names of the columns) # You should add/rename the columns as appropriate f.write("time,value\n") # Log 10 data points # You can replace this with whatever you want, or use while(True) to log until # you halt the program or power down the ESP32. for i in range(10): # Read some data (from whatever source you want) # For this example, we'll just make up a random number: data = random.random() # Grab the current time (in seconds) # If you need more resolution, you could use time.ticks_ms() instead current_time = time.time() # Write the data # Remember that the format() function replaces each {} with the corresponding value f.write("{},{}\n".format(current_time, data)) time.sleep(1) # Clean up! f.close()