Regn0
Posts: 10
Joined: Mon Apr 13, 2015 12:52 pm

Using UART on RPI

Mon Aug 08, 2016 7:47 am

Hello there,

Currently I'm working on a personal project. This project contains a Raspberry Pi and a RN2483. The RN2483 has a ASCII command interface over UART. So in order to use the RN2483 chip connected to my Pi, I'll have to use UART...

Can I use Pi4J and its Serial example to start off implementing the UART communication to the RN2483? I'm kind of new to UART and serial communication on a Pi, that's why I ask :)

Thanks in advance!

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: Using UART on RPI

Mon Aug 08, 2016 8:22 am

Yes it shouldn't be a problem.

The RN2483 operates at 3.3V so you won't need any logic level conversion to get it working. Just connect the UART pins for each device together remembering to swap so that TX connects to RX and vice versa.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Regn0
Posts: 10
Joined: Mon Apr 13, 2015 12:52 pm

Re: Using UART on RPI

Mon Aug 08, 2016 8:32 am

Thanks a lot! Is it possible to debug my serial code by simply connecting the Tx and the Rx of the Pi. This way the Pi will send data over it's Tx and this data will be looped back to the Rx, making it echo what it send. Am I right?

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: Using UART on RPI

Mon Aug 08, 2016 8:59 am

That is correct.

A simple loopback is a good test of your code.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Regn0
Posts: 10
Joined: Mon Apr 13, 2015 12:52 pm

Re: Using UART on RPI

Mon Aug 08, 2016 12:47 pm

Great thanks for the help so far! If I do connect the rx and the tx pins, should I put a resistor in between the two pins? I am quite a noob on the electrical engineering part...

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: Using UART on RPI

Mon Aug 08, 2016 1:25 pm

No need. If both ends are operating on 3.3v then you shouldn't need any resistors.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Regn0
Posts: 10
Joined: Mon Apr 13, 2015 12:52 pm

Re: Using UART on RPI

Mon Aug 08, 2016 2:12 pm

Great! Thanks again :) You really helped a lot!

Regn0
Posts: 10
Joined: Mon Apr 13, 2015 12:52 pm

Re: Using UART on RPI

Tue Aug 09, 2016 6:05 pm

I'm having trouble using Pi4J at the moment. I've copied their example and changed it a bit. I've connected my pin8 and pin10 with eachother, since these are the UART pins. I've written code that writes some string to the serial and then reads it. However I am getting an error:

Code: Select all

Unable to connect to the serial device/port. Error #2
It seems like an IOException but I have no clue what Error#2 means...

Anyone has an idea?

Regn0
Posts: 10
Joined: Mon Apr 13, 2015 12:52 pm

Re: Using UART on RPI

Thu Aug 11, 2016 3:51 pm

I've found the issue. In the example they tell you to use raspi-config to disable the OS from using the serial port. This is done via this guide: https://www.cube-controls.com/2015/11/0 ... -raspbian/

What happens when I use disable the serial port via raspi-config, is that /dev/ttyAMA0 dissappears and because of that the port/device cannot be opened. That's why I was getting the error.

However when I enable the serial port in raspi-config, the example program seems to hang on: serial.open() and after that no output is shown. Does anyone know what might be the problem?

Return to “Java”