Raspberry Pi Serial Port Usage
How to use the serial port on your Raspberry Pi with a Serial Pi
Created: 02/10/2015 | Last Updated: 02/10/2015
The serial port on the Raspberry Pi is configured as default for console input/output. This allows you to login and interact with the Raspberry Pi via the serial port but you cannot use the serial port with your programs.
To use the serial port with other programs and hardware such as modems, arduino boards etc you need to disable the console login.
To Disable Serial Port Login
You need to edit two files in order to use the serial port with your own programs.
When the Raspberry Pi boots, the bootup information is sent to the serial port. You can disable this by editing the /boot/cmdline.txt file
Depending on the version of Raspbian Linux you are using the contents of the file look like this
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
dwc_otg.lpm_enable=0 console=serial1,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Remove all references to ttyAMA0 and serial1 so the file looks like this:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Save the file to save your changes.
For Raspbian Wheezy you will also need to edit a second file /etc/inittab
sudo nano /etc/inittab
The /etc/ inittab file has the command which enables the login prompt which needs to be disabled.
Near the end of the file will be a line similar to this:
respawn:/sbin/getty -L ttyAMA0 115200 vt100
Disable this line by adding a # character to the beginning.
#respawn:/sbin/getty -L ttyAMA0 115200 vt100
Save the file.
You should then reboot your raspberry pi with the following command
sudo shutdown -r now
You can now use your serial port with other applications on your Raspberry Pi.