Skip to content
vihaanvp edited this page Jul 4, 2026 · 7 revisions

MegaWrapper

Version: 0.2.1
Author: Vihaan Parlikar
License: MIT
PyPI: megawrapper

A unified Python library for Arduino-style DC motor and servo control over Firmata. Wraps pyfirmata2 to give you a simple, Arduino-inspired API.


Quick Links

Page Description
Board API Board class, connection, motor management, standby pin
Motor API DC motor control — forward, backward, stop, brake
Servo API Servo control — write, read, smooth movement, sweep
Sensor API VL53L0X time-of-flight distance sensor
Utilities delay(), millis() helpers
Exceptions Exception hierarchy and catch-all patterns
Examples 9 runnable example scripts
Edge Cases & Notes Behavioural details and gotchas

Installation

From PyPI (recommended):

pip install megawrapper                  # core (pyfirmata2)
pip install 'megawrapper[pyserial]'      # + built-in Firmata backend
pip install 'megawrapper[sensor]'        # + VL53L0X ToF sensor
pip install 'megawrapper[pyserial,sensor]'  # all extras

From source (editable):

git clone https://github.com/vihaanvp/MegaWrapper.git
cd MegaWrapper/repo
pip install -e .

Only pyfirmata2 is required. Optional extras:

  • pyserial — built-in Firmata backend
  • adafruit-circuitpython-vl53l0x — ToF sensor

Arduino Setup

  1. Open the Arduino IDE.
  2. Go to File → Examples → Firmata → StandardFirmata.
  3. Upload the sketch to your Arduino board.
  4. Leave the USB cable connected — that's the serial link the library uses.

Port Identification

OS Typical port
Linux /dev/ttyUSB0, /dev/ttyACM0
macOS /dev/tty.usbserial-*, /dev/tty.usbmodem*
Windows COM3, COM4, etc.

To find the right port on Windows, open Device Manager and look under Ports (COM & LPT). On Linux/macOS, run ls /dev/tty* before and after plugging in the Arduino and see what appears.


Package Overview

from megawrapper import (
    Board,                     # Arduino connection
    Motor,                     # DC motor (H-bridge)
    Servo,                     # Servo motor
    VL53L0X,                   # Time-of-flight distance sensor
    delay,                     # Pause (ms)
    millis,                    # Epoch time (ms)

    set_mode,                  # Switch backend: "pyfirmata2" / "pyserial"
    get_mode,                  # Current backend name

    MegaWrapperError,          # Base exception
    InvalidSpeedError,         # Speed out of 0-100
    BoardConnectionError,      # Can't reach Arduino
    StandbyNotConfiguredError, # STBY pin not set

    __version__,               # current version
)

All public symbols are importable directly from megawrapper:

from megawrapper import Board, Motor, Servo

Clone this wiki locally