msmithy12
Posts: 94
Joined: Fri Aug 10, 2012 8:57 am

UART

Wed Nov 28, 2012 10:17 am

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
I assume I know what I`m talking about... I probably don`t

Home: 256mb Made in UK, Rasbmc, 40" Sony Bravia KDL-40v3000
Work: 2b+, Rasbian, 6" Lilliput touchscreen

msmithy12
Posts: 94
Joined: Fri Aug 10, 2012 8:57 am

Re: UART

Thu Nov 29, 2012 3:26 pm

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
I assume I know what I`m talking about... I probably don`t

Home: 256mb Made in UK, Rasbmc, 40" Sony Bravia KDL-40v3000
Work: 2b+, Rasbian, 6" Lilliput touchscreen

stedew
Posts: 4
Joined: Sun Oct 21, 2012 9:37 am

Re: UART

Thu Nov 29, 2012 7:27 pm

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.

User avatar
tedhale
Posts: 114
Joined: Thu Sep 20, 2012 4:52 pm
Location: Williamsburg, VA, USA
Contact: Website

Re: UART

Thu Nov 29, 2012 8:11 pm

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.
- Ted B. Hale
http://raspberrypihobbyist.blogspot.com

User avatar
tedhale
Posts: 114
Joined: Thu Sep 20, 2012 4:52 pm
Location: Williamsburg, VA, USA
Contact: Website

Re: UART

Thu Nov 29, 2012 8:15 pm

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.
- Ted B. Hale
http://raspberrypihobbyist.blogspot.com

msmithy12
Posts: 94
Joined: Fri Aug 10, 2012 8:57 am

Re: UART

Fri Nov 30, 2012 9:07 am

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
I assume I know what I`m talking about... I probably don`t

Home: 256mb Made in UK, Rasbmc, 40" Sony Bravia KDL-40v3000
Work: 2b+, Rasbian, 6" Lilliput touchscreen

msmithy12
Posts: 94
Joined: Fri Aug 10, 2012 8:57 am

Re: UART

Thu Dec 13, 2012 10:57 am

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!
I assume I know what I`m talking about... I probably don`t

Home: 256mb Made in UK, Rasbmc, 40" Sony Bravia KDL-40v3000
Work: 2b+, Rasbian, 6" Lilliput touchscreen

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: UART

Thu Dec 13, 2012 11:36 am

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
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

thivtulz
Posts: 56
Joined: Tue Dec 18, 2012 10:05 am

Re: UART

Wed Mar 13, 2013 8:37 am

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 .

thivtulz
Posts: 56
Joined: Tue Dec 18, 2012 10:05 am

Re: UART

Wed Mar 13, 2013 10:31 am

how to receive data from terminal to the raspberry pi through UART.?

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: UART

Wed Mar 13, 2013 1:17 pm

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.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

Piciu
Posts: 2
Joined: Thu Nov 22, 2012 9:49 am

Re: UART

Sun Mar 24, 2013 1:34 pm

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.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 4608
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: UART

Sun Mar 24, 2013 3:32 pm

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.
Still running Raspbian Jessie on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W) but Stretch on my P3B+, P3B, B+, A+ and a B2. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

vijay_nav
Posts: 6
Joined: Thu Oct 17, 2013 11:08 am

Re: UART

Wed Oct 23, 2013 5:57 am

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

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: UART

Wed Oct 23, 2013 9:10 am

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
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

User avatar
CopterRichie
Posts: 131
Joined: Tue Mar 26, 2013 3:14 am
Location: Los Angeles CA.

Re: UART

Thu Jan 02, 2014 2:28 pm

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.

User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: UART

Thu Jan 02, 2014 3:31 pm

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?

User avatar
CopterRichie
Posts: 131
Joined: Tue Mar 26, 2013 3:14 am
Location: Los Angeles CA.

Re: UART

Thu Jan 02, 2014 4:21 pm

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

User avatar
joan
Posts: 13578
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: UART

Thu Jan 02, 2014 4:33 pm

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.

User avatar
CopterRichie
Posts: 131
Joined: Tue Mar 26, 2013 3:14 am
Location: Los Angeles CA.

Re: UART

Thu Jan 02, 2014 5:45 pm

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.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: UART

Thu Jan 02, 2014 5:52 pm

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.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

shyamgeek
Posts: 1
Joined: Mon May 08, 2017 5:27 pm

Re: UART

Mon May 08, 2017 5:28 pm

For those wanting a python way to program Raspberry Pi for UART

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

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20741
Joined: Sat Jul 30, 2011 7:41 pm

Re: UART

Tue May 09, 2017 8:59 am

Some docs here, but this is a very old thread...

https://www.raspberrypi.org/documentati ... on/uart.md
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

Return to “Interfacing (DSI, CSI, I2C, etc.)”