Skip to main content

Python library for interfacing with the Acrome SMD Red hardware platform.

Project description

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.


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

acrome_smd_python-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

acrome_smd_python-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file acrome_smd_python-0.1.0.tar.gz.

File metadata

  • Download URL: acrome_smd_python-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for acrome_smd_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d458e993ebbbb71aa0feb5db9c8453f3f8354c7d1717197a0697ec9b1610cd9f
MD5 adc00928c17cb6d1c9990c002bdfafce
BLAKE2b-256 3f20ec41f7ea522ebfb51e3546f5bddaff23244509710c06a8090433a8214760

See more details on using hashes here.

File details

Details for the file acrome_smd_python-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for acrome_smd_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70f8a98357dcdc700b2f957891f20bb8a850be77494ac9d43ffe745490293d27
MD5 d2cb134dad6b67e36ec61b01c87e2131
BLAKE2b-256 b35f9f25e7d1670c95e87c3c7ad9d71ef9e5323cbe44240c40f0f3bad195caa6

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