Openning Serial Ports


6 posts
by Venturer » Thu Aug 02, 2012 5:54 pm
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
Posts: 2
Joined: Fri Jul 27, 2012 7:50 pm
by timhoffman » 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
Posts: 85
Joined: Sat Nov 05, 2011 11:31 pm
by Venturer » Fri Aug 03, 2012 6:51 pm
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
Posts: 2
Joined: Fri Jul 27, 2012 7:50 pm
by rmashrmash » Sat Mar 08, 2014 7:33 pm
Thanks very much. This worked nicely for me.
Posts: 1
Joined: Wed Sep 04, 2013 12:16 am
by AndrewS » Mon Jun 23, 2014 8:40 pm
I wrote a little script to make it easier to disable (and re-enable) the getty https://github.com/lurch/rpi-serial-console
User avatar
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
by tribesh » Fri Jan 27, 2017 8:50 pm
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
Posts: 1
Joined: Fri Jan 27, 2017 8:41 pm