Raspberry Pi Serial Pins

The Raspberry Pi has 40 GPIO pins that connect to sensors, lights, motors and other devices. Here's a map and detailed explanation of what each does, including on the Pi 4. Read and Write From Serial Port With Raspberry Pi: In this tutorial we will see how to use the serial port on Raspberry Pi. We will use the serial port available on Raspberry with a RS232/TTL 3-5,5V adapter and a USB-serial adapter. By default the Raspberry Pi’s serial port is configured to be u. One way to connect the Raspberry Pi and Arduino is by connecting the GPIO on the Raspberry Pi and the Serial Pins on the Arduino. Because there is a voltage difference between the two device on these interface, a voltage divider or logic level converter would be required. Check my article about.

Mohammadreza Akbari

In this tutorial, you’ll learn about Raspberry Pi serial communication (UART), and how to connect your Raspberry Pi board to the Arduino boards or PC using serial communication.

  • Serial communication between Raspberry Pi and PC
  • Serial communication between Raspberry Pi and Arduino

Serial communication (UART) is one of the most popular communication protocols. Most processors support this two-wire connection. Also, many of modules and sensors use serial communication to connect to the other devices.

Serial communication requires only two wires; one for transmitting data and the other one for receiving it.

The rate of the data transfer in this protocol is called the Baud rate. The unit of baud rate is bit per second.

Raspberry Pi boards have two types of UART communications. One is called PL011 and the other is called miniUART. The Raspberry Pi boards that have Bluetooth/Wireless module, use the PL011 for UART communication by default.

Warning

The voltage level of all Raspberry Pi pins, including the RX and TX pins, is 3.3 volts. So to connect a device with 5 volts voltage level to the Raspberry Pi, you should use a voltage level converter or resistance-split circuit.

You can check the Raspberry Pi website for more information about the Raspberry Pi serial communication

Raspberry Pi 3 B or B+×1
Arduino UNO R3×1
TTL to USB converter×1
Male to Female jumper wire×1
Bread board×1
1K Ohm Resistor×3

To establish a serial communication between the Raspberry Pi board and your PC you need a serial to USB converter.

Follow the steps below to start the Raspberry Pi UART communication:

Step 1: Connect the serial to USB converter to the Raspberry Pi board as is shown in the circuit. Then plug the Raspberry Pi supply and connect the converter to your PC.

Step 2: Go to the Device Manager and find the port number that is connected to the converter.

Step 3: Open your terminal software and set up the configuration.

Step 4: Enable UART in the Raspberry Pi.

Open the Raspberry Pi terminal and insert the following commands.

1. Open the config.txt file in the nano editor using the following command.


Add the following lines to the end of the file.

2
enable_uart=1

Then press Ctrl+x and press Y to save the file and close it.

2. Reboot your Raspberry Pi.


3. Check the terminal software on your computer

4. Disconnect the serial communication between the Raspberry Pi and the Bluetooth module.


5. Open cmdline.txt in nano editor.
Delete the “console=serial0,115200” line and save the file.
6. sudo nano /boot/cmdline.txtReboot your Raspberry Pi again.


7. Install the minicom terminal on your Raspberry Pi.

The following command opens the minicom terminal, set the baud rate to 115,200, and starts the serial communication.


After executing this command, you should see the following window.

Now you can test the serial communication between the Raspberry Pi and your pc.

Note

If you want to see the commands you write in the minicom terminal, you need to enable the Echo mode by pressing Ctrl+A and then entering E in the minicom terminal.

To exit minicom, first press Ctrl+A and then enter X.

Serial Communication Between Raspberry Pi and Arduino

You can connect your Arduino boards to the Raspberry Pi using a USB cable. By doing this, you provide the Arduino supply voltage, and you can also transfer your information between Arduino and the Raspberry Pi through the serial interface

Using the following command you can open the minicom terminal at 9600 bit/sec baud rate.

Raspberry Pi 2 Serial Pins

Now upload your code on the Raspberry Pi board and you can transfer the information between the Raspberry Pi and Arduino.

The following code sends any text you write in the minicom terminal from the Raspberry Pi to the Arduino. Then the Arduino returns the same text to the Raspberry Pi.