Page 1 of 1

UART

Posted: Wed Nov 28, 2012 10:17 am
by msmithy12
Ok, so i wanna start using the UART pins on the GPIO (GPIO14,15) and i just wanna start walking by looping the tx and rx and sending data to and from my PI.

In a future far far away i plan on having a C program running with an interrupt that is started from a serial command. (but i dont wanna be spoon fed) i just wanna start using UART and build up slowly.

My question is after physically looping TX and RX then what do i do? ( i haven't looped TX and RX in case i need to put something between them)

Thanks in advance
Matt

Re: UART

Posted: Thu Nov 29, 2012 3:26 pm
by msmithy12
OK, so i got a bit further with this:

I ran the following code in terminal:

Code: Select all

echo - "sent from pi" > /dev/ttvAMA0
and all i got was
bash: /dev/ttyAMA0: Permission denied

so i tried

Code: Select all

sudo echo - "sent from pi" > /dev/ttvAMA0
same error
bash: /dev/ttyAMA0: Permission denied

I guessing i have a command wrong somewhere, any help?

(also noticing 50 views no replies: am i being stupid is this something that should be easier and people dont wanna offend me, please offend away I'm thick / thick skinned

Matt

Re: UART

Posted: Thu Nov 29, 2012 7:27 pm
by stedew
ok to be not the 51the in your list:
the builtin serial port is imho (i 'am not a expert neither) used for the logon console.
you have that one turned of becuase the serial is "owned" by the bootloader/kernel (getty)
some ideas are in viewtopic.php?f=44&t=17360
Hope this one helps,
cheers.

Re: UART

Posted: Thu Nov 29, 2012 8:11 pm
by tedhale
stedew is correct, another process already has the device open, so you get that error.

Look at my blog post
http://raspberrypihobbyist.blogspot.com ... -port.html

Look at the 2nd half of the post for instructions on how to "free up" the serial port.

Re: UART

Posted: Thu Nov 29, 2012 8:15 pm
by tedhale
BTW,
you will see a lot of views and few posts because most people coming here are looking for answers, not giving them out.
Most likely, the first 50 viewers had no clue how to solve your problem.

I read this forum for two reasons
1. I need to find answers myself sometimes, but mostly
2. I enjoy helping people, so I look for new posts that I can add info to.

Re: UART

Posted: Fri Nov 30, 2012 9:07 am
by msmithy12
thanks guys!
Modified those 2 files and everything works great
http://raspberrypihobbyist.blogspot.co.uk has some great stuff if any1 is reading this looking for similar solutions give that page a look

Re: UART

Posted: Thu Dec 13, 2012 10:57 am
by msmithy12
wiringPi has a serial out command that i have found, so if your reading this looking for some sample C code check out

https://projects.drogon.net/raspberry-p ... mment-1116

Gordon floats around the forum so he might pick up questions but his website/blog is so comprehensive I have learnt some great stuff C programming wise!

Re: UART

Posted: Thu Dec 13, 2012 11:36 am
by Joe Schmoe
Sort of appropos of nothing, but...

Nobody has commented on this, so I'll pipe in. Note that:

sudo echo foo > /dev/ttyAMA0

won't do what you expect it to, because the shell redirection is performed by your local shell, not by the command run under sudo.

You can verify this by doing (assuming, of course, that plugh doesn't already exist):

sudo touch /tmp/plugh
sudo echo test > /tmp/plugh # Fails
sudo bash
echo test > /tmp/plugh # works
exit

Re: UART

Posted: Wed Mar 13, 2013 8:37 am
by thivtulz
my objective is want to display the output in my laptop...
this is my coding..

Code: Select all

import serial
ser = serial.Serial("/dev/ttyAMA0",9600)
ser.write("My String outputto serial port")
is there any mistake in my coding.Thanks .

Re: UART

Posted: Wed Mar 13, 2013 10:31 am
by thivtulz
how to receive data from terminal to the raspberry pi through UART.?

Re: UART

Posted: Wed Mar 13, 2013 1:17 pm
by techpaul
How have you connected the Pi to the PC/Laptop?

It needs an RS232 converter between GPIO UART and PC/Laptop?

Have you disabled the kernel from using the GPIO UART?
This is detailed in many places and posts in this thread.

Re: UART

Posted: Sun Mar 24, 2013 1:34 pm
by Piciu
By the way, it's not

Code: Select all

echo - "sent from pi" > /dev/ttvAMA0
It's

Code: Select all

echo - "sent from pi" > /dev/ttyAMA0
Difference is in the name of the port ( I guess it's a port) ;)
There is ttY, not ttV. Maybe someone will have this problem in future.

Re: UART

Posted: Sun Mar 24, 2013 3:32 pm
by FTrevorGowen
thivtulz wrote: my objective is want to display the output in my laptop...
FWIW (and slightly off-topic) Whilst I havn't done anything much with the Pi's own UART (yet - I'm just starting to do "GPIO things" "at the mo.") I did test out a USB - RS232 cable a while ago and logged it as "working" in the wiki. Some pictures & screenshots etc. are at http://www.cpmspectrepi.webspace.virgin ... apter.html where I'm using a ancient serial printer/terminal to display the output etc. There's also some general "RS232" stuff elsewhere in my webpages that goes "way back".
Trev.

Re: UART

Posted: Wed Oct 23, 2013 5:57 am
by vijay_nav
please help me how to work with uart in raspberry pi....
please provide some projects or some links regarding uart in raspberry pi...........by using python scripting

Re: UART

Posted: Wed Oct 23, 2013 9:10 am
by DeeJay
Try a Google search for "raspberry uart python"

These hits look useful -

https://sites.google.com/site/semillero ... rials/gpio

http://www.stuffaboutcode.com/2013/09/r ... ython.html

Re: UART

Posted: Thu Jan 02, 2014 2:28 pm
by CopterRichie
Hello one and all, I have a question please. I would like to use the Raspberry Pi to program an Arduino chip directly using /dev/ttyAMA0 however, the Arduino requires the DTR to be toggled prior to uploading the code. So, which GPIO pin on the Raspberry Pi correspond to the DTR?

Thank you.


I will be using the Arduino IDE on the Raspberry PI for programming.

Re: UART

Posted: Thu Jan 02, 2014 3:31 pm
by joan
CopterRichie wrote:Hello one and all, I have a question please. I would like to use the Raspberry Pi to program an Arduino chip directly using /dev/ttyAMA0 however, the Arduino requires the DTR to be toggled prior to uploading the code. So, which GPIO pin on the Raspberry Pi correspond to the DTR?

Thank you.


I will be using the Arduino IDE on the Raspberry PI for programming.
I'm not sure the Pi's UART supports DTR.

Regardless of that can you not choose any spare gpio and call that DTR, i.e. connect it to the Arduino and toggle the line in your code?

Re: UART

Posted: Thu Jan 02, 2014 4:21 pm
by CopterRichie
joan wrote: I'm not sure the Pi's UART supports DTR.

Regardless of that can you not choose any spare gpio and call that DTR, i.e. connect it to the Arduino and toggle the line in your code?
I located the following but not sure how to implement it.

http://www.raspberrypi.org/phpBB3/viewt ... 241#p39241

Re: UART

Posted: Thu Jan 02, 2014 4:33 pm
by joan
The solution in the other thread seems to require changing gpios 16/17 to an ALT mode (Alt 5, CTS/RTS) and using them as DSR/DTR.

I don't see the point. To my mind it's simpler to toggle a gpio.

Anyhow there are C libraries to allow you to set the ALT modes if that's what you want to do.

Re: UART

Posted: Thu Jan 02, 2014 5:45 pm
by CopterRichie
I think but not sure, the Arduino IDE toggles both the DTR and the CTS lines. So I might be ok, will have to test to be sure.

Thank you for the assistance.

Re: UART

Posted: Thu Jan 02, 2014 5:52 pm
by Richard-TX
I am going out on a limb anticipating the nest question.

To change the speed of the uart one has to open the device and then change the speed using an ioctl call or issue a stty command depending on the programming language. Closing the device and reopening it results in it reverting back to the default settings.

Re: UART

Posted: Mon May 08, 2017 5:28 pm
by shyamgeek
For those wanting a python way to program Raspberry Pi for UART

http://radiostud.io/understanding-raspb ... unication/

Re: UART

Posted: Tue May 09, 2017 8:59 am
by jamesh
Some docs here, but this is a very old thread...

https://www.raspberrypi.org/documentati ... on/uart.md