I have no idea why this is happening but I'll try to explain it as best I can, also sorry if this is a question that's been asked before, I looked around but couldn't really find anything related to what my issue is.
Essentially, I have a simple python program that is supposed to control a servo motor. I'm using pyfirmata for this. Whenever I try to move the servo, though, I get the error serial.serialutil.SerialException: WriteFile failed (PermissionError(13, 'Access is denied.', None, 5))
. I've had this is in the past and known its been an issue where the port is already in use, however unplugging the servo motor immediately gets rid of this error. I also hear the windows USB disconnect sound, but I'm not sure if that's relevant.
In short, I get a permission error when my servo motor is plugged in and connected, but if I remove the wire at the D6 pin or remove the VCC pin from the servo motor I get no error. Any thoughts on what's causing this?
This is some example code I tried that still resulted in the error. I've also already tried using a different servo with no luck.
import time
from pyfirmata import Arduino, SERVO
PORT = "COM10"
servoPin = 6
try:
board = Arduino(PORT)
except:
print("Arduino board not plugged in! (Or not accessible on specified port)")
time.sleep(5)
quit()
board.digital[servoPin].mode = SERVO
for i in range (0, 180, 8):
board.digital[servoPin].write(i)
time.sleep(0.1)
Ok, got it working, this is still so weird.
I just bought and tried a different Arduino Nano and everything worked perfectly for whatever reason. The original Nano still works perfectly as long as its not being used with a servo? I have no clue why.
Anyways, if you have this issue, just switch out your Arduino board and everything should work.