Controling 2 servos and distance sensor over serial.

I am trying to connect over same serial 2 servos and distance sensor. In Arduino, I have this code. If I write in Arduino’s serial monitor values for my servos like 120,120, it works. I wrote a program in python to change values depending on the result of the sensor, but the program sends values, but nothing is happening. Can you help me what I am doing wrong?

    #include <NewPing.h>
    #include <Servo.h>
    #define TRIGGER_PIN   12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define ECHO_PIN      11 // Arduino pin tied to echo pin on the ultrasonic sensor.
    #define MAX_DISTANCE  200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
    
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    
    Servo servo1;  
    Servo servo2; 
    int num1,num2;  
    
    void setup()
    {
      servo1.attach(9);
      servo2.attach(10);
      Serial.begin(115200); // Open serial at 115200 baud to see ping results.
    }
    
    void loop()
    {
       Serial.println(sonar.ping_cm(),DEC); 
       num1= Serial.parseInt(); 
       num2= Serial.parseInt();          
       servo1.write(num1);     
       servo2.write(num2);
 }

Program in python

    if  mean10 > 8:
                 ser.write( "130,130".encode())                
    else:
                 ser.write( "30,30".encode())

Your Arduino program is not complete.

This Python - Arduino demo may help. Also see the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable.

You can send data in a compatible format with code like this

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

You can do the equivalent in Python

…R