Difference between revisions of "Serial port programming"

From eLinux.org
Jump to: navigation, search
(Created page with "This is a guide to using the serial port under Linux; it was written for the Raspberry Pi serial port")
 
Line 1: Line 1:
This is a guide to using the serial port under Linux; it was written for the [[RPi_Serial_Connection| Raspberry Pi serial port]]
+
This is a step-by-step guide to using the serial port from a program running under Linux; it was written for the [[RPi_Serial_Connection| Raspberry Pi serial port]] with the [[Raspbian]] ''Wheezy'' distribution. However, the same code should work on other systems.
 +
 
 +
==Step 1: Connect to a terminal emulator using a PC==
 +
 
 +
If you are starting completely from scratch, follow the instructions at [[RPi_Serial_Connection#Connection_to_a_PC]], so that you end up with your Pi's serial port connected to a PC, running a terminal emulator such as ''minicom'' or ''PuTTY''.
 +
 
 +
The default Wheezy installation sends console messages to the serial port as it boots, and runs ''getty'' so you can log in using the terminal emulator. If you can do this, the serial port hardware is working.
 +
 
 +
===Possible problems===
 +
 
 +
{| class="wikitable"
 +
! Symptoms
 +
! Possible causes
 +
|-
 +
| Nothing at all shown on terminal emulator
 +
| Connected to wrong pins on GPIO header
 +
 
 +
Faulty USB-serial cable or level shifter
 +
 
 +
/boot/cmdline.txt and /etc/inittab have already been edited
 +
 
 +
Flow control turned on in terminal emulator
 +
 
 +
Wrong baud rate in terminal emulator
 +
|-
 +
| Text appears corrupted
 +
| Wrong baud rate, parity, or data settings in terminal emulator
 +
 
 +
Faulty level shifter
 +
|-
 +
| Can receive but not send
 +
 
 +
(nothing happens when you type)
 +
| Connected to wrong pins on GPIO header
 +
 
 +
Flow control turned on in terminal emulator
 +
 
 +
Faulty level shifter
 +
|}

Revision as of 13:34, 17 April 2013

This is a step-by-step guide to using the serial port from a program running under Linux; it was written for the Raspberry Pi serial port with the Raspbian Wheezy distribution. However, the same code should work on other systems.

Step 1: Connect to a terminal emulator using a PC

If you are starting completely from scratch, follow the instructions at RPi_Serial_Connection#Connection_to_a_PC, so that you end up with your Pi's serial port connected to a PC, running a terminal emulator such as minicom or PuTTY.

The default Wheezy installation sends console messages to the serial port as it boots, and runs getty so you can log in using the terminal emulator. If you can do this, the serial port hardware is working.

Possible problems

Symptoms Possible causes
Nothing at all shown on terminal emulator Connected to wrong pins on GPIO header

Faulty USB-serial cable or level shifter

/boot/cmdline.txt and /etc/inittab have already been edited

Flow control turned on in terminal emulator

Wrong baud rate in terminal emulator

Text appears corrupted Wrong baud rate, parity, or data settings in terminal emulator

Faulty level shifter

Can receive but not send

(nothing happens when you type)

Connected to wrong pins on GPIO header

Flow control turned on in terminal emulator

Faulty level shifter