Skip to content

nguterresn/esp-drv8833

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

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:

  • It is better suited for motor control, since the frenquency is quite low, e.g. < 20kHz.
  • It is more power efficient.
  • It can still work under sleep modes.

Drive forward with 100% duty cycle

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)?;

Drive backwards with 50% duty cycle

motor.backward(50)?;

Brake motor

motor.brake()?;

Setup a slow decay motor

let motor: MotorSlowDecay = Motor::new(
    &ledc,
    &motor_conf,
    MotorLink::new(channel::Number::Channel0, peripherals.GPIO1),
    MotorLink::new(channel::Number::Channel1, peripherals.GPIO2)
)?;

Setup two motors

// 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),
)?;

Setup a stepper motor

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);
}

Build

cargo build --example forward --features esp32c6

About

no std drv8833 motor driver.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages