send data to RP2040 through USB

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
User avatar
Frenk.98K
Posts: 6
Joined: Thu May 05, 2022 8:07 pm

send data to RP2040 through USB

Post by Frenk.98K » Thu May 05, 2022 8:34 pm

Hi, i'm trying to connect my RP2040-Zero board to my PC through the normal USB and talk with a companion JavaFX application.
JavaFX side I think I should to connect to the port "COM3" with 9600 "baud" and send the data i need there.

The first problem is that I haven't found anything recent or useful rearding USB communication for JavaFX, and the only seemingly working library I found after days of scouring google is the "NRSerialPort", but perhaps I'm not aware of the right terminology for the right searches here...

The second issue is that Thonny IDE seems to somehow always know what's the exact port the Pi is connected to, while in the JavaFX App I only get the "COM3" port available, but with no description or owner or anything to identify the port with when calling "getPortIdentifiers()".

Finally, the major setback is that on the controller board I need a loop of code always running and doing stuff, and the only "working" peace of code to read USB serial data I found is "sys.stdin.readline()", but if I don't write anything to COM3 it hangs the whole program untill I eventually do, then executes the rest of the cycle and on the next loop iteration it hangs again, waiting for the next line to read.
Isn't there a way to check if there's something new and if not keep executing other stuff?
I read about interrupts but I'm not too sure how to implement it here... PyBoard has a lybrary pyb.USB_VCP, which looks so much more painless, but have no idea if there is something similar for my board too.

after days of trying, perhaps because of me being clueless due to my USB-communication un-knowledge, I still haven't found a way to send and recive data between the two.
I'm starting to feel that either it's really not that simple and straight forward as I hoped/imagined, or I'm really missing something big here...

Hope someone can help me!
Thank you in advance!
- Diego

hippy
Posts: 130
Joined: Sat Feb 20, 2021 2:46 pm
Location: UK

Re: send data to RP2040 through USB

Post by hippy » Tue May 10, 2022 12:35 pm

IMO the best way, and only sensible way, of developing code which communicates via USB serial while using Thonny to develop code, is to add additional USB Virtual Serial Ports - https://forums.raspberrypi.com/viewtopic.php?t=305834

I can't help with your JavaFX issues or identifying which COM ports Windows has decided to use, but it should solve some of your other issues.

Post Reply