0

Using PySerial I was successful in sending data from Raspberry Pi Pico to Windows PC but not the other way around.

Windows PC code:

import serial
# Configure the serial connection
port = "COM5"
ser = serial.Serial(port, 9600)

message = b"Hey This is the message!!!!"
ser.write(message)

Raspberry Pi Pico code:

file = open('Results77.txt', 'wb')

while (True):
   # I do not know what to do here to get the message that I sent into the variable data
   data = input()
   file.write(data)
user4157124
  • 2,809
  • 13
  • 27
  • 42
HEL
  • 43
  • 4
  • Does this answer your question? [Read/write data over Raspberry Pi Pico USB cable](https://stackoverflow.com/questions/76138267/read-write-data-over-raspberry-pi-pico-usb-cable) – user4157124 Aug 06 '23 at 16:43

1 Answers1

0

This is the same question as Pi Pico: read/write data over usb cable

The Pico Code could look like

import select
import sys

# Set up the poll object
poll_obj = select.poll()
poll_obj.register(sys.stdin, select.POLLIN)

# Loop indefinitely
while True:
    # Wait for input on stdin
    poll_results = poll_obj.poll(1) # the '1' is how long it will wait for message before looping again (in microseconds)
    if poll_results:
        # Read the data from stdin (read data coming from PC)
        data = sys.stdin.readline().strip()

Ensure your Windows device uses the expected line ending

ser.write("Hey This is the message!!!!\r".encode())