0

Here is my code:

Main.py (PICO code)

import time 

for i in range(15):
    print("Hello World")
    time.sleep(1)

Windows Desktop Python Code

import serial
port = "COM5"
ser = serial.Serial(port, 9600)
file = open("C:\\Users\\hamza\\OneDrive\\Desktop\\data.txt", "ab")
while True:
   data = ser.read(12)
   file.write(data)
   print(data)

I am fairly new to serial communications and I have a couple of questions:

  1. The output is an infinite loop. If I terminate the program as the data is being read and I go on and open the text file, I see what has been read inside my text file which is good

If I let it go on until all the data has been read and then terminate the program and open the text file it is empty.

  1. Right now, the Pico Code is started by unplugging and plugging the USB cable. I learned that whenever it is hooked the main.py executes. Is there a way where I can choose when to start reading the data? maybe Like a condition? If so how do I ask for an input in the Pico and send that information back and forth between my windows and pico.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.