Skip to main content

Python library for controlling iRobot Roomba/Create via serial Open Interface

Project description

create-serial

Python 3 library for controlling iRobot Roomba/Create via the serial Open Interface (OI) protocol over USB cable. This work is based on the script from this course. I adjusted it a bit to get access to the light bump in the Create 2 and my Roomba 770.

Ported to Python 3 from the original Python 2.7 code by Martin Schaef.

Installation

pip install create-serial

To include pygame for the game controller:

pip install create-serial[game]

Files

  • src/create_serial/create.py — Library module. Provides the Create class that handles all serial communication with the Roomba. Not run directly.
  • src/create_serial/game.py — Pygame-based controller. Opens a window to drive the Roomba with w/a/s/d and displays live sensor data.
  • src/create_serial/starwars.py — Plays the Star Wars Imperial March through the Roomba's speaker.

Dependencies

pip install pyserial pygame-ce

(pygame-ce is the community edition of pygame, required for Python 3.14+ support.)

Running

Both commands auto-detect the serial port. Just plug in the USB cable and run:

roomba-game
roomba-starwars

To specify a port explicitly, pass it as an argument:

roomba-game /dev/ttyUSB0
roomba-starwars /dev/tty.usbserial-XXXXXXXX

You can also run as modules from a development checkout:

python -m create_serial.game [/dev/ttyUSB0]
python -m create_serial.starwars [/dev/ttyUSB0]

If no port is given, the scripts scan /dev/ for tty.usbserial-* (macOS) and ttyUSB* (Linux/RPi). If zero or multiple ports are found, an error message is printed with instructions.

Game controls

  • w/a/s/d — Drive forward/left/back/right
  • Up/Down — Adjust speed
  • m — Main brush (Shift+m to reverse)
  • o — Side brush (Shift+o to reverse)
  • v — Vacuum
  • Space — Reset position estimate
  • Esc — Quit

Use as library

from create_serial import Create, WALL_SIGNAL
import time

robot = Create()              # auto-detect port
robot = Create('/dev/ttyUSB0') # or specify port
robot.printSensors()
wall_fun = robot.senseFunc(WALL_SIGNAL)
print(wall_fun())
robot.toSafeMode()
robot.go_differential(0, 1.75)  # spin at ~1.75 rad/sec
time.sleep(2.0)
robot.close()

For more information read the original tutorial. The list of all available sensors is here.

Setup

Tested with a Roomba 770 using the iRobot serial cable on macOS and Raspberry Pi.

Serial port names by platform:

  • macOS: /dev/tty.usbserial-XXXXXXXX
  • Raspberry Pi / Linux / Ubuntu: /dev/ttyUSB0

Linux permissions: On Ubuntu and other Linux distros, you need to be in the dialout group to access serial ports:

sudo usermod -aG dialout $USER

Log out and back in (or reboot) for this to take effect. Without this you'll get Permission denied when connecting.

If the Roomba does not connect properly, check the cable first, then check if the port is correct, and then check if the baud rate in create.py is correct.

Odometry calibration

Encoder-based odometry will always drift over time, but it should be reasonable for short distances. If rotation angles are consistently off, adjust the WHEEL_SPAN constant in create.py — increase it if the robot over-rotates, decrease it if it under-rotates. The default of 235mm matches the Create 2 spec but the effective wheelbase varies with floor surface and tire wear.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

create_serial-0.2.0.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

create_serial-0.2.0-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file create_serial-0.2.0.tar.gz.

File metadata

  • Download URL: create_serial-0.2.0.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for create_serial-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f2874113b720084272e0cfe024da7fcab77bfcfb56b3dcc8ff081c20a1ebc3d7
MD5 ec0f6ac04c0872533f3b46231c68155d
BLAKE2b-256 41391eca76d9f594c3a98e13e7eeb34d2566eba715397a33d9d858a1230c3fbf

See more details on using hashes here.

File details

Details for the file create_serial-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: create_serial-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for create_serial-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e328ab50e22cff47f801156a58947b389f8bb75d24af8f4047279c0ce71fd7b5
MD5 65f44a8c522718f74e313a6e9018a794
BLAKE2b-256 41e3bd282225f77cc1c42e4db486253277aeb3b88a30b3fe6226da987df51644

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page