1

Background: I am working on a project that is supposed to have an Arduino mega send data from ultra sonic sensors to the computer via USB and I keep getting the same errors. I have checked the device manager and I am sure that the Arduino is on the correct port.

My python errors:

Traceback (most recent call last):
File "----", line 6, in <module>
ser = serial.Serial('COM4', 115200)
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 38, in __init__
SerialBase.__init__(self, *args, **kwargs)
File "C:\Python27\lib\site-packages\serial\serialutil.py", line 282, in __init__
self.open()
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 66, in open
raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM4': WindowsError(5, 'Access is denied.')
[Finished in 0.1s]

My Arduino error:

[Stino - Start building "---"...]
Sketch uses 4,922 bytes (1.9%) of program storage space. Maximum is 258,048 bytes.
Global variables use 727 bytes (8.9%) of dynamic memory, leaving 7,469 bytes for local variables. Maximum is 8,196 bytes.
[Stino - Done building "----" in 0.1s.]
[Stino - Start uploading...]
avrdude: ser_open(): can't open device "\\.\COM4": Access is denied.
avrdude: ser_drain(): read error: The handle is invalid.
[Stino - Exit with error code 1.]

I have been working at this for awhile now and I still do not understand how to fix this. Please help.

2 Answers 2

3

The error is very basic here. Your arduino COM port is not COM4. You can see this by the fact you are not even able to upload your program. Inspect the Ports section in your Device Manager to find out which is the right one.
Upd: Or if it is COM4, as suggested in the other answer, it is opened by some other program. It can be another Arduino IDE or your previously ran python program attempts that are still in the memory. Check the task manager in order to find and kill the suspects.

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

2 Comments

Like I said above it is COM4. I just checked it again.
Found that my python was still executing and I didn't realize. Thanks!
2

A common cause for this kind of error, if you are sure "COM4" is correct, is that another program currently is using the port and not allowing python to access it. Close any other programs trying to talk to the arduino on COM4 and try again.

1 Comment

The only programs that I have running are Sublime 3 and Chrome. So I don't think that is the problem.

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.