This project provides a simple Python interface for controlling the ST3215 bus servo using the Waveshare Bus Servo Adapter.
It builds upon the original Waveshare examples and restructures them into a cleaner, easier-to-use format—similar to how standard hobby servos are used.
- Easy-to-use Python API for ST3215 servos
- Based on Waveshare communication protocol
- Simplified commands for position, speed, and control
- Designed for quick integration into robotics projects
The original Waveshare resources for ST3215 servos were difficult to locate and not well structured. This repository consolidates the required code and improves usability for developers.
- Python 3.x
- Waveshare Bus Servo Adapter
- ST3215 Servo
pyserial==3.5
git clone https://github.com/Saksham-Agarwal/ST3215-Servo-Python.git
cd ST3215-Servo-Pythonpython -m venv .venv
.venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Deactivate environment
deactivatepython3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Deactivate environment
deactivatefrom servo_control.ST3215 import ST3215
bus = ST3215("COM5")
ids = bus.scan()
print(ids)
bus.write_angle(ids[0], 2048)
bus.close()Initializes the servo bus connection.
- device_name: Serial port (e.g.,
COM5,/dev/ttyUSB0) - baudrate: Communication speed (default: 1 Mbps)
- speed: Default movement speed
- acceleration: Default acceleration
Checks if a servo is connected and responding.
- servo_id: ID of the servo
- Returns:
Trueif detected, elseFalse
Scans a range of IDs and finds connected servos.
- start: Starting ID
- end: Ending ID
- Returns: List of detected servo IDs
Changes the ID of a servo.
- current_id: Existing ID
- new_id: New ID (0–253)
- Returns:
Trueif successful
Moves the servo to a specific position.
- servo_id: Servo ID
- angle: Target position (raw value, typically
0–4095)
Reads current position and speed of a servo.
- servo_id: Servo ID
- Prints position and speed
Sets the servo to continuous rotation mode.
- servo_id: Servo ID
- rot_speed: Rotation speed (sign = direction, magnitude = speed)
Returns Temperature value in celsius.
- servo_id: Servo ID
Returns current draw of the servo motor in mA.
- servo_id: Servo ID
Closes the serial port connection.