Skip to main content

License: MIT

acrome-lib

acrome-lib is a Python library for interfacing with the Acrome SMD Red hardware platform. It provides a high‑level SMDGateway class to manage the USB gateway and a collection of module wrappers for all supported add‑on devices (buttons, sensors, actuators, motors, etc.).


Features

  • Automatic module discovery (with fallback to DEFAULT_MODULES)

  • Convenient wrappers for:

    • Digital inputs: Button, Joystick button
    • Analog inputs: Potentiometer, QTR line sensor array, Light sensor, Distance sensor, IMU (accelerometer & gyroscope)
    • Actuators: RGB LED, Buzzer, Motor (PWM, velocity, position, torque)
  • Extensible: easily add new module types by following the wrapper pattern

  • Built‑in testing: standalone test scripts under tests/ ensure compatibility


Installation

  1. Clone this repository:

    git clone https://github.com/MehmetBener/acrome-lib.git
    cd acrome-lib
    
  2. (Optional) Install in editable mode:

    pip install -e .
    
  3. Ensure you have the Acrome Python SDK (smd.red) installed via pip and your USB gateway drivers.


Usage

1. Initialize the Gateway

from smd_gateway import SMDGateway
from lib.usb_port_finder import USBPortFinder

# Auto‑detect the USB gateway
port = USBPortFinder.first_gateway()
if port is None:
    raise RuntimeError("No USB gateway connected")

# Create gateway (overriding auto‑scan with DEFAULT_MODULES)
gw = SMDGateway(port, modules_override=None)

2. Create and Use Module Wrappers

from lib.button import Button
from lib.led import Led
from lib.distance import DistanceSensor
# ... other wrappers ...

# Example: Button on module index 0 (Button_5)
btn = Button(gw, module_id=0)
if btn.is_pressed():
    print("Button pressed!")

# Example: Blink LED (module index 7 = RGB_5)
led = Led(gw, module_id=7)
led.blink(on_rgb=(0,255,0), off_rgb=(0,0,0), period=0.3, cycles=5)

# Example: Read distance (module index 4 = Distance_1)
dist = DistanceSensor(gw, module_id=4)
print("Distance (cm):", dist.read_cm())

3. Motor Control

from lib.motor import Motor
from smd.red import OperationMode

motor = Motor(gw, cpr=6533)

# PWM control
motor.run_pwm(duty=50, duration_s=1.0)

# Velocity control
motor.set_operation_mode(OperationMode.Velocity)
motor.enable_torque(True)
motor.set_shaft_rpm(120)

# Cleanup
gw.close()

Testing

All module wrappers include standalone test scripts under tests/. To run tests:

cd acrome-lib
# Example: test the QTR sensor wrapper
env/bin/python tests/test_qtr.py

Each script auto‑adds the project root to PYTHONPATH and uses modules_override to fix module IDs.


Contributing

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feature/YourFeature.
  3. Commit your changes: git commit -m "Add your feature".
  4. Push to your fork: git push origin feature/YourFeature.
  5. Open a Pull Request.

Please run existing tests and add new ones for any functionality you introduce.


License

This project is licensed under the MIT License. See LICENSE for details.


Metadata

Release files for acrome-smd-python 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for acrome-smd-python 0.1.0
File Size Uploaded
acrome_smd_python-0.1.0.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for acrome-smd-python 0.1.0
File Interpreter ABI Platform
acrome_smd_python-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / acrome_smd_python-0.1.0.tar.gz

Download URL acrome_smd_python-0.1.0.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d458e993ebbbb71aa0feb5db9c8453f3f8354c7d1717197a0697ec9b1610cd9f
BLAKE2b-256 checksum
How to use checksums
3f20ec41f7ea522ebfb51e3546f5bddaff23244509710c06a8090433a8214760
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Release files / acrome_smd_python-0.1.0-py3-none-any.whl

Download URL acrome_smd_python-0.1.0-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70f8a98357dcdc700b2f957891f20bb8a850be77494ac9d43ffe745490293d27
BLAKE2b-256 checksum
How to use checksums
b35f9f25e7d1670c95e87c3c7ad9d71ef9e5323cbe44240c40f0f3bad195caa6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page