You need three file: On your pi, boot.py (Note you have reboot the pi to run this) This turns on the data serial port
import storage
import usb_cdc
usb_cdc.disable() # Disable both serial devices.
usb_cdc.enable(console=True, data=True)
On your pi. This runs the code and has it send text to the serial port
# usb_io for Raspberry Pi Pico with rp2040
import supervisor
import usb_cdc
import time
while not supervisor.runtime.usb_connected:
pass
ser = usb_cdc.data
def usb_writeline (usb_data_port, x):
print (str(x))
usb_data_port.write(bytes(str(x) + "\n", "utf-8"))
usb_data_port.flush()
while True:
usb_writeline(ser, 'Grahammers')
On your laptop
This code reads the serial port
# usb_io.py
import serial
import adafruit_board_toolkit.circuitpython_serial
import select
ser = serial.Serial( None, 115200, 8, "N", 1, timeout=120)
ser.port = "COM5"
ser.open()
s = ser.readline()
print(s)