I am trying do receive data from arduino serial port. I write code like this when i run this code in cmd (after write python) this work properly. but i am try do this in pycharm AttributeError: module 'serial' has no attribute 'Serial'. i research about this bug. i try some method like uninstall pyserial then reinstall pyserial but it doesnt work. i install pyserial package like this pip install pyserial and also i try python -m pip install pyserial but it still dont work. i need your help
my code is here:
import serial
ser = serial.Serial('COM3',9600)
ser.flushInput()
while True:
try:
ser_bytes = ser.readline()
decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
print(decoded_bytes)
except:
print("Keyboard interrupt")
break
and also i try from serial import Serial i get this error:
ImportError: cannot import name 'Serial' from 'serial' (C:\Users\NU-telebe\PycharmProjects\pythonProject1\venv\lib\site-packages\serial\__init__.py)
enter code here
This is an arduino forum, dealing with the code that runs on the arduino, no the python code on you PC. You would probably get more/better help on a python related forum
That's true: "not a question for Arduino, MCUs, embedded SW". An issue with Python on host side (a real Python question only).
BTW: I do the following code when reading MCU UART via/into Python.
I think: you have the correct "serial" library imported, just using it is a bit wrong.
import serial
ser = serial.Serial()
debug = False
def select_port():
global ser
#get_ipython().magic(u'gui qt')
#ports = serial_ports()
#port, ok = QtGui.QInputDialog.getItem(None,
# "Select a serial port", "PORT", ports,
# current=(len(ports)-1),
# flags=QtCore.Qt.WindowStaysOnTopHint)
#get_ipython().magic(u'pylab inline')
#if ok:
ser = serial.Serial()
ser.baudrate = 9600
ser.timeout = 1 # sec
ser.rtscts = 0
ser.port = 'COM3'
The biggest "problem": what is the device name? In Linux it is often a path, a completely different name as in Windows with "COMx".
I think, you call serial.Serial() with wrong parameters.
A real Python question.