The Serial Port is a low-level way to send data between the Raspberry Pi and another computer system. There are two main ways in which it can be used:

The Serial Port is a low-level way to send data between the Raspberry Pi and another computer system. There are two main ways in which it can be used:

−

* Connecting to a PC to allow access to the Linux [http://en.wikipedia.org/wiki/System_console console]

+

* Connecting to a PC to allow access to the Linux [http://en.wikipedia.org/wiki/System_console console]. This can help to fix problems during boot, or to log in to the Pi if the video and network are not available.

−

* Connecting to a microcontroller or other peripheral which has a [http://en.wikipedia.org/wiki/Serial_port serial] interface

+

* Connecting to a microcontroller or other peripheral which has a [http://en.wikipedia.org/wiki/Serial_port serial] interface. This can be useful if you want the Pi to control another device.

== Connection to a PC ==

== Connection to a PC ==

Line 14:

Line 14:

If you have a serial connection using 5V logic levels, you should ideally have a circuit to convert between the voltage levels. See [http://www.element14.com/community/groups/raspberry-pi/blog/2012/07/18/look-ma-no-display-using-the-raspberry-pi-serial-console this tutorial] for an example circuit. For prototyping work, provided the connections are kept short you may connect the GPIO TxD directly to the 5V RxD, and the 5V TxD can be connected via a [http://en.wikipedia.org/wiki/Voltage_divider voltage divider] to the GPIO RxD. A 5V to 3V resistor divider can be built from a 2K2 (top) and a 3K3 (bottom) resistor.

If you have a serial connection using 5V logic levels, you should ideally have a circuit to convert between the voltage levels. See [http://www.element14.com/community/groups/raspberry-pi/blog/2012/07/18/look-ma-no-display-using-the-raspberry-pi-serial-console this tutorial] for an example circuit. For prototyping work, provided the connections are kept short you may connect the GPIO TxD directly to the 5V RxD, and the 5V TxD can be connected via a [http://en.wikipedia.org/wiki/Voltage_divider voltage divider] to the GPIO RxD. A 5V to 3V resistor divider can be built from a 2K2 (top) and a 3K3 (bottom) resistor.

+

+

When this is done, you will need to set up a [http://en.wikipedia.org/wiki/Terminal_emulator terminal emulator] program on your PC as described below.

Contents

Connection to a PC

Note that the Raspberry Pi cannot be wired directly to an RS232 serial port. To do so, some additional electronics are required!

A UART is available in the Broadcom SoC, and its RxD and TxD lines are available on the GPIO header. However, these use 0 and 3.3V logic levels, not the +/-12V used by RS-232 serial ports. If you wish to connect one of these, you need a board or adapter to convert the signal levels. See this tutorial for one example on how to build a 3.3V to RS-232 level converter with a breadboard, a MAX3232CPE IC and five 0.1 uF capacitors.

If your PC has a USB port, it is possible to connect a USB-to-serial cable which uses 3.3V logic levels (e.g. the Adafruit 954 or the FTDI TTL-232R-RPI cables) directly to the GPIO pins.

If you have a serial connection using 5V logic levels, you should ideally have a circuit to convert between the voltage levels. See this tutorial for an example circuit. For prototyping work, provided the connections are kept short you may connect the GPIO TxD directly to the 5V RxD, and the 5V TxD can be connected via a voltage divider to the GPIO RxD. A 5V to 3V resistor divider can be built from a 2K2 (top) and a 3K3 (bottom) resistor.

When this is done, you will need to set up a terminal emulator program on your PC as described below.

Serial Parameters

The following parameters are needed to connect to the Raspberry. All parameters except Port_Name and Speed are default values and may not need to be set.

Start GtkTerm, select Configuration->Port and enter the values above in the labeled fields.

Windows Users

Windows Users above Windows XP must download putty, TeraTerm or a comparable terminal program.
Users of XP and below can choose between using putty and Hyperterminal.

First Dialog

If you get the prompt below, you are connected to the Raspberry Pi shell!

prompt> #

First command you might want try is "help":

prompt> # help

If you get some output, you are correctly connected to the Raspberry Pi! Congratulations!

Unwanted serial garbage input

Note that on older software by accident the internal pullups of the RxD GPIO pins were not enabled, this could lead to lots of serial garbage being picked up if the GPIO pin was touched, or even if a finger was nearby. In extreme case this could lead to kernel warnings and other problems.

Connection to a microcontroller or other peripheral

The TxD and TXD signals can also be connected directly to similar signals on a microcontroller board like the arduino provided the signals are all at 3V3 levels. It's still a good idea to put 2K2 series resistors in the lines to prevent damage when two outputs are connected together, which could also happen if a GPIO input pin is accidentally programmed as output.

there are several minor things in the way if you want to have dedicated control of the serial port on a raspberry pi

the first is kernel boot messages at startup, those are caused by the kernel parameter console=ttyAMA0,115200 set in /boot/cmdline.txt

next is the login prompt, set in /etc/inittab with the line T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

kernel debuging is also on the serial port and i dont know what effect it may have on the end-use, so you may want to turn that off also in cmdline.txt, just remove kgdboc=ttyAMA0,115200

once all of those are off, you can use /dev/ttyAMA0 like any normal linux serial port, and you wont get any unwanted traffic confusing the attached devices

some distro's may be setup differently, just double check 'ps aux|grep ttyAMA0' and 'cat /proc/cmdline' to verify ttyAMA0 is not in use anywhere

You can have the RTS0 signal on GPIO 17 (P1-11) if you set it to ALT function 3. Likewise, the CTS0 is available on GPIO 30 (P5-05), if it is set to ALT function 3. You can control the settings of IOs with gpio_setfunc