Raspberry Pi Serial Port

RPI serialOver the past couple of years, I’ve installed operating systems on a number of little boards and I have to say, that while the Raspberry Pi with Raspbian is generally the easiest when it comes to enabling GPIO, the serial port can be a pain.

Here is how to ease the pain.

It completely escapes me why user Pi (the one everyone recommends you use) does not by default have access to the serial ports. This is, after all supposed to be an educational machine, not an example of a security system. There are generally two problems with serial… Pi doesn’t have access and this is by default used for debugging (apparently, though I’ve never used it for that). There have been various explanations as to how to get around this… editing out the bit in /boot/cmdline.txt that refers to the serial port seems to be the important one.

You might expect the serial port, being the only one available, to be called /dev/ttyS0, but you would be wrong, it is /dev/AMA0

You need to give user Pi permission – at the command line prompt…

sudo usermod -a -G dialout pi

That’s a one-off. Done. Now turn off the debugging serial.

Remove references to /dev/ttyAMA0 from /boot/cmdline.txt – which sets up the serial console on boot.

If you have similar references in /etc/inittab do the same. I don’t have that file.

Lastly for Node-Red users, the SERIAL node can be iffy to upgrade. Follow the recommendations from the Node-Red designers if you have trouble. I did have minor trouble on one older installation, not on a new installation. Thanks to their advice the problem went away.

This link is for installing/upgrading Node-Red on the Pi and refers to serial port node issues. https://nodered.org/docs/hardware/raspberrypi

While I’m here – I2c on the PI… (enable if you want to use it) on most boards I’ve set up you need pull-up resistors on data and clock lines, on the Pi these seem to be already fitted. I2c is ready to go.

5 thoughts on “Raspberry Pi Serial Port

  1. I’m a bit confused… there should be two uarts total that are named differently because they are connected on different buses. ttyS0 is the default name for the serial port that is broken out on the header pins, while ttyAMA0 should be connected internally to Bluetooth, at least on the models that have it. I’m using a Zero W right now with a GPS unit hooked up to ttyS0 through the header (after disabling console output from the OS). You can get access to ttyAMA0 by making some changes to disable Bluetooth, but I don’t know if there’s any external connection to access both. You can swap the primary serial as well, and the currently selected default console will always be aliased to serial0, but ttyS0 should be the default.

    It’s dumb that the default user doesn’t have access, but it’s the tradition. Probably goes back to the days of actual serial consoles.

    https://www.raspberrypi.org/documentation/configuration/uart.md

  2. You could also use raspi-config to enable or disable the console on the serial port. It doesn’t add the pi user to the dialout group, though.

Comments are closed.