Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8015

MicroPython • Convert pyboard code to RP2040 USB_VCP

$
0
0
Hi, I have some STM32 pyboard Micropython code that I want to run on my RP2040. It is a USBTMC emulator and works great when connected to Linux and windows PCs. I don't believe the RP2040 supports USB_VCP in the same way that STM32 supports it. With that said, isn't the REPL just a virtual com port anyways? Here is the script that I would like to convert:

Code:

import pybUSB_VCP = pyb.USB_VCPclass USBTMCDevice:    def __init__(self):        self.usb = USB_VCP()        def wait_for_command(self):        while not self.usb.any():            time.sleep(0.1)        return self.usb.read(64) # Read up to 64 bytes (adjust as needed).        def send_response(self, response):        self.usb.write(response)def main():    usb_tmc = USBTMCDevice()    while True:        data = usb_tmc.wait_for_command()        if data:            command = data.decode('utf-8').strip()                        if command.upper() == "*IDN?":                response_text = "MicropythonDevice, Model X, Serial: 12345, Version: 1.0\n"            else:                response_text = "Error: Command not recognized\n"                            usb_tmc.send_response(response_text.encode('utf-8'))if __name__ == "__main__":    main()
I tried replacing the "self.usb.any()" with "input()" and "self.usb.write()" with "print()" for the RP2040, but I get timeouts.

Any ideas on how to port this over to RP2040?
Thanks.

Statistics: Posted by chipace — Mon Jun 23, 2025 12:16 am



Viewing all articles
Browse latest Browse all 8015

Trending Articles