Using the Raspberry Pi’s serial port

The stock Debian image for the Raspberry Pi uses the UART as a serial console. I was able to connect to it from my Ubuntu laptop via my 3.3-volt USB FTDI TTL-232 cable. I connected Raspberry Pi’s ground pin to the ground pin of the FTDI, the Rasberry Pi’s TX pin to the FTDI’s RX pin and vice versa. (The Raspberry Pi’s pinout is available here.) Then on my Ubuntu laptop I installed minicom (sudo apt-get install minicom) and fired it up with:

minicom -b 115200 -o -D /dev/ttyUSB0

After typing in a username, I got a password prompt and was able to log in. Also, the serial console allowed me to see all the kernel output during boot, which could be handy someday.

But I wanted to use the Raspberry Pi’s UART for my own purposes, not as a serial console. To achieve that, I did the following.

First, I made a backup of the /boot/cmdline.txt file, which contains the kernel parameters:

sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt

Then I edited it:

sudo vi /boot/cmdline.txt

Originally it contained:

dwc_otg.lpm_enable=0 rpitestmode=1 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

I deleted the two parameters involving the serial port (ttyAMA0) to get the following:

dwc_otg.lpm_enable=0 rpitestmode=1 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

I rebooted (sudo reboot) to confirm that kernel output was no longer going to the serial port. But the serial console was still available. So I edited /etc/inittab:

sudo vi /etc/inittab

I commented out the following line:

2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Finally, I rebooted again and confirmed that nothing was touching the serial port anymore. Then, to test it out I installed minicom on the Raspberry Pi:

sudo apt-get install minicom

And ran it:

minicom -b 115200 -o -D /dev/ttyAMA0

After firing up minicom on my Ubuntu laptop again, I was able to send data in both directions!

Now to get the Raspberry Pi talking to an Arduino…

53 thoughts on “Using the Raspberry Pi’s serial port”

  1. Hi there, great write-up that is accessible to linux n00bs like me. I wonder if you can help me at all further please?
    I want to attach a serial mouse systems mouse to my Pi.

    I have a RS232 breakout board, and have swapped a MAX3232CPE chip in to make sure it’s 3V3 friendly.
    I followed all of the above to help me detach the console from ttyAMA0
    I learned about apt-get and installed inputattach and ldattach.
    Set ldattach -s 1200 MOUSE /dev/ttyAMA0
    Set inputattach –mousesystems /dev/ttyAMA0 &

    sadly this does not seem to have resulted in, as I hoped, a working mouse :(

    Out of ideas – all of the above was new to me!!! Can you offer any pointers please?
    Cheers, Alex

    1. You’d probably be better off trying to set it up with the USB’s serial connection. you can get a USB that separates the internal wires into ones that are breadboard compatible and then simply attach the mouse output wire with the computer’s input wire, connect the ground and either convert the USB’s power output into what you need or use an external power source. I’d be interested to see what comes out of this, for example if there’s a usable driver for it.

  2. Most serial mouses “steal” power from the other datalines (RTS/CTS etc.) to power themselves.. the RS232 breakoutboard you are using does not support these lines so the mouse is probably just not getting enough power to work.

  3. Great post

    Can you maybe give me an advice how to enable the RPi serial port adapter (USB) to send data from the RPi to a device with FTDI chip attached (connected to RPi USB)?


  4. Hi, I have the RPi serial port working as a console connected to my PC. Like you, I wish to use the serial port for another purpose, sending and receiving ascii words to control off the shelf I/O cards.

    I tried to edit the RPi’s cmdline.txt file; however, could not. Opening it in vi, I get one line of code “datadev=mmcblk0ps”. Then there are 21 lines with only the tilda character and then one line:
    “/boot/cmdline.txt” [Incomplete last line] 1 line, 17 characters

    Any help would be much appreciated!

    1. Found my faults. Had installed Raspi using berry bootloader. This did load and run; however, there were discrepancies.

      After loading the OS image using wind32diskimager, all is fine. Now looking at serial communication!

      Thanks for the great info.

  5. I did follow the above instruction but still i am not able to use the uart;
    I get the error as “Read failed- : Resource temporarily unavailable”

    Can you please help me solve the same.


        1. Unfortunately I’m out of ideas, and I won’t have my Pi on hand again for another couple weeks so I can’t try anything out. I’d suggest asking on the Raspberry Pi forums. Let me know if you find a solution so I can add it to my article.

  6. The project I’m working on requires inputting ASCII strings from two separate RS232 serial interfaces (operating at different speeds). My current thinking is to just MUX them into GPIO 15 (RxD) one at a time (with the MUX selector being one of the other GPIO pins). The data strings are repeating, and no transmit from the RPI to either of the other devices is required.

    I’m curious – is there a simpler way to interface these two RS232 inputs to the RPI than to have the external MUX logic?

    Any and all input is appreciated – Thanks!

    1. hey hi !

      I’m currently working on two RS232 inputs too !
      Have you completed your project ?
      Mind share any experience ? :)

  7. I tried commenting out “2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100″
    as you said but the my line was not exactly like this, it was TO:2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100”

    and was right at the end of the file

    i did the sudo reboot ( the first time i ever did this command)

    now my pi said “cannot Restart”

    now it wont start at all even if I turn it off and on again

    After I put the soft float os then installed JDK Java

    Compiled all the programs in the PI4j

    now I have to start all over again

  8. Great stuff, am able to talk to my XBee after disabling both of those… Another site only mentioned disabling the first one, so I battled for awhile.

  9. Hi,

    we have one problem for about Rs232

    example I want give or take 1 data Pi to PC, I can send to PC no problem but I cant take Pc to Pi any data… if I send 30 times or 40 times after I can send PC to Pi… then it be normaly… but if I push caracter from keyboard after lock serial com… after I send again 30 or 40 times data then open again… after normaly…

    I tried resister then I use max3232 but no change… only I have problem for Pi to PC send wire…

    example some example I have from internet “Pi serial com. to ardiuno” but this not work…

    I will wait your helps …

    thanks a lot…

  10. The simplest way to do it is just comment out the line in /etc/inittab that uses the serial port

    #2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

    Then reboot.

    The serial port will be active while the system boots, but then will be idle once booting is complete.

  11. hello… just wondering… is it possible to connect the raspberry pi A to a digital clock? my clock is TL – 4819. it is a digital wall clock.. i want its time to synchronize with my raspberry time…

  12. Awesome, did not understand why the Raspberry Pi was not showing anything coming from the Arduino! Did the two changes, rebooted and it finally worked :) (BTW, using a 3V3/5V logic level converter chip)

  13. im using debian. i wanna make serial communication using rs232 cable. how should i know what the serial device connected to the raspberry pi? so that i can declare it in minicom or cutecom to open the device

  14. What if i wanna test serial communications between 2 serial devices on my Pi without using any PC? what would i have to do? i mean i have made a program using vs2010.. but now i need to terminate the usage of pc but still maintaining the capability of monitoring 2 serial devices on the Pi.. i seriously need the guidance.. 😀

  15. Hello all of You.

    I am trying to use the rpi2 serial port using a windows terminal.exe software.
    I am usiing the Exagear x86 emulator and the wine system on top for emulating the windows environment.
    My ttyAMA0 is tested using minicom under Linux
    My Exagear and wine is running, because I can start other windows programs.
    But – can anyone explain how to make the connection between the uart (ttyAMA0) and the COM1 used by the terminal.exe software ??

Leave a Reply

Your email address will not be published. Required fields are marked *