I'm looking for a way to save data that I have stored into an array on the Raspberry Pi Pico using Thonny into a .txt file on my computer so that I can access it. This is the code I am using:
Code: Select all
import machine
from utime import sleep, ticks_ms, ticks_diff
# This code reads the serial data and assigns it to an array which then sends it to a .txt file after
analog_value = machine.ADC(26) # Assign pin 26 to the input
reading = [None] * 20000 # Setup array of 20,000 elements for 20,000 recordings
timer_start = ticks_ms() # Just used to check how long the recording takes
for i in range(20000):
reading[i] = analog_value.read_u16() # Takes down ADC output value
time_difference = ticks_diff(ticks_ms(), timer_start) # Stops and prints timer value
print("Recording time: " + str(time_difference) + " miliseconds.")
file = open("microphone_readings.txt", "w")
timer_start = ticks_ms() # Just to check how long printing to the .txt file takes
for i in range(20000):
file.write(str(reading[i]) + "\n") # Writes readings to .txt fie saved on Pico
file.flush
time_difference = ticks_diff(ticks_ms(), timer_start)
print("Print time: " + str(time_difference) + " miliseconds.")
Any ideas?