0

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() 
1
  • please i need an answer Commented Jun 27, 2024 at 9:35

2 Answers 2

0

It says: serial.serialutil.SerialException: could not open port 'COM4': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)

As you did not confirm whether COM4 is the correct port on your system for your connected Arduino: Is it?

And if it is, close any other tool having the port open, e.g. the monitor part of Arduino IDE.

Sign up to request clarification or add additional context in comments.

3 Comments

ill try right now
i changed it com 6 and still dosent work and thanks for the response
and huge thanks for early response
0

I found out the issue I just needed to close Serial monitor of Arduino IDE. It is a simple fix but I couldn't find it anywhere. I found it accidently.

Thank you for anyone who responded.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.