Skip to main content

6.2 Python API

System Requirements

  1. Hardware:

    • ST3215 Servo Motor.
    • A driver board (e.g., ESP32-based, Raspberry Pi, or Jetson-compatible) for servo control.
    • Power supply (6-12V DC depending on the servo's requirements).
    • Computer or development environment (Windows, Linux, or macOS).
    • USB cable for connecting the driver board to your computer.
  2. Software:

    • Python 3.x installed on your computer.
    • Required Python libraries (e.g., pyserial for serial communication).
    • Example Python scripts for controlling servos.

Steps to Control the ST3215 Servo Motor

Step 1 : Understand Servo Configuration:

  • The ST3215 servo operates with a digital signal range of 0-4095 and a rotation angle of 360°.
    • It supports motor mode for continuous rotation or servo mode for precise angular control.

Step 2 : Prepare the Control Setup:

  • Connect the ST3215 servo motor to a compatible driver board. Ensure proper pin alignment:
    • Signal (PWM control).
      • Power (6-12V, depending on requirements).
      • Ground.
    • Attach the driver board to your computer via USB for programming and control.

Step 3 : Install Python and Libraries:

Install Python 3.x and the pyserial library:

pip install pyserial

Step 4 : Configure the Driver Board:

  • Set the driver board to communicate with the servo using the correct protocol and baud rate:
    • UART Baud Rate: 115200.
    • If you're using an ESP32 or similar, ensure the board is flashed with a compatible firmware for servo control (refer to the manual for .ino files or configuration steps).

Step 5 : Control the Servo Using Python:

  • Download the example scripts provided with the servo motor documentation or create your own.
    • Here’s a basic example to control the servo:
import serial  
import time

# Configure the serial port (Update as per your system)
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)

def send_command(id, position):
"""
Sends a command to move the servo to a specific position.
ID: Servo ID (integer)
Position: Target position (0-4095 for ST series)
"""
# Create the command packet
command = bytearray([id, 0x03, position & 0xFF, (position >> 8) & 0xFF])
ser.write(command)
time.sleep(0.1) # Small delay for stability

# Example usage: Move servo with ID 1 to position 2048 (midpoint)
send_command(1, 2048)

ser.close()

Step 6 : Advanced Configuration:

  • To enable motor mode, configure the servo using the provided AT commands or web interface:
    • Set the mode via a Python script or the driver board's interface.
    • For multiple servos, ensure each has a unique ID set via the configuration tools.

Step 7 : Test and Validate:

  • Power on the setup.
    • Run the Python script to ensure the servo responds correctly.
    • Use feedback scripts (if available) to verify servo status (e.g., position, speed).

For more information, refer to the https://www.waveshare.com/w/upload/f/f4/ST3215_Servo_User_Manual.pdf .