astra/nema17-stepper-motor-controller-spring-clamp-rp2040
A 4-layer RP2040 controller board that negotiates USB‑C PD motor power and drives a NEMA17 stepper via a DRV8825, with current sensing, thermal shutdown, RGB status LED, buzzer alarm, optional AS5600 encoder, protection/filtering, and test points.
- Version
- 1.4.0
- License
- unset
- Stars
- 0
firmware/status_led.py
"""Common-anode RGB through three prebiased NPN sinks (active-high PWM)."""
from tmp102 import WARN_C, TRIP_C
def health_color(policy):
if not policy.healthy or policy.temperature_c is None or policy.temperature_c >= TRIP_C:
return (1, 0, 0)
if policy.latched and policy.reason not in ("startup: explicit arm required", "user stop"):
return (1, 0, 0)
if policy.temperature_c >= WARN_C:
return (1, 0.35, 0)
return (0, 1, 0) if policy.enabled else (0, 0, 1)
class StatusLed:
def __init__(self, red, green, blue):
self.channels = (red, green, blue)
for channel in self.channels:
channel.freq(1000)
channel.duty_u16(0)
def update(self, policy, measurement_ok=True):
color = health_color(policy) if measurement_ok else (1, 0, 0)
for channel, brightness in zip(self.channels, color):
channel.duty_u16(round(65535 * brightness))
def close(self):
for channel in self.channels:
channel.duty_u16(0)
channel.deinit()