I'm controlling the position of a servo with Python and an Arduino. I type in the angle in python and it sends to the Arduino which then moves the servo to that specific angle. Arduino code:
#include <Servo.h>
Servo servo;
void setup() {
servo.attach(9);
Serial.begin(9600);
}
void loop() {
while(Serial.available())
{
int pos = Serial.parseInt();
if(pos >= 0)
{
servo.write(pos);
}
else
{
continue;
}
}
}
python code:
import serial
port = serial.Serial('COM3',9600)
while(port.isOpen()):
int_data = int(input("Enter servo position: "))
str_data = str(int_data)
byte_data = str_data.encode()
port.write(byte_data)
Everything works fine for like 30 seconds and I can control the servo, but then it suddenly gives me the error: WriteFile failed (PermissionError(13, 'the device does not recognize the command ', None, 22))