Many Raspberry Pi Pico W project in microPython require the logging of sensor data. With these log files, we need a convenient way to transfer the data from the Pi Pico to a desktop PC. In earlier lessons, we showed how to log data to the Pi Pico flash memory. In today’s lesson we show how to transfer those log files to your PC. This is the code we developed in the video lesson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import serial import time serialPort= 'COM7' baudRate = 115200 ser = serial.Serial(serialPort,baudRate, timeout=5) time.sleep(1) ser.write(b"f=open('log.txt','r')\r\n") line =ser.readline().decode('utf-8').strip() print(line) time.sleep(.1) with open('log.txt','w') as file: while line !="''": ser.write(b"f.readline()\r\n") line =ser.readline().decode('utf-8').strip() print("LINE: ",line) line =ser.readline().decode('utf-8').strip() print("LINE: ",line) if line.startswith("'") and line !="''": line = line[1:-3] file.write(line+'\n') ser.write(b"f.close()\r\n") ser.close() |