I am trying to use the serial port on the Raspberry but when I run the example below I have the message:
TypeError: 'module' object is not callable
import time
import serial
ser = serial.serial(
port='/dev/ttyUSB0',
baudrate = 9600,
parity=0,
stopbits=1,
bytesize=8,
timeout=1
)
while 1:
ser.write('A')
x=ser.readline()
print (x)
time.sleep(1)
joan
71.9k5 gold badges76 silver badges108 bronze badges
asked Nov 27, 2019 at 12:26
-
Hi @Wagner Ideali, Welcome. Ah let me see. Your edited program does not seem to match the earlier error message, therefore should mislead future readers. Anyway, I tried tracin back the original picture and reproduce your situation, but failed: imgur.com/gallery/1Rh4vVk.tlfong01– tlfong012019年11月28日 03:13:07 +00:00Commented Nov 28, 2019 at 3:13
-
Your original version seems to have a syntax/typo error of "serial.serial(...)" which should read "serial.Serial(...)". So I tried to run your version 1 and got the same error as yours. So far so good. Now your version 2 have a new error. I guess it is the serial/.write and serial readline error. Anyway I have summarized version 1 and version 2 results in the following penzu link:penzu.com/p/350d51c9. If you can confirm I have understood your question correctly, then I would move on to compile my answer. Cheers..tlfong01– tlfong012019年11月28日 03:36:31 +00:00Commented Nov 28, 2019 at 3:36
-
I removed the pyserial and re install it and running ok nowWagner Ideali– Wagner Ideali2019年12月01日 04:50:17 +00:00Commented Dec 1, 2019 at 4:50
-
Thank you for your update. How nice to hear that problem solved. Cheers.tlfong01– tlfong012019年12月01日 05:13:49 +00:00Commented Dec 1, 2019 at 5:13
-
Hi tlfong01, I didnt understand very weel your comment above and so, I formatted the SD card, installed again the raspbian and re installed the pyserial and now is ok, but new problem is happen with pynput module and I put this problem in another questionWagner Ideali– Wagner Ideali2019年12月01日 10:02:28 +00:00Commented Dec 1, 2019 at 10:02
1 Answer 1
Linux and Python are case sensitive.
Try ser = serial.Serial(
answered Nov 27, 2019 at 12:34
lang-py