How to Send/Receive via Pico USB
Posted: Thu Oct 21, 2021 9:54 am
Hi all, i'm a beginner playing with MP on the Raspberry Pico.
In a simple project i need the Pico, attached via USB to the PC, to receive a string, modify the string, and send back the modified string to PC.
On the PC i wrote the Python script that sends the string via serial.write to /dev/ttyACM0
On the Pico what is best way to wait for data and send back result?
I'd like to do something similar to the circuitpython way, where you import the usb_cdc module (it allows access to USB CDC serial communications) and then you can enable even 2 serial objects that can be used to send and receive binary data to and from the host, tipically usb_cdc.console (REPL) and usb_cdc.data, and on pc you will see two new /dev/ttyxxx attached.
Then you can use usb_cdc.data.write() to send data, and usb_cdc.data.read() to receive.
So how can this be done with MP?
the script on PC is using serial.readline() to retrieve result.
Thanks in advance for any suggestions!
In a simple project i need the Pico, attached via USB to the PC, to receive a string, modify the string, and send back the modified string to PC.
On the PC i wrote the Python script that sends the string via serial.write to /dev/ttyACM0
On the Pico what is best way to wait for data and send back result?
I'd like to do something similar to the circuitpython way, where you import the usb_cdc module (it allows access to USB CDC serial communications) and then you can enable even 2 serial objects that can be used to send and receive binary data to and from the host, tipically usb_cdc.console (REPL) and usb_cdc.data, and on pc you will see two new /dev/ttyxxx attached.
Then you can use usb_cdc.data.write() to send data, and usb_cdc.data.read() to receive.
So how can this be done with MP?
the script on PC is using serial.readline() to retrieve result.
Thanks in advance for any suggestions!