I use Win 10, I was trying to connect Python to Arduino using serial.Serial, and it gave an attribute error. I think this error is fixed, but now it says:
Also, Arduino doesn't connect, I am in serious trouble, and I am thankful to whomever helps me.
arduino = serial.Serial('COM4', 9600) # Replace 'COM3' with the appropriate serial port on your computer ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\serial\serialwin32.py", line 33, in __init__ super(Serial, self).__init__(*args, **kwargs) File "C:\Users\hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\serial\serialutil.py", line 244, in __init__ self.open() File "C:\Users\hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\serial\serialwin32.py", line 64, in open raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError())) serial.serialutil.SerialException: could not open port 'COM4': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2) PS C:\Users\hp>
I would appreciate quick response.
the code:
import serial
import time
arduino = serial.Serial('COM4', 9600)
time.sleep(2)
arduino.write('Hello Arduino!')
time.sleep(0.2)
arduino.close()