| Crates.io | embedded-stepper |
| lib.rs | embedded-stepper |
| version | 0.1.2 |
| created_at | 2025-08-17 14:45:27.020021+00 |
| updated_at | 2025-08-18 19:58:41.962939+00 |
| description | Hardware agnostic, no_std stepper motor driver based on Arduino stepper using embedded-hal |
| homepage | |
| repository | https://github.com/ray33ee/embedded-stepper |
| max_upload_size | |
| id | 1799449 |
| size | 33,881 |
no_std stepper motor library for Rust, built on
embedded-hal— and a port of the classic ArduinoStepperinterface/behavior.
This crate provides a tiny, portable stepper motor controller for bare-metal targets. It reuses the familiar Arduino Stepper API concepts (steps per revolution, setSpeed, step) while embracing Rust’s generics and the [embedded-hal] traits for GPIO and timing.
Stepper: same model and sequencing style, now in Rust.no_std: suitable for MCUs; no heap, no OS.embedded-hal 1.0 compatible:
embedded_hal::digital::OutputPinembedded_hal::delay::DelayNsThe following example works with the esp32-c3 development board:
#![no_std]
//Setup clock and peripherals
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::default());
let peripherals = esp_hal::init(config);
//Get the 4 GPIO pins, change these values based on your wiring
let p1 = peripherals.GPIO0;
let p2 = peripherals.GPIO1;
let p3 = peripherals.GPIO2;
let p4 = peripherals.GPIO3;
//Setup the 4 pins as output, low, no pull and Push/Pull (default output config)
let op1 = Output::new(p1, Level::Low, OutputConfig::default());
let op2 = Output::new(p2, Level::Low, OutputConfig::default());
let op3 = Output::new(p3, Level::Low, OutputConfig::default());
let op4 = Output::new(p4, Level::Low, OutputConfig::default());
//Adjust these values to fit your stepper motor. See the Arduino stepper library for more info
let speed = 625;
let steps_per_rev = 48;
//Instantiate the motor with the 4 output pins
let mut motor = create_stepper_4pin(op1, op2, op3, op4, Delay::new(), steps_per_rev);
motor.set_speed(speed);
//Turn motor
let _ = motor.step(steps_per_rev as i32 * 10);
//Reverse motor
let _ = motor.step(steps_per_rev as i32 * -10);
//Deenergise coils after use
let _ = motor.deenergise();
Stepper where it makes sense (e.g., set_speed, step, steps per revolution). Internally, the controller is generic and decoupled.Stepper::step is blocking. For tight real-time loops, consider calling it from a cooperative scheduler or extend the crate with a non-blocking tick() style API.type Error = () and ignore pin I/O errors (they let _ = pin.set_*()).Error to the underlying pin error (type Error = <P1 as OutputPin>::Error) and propagate with ? for full embedded-hal compliance.tick()), plus acceleration/deceleration profiles.Add to your Cargo.toml:
[dependencies]
embedded-stepper = { git = "https://github.com/ray33ee/embedded-stepper", default-features = false }
embedded-hal = { version = "1.0", default-features = false }
This crate is no_std by default; keep default-features = false.
MIT © 2025 — see LICENSE.
This work intentionally ports the behavior and ergonomics of the Arduino Stepper library to Rust, while integrating with the embedded-hal ecosystem.