Hello there I use win 10 I was trying to connect python to arduino using serial.Serial and it gave atribute error. I think this error is fixed but now it says:
Also arduino dosent connect i am in serious trouble and i am thankful to whom helps me
<code> arduino = serial.Serial('COM4', 9600) # Replace 'COM3' with the appropriate serial port on your computer ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:UsershpAppDataLocalProgramsPythonPython312Libsite-packagesserialserialwin32.py", line 33, in __init__ super(Serial, self).__init__(*args, **kwargs) File "C:UsershpAppDataLocalProgramsPythonPython312Libsite-packagesserialserialutil.py", line 244, in __init__ self.open() File "C:UsershpAppDataLocalProgramsPythonPython312Libsite-packagesserialserialwin32.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:Usershp>
</code>
<code> arduino = serial.Serial('COM4', 9600) # Replace 'COM3' with the appropriate serial port on your computer ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:UsershpAppDataLocalProgramsPythonPython312Libsite-packagesserialserialwin32.py", line 33, in __init__ super(Serial, self).__init__(*args, **kwargs) File "C:UsershpAppDataLocalProgramsPythonPython312Libsite-packagesserialserialutil.py", line 244, in __init__ self.open() File "C:UsershpAppDataLocalProgramsPythonPython312Libsite-packagesserialserialwin32.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:Usershp>
</code>
arduino = serial.Serial('COM4', 9600) # Replace 'COM3' with the appropriate serial port on your computer ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:UsershpAppDataLocalProgramsPythonPython312Libsite-packagesserialserialwin32.py", line 33, in __init__ super(Serial, self).__init__(*args, **kwargs) File "C:UsershpAppDataLocalProgramsPythonPython312Libsite-packagesserialserialutil.py", line 244, in __init__ self.open() File "C:UsershpAppDataLocalProgramsPythonPython312Libsite-packagesserialserialwin32.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:Usershp>
I would appreciate quick response.
Thankyou
the code:
<code>
import serial
import time
arduino = serial.Serial('COM4', 9600)
time.sleep(2)
arduino.write('Hello Arduino!')
time.sleep(0.2)
arduino.close()
</code>
<code>
import serial
import time
arduino = serial.Serial('COM4', 9600)
time.sleep(2)
arduino.write('Hello Arduino!')
time.sleep(0.2)
arduino.close()
</code>
import serial
import time
arduino = serial.Serial('COM4', 9600)
time.sleep(2)
arduino.write('Hello Arduino!')
time.sleep(0.2)
arduino.close()
New contributor
Syed Mohammad Hasnain Raza Riz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.