{"id":7054,"library":"brainstem","title":"Acroname BrainStem Software Control Package","description":"The `brainstem` Python package provides a robust interface for controlling and interacting with Acroname BrainStem hardware devices, such as programmable USB hubs and switches. Currently at version 2.12.2, the library enables Python applications to discover, connect to, and manage BrainStem modules. It is actively maintained with updates typically released alongside new BrainStem Development Kits, ensuring compatibility with various operating systems and Python versions.","status":"active","version":"2.12.2","language":"en","source_language":"en","source_url":"https://www.acroname.com/support/downloads","tags":["hardware-control","usb","ethernet","embedded","robotics"],"install":[{"cmd":"pip install brainstem","lang":"bash","label":"Windows"},{"cmd":"pip3 install brainstem","lang":"bash","label":"macOS / Linux"}],"dependencies":[{"reason":"Required for the underlying C library interface. On Linux, `libffi-dev` or similar package might need manual installation.","package":"libffi","optional":false},{"reason":"A relatively up-to-date version is needed for installing platform-specific wheels.","package":"setuptools","optional":false},{"reason":"On Linux, development headers (e.g., `python-dev` or `python3-dev`) may be required by the distro's package manager for successful installation.","package":"python-dev","optional":true}],"imports":[{"note":"Used for finding connected BrainStem modules.","symbol":"brainstem.discover","correct":"import brainstem.discover"},{"note":"Contains classes for specific BrainStem module types (e.g., USBStem, EtherStem).","symbol":"brainstem.stem","correct":"import brainstem.stem"},{"note":"Provides the `Spec` class for defining connection parameters to a module.","symbol":"brainstem.link","correct":"import brainstem.link"},{"note":"Provides definitions and constants, such as module model information.","symbol":"brainstem.defs","correct":"import brainstem.defs"}],"quickstart":{"code":"import brainstem\nimport time\n\ntry:\n    # Discover the first USB BrainStem module\n    print(\"Discovering modules...\")\n    specs = brainstem.discover.findAllModules(brainstem.link.Spec.USB)\n    if not specs:\n        print(\"No BrainStem modules found. Please connect a device.\")\n        exit()\n    \n    # Connect to the first discovered USB module\n    spec = specs[0]\n    print(f\"Found module: {str(spec)}\")\n    stem = brainstem.stem.USBStem()\n    error = stem.connectFromSpec(spec)\n\n    if error == brainstem.result.Result.NO_ERROR:\n        print(f\"Connected to {brainstem.defs.model_info(stem.system.getModel().value)}\")\n        print(\"Blinking user LED for 5 seconds...\")\n        for i in range(10):\n            stem.system.setLED(i % 2) # Toggle LED (0 for off, 1 for on)\n            time.sleep(0.5)\n        stem.system.setLED(0) # Ensure LED is off at the end\n        print(\"LED blinking complete.\")\n    else:\n        print(f\"Failed to connect to module: {error}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    if 'stem' in locals() and stem.isConnected():\n        stem.disconnect()\n        print(\"Disconnected from BrainStem module.\")\n","lang":"python","description":"This quickstart code demonstrates how to discover an Acroname BrainStem USB module, connect to it, and then blink its user-programmable LED. This example requires a physical BrainStem USB module to be connected to your computer for successful execution. The code handles discovery, connection, a simple LED toggle loop, and proper disconnection."},"warnings":[{"fix":"Ensure your Python environment is within the supported range. Consider using a virtual environment.","message":"The `brainstem` library is compatible with Python 2.7.9+ and Python 3.6 through 3.10. Using unsupported Python versions may lead to installation failures or runtime errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install the necessary development packages for libffi and Python using your distribution's package manager before attempting `pip install brainstem`.","message":"On Linux, installation often requires `libffi-dev` and `python-dev` (or `python3-dev`) to be installed via the system's package manager (e.g., `sudo apt-get install libffi-dev python3-dev` on Debian/Ubuntu, `sudo yum install libffi-devel python-devel` on CentOS/RHEL). Failure to install these system dependencies will result in `pip` installation errors.","severity":"breaking","affected_versions":"All versions on Linux"},{"fix":"Ensure a compatible BrainStem module is physically connected and powered on before running code that attempts device interaction.","message":"Many core functionalities and quickstart examples require a physical Acroname BrainStem module to be connected to the host computer (via USB or Ethernet). Without a connected device, module discovery and connection attempts will fail.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `pip3 install brainstem` for Python 3 environments on macOS and Linux.","message":"On macOS and Linux, `pip` typically refers to the Python 2 package installer, while `pip3` is used for Python 3. Incorrectly using `pip` instead of `pip3` can lead to the library being installed in the wrong Python environment or failing to install altogether.","severity":"gotcha","affected_versions":"All versions on macOS/Linux"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify that your BrainStem module is properly connected and powered on. Ensure you are calling the correct discovery function (e.g., `brainstem.discover.findAllModules(brainstem.link.Spec.USB)`) for your device's connection type.","cause":"The BrainStem library's discovery methods failed to locate any connected BrainStem devices, or the specified transport type (e.g., USB, TCP/IP) was incorrect.","error":"Could not find a module."},{"fix":"Install the package using `pip install brainstem` (or `pip3 install brainstem` on macOS/Linux). On Linux, ensure `libffi-dev` and `python-dev` (or `python3-dev`) are installed system-wide.","cause":"The `brainstem` package is not installed in the active Python environment, or its installation failed due to missing dependencies.","error":"ModuleNotFoundError: No module named 'brainstem'"},{"fix":"Import the specific submodules required, for example, `import brainstem.stem` and `import brainstem.discover`.","cause":"The `stem` (or `discover`, `link`, etc.) functionality is contained within submodules of `brainstem`, not directly exposed at the top level of the `brainstem` package without explicit import.","error":"AttributeError: module 'brainstem' has no attribute 'stem'"}]}