Python is a natural fit for controlling a robotic arm: the code is readable, the libraries are excellent, and it bridges easily into computer vision, machine learning and web interfaces. Here are the three paths from Python to moving servos, ordered from simplest to most capable.

Path 1 — Python on laptop, Arduino drives servos

The easiest entry point. Your laptop runs the Python logic; a USB cable connects to an Arduino that translates commands into servo PWM. No Linux headaches, no GPIO, and you can use any machine.

Arduino side (simple serial protocol)

#include <Servo.h>
Servo joints[4];
const int PINS[] = {9, 10, 11, 12};

void setup() {
  Serial.begin(115200);
  for (int i = 0; i < 4; i++) joints[i].attach(PINS[i]);
}

void loop() {
  // Read "J0 090\n" → set joint 0 to 90 degrees
  if (Serial.available()) {
    char cmd = Serial.read();         // 'J'
    int joint = Serial.parseInt();    // 0-3
    int angle = Serial.parseInt();    // 0-180
    if (cmd == 'J' && joint < 4)
      joints[joint].write(angle);
  }
}

Python side (pyserial)

import serial, time

arm = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
time.sleep(2)  # wait for Arduino reset

def move(joint: int, angle: int):
    arm.write(f'J{joint} {angle:03d}\n'.encode())
    time.sleep(0.05)

# Home position
for j in range(4):
    move(j, 90)
time.sleep(1)

# Simple pick motion
move(0, 45)   # rotate base
move(1, 60)   # shoulder down
move(3, 30)   # close gripper

Install with pip install pyserial. On Windows the port is COM3 or similar; on Mac/Linux it’s /dev/ttyUSB0 or /dev/cu.usbmodem*.

Path 2 — Python directly on Raspberry Pi

A Raspberry Pi runs Python and controls servos directly — no separate Arduino needed. The cleanest way is a PCA9685 driver over I2C, which gives 16 clean PWM channels and works perfectly with Adafruit’s ServoKit library.

pip3 install adafruit-circuitpython-servokit
from adafruit_servokit import ServoKit
import time

kit = ServoKit(channels=16)

def move(channel: int, angle: int):
    kit.servo[channel].angle = angle
    time.sleep(0.02)

# Home
for ch in range(4):
    move(ch, 90)

# Sweep base
for angle in range(45, 136, 5):
    move(0, angle)
    time.sleep(0.05)

Enable I2C first: sudo raspi-config → Interface Options → I2C → Enable. See the full wiring walkthrough in the Raspberry Pi robotic arm guide.

Adding computer vision

Because the Pi runs Python, plugging in a camera and adding OpenCV is straightforward. The camera and vision guide covers detecting objects and feeding coordinates back into servo commands — the same ServoKit calls, but driven by image data instead of hardcoded angles.

Path 3 — ROS (Robot Operating System)

ROS is not a library but a middleware framework for robotics: it handles inter-process communication, sensor fusion, logging and motion planning (via MoveIt). It’s the standard in research and industry, and it runs on Python 3.

For a DIY arm, ROS is worth considering if you want:

  • MoveIt motion planning — plan paths that avoid joint limits and self-collision
  • Multi-sensor fusion — combine camera, encoder, IMU data cleanly
  • A path toward professional robotics — ROS 2 is the de-facto industry language

The overhead is real: expect an hour or two just installing ROS 2 Humble on Ubuntu/RPi OS. For a first arm, Path 1 or 2 will get you moving far faster.

Choosing your path

Laptop + ArduinoRaspberry PiROS
Setup time15 minutes1 hour2–4 hours
Python comfort neededBeginnerBeginner+Intermediate
Vision/ML possible?Via laptop GPUYes (slower)Yes (best)
Best forLearning, quick demosStandalone armResearch / complex systems

Start with Path 1 to understand the control loop, graduate to Path 2 when you want the arm to run standalone, and explore ROS when motion planning or multi-sensor work becomes the bottleneck.

For the hardware side, pair a PCA9685 driver with an Arduino or Raspberry Pi and follow the wiring diagram before writing your first line of Python.

Frequently asked questions

Can I control a robotic arm with Python?

Yes — two main approaches: send commands over serial USB from a Python script on your laptop to an Arduino that drives the servos, or run Python directly on a Raspberry Pi and control the servos via GPIO or a PCA9685 driver. Both work well; serial is simpler to start, Raspberry Pi gives more computational headroom for vision or ML.

What Python library controls servos on a Raspberry Pi?

The Adafruit CircuitPython ServoKit library (for a PCA9685 driver) is the simplest: `kit = ServoKit(channels=16); kit.servo[0].angle = 90`. For GPIO PWM directly, RPi.GPIO or the newer gpiozero library both work. Using a PCA9685 with ServoKit is the recommended path because it offloads timing from the Pi's CPU.

How do I send servo commands from Python to an Arduino?

Write a simple serial protocol on the Arduino side (e.g. read 'A090\n' to set joint A to 90°), then use Python's pyserial library on the laptop to open the COM/ttyUSB port and send those strings. The round-trip latency is typically 10–50 ms over USB — fast enough for smooth arm motion.

Do I need ROS to control a robotic arm with Python?

No — ROS is powerful but overkill for a hobby arm. pyserial + Arduino or RPi + ServoKit cover 90% of DIY projects. ROS is worth learning if you want multi-robot coordination, sensor fusion, a MoveIt motion planner, or to build toward industrial-level control.