Can I use PI4J to create and use virtual serial ports on Raspberry Pi? #97
-
I hope to use Raspberry Pi as the test machine, but the number of serial ports is only 1, adding STM32 will increase the amount of code, I would like to ask if you can set some pins as serial ports through PI4J? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Can someone give me a hand? |
Beta Was this translation helpful? Give feedback.
-
From first quick look it seems the underlying PiGpio expects a device name, not a pin number. https://github.com/Pi4J/pi4j-v2/blob/main/libraries/pi4j-library-pigpio/src/main/java/com/pi4j/library/pigpio/PiGpio_Serial.java#L54 So a solution could be to use USB-connected serial adapters, which would be listed as |
Beta Was this translation helpful? Give feedback.
-
When you say "virtual" serial ports, do you mean "bit-banged" serial ports? (The ability to emulate serial communication, signaling and timing via software over arbitrary GPIO pins). The underlying PiGpio library does support bit-banded serial ports using custom GPIO pins to some degree. I don't think this is exposed via Pi4J however at this time. If you are just looking for expandability, like @FDelporte mentioned, you can easily add USB to serial port adapters to expand the serial capability of the RaspberryPi. If by "virtual" serial port you mean a serial port exposed over the network, then I would suggest using the |
Beta Was this translation helpful? Give feedback.
-
I realize this is an old thread but I'm just responding for any future readers. The RaspberryPi 3 has a couple of UARTS where you can access at least two serial ports (with some notable caveats) The RPi4 has an additional 4 UARTS for serial communication. These additional ports require special configuration but when properly configured, Pi4J can allow serial communication via the ports. At this time Pi4J does not directly support any "virtual" / "software serial" / "bit-banged" serial ports via its APIs. The PiGPIO library does provide some limited bit-banged (software) serial communication and you couple probably use the underlying Pi4J PiGPIO library directly to try and use these functions from Java. See: Thanks, Robert |
Beta Was this translation helpful? Give feedback.
When you say "virtual" serial ports, do you mean "bit-banged" serial ports? (The ability to emulate serial communication, signaling and timing via software over arbitrary GPIO pins). The underlying PiGpio library does support bit-banded serial ports using custom GPIO pins to some degree. I don't think this is exposed via Pi4J however at this time.
If you are just looking for expandability, like @FDelporte mentioned, you can easily add USB to serial port adapters to expand the serial capability of the RaspberryPi.
If by "virtual" serial port you mean a serial port exposed over the network, then I would suggest using the
ser2net
utility:https://linux.die.net/man/8/ser2net#:~:text=The%20ser…