[Tutor] Python Serial Communication

Alan Gauld alan.gauld at btinternet.com
Mon Sep 29 13:58:09 CEST 2014


On 28/09/14 10:32, m.v gautam wrote:

> import serial
> ser = serial.Serial('/dev/ttyAMA0',38400,timeout = 10)
> while True:
>          print "try"
>          val = ser.read(10)
>          print val

> There is a blank line being printed every time in place of val.

How do you know that val is not a blank line?
Remember that a blank line is not necessarily empty, it might be full of 
unprintable characters.

Try this instead:

while True:
      print "try"
      val = ser.read(10)
      print 'len: ', len(val)
      for char in val:
         print ord(char)

That will tell you ow many characters you actually
read and what character values are being read.
You might find you have and end of file in there or similar.

> The logic level conversion between atmega and rpi has been done perfectly.

That's a very bold claim. Very little is ever perfect in programming.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list