User avatar
subw0fer
Posts: 18
Joined: Sat Dec 26, 2020 7:07 pm

PI4J and UART

Sat Apr 10, 2021 9:04 pm

HI all,

stuck with receiving data from UART on RPI4B. Did already several things, upgraded to PI4J 1.4 (installed on RPI), upgraded WiringPI to non deprecated version, Enabled UART in raspi-config.

Use this code modified for my needs, https://github.com/Pi4J/pi4j/blob/maste ... ample.java
but no data is coming from the port. (use ttyAMA0)

What else I should check?

User avatar
subw0fer
Posts: 18
Joined: Sat Dec 26, 2020 7:07 pm

Re: PI4J and UART

Sun Apr 11, 2021 7:53 am

By the way, if I have this kind of connection,
  • Start bit = 1
  • Data bit = 8
  • Parity = EVEN
  • Stop bit = 1
If this enough to set? That is bugging me, this start bit, which I cant set at all.

Code: Select all

SerialConfig config = new SerialConfig();
            config.device(serialDevice)
                    .baud(Baud._9600)
                    .dataBits(DataBits._8)
                    .parity(Parity.EVEN)
                    .stopBits(StopBits._1)
                    .flowControl(FlowControl.NONE);

User avatar
joan
Posts: 15653
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PI4J and UART

Sun Apr 11, 2021 10:19 am

There is always one start bit.

User avatar
DougieLawson
Posts: 41441
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: PI4J and UART

Sun Apr 11, 2021 11:14 am

You should ask the Pi4J author by creating an issue at https://github.com/Pi4J/pi4j/issues

Does your serial device work if you attempt to drive it with something like python?
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

User avatar
subw0fer
Posts: 18
Joined: Sat Dec 26, 2020 7:07 pm

Re: PI4J and UART

Sun Apr 11, 2021 12:27 pm

DougieLawson wrote:
Sun Apr 11, 2021 11:14 am
You should ask the Pi4J author by creating an issue at https://github.com/Pi4J/pi4j/issues

Does your serial device work if you attempt to drive it with something like python?
Ok, will try there. Serial on the connected device is working, constantly sending messages, but I don't see them on RPI. I'll try to use port itself through Wiring PI, will see how it works. For now I think, either connection parameters are wrong, or something between pi4J and wiringPI is broken.

User avatar
subw0fer
Posts: 18
Joined: Sat Dec 26, 2020 7:07 pm

Re: PI4J and UART

Wed Apr 14, 2021 4:38 pm

I found that it doesn't relate to pi4J, there is Rx port that don't send anything. Now I trying to figure out is this dead already or I can force it to live.

User avatar
subw0fer
Posts: 18
Joined: Sat Dec 26, 2020 7:07 pm

Re: PI4J and UART

Thu Apr 15, 2021 6:28 pm

Ok, solved this problem. Writing here for the history. There was a problem with cheap TTL-RS232 converter, it doesn't work with 3.3 V, probably needs higher voltage. But with 5V it already starts sending garbage.

I changed converter and it all works now.

WiringPI (from github) works, PI4J latest 1.4 works. Java call back with Pi4J and also direct request like serial.read() work.

End of story, everybody's happy, except my last Saturday and Sunday, where I spent figuring this out. :)

luixxx
Posts: 3
Joined: Thu Mar 09, 2017 1:49 am

Re: PI4J and UART

Fri Jun 18, 2021 5:18 pm

HI subw0fer, do you use Parity.EVEN
it works fine for you?

I'm migrating an aplication to Rpi4 with pi4j 1.4 and it doesnt work because serial por always sends data with NO parity.
I change the parity with NONE, EVEN, ODD, MARK, SPACE but the frame in oscilloscope is always the same
do you have some suggestion?
thankyou

Return to “Java”