Python library for interfacing with the Acrome SMD Red hardware platform.
Project description
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
-
Clone this repository:
git clone https://github.com/MehmetBener/acrome-lib.git cd acrome-lib
-
(Optional) Install in editable mode:
pip install -e .
-
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
- Fork the repository.
- Create a feature branch:
git checkout -b feature/YourFeature. - Commit your changes:
git commit -m "Add your feature". - Push to your fork:
git push origin feature/YourFeature. - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d458e993ebbbb71aa0feb5db9c8453f3f8354c7d1717197a0697ec9b1610cd9f
|
|
| MD5 |
adc00928c17cb6d1c9990c002bdfafce
|
|
| BLAKE2b-256 |
3f20ec41f7ea522ebfb51e3546f5bddaff23244509710c06a8090433a8214760
|
File details
Details for the file acrome_smd_python-0.1.0-py3-none-any.whl.
File metadata
- Download URL: acrome_smd_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70f8a98357dcdc700b2f957891f20bb8a850be77494ac9d43ffe745490293d27
|
|
| MD5 |
d2cb134dad6b67e36ec61b01c87e2131
|
|
| BLAKE2b-256 |
b35f9f25e7d1670c95e87c3c7ad9d71ef9e5323cbe44240c40f0f3bad195caa6
|