when i execute the python script, the arduino response but the code between the if(Serial.available()) not responding.
python script
import time, serial
arduino = serial.Serial('COM7', 9600)
time.sleep(2)
while True:
arduino.write(str(input("1"))) # write position to serial port
# and the pysthon script cant read the code below this line
reachedPos = str(arduino.readline()) # read serial port for arduino echo
data.append(reachedPos)
arduino.close()
arduino script
#include <Servo.h>
Servo servo;
int angle = 0;
String in;
int pos = 1;
void setup() {
servo.attach(7);
Serial.begin(9600);
servo.write(0);
}
void loop() {
in = Serial.readStringUntil('\n');
Serial.print(in);
pos = in.toInt();
if(Serial.available()) // if data available in serial port
{
if(pos == 1){
if(angle == 0){
servo.write(180);
delay(10);
angle = 180;
delay(1000);
}
if(angle == 180){
servo.write(0);
delay(10);
angle = 0;
delay(1000);
}}
}
}
What is the problem? Te arduino code works fine