Arduino-pyFirmata-Python error (5, access denied)

Good morning

I want to connect the board Arduino

to my computer using pyFirmata lib

, but there was a strange problem. Premise: pySerial

and pyFirmata

installed successfully on my computer. I have windows 8.0 64 bit

. The port Arduino

and USB drivers are working fine (since I can download each thumbnail to Arduino

).

The code I want to run is very simple:

If a button

(connected to output 4 configured as input signal method.get_pin()

from firmata library

) then red LED is pressed, otherwise green LED will be executed. I make them blink with a light function:

from time import sleep
def Blink(pin):
    board.digital(pin).write(1)
    sleep(1)
    board.digital(pin).write(0)
    sleep(1)

      

Pay

defined in the global scope as pyfirmata.Arduino('com3')

All pins work fine as I tested them with firmata_test.exe

and I am pretty sure no serial connections are open until python is running.

Here's a weird thing:

If I write each command in python shell everything works fine, leds are blinking correctly! BUT, if I write all the commands on the module and then run, it throws this error:

"Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    board = pyfirmata.Arduino('com3')
  File "C:\Python27\lib\site-packages\pyfirmata\__init__.py", line 16, in __init__
    super(Arduino, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\pyfirmata\pyfirmata.py", line 89, in __init__
    self.sp = serial.Serial(port, baudrate, timeout=timeout)
  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()))
SerialException: could not open port 'com3': WindowsError(5, 'Access denied.')"

      

That is, it cannot open the port. I tried some debugging but that didn't work for me.

If I check the port status on

por = serial.Serial()
    por.port = 'com3'
    por.isOpen()
>>False

      

BUT if I use

por = serial.Serial('com3')

      

the same error appears.

Looking at Arduino

, TX was lighting up regularly, so I can imagine it is sending some data to the serial port. If I open arduino app it will tell me the port is busy. I can't get rid of if it's an admin permissions issue because I am running py IDLE as admin. Even if I run the script from CMD in admin mode, the error remains.

Thanks a lot for every answer.

+3


source to share


1 answer


Guys, I solved the problem! I rebooted my computer (FIRST ALL) I started CMD in administrator mode and started the module. Now it works! Not sure why, it seems so far I worked the first time without admin rights. After that, even though I open CMD in admin mode, the error kept popping up.

Hope this might be helpful to someone.



Thank.

+2


source







All Articles