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 23 24 25 26 27 28 29 30 31 32 33 34 |
# ==================================================================== # DISCLAIMER: # This code is provided as-is for educational and experimental # purposes only. The author makes no representations or warranties of # any kind concerning the safety, suitability, or accuracy of this # code. Use at your own risk. The author assumes no liability for any # damages, system failures, security breaches, or network issues # resulting from the use or implementation of this script. # ==================================================================== import serial import time serialPort= 'COM7' baudRate = 115200 ser = serial.Serial(serialPort,baudRate, timeout=5) ts=1 time.sleep(ts) ser.write(b"f=open('log.txt','r')\r\n") line =ser.readline().decode('utf-8').strip() print(line) ts=.1 time.sleep(ts) 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() |