I was writing a program to control a servo motor through a python code using PySerial and ran into a problem.
The code regularly sends a position to arduino code which should move the motor.
But if I change time.sleep(0.9) for time.sleep(0.8) or less - it stops working at all. Why?
(python code)
import serial
import time
ser = serial.Serial('COM3', 9600)
angle = 0
while True:
angle += 3
ser.write(bytes(bytearray([angle])))
if angle > 179:
break
time.sleep(0.9)
(arduino code)
#include <Servo.h>
Servo servo;
int pos;
unsigned char buff[5];
void setup() {
servo.attach(8);
Serial.setTimeout(10);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
Serial.readBytes(buff, 1);
//Serial.print(buff[0], 1);
pos = buff[0];
servo.write(pos);
}
}