User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4257
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: UART

Fri Mar 22, 2013 9:52 am

It works for me in Windows:

Code: Select all

import serial
usbport = '/dev/ttyAMA0'
ser = serial.Serial(usbport, 9600, timeout=1)
ser.write("Raspberry pi\r\n")
x = ""
while chr(3) not in x:
	x = ser.readline()
	print x

ser.close()
Which line has the error? For example, if I put the old error back in:
File "sertest.py", line 6, in <module>
while 3 not in x:
TypeError: 'in <string>' requires string as left operand, not int
it tells you the line number (6) and what is on that line. Otherwise I am guessing which line is at fault and what is on it.

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

Re: UART

Mon Mar 25, 2013 1:03 am

this is my code..

Code: Select all

import serial
usbport = '/dev/ttyAMA0'
ser = serial.Serial(usbport, 9600, timeout=1)
ser.write("Raspberry pi\r\n")
x = ""
while chr(3) not in x:
   x = ser.readline()
   print x

ser.close()



here the error after i ran the given source code...

Code: Select all

File"hello.world.py", line 9, in <module>
while chr(3) not in x:
TypeError: argument of type 'builtin_function_or_method'  is not iterable
in python it doesn't works.Now my objective is once i run the python code in RPi i must send a text to the PC and must received the text which is type in the PC and display on RPi.

Please help me on it ..

dhuertas
Posts: 4
Joined: Fri Apr 19, 2013 10:17 pm

import serial

Thu Apr 25, 2013 2:26 am

hey so when I tried writing the code, it gives me an error saying that there is no module named serial when I say
import serial. Did you guys download pyserial for this?

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4257
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: UART

Thu Apr 25, 2013 2:37 am

Yes. For some unaccountable reason there is no serial module in the otherwise incredibly well stocked Python standard library.

yapodurt
Posts: 1
Joined: Fri Jul 12, 2013 9:37 am

Re: UART

Fri Jul 12, 2013 9:41 am

I get the same error that dhuertas was getting. I have installed pyserial. I can even get import serial to work in the Python Shell but not when I try it within a script. Can anyone help me?

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1665
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: UART

Fri Jul 12, 2013 10:10 am


Return to “Python”