I’m new to ESP32’s and ESPHome but, goodness me, it has been superb in getting started. I’m having a bit of a problem understanding how to use an hbridge (L298N) with my board to get a PWM controlled motor though, and hoping someone might be able to give some advice.
The docs there not that pin_a and pin_b need to point to a float. I tried using platform: gpio but get:
ID ‘motor_forward_pin’ of type gpio::GPIOBinaryOutput doesn’t inherit from output::FloatOutput. Please double check your ID is pointing to the correct value.
Fair enough. So two questions:
I thought those pins on the h bridge were simply high or low and the “enable” pin can be used for PWM speed control. I don’t understand why the should be floats?
What do I use for the platform? I can’t figure it out from the docs.
Seeing your reply just now, sorry!
Just had a look in the docs and it seems you are correct.
That, however, doesn’t make any sense to me at all. The h-bridge is expecting a binary state on pin a and pin b. It would work with pwm 0% and 100% as well, but what’s the benefit?
Very curious now as well.
PWM is considered “analog” in the microcontroller output context, because a 50% duty cycle pwm is half the voltage for an inductive load, and half as bright for an LED (as a simplification).
I agree that PWM is wrong here.
Yes we need a PWN for the motor speed.
But a binary for the INx / PIN_x. since they only expect low/high. ( pin_a = forward, pin_b = backwards spin)
PWM is not wrong. It is just not properly documented.
Did you try my solution posted above? Before you can use PWM, you have to assign the respective pins under the output section - and you obviously have to have an H-bridge wired to these pins in your physical circuit to drive the motor. You could for example use the cheap DRV8833 or the L293N integrated motor drivers with appropriate external passive components connected.