myCobot 280 M5 Python Quick Start with pymycobot

Use this myCobot 280 M5 Python quick start to verify USB serial communication before sending a motion command. Keep the M5 base on Atom: OK, install pymycobot, find the real serial port, and run the read-only test below at 115200 baud.

A PASS result confirms a controller response and six numeric joint angles. It does not verify motion, calibration, payload, path clearance, or mechanical safety.

Four-step myCobot 280 M5 Python and pymycobot serial readiness workflow

Verify the Python and serial layers before starting a separate movement test.

What the no-motion Python check proves

The readiness test establishes two narrow results:

  • The host received controller responses through the selected serial port at 115200 baud.
  • pymycobot returned six numeric values from get_angles().

Warning: A successful read-only test is not a motion-readiness certificate. Keep the workspace clear and follow a separate low-speed procedure before commanding a joint.

Before connecting the myCobot 280 M5 to Python

  1. Power the robot with the supplied adapter.
  2. Connect the M5Stack Basic base to the host with a data-capable USB cable.
  3. On the base, open miniRobot, select Transponder, and press button A.
  4. Keep the display on Atom: OK while Python uses the serial connection.
  5. Confirm that Windows, Linux, or macOS detects a serial device.

If the display shows Atom: no, stop at this stage. Use the myCobot 280 M5 Atom: no recovery guide before opening Python.

The M5 communication menu and baud rate are documented in the Elephant Robotics Python environment guide.

Step 1: Create a Python virtual environment

A virtual environment keeps the tutorial package separate from system Python and ROS packages.

Windows PowerShell:

python -m venv mycobot_env
.\mycobot_env\Scripts\Activate.ps1

Linux or macOS:

python3 -m venv mycobot_env
source mycobot_env/bin/activate

Elephant Robotics recommends Python 3.9 when troubleshooting compatibility problems. PyPI does not currently exclude Python 3.12, so treat Python 3.9 as a fallback when a clean 3.12 environment fails.

Step 2: Install and verify pymycobot

Install the package through the active interpreter:

python -m pip install --upgrade pymycobot

Print the installed version so the setup can be reproduced later:

python -c "from importlib.metadata import version; print(version('pymycobot'))"

Use the model-specific MyCobot280 class. The generic MyCobot class has not been maintained since pymycobot 3.6.0.

Step 3: Find the actual serial port

Do not copy an example port without checking the current host.

Windows serial port

Open Device Manager → Ports (COM & LPT). Record the COM port assigned to the robot, such as COM3 or COM7.

Linux serial port

ls /dev/ttyUSB* /dev/ttyACM* 2>/dev/null

Use the device that appears after the robot is connected. If access is denied, inspect its owner and group before changing permissions.

macOS serial port

ls /dev/cu.*

Compare the list before and after connecting the robot. Use the new /dev/cu.* device as PORT.

Step 4: Run the zero-motion readiness script

Save the code as mycobot_readiness.py. Replace PORT with the detected device, then run python mycobot_readiness.py.

from importlib.metadata import version
from numbers import Real
import time

from pymycobot import MyCobot280


# Replace this example with the port detected on your computer.
PORT = "COM3"
BAUD = 115200
MAX_ATTEMPTS = 3


def valid_joint_angles(values):
    return (
        isinstance(values, list)
        and len(values) == 6
        and all(isinstance(value, Real) for value in values)
    )


def run_readiness_test():
    print(f"[INFO] pymycobot version: {version('pymycobot')}")
    print(f"[INFO] Opening {PORT} at {BAUD} baud...")

    arm = None
    try:
        arm = MyCobot280(PORT, BAUD)
        time.sleep(1.0)

        last_status = None
        last_version = None
        last_angles = None

        for attempt in range(1, MAX_ATTEMPTS + 1):
            last_status = arm.is_controller_connected()
            last_version = arm.get_system_version()
            last_angles = arm.get_angles()

            print(f"[INFO] Attempt {attempt}/{MAX_ATTEMPTS}")
            print(f"[INFO] Controller status: {last_status}")
            print(f"[INFO] System version: {last_version}")
            print(f"[INFO] Joint angles: {last_angles}")

            if last_status == 1 and valid_joint_angles(last_angles):
                print("[PASS] Controller response and six numeric angles received.")
                return

            if attempt < MAX_ATTEMPTS:
                time.sleep(0.75)

        raise RuntimeError(
            "Read-only verification failed after three attempts. "
            f"Last status={last_status}, angles={last_angles}"
        )
    finally:
        if arm is not None:
            try:
                arm.close()
                print("[INFO] Serial connection closed.")
            except Exception as close_error:
                print(f"[WARN] Serial close reported: {close_error}")


if __name__ == "__main__":
    run_readiness_test()

Expected PASS output

The values below show the expected structure. They are not an OpenELAB hardware test record.

[INFO] pymycobot version: <installed version>
[INFO] Opening COM3 at 115200 baud...
[INFO] Attempt 1/3
[INFO] Controller status: 1
[INFO] System version: <reported version>
[INFO] Joint angles: <six numeric values>
[PASS] Controller response and six numeric angles received.
[INFO] Serial connection closed.

The script waits after opening the port and allows three read-only attempts. It sends no joint, Cartesian, gripper, servo-power, or digital-output command.

Troubleshoot the pymycobot serial connection

Symptom Likely layer Check Next action
ModuleNotFoundError Python environment python -m pip show pymycobot Install with the same interpreter used to run the script.
No serial device Cable or driver Reconnect the data cable and compare the device list. Install the correct USB serial driver, then reconnect.
PermissionError Linux permissions ls -l /dev/ttyUSB0 Join the device group, then sign out and back in.
Port busy or locked Competing process Check myStudio, serial monitors, IDEs, and other scripts. Close the competing process and rerun the same test.
Status 0 or -1 Controller communication Confirm power, port, baud rate, cable, and Atom: OK. Correct one layer, then rerun the read-only checkpoint.
Python 3.12 runtime error Version compatibility python --version Retry in a clean Python 3.9 environment.

ModuleNotFoundError: No module named 'pymycobot'

This error means the interpreter running the script cannot see the package. Compare the active Python executable with the environment where pip installed pymycobot.

python -c "import sys; print(sys.executable)"
python -m pip show pymycobot
python -m pip install --upgrade pymycobot

Run the script with the same python command used for installation. Do not mix a system interpreter, a virtual environment, and a ROS interpreter without checking their paths.

ImportError or AttributeError after copying an old MyCobot example

Current myCobot 280 code should use the model-specific MyCobot280 class. The older generic MyCobot interface is no longer maintained for new examples.

from pymycobot import MyCobot280

arm = MyCobot280(PORT, 115200)

After changing the class, rerun the read-only readiness script. A class-name fix does not replace the port, firmware, or power checks.

Why get_angles() returns -1 or an empty list

An invalid angle response usually points to the serial layer. Confirm Atom: OK, the detected port, 115200 baud, robot power, and a data-capable USB cable.

If the port exists but replies remain invalid, follow the firmware and serial-port troubleshooting guide.

Close myStudio and any serial monitor before rerunning the script. Two programs cannot reliably control the same serial port at the same time.

How to fix PermissionError on Linux

Inspect the device owner and group with ls -l. On distributions that use dialout, add the current user to that group, then sign out and back in.

sudo usermod -aG dialout $USER

Do not make the serial device world-writable as a permanent workaround.

How to fix a busy myCobot serial port

Exit myStudio, close IDE serial tools, and stop other Python or ROS processes that use the same port. Reconnect the USB cable only after the competing process has released it.

What to do after the readiness test passes

Record the working port, baud rate, Python version, pymycobot version, and firmware state. This turns a one-time connection into a reproducible setup.

For Ubuntu 22.04, continue with the ROS 2 Humble and RViz2 guide. Use the complete setup guide for the broader project path.

Elephant Robotics 6 DOF Arm myCobot 280 M5Stack

Elephant Robotics 6 DOF Arm myCobot 280 M5Stack

View Product

Official myCobot 280 M5 Python resources

Leave a comment

Your email address will not be published. Required fields are marked *

Sidebar

Blog Categories
Latest post

This section doesn’t currently include any content. Add content to this section using the sidebar.

Register for our newsletter

Get the latest information about our products and special offers.

Website Feedback

Help us improve OpenELAB

Found a website issue or have an idea? Tell us what would make your experience better.