Page 1 of 1

Openning Serial Ports

Posted: Thu Aug 02, 2012 5:54 pm
by Venturer
Hi,

I have been going round in ever decreasing circles for the past few days trying to connect to the serial port on the GPIO.

I have installed PySerial and I have tryed to add the pi user to the dialout group with:

sudo usermod -a -G dialout pi

which returns without error.

When I try to connect to '/dev/ttyS0' i get file or directory not found.

I have tried '/dev/ttyAMA0' and get permission denied

1) which is the correct device name to use?

2) How do I get permission to open it?

Thanks,

Steve

Re: Openning Serial Ports

Posted: Fri Aug 03, 2012 1:18 am
by timhoffman
Hi

You need to use /dev/ttyAMA0

But this requires you do a few things.

1.Make sure your userid (default is pi) is a member of the dialout group. (which your usermod command did)
2. You need to stop the getty running on the GPIO serial console.

To do this you need
- remove references to /dev/ttyAMA0 from /boot/cmdline.txt - which sets up the serial console on boot.
In my case old contents

Code: Select all

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
and new contents

Code: Select all

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
Also you need to disable the getty on that serial port in /etc/inittab
Comment out the following line

Code: Select all

#2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Oh and reboot ;-)

Cheers

Tim

Re: Openning Serial Ports

Posted: Fri Aug 03, 2012 6:51 pm
by Venturer
Tim,

Thank you for that information. I have done the changes and I can now open ttyAMA0 and (apparently) write to it.

The contents of my two files were slightly different. When I have confirmed I am actually send the data (I have to do a bit of hardware first!) I shall post the complete sequence I have done in case it helps someone else.

Steve

Re: Openning Serial Ports

Posted: Sat Mar 08, 2014 7:33 pm
by rmashrmash
Thanks very much. This worked nicely for me.

Re: Openning Serial Ports

Posted: Mon Jun 23, 2014 8:40 pm
by AndrewS
I wrote a little script to make it easier to disable (and re-enable) the getty https://github.com/lurch/rpi-serial-console

Re: Openning Serial Ports

Posted: Fri Jan 27, 2017 8:50 pm
by tribesh
I did as AndrewS advised. But it lead to "no directory found"; instead from "permission denied".
I'm using Pi model B rev1 Raspbian Pixel

Re: Openning Serial Ports

Posted: Wed Apr 19, 2017 6:23 pm
by EmmanuelCaster
Please any update on this issue for Raspbian Jessie Pixel Since /etc/inittab is no longer? plus I already checked this link posting.php?mode=reply&f=66&t=123081&si ... be0bf8126c and I couldn't coin a solution out of it 

Re: Openning Serial Ports

Posted: Fri Apr 21, 2017 4:08 pm
by klintkrossa
Hello,

I have noticed that raspi-config the serial port is not enabled. ???? :|

Re: Openning Serial Ports

Posted: Tue Aug 29, 2017 2:48 pm
by nathan.t.holder
timhoffman wrote:
Fri Aug 03, 2012 1:18 am
Hi

You need to use /dev/ttyAMA0

But this requires you do a few things.

1.Make sure your userid (default is pi) is a member of the dialout group. (which your usermod command did)
2. You need to stop the getty running on the GPIO serial console.

To do this you need
- remove references to /dev/ttyAMA0 from /boot/cmdline.txt - which sets up the serial console on boot.
In my case old contents

Code: Select all

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
and new contents

Code: Select all

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
Also you need to disable the getty on that serial port in /etc/inittab
Comment out the following line

Code: Select all

#2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Oh and reboot ;-)

Cheers

Tim
Does not exist on my raspbian machine!
/etc/inittab

Re: Openning Serial Ports

Posted: Tue Aug 29, 2017 10:32 pm
by DougieLawson
/etc/inittab hasn't existed since Jessie arrived with systemd - two years ago.

The console getty is started with a systemd service file.