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

MicroPython • Re: Convert pyboard code to RP2040 USB_VCP

$
0
0
With that said, isn't the REPL just a virtual com port anyways?
Yes. Here's how I read input a character at a time -

Code:

import micropythonimport selectimport sysmicropython.kbd_intr(-1)while True:  while sys.stdin in select.select([sys.stdin], [], [], 0)[0]:    ch = sys.stdin.read(1)    print("Got 0x{:02X}".format(ord(ch)))
Thanks for the suggestion. I will try sys.stdin.read() for input. I guess I should try sys.stdout.write() for output. I'll let you know how it goes.

I tried this code, but still get the timeout. I played with the select timeout value and removing/keeping micropython.kbd_intr... no dice.

Code:

import micropythonimport sysimport selectimport timedef main():    time.sleep(2)    micropython.kbd_intr(-1)    while True:        while sys.stdin in select.select([sys.stdin], [], [], 0)[0]:            data = sys.stdin.read(64)            if data:                command = data.decode('utf-8').strip().upper().replace(" ","")                            if command == "*IDN?":                    response_text = "MicropythonDevice, Model X, Serial: 12345, Version: 1.0"                else:                    response_text = "Error: Command not recognized"                                print(response_text.encode('utf-8'))if __name__ == "__main__":    main()

Statistics: Posted by chipace — Tue Jun 24, 2025 1:53 am



Viewing all articles
Browse latest Browse all 8015

Trending Articles