Skip to main content
rcservo logo

rcservo

PyPI version License: MIT MicroPython Compatible

A lightweight, zero-dependency Python library for controlling hobby servo motors and RC servos with PWM (Pulse Width Modulation). Works seamlessly on CPython and MicroPython platforms.

Keywords: micropython rc servo, micropython hobby servo, servo control, PWM, robotics

Features

  • ✨ Simple, intuitive API for servo control
  • 🎯 Angle-based and PWM pulse-width control
  • 🔧 Flexible configuration for different servo types and ranges
  • 🐍 Works on both standard Python and MicroPython (Raspberry Pi Pico, ESP32, etc.)
  • 📦 Zero external dependencies
  • ⚡ Lightweight and efficient

Installation

Standard Python (PyPI)

pip install rcservo
  1. Open https://viperIDE.org and launch the IDE.
  2. Go to Tools > Package Manager > Install package via link.
  3. Paste the manifest URL:

https://raw.githubusercontent.com/antonvh/rcservo/master/package.json

  1. Confirm and let mip install the library on your board.

You can install the same manifest from a terminal with mpremote:

mpremote mip install github:antonvh/rcservo

MicroPython (manual copy)

Copy servo.py to your MicroPython device:

# Using mpremote (Raspberry Pi Pico, etc.)
mpremote cp servo.py :

# Or using ampy (ESP32, ESP8266, etc.)
ampy --port /dev/ttyUSB0 put servo.py

Quick Start

from servo import Servo

# Create a servo instance on GPIO pin 12
servo = Servo(pin=12)

# Set servo angle (-90 to +90 degrees)
servo.angle(45)

# Set servo angle to neutral (0 degrees)
servo.angle(0)

# Set servo angle to far left (-90 degrees)
servo.angle(-90)

Usage

Basic Initialization

from servo import Servo

# Default configuration (1000-2000 µs pulse width, -90 to +90 degrees)
servo = Servo(pin=12)

Custom Configuration

# Custom servo with different pulse width ranges
servo = Servo(
    pin=12,
    min_pulse=800,      # Minimum pulse width in microseconds
    max_pulse=2200,     # Maximum pulse width in microseconds
    min_angle=-120,     # Minimum angle
    max_angle=120       # Maximum angle
)

Control Methods

# Set servo angle
servo.angle(45)  # Move to 45 degrees

# Set servo PWM pulse width directly (in microseconds)
servo.pwm(1500)  # Set to 1500 µs pulse

Hardware Requirements

  • Servo motor: Standard hobby servo or RC servo with PWM control
  • Microcontroller: Any board with PWM GPIO output capability:
    • Raspberry Pi Pico (MicroPython)
    • ESP32 / ESP8266 (MicroPython)
    • Arduino (with Python via Micropython)
    • Raspberry Pi / BeagleBone (standard Python)
    • Any board supported by CPython or MicroPython
  • Power supply: Appropriate for your servo (typically 4.8–6V for hobby servos)

API Reference

Servo Class

__init__(pin, min_pulse=1000, max_pulse=2000, min_angle=-90, max_angle=90)

Initialize a servo on the specified pin.

Parameters:

  • pin (int): GPIO pin number
  • min_pulse (int): Minimum pulse width in microseconds. Default: 1000
  • max_pulse (int): Maximum pulse width in microseconds. Default: 2000
  • min_angle (int): Minimum angle. Default: -90
  • max_angle (int): Maximum angle. Default: 90

angle(angle)

Set the servo to a specific angle.

Parameters:

  • angle (float or int): Target angle. Will be clamped between min_angle and max_angle.

pwm(pwm)

Set the servo pulse width directly.

Parameters:

  • pwm (int or float): Pulse width in microseconds. Will be clamped between min_pulse and max_pulse.

Notes

  • Angles are clamped to the configured min/max range
  • Pulse widths are clamped to the configured min/max range
  • Standard hobby servo pulse: 1000–2000 µs for −90 to +90 degrees
  • 1500 µs corresponds to neutral (0 degrees) by default
  • MicroPython implementation is memory-efficient and suitable for embedded devices

Use Cases

  • Robotics: Pan-tilt camera mounts, robot arms, legs
  • RC Projects: Model airplanes, cars, boats with servo control
  • IoT: Home automation with servo-controlled blinds, doors, valves
  • Education: Teaching microcontroller PWM and servo control concepts
  • Hobbyist Projects: Camera sliders, gimbal systems, mechanical displays

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License — See LICENSE file for details.

Author

Anton Vanhoucke

Metadata

Release files for rcservo 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rcservo 0.2.0
File Size Uploaded Provenance Actions
rcservo-0.2.0.tar.gz 4.9 kB Without provenance Details for rcservo-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rcservo 0.2.0
File Interpreter ABI Platform Actions
rcservo-0.2.0-py3-none-any.whl Python 3 none any Details for rcservo-0.2.0-py3-none-any.whl

Total release size: 9.2 kB

Release files / rcservo-0.2.0.tar.gz

Download URL rcservo-0.2.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
851f24f31076cb765337c4d968052a13447298a70b8e0e15dcc55cb5d7a74de1
BLAKE2b-256 checksum
How to use checksums
0bce97332267ce708bb9619b21c3b0bc2e171ff40e635c687644042af66fb273
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release files / rcservo-0.2.0-py3-none-any.whl

Download URL rcservo-0.2.0-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31fc6dc063c9391cdbe1a226810a9ef6a56d9292a635be5481250c3696df654d
BLAKE2b-256 checksum
How to use checksums
c05b10c870ba5c6907cd6478134b6f9d7ee59fd74f410018a656272d9cb5f225
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Security for rcservo 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page