Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 12:46 pm

hello,
I just observed that there is a new procedure to enable Pi 2 UART pins for C programs, other than about 1 1/2 years ago.
At that time, one has to edit boot/config.txt (delete console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 ) and outcomment sth in etc/inittab,
but that file does not exist any more.

Via raspi-config one could disable 9.Advanced - A8 Serial
"Would you like a login shell to be accessable over Serial?"
choose <No> click button, ENTER .
message:
"Serial is now disabled". <OK> confirm, reboot.

This menu is also different now and I don't see the correct preferences any more.

Via the Pixel menu UART is disabled.
If so, I can't get UART communication to a device (Arduino) at all any more (formerly, 1-2 years ago, it worked).
if UART is enabled in the Pixel menu, I get a UART communication, but everything is messed up by weird extra messaging, or it always gets stucked, and I can't get it synced correctly and quickly.

So what is the correct procedure to disable the serial UART console and enable it for programming?
Is there a GUI menu? or a script? Or what is the correct procedure?

(Pi 2, old one, current Jessie, last update/upgrade last month)

User avatar
bensimmo
Posts: 4157
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 12:57 pm

None of this is 'c' specific, it's just hardware setup.

Open a terminal window or be at the command line.

sudo raspi-config
Goto the interfaces option (5)
Find serial. (6)
Select it and turn off.
Select No to do you want console.
Select Yes to do you want serial device
When it asks.
Reboot.

That should setup UART serial on /dev/serial0

You should hopefully see information with
(At a Terminal)
cat /dev/serial0


Last time I tried for helping with GPS and something else (LoRA) a few weeks back, The desktop (then called pixel) configuration tool had not been updated to match raspi-config and so did not work for this.

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 1:13 pm

thank you, I did so, but typing
cat /dev/serial0
the command is stuck, nothing shows, nothing happens (exept line feed), not even a new prompt.

only ^C then stops it and I get a new prompt.

dgordon42
Posts: 760
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 1:22 pm

To complement @bensimmo's post above, if you cannot or do not wish to use 'raspi-config', you can achieve the same results by:

1. Add the line

Code: Select all

enable_uart=1
to the '/boot/config.txt' file, this line will set up the Serial Port UART and the necessary clocks on all Pi models.

2. Remove the phrase "console=serial0,115200" from the '/boot/cmdline.txt' file. This action prevents Linux from starting a Console on the Serial Port.

Reboot your Pi.
Stiller wrote:thank you, I did so, but typing
cat /dev/serial0
the command is stuck, nothing shows, nothing happens (exept line feed), not even a new prompt.
Post the output of

Code: Select all

ls -lh /dev/serial*
Hope this helps,
Dave.

User avatar
bensimmo
Posts: 4157
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 1:53 pm

Does that method (good old traditional method :-))
Also need
$ sudo systemctl stop serial-getty@ttyAMA0.service
$ sudo systemctl disable serial-getty@ttyAMA0.service

To disable the console on the Pi2 (and Pi1 based) in question.

(ttyS0 on Pi3/ZeroW)
Last edited by bensimmo on Fri Jul 07, 2017 2:39 pm, edited 1 time in total.

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 2:29 pm

I did now what dgordon42 wrote, and beth before and also now
ls -lh /dev/serial*
shows /dev/serial0 -> ttyAMA0

nevertheless, I don't get the UART communication working to Arduino. I wanted to send 64bit byte arrays there and back.
>1 year ago I run that code the last time, and everyting was fine, both for Arduino-Arduino and even for Raspi-Arduino - now everything is corrupt.

I think I open a new topic about that issue. Hopefully this time someone could provide a code which works for that purpose - I am really clueless.

It's frustrating.

dgordon42
Posts: 760
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 2:41 pm

bensimmo wrote:Does that method (good old traditional method :-))
Also need
$ sudo systemctl stop serial-getty@ttyAMA0.service
$ sudo systemctl disable serial-getty@ttyAMA0.service
As far as I know, no. Removing "Console=serial0,115200" from '/boot/config.txt' is enough.
It prevents the Linux Kernel from setting up the Console on the UART and sending the boot messages to it, which would happen before SystemD gets going during the boot.

I posted in case the OP wanted to incorporate code in his C program to check or set the Serial Port UART, or configure SD Cards programmatically. My post was meant to point him in that direction. Your 'raspi-config' is a better option for a user sitting at their Pi, and it can be run from the CLI or the GUI.

Dave.

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 2:51 pm

Well, in that GPS threads, I post the link to https://www.raspberrypi.org/documentati ... on/uart.md , so you didn't pick it up. I post it again.

+1 and a little correction on Removing "Console=serial0,115200" from '/boot/cmdline.txt' is enough.

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 3:08 pm

allfox wrote:Well, in that GPS threads, I post the link to https://www.raspberrypi.org/documentati ... on/uart.md , so you didn't pick it up. I post it again.

+1 and a little correction on Removing "Console=serial0,115200" from '/boot/cmdline.txt' is enough.
that I had already done, from the start (it's been removed since > 1 year already).

- but do you mean:
in /boot/config.txt no
enable_uart=1
at all, opposite to what dgordon42 wrote?

the description in the link is really impossible to understand, much too many words, totally unsorted, and much too complicated explained what to do.

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 3:26 pm

Stiller wrote: - but do you mean:
in /boot/config.txt no
enable_uart=1
at all, opposite to what dgordon42 wrote?
It's not opposite, it's about "complete".
enable_uart=1 means lock the core_freq, so you have a stable baud rate for mini-UART. With this line, new Pi like Pi 3 or Pi W would work.
But you have a Pi 2. So you could ignore it.
dgordon42's answer would always work on currently any Pi. Without enable_uart=1, it would work on Pi 1 and Pi 2.

You could try to read document.

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 3:32 pm

my English is poor, I don't understand complex English documents, just single short sentences.
So I removed already "Console=serial0,115200" from '/boot/cmdline.txt' since > 1 year and ignored that enable_uart=1 but it still does not work for UART communication with my Arduino - 1 year from now it did.

User avatar
bensimmo
Posts: 4157
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: new procedure to enable Pi 2 UART pins for C programs?

Fri Jul 07, 2017 4:18 pm

Stiller wrote:my English is poor, I don't understand complex English documents, just single short sentences.
So I removed already "Console=serial0,115200" from '/boot/cmdline.txt' since > 1 year and ignored that enable_uart=1 but it still does not work for UART communication with my Arduino - 1 year from now it did.
The linked document is overly complicated for a 'i just want to do it's or 'beginner' user.

It's also not pretty on my phone.

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: new procedure to enable Pi 2 UART pins for C programs?

Sat Jul 08, 2017 8:26 am

update:

I have no idea why it didn't work yesterday at all, now it suddenly works with UART on my Pi again. Perhaps a broken wire? no idea, anyway, but I'm glad that I can state that it's ok with UART like before, finally.
Thanks to all for helping about UART configuration!

Return to “C/C++”