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

UART on raspberry pi

Thu Jan 31, 2013 5:21 am

How to use UART on raspberry pi board?Any one can help me about this?.

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: UART on raspberry pi

Thu Jan 31, 2013 2:22 pm

Something here http://www.raspberrypi.org/phpBB3//view ... =44&t=9931 ...not sure how helpful...
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: UART on raspberry pi

Thu Jan 31, 2013 7:39 pm

thivtulz wrote:How to use UART on raspberry pi board?Any one can help me about this?.
What do you want to do? It's there and it works like any other Linux serial port. There is no magic there.

If you want a set of relatively easy to use wrappers for the serial port under C, then look for the wiringSerial library that's part of wiringPi.

https://projects.drogon.net/raspberry-p ... l-library/

but these are nothing more than wrappers round the standard stuff that Linux has suported forever.

Do remember that it's 3.3v though, so you may need level convertors.

-Gordon
--
Gordons projects: https://projects.drogon.net/

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

Re: UART on raspberry pi

Fri Feb 01, 2013 3:23 am

i'm using python.so there's any way to play with UART in raspberry pi

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: UART on raspberry pi

Fri Feb 01, 2013 1:48 pm

There is a Python wrapper on top of Gordon's C-library https://github.com/WiringPi/WiringPi-Python - seems to include some serial stuff...
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: UART on raspberry pi

Thu Feb 07, 2013 10:43 am

thivtulz wrote:i'm using python.so there's any way to play with UART in raspberry pi

Code: Select all

sudo apt-get install python-serial

3gws
Posts: 49
Joined: Sat Oct 20, 2012 10:32 am

Re: UART on raspberry pi

Fri Feb 08, 2013 11:38 am

I am using a serial port in my C# Mono program, I have a MAX232 circuit connected to the UART on the PI and which drive the text output from the pi to Hyperterm on the PC and then I have a USB2Serial Converter and a USB GPS device connected to the R-Pi and I am able to read both from both and write to the USB2Port also. I don't have a Display attached to the PI as I already have two displays on my desk along with a tablet and smart phone, I VNC onto the R-Pi.

You can also buy TTL to RS232 converters on the web for about €10.00 which you can attach directly to the R-Pi ( I think there is an example on the home automation forum on this site.)

Mono have a C# environment for the R-Pi, if you search the site you can find details on installing Mono on the R-Pi. Mono does not work fully with Hardware Floating Point versions of Raspian just yet (Hopefully it will be fully supported soon).

Some sample C# code for using a Serial Port :-

mySerial = new SerialPort("/dev/ttyUSB0", 115200);
mySerial.Open(); // open the port
mySerial.ReadTimeout = 60000; //time out 60 seconds

for (int x = 0; x <= 9; x++) // send a message 10 time to the serialport
{
mySerial.Write("This is a test " + x.ToString() +"\r" + "\n");
}

You can use Microsoft Visual Studio Express on the PC to write/Compile the code and transfer the executable file over to the pi using WinSCP.

Regards

3gws

Mice
Posts: 2
Joined: Fri Mar 08, 2013 10:44 pm

Re: UART on raspberry pi

Fri Mar 08, 2013 10:46 pm

Hey.
Can You share with us a way to read data from port and store in string, for example?

3gws
Posts: 49
Joined: Sat Oct 20, 2012 10:32 am

Re: UART on raspberry pi

Sat Mar 09, 2013 9:00 am

not to sure who your request is directed at, if is is me regarding mono code to read the serial port using c# let me know and I will post it in the next day or two.

Regards

3gws

Mice
Posts: 2
Joined: Fri Mar 08, 2013 10:44 pm

Re: UART on raspberry pi

Sat Mar 09, 2013 3:27 pm

not to sure who your request is directed at, if is is me regarding mono code to read the serial port using c# let me know and I will post it in the next day or two.

Regards

3gws
t now and is really a

Yes:)
I am fighting with this code right now, but still unsuccessful...

3gws
Posts: 49
Joined: Sat Oct 20, 2012 10:32 am

Re: UART on raspberry pi

Sun Mar 10, 2013 4:23 pm

Christopher Landress has a good post on using the serial Port using C# on the R-Pi.

http://www.raspberrypi.org/phpBB3/viewt ... 0&start=50

I hope this help you out.

Regards

3gws.

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

Re: UART on raspberry pi

Wed Mar 13, 2013 2:33 am

how to find the serial port number of raspberry pi board

theimmc
Posts: 53
Joined: Tue Feb 05, 2013 10:31 pm

Re: UART on raspberry pi

Wed Mar 13, 2013 3:15 am

thivtulz wrote:how to find the serial port number of raspberry pi board
If you are running Raspbian, it is /dev/ttyAMA0

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

Re: UART on raspberry pi

Wed Mar 13, 2013 6:29 am

i'm using wheezy raspbian....so the port number will be same is it....

Here my code..

Code: Select all

import serial
serialport = serial.Serial('dev/ttyAMAO,9600)
serialport.write("My string output to serial port")

My objective is want to display in my pc using uart.thanks

Devangini
Posts: 1
Joined: Mon Mar 18, 2013 9:27 pm

Re: UART on raspberry pi

Mon Mar 18, 2013 9:30 pm

My pi has debian running on it. What would be the USB port for it? I can see ttyAMA0 in /dev directory but when i write Python code as mentioned in the earlier posts, no data is sent to that port.

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

Re: UART on raspberry pi

Mon Mar 25, 2013 7:13 am

Is there the python code giving any errors; if not check UART connection cable between RPi and PC.

Return to “Other programming languages”