| Crates.io | esp-drv8833 |
| lib.rs | esp-drv8833 |
| version | 0.1.6 |
| created_at | 2025-06-06 14:09:45.875405+00 |
| updated_at | 2025-06-23 16:07:38.609694+00 |
| description | A crate that provides control over the DRV8833 Dual H-Bridge Motor Driver |
| homepage | |
| repository | https://github.com/nguterresn/esp-drv8833 |
| max_upload_size | |
| id | 1703059 |
| size | 55,286 |
This crate provides control over the DRV8833 Dual H-Bridge Motor Driver.
The crate requires no external or standard library and only depends on the esp-hal crate. The code uses the espressif LEDC peripheral to control the DRV8833.
The crate uses the slow clock as default:
The followig example shows how to use the crate to drive a brushed motor forward with max duty cycle (100%), using the GPIO1 and GPIO2:
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
let mut ledc = Ledc::new(peripherals.LEDC);
ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
let motor_conf = MotorTimerConfig::new(
&ledc,
timer::Number::Timer0,
timer::config::Duty::Duty12Bit,
Rate::from_khz(1),
)?;
let motor: MotorFastDecay = Motor::new(
&ledc,
&motor_conf,
MotorLink::new(channel::Number::Channel0, peripherals.GPIO1),
MotorLink::new(channel::Number::Channel1, peripherals.GPIO2)
)?;
motor.forward(100)?;
motor.backward(50)?;
motor.brake()?;
let motor: MotorSlowDecay = Motor::new(
&ledc,
&motor_conf,
MotorLink::new(channel::Number::Channel0, peripherals.GPIO1),
MotorLink::new(channel::Number::Channel1, peripherals.GPIO2)
)?;
// A channel number from 0-7;
let motor_right: MotorFastDecay = Motor::new(
&ledc,
&motor_timer_conf,
MotorLink::new(channel::Number::Channel0, peripherals.GPIO1),
MotorLink::new(channel::Number::Channel1, peripherals.GPIO2),
)?;
let motor_left: MotorFastDecay = Motor::new(
&ledc,
&motor_timer_conf,
MotorLink::new(channel::Number::Channel2, peripherals.GPIO3),
MotorLink::new(channel::Number::Channel3, peripherals.GPIO4),
)?;
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
let mut stepper = Stepper::new(
peripherals.GPIO0,
peripherals.GPIO1,
peripherals.GPIO10,
peripherals.GPIO9,
Rate::from_hz(200), // 200hz, i.e. 5ms
200, // steps per rev
);
let delay = Delay::new();
loop {
stepper.angle(30.0, &delay);
}
cargo build --example forward --features esp32c6