3

Enable serial port on Raspberry Pi

This post describe how to enable the serial port avalaible on Raspberry Pi connector. By default it is used by the Linux console and you can not use it for another usage.

We will disable the Linux console mode for using the RX and TX as we want

I’m connecting to my Pi with SSH because mine do not have screen or keyboard connected,

Edit July 2016

For latest Jessie version

you should be able to get use of Serial just running

go to Advanced Options/Serial and set No to “Would you like a login shell to be accessible over serial?”, valid and reboot, that’s all. Take a look for specific to Raspberry PI V3 at the end of this post.

I also noticed sometimes UART is disabled in kernel. The enable it you need to check in /boot/config.txt the line enable_uart

If it’s set to 0 like follow

You need to change to 1 as follow

And reboot of course!

For older version of Raspbian

If the  raspi-config tool does not have this option (mainly for old operating system), here is the manual operations to follow :

  • Modifiy in /boot/cmdline.txt  file the line that contains the following text and delete froml this line just the following text

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200

After modification, the line should look like this one :
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
Do not forget to save the the file !!

  • Now we need to disable the login on serial port. So you just need to modify the  /etc/inittab, file. You will find in this file the following line :

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Comment the line adding # before, this should now look like
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Once again, save your file and now, reboot you Rasperry Pi issuing a
shutdown -r now
That’s it, now you can play with the serial port that is called /dev/ttyAMA0

You may need to add your username to the dialout group if you are not root, doing this issuing a
sudo usermod -a -G dialout yourusername

Serial has changed with Raspberry PI Version 3

With Raspberry PI version 3, things have changed, the real UART (Serial) is now affected to Bluetooth hardware module and the old one is now managed by software. Old serial on PI3 is /dev/ttyS0  and no more /dev/ttyAMA0 because this one is connected to Bluetooth.

It seems in the latest Jessie version there is a /dev/serial0 so you should replace /dev/ttyAMA0  with /dev/serial0 to use as before.

But, as it’s software managed, this serial interface has a number of drawbacks.

  • There is no support for parity
  • Speed is limited (it’s software managed)
  • If your CPU is under heavy load it could corrupt the data especially at high speeds.

So if you really need reliable Serial on /dev/ttyAM0  (as before) I strongly suggest to use the hardware one.

To do so, use overlays remap as follow (select the one you need)

 

To disable bluethooth and set /dev/ttyAM0 to real UART (as before)

Edit the file /boot/config.txt and add the following line at the end :

Then stop bluetooth service with sudo systemctl disable hciuart and reboot

 

To switch bluetooth to software UART and set /dev/ttyAM0 to real UART (as before)

Keep in mind that this one will remain possible software problem on bluetooth (software UART), but not on Serial (Hardware)

Edit the file /boot/config.txt and add the following line at the end :

Edit the file /lib/systemd/system/hciuart.service and replace  /dev/ttyAMA0  with  /dev/ttyS0

If you have a system with udev rules that create /dev/serial0  and /dev/serial1 (look if you have these one), and if so use /dev/serial1 .

Then reboot

See detailled READ ME about this point on official Raspberry PI Firmware repo

 

Charles

Charles

Comments on this topic in community Forums.