Difference between revisions of "RPi Serial Connection"
IanH (talk | contribs)
(Separate section for level conversion)
Mlh (talk | contribs)
You will need to be a member of the ''dialout'' group to access this port (for later releases the required group is ''tty''). You can check which is needed with:
and you will see something like "crw-rw----T 1 root dialout ..." which says root can 'create,read,write' and the group xxx can 'read,write' to the port and everyone else cannot access it.
and you will see something like "crw-rw----T 1 root dialout ...", ''c'' means character device, and root can 'read,write' and the group ''dialout'' can 'read,write' to the port and everyone else cannot access it.
Connecting to a PC to allow access to the Linux 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 serial interface. This can be useful if you want the Pi to control another device.
3.1 Preventing Linux using the serial port
The Broadcom chip at the heart of the Pi uses 0 and 3.3V logic levels, not the +/-12V used by RS-232 serial ports found on some older PCs. 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 you wish to connect your Pi to a PC with a USB port, the simplest option is to use a USB-to-serial cable which uses 3.3V logic levels (e.g. the Adafruit 954 or the FTDI TTL-232R-RPI cables). These can be simply plugged in directly to the GPIO header (see illustration).
If you wish to connect to a peripheral which has 0/5V signals, 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.
You can connect the Pi to a PC using a USB-serial cable, or (if it has an RS232 port) a level-converter circuit - see above for details. When this is done, you will need to set up a terminal emulator program on your PC as described below.
The following parameters are needed to connect to the Pi console, and apply on both Linux and Windows.
Users of Windows Vista or later will need to download a terminal program, for instance PuTTY, or TeraTerm. Users of XP and below can choose between using PuTTY and the built-in Hyperterminal.
If your connection is set up correctly, when the Pi is booted you should see many messages as the system comes up:
The TxD and RxD signals can also be connected directly to similar signals on a microcontroller board like the Arduino provided the signals are all at 3V3 levels. Some Arduino variants use 5V levels, and should have level conversion (see 'Connections and Signal levels' above). Even 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.
If your microcontroller uses 5V logic levels, level conversion is usually necessary - see 'Connecting to a PC' for details.
Preventing Linux using the serial port
Finally you will need to reboot the Pi for the new settings to take effect. Once this is done, you can use /dev/ttyAMA0 like any normal linux serial port, and you wont get any unwanted traffic confusing the attached devices.
A tutorial on accessing the Pi's serial port from Python is available at Serial_port_programming.
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