Turning off the UART functioning as a serial console
UPDATE – You can now disable serial via the GUI or command line raspi-config tool. The below is no longer good for Raspbian Jessie and above, it doesn’t work
(This is based on Clayton Smiths nifty guide).
Backup the /boot/cmdline.txt file before you edit it just in case of screw-ups:
sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt
Edit the file:
sudo nano /boot/cmdline.txt
Running “2014-09-09-wheezy-raspbian.img” the file contained the following:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
Delete any parameters involving the serial port “ttyAMA0” or “serial0”, which in this example is:
console=ttyAMA0,115200
Which gives:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
Press CTRL+X to exit and save .
You also need to edit this file <<This is no longer present with Raspbian Jessie:
sudo nano /etc/inittab
Search for the serial port usage by using CTRL+W and typing:
ttyAMA0
This should find the line of the file specifying the serial port (if there is one). Use “#” at the start of the line to comment it out. Then press CTRL+X to save and exit.
Enter “sudo reboot” to restart the pi and now the UART will be available for another process to use it, or the pins can simply be used as general IO.
4 years ago
I tried as below but not working
if (!empty($key))
{
//Send string including variables
system(” . escapeshellarg($key) . “” > /dev/ttyAMA0″);
}
8 years ago
I wrote to script to automate this, available on GitHub: https://github.com/itemir/raspberry_pi_utils
May help those who are struggling on the command line.
8 years ago
Works! Thanks!
But up to date its “console=serial0,115200” instead of “console=ttyAMA0,115200”
9 years ago
I did all this but still I am getting error like
/home/pi/uart/uartconf.cpp:6:11: error: expected initializer before ‘open’
I used the function open for opening the uart filestream like this
uart0_filestream = open(“/dev/ttyAMA0”, O_RDWR | O_NOCTTY | O_NDELAY);
Does anyone have any suggestions?
9 years ago
Please edit your HOWTO to point that “You SHOULD change 2 settings: one in /etc/inittab and one in /boot/cmdline.txt”. Because the “inittab” part can easily go unnoticed. Thanks by the way.
9 years ago
Not sure I understand, both are there as separate steps?
9 years ago
I didn’t notice the part about /etc/inittab changes in the first place, it’s not attention grabbing. That’s why I debugged for hours because if you pass the second step, the errors look like it is caused from elsewhere (it opens the port but there ore some random error messages like ‘input/output error’) OK, it’s my fault, I know, I should RTFM. Anyway, I suggest changing the layout of this howto in order to get a clearer look of the two separate steps. Everything is on the same indentation, no step counts, no abstract at the beginning.
9 years ago
Ahh well yes, RTFM and if in doubt read it again! Will leave your comment here in case anyone has the same problem, but trying to make every page on here perfectly idiot proofed (pardon the expression :-) ) would be too big a task, plus we much prefer to keep these notes short and sweet where possible without any waffle!
9 years ago
no excuses, I know, I know :)
9 years ago
I could not connect to my pi over ssh after doing this, why is this happenning ?
10 years ago
NEVER DO THIS!!! I HAD to reinstall the raspbian 3 times!!! Never do this sh*t.
10 years ago
I tried this before and I had to reinstall the OS, is there another way?
9 years ago
You’ve done it wrong, try again.
4 years ago
…or you could just use the easy script I’ve developed to do this for you :-)
https://github.com/lurch/rpi-serial-console