HBridgeIC - H-bridge integrated circuit. #10983
Replies: 7 comments 8 replies
-
Do You mean a driver for H_Bridge? |
Beta Was this translation helpful? Give feedback.
-
I used in the past this module: https://www.sparkfun.com/products/14451 (TB6612FNG)
Here something to start (not tested with hardware): import math
from machine import Pin, PWM
U16 = 65535
class HBridge:
"""
For TB66FNG12
Datasheet: https://www.sparkfun.com/datasheets/Robotics/TB6612FNG.pdf
Page: 4
The modes of the bridge are:
- Short brake
- Turn Clockwise
- Turn Counter clockwise
- Stop (no breake, high impendance)
- Standby (high impendance)
"""
def __init__(self, pwm: PWM, ain1: Pin, ain2: Pin, standby: Pin, invert=False):
self._pwm = pwm
self._ain1 = ain1
self._ain2 = ain2
self._standby = standby
if invert:
# swapping methods
self.left, self.right = self.right, self.left
self._setup()
def _setup(self):
self._pwm.init(freq=1_000, duty_u16=0)
self._ain1.init(mode=Pin.OUT, value=0)
self._ain2.init(mode=Pin.OUT, value=0)
self._standby.init(mode=Pin.OUT, value=0)
@staticmethod
def to_u16(value) -> int:
return min(max(math.floor(value / 100 * U16), 0), U16)
def stop_breake(self):
"""
Short breake
"""
self._pwm.duty_u16(0)
self._ain1.value(1)
self._ain2.value(1)
self._standby.value(1)
def stop(self):
"""
Stop (high impendance)
"""
self._pwm.duty_u16(U16)
self._ain1.value(0)
self._ain2.value(0)
self._standby.value(1)
def standby(self):
"""
Standby, same like stop
"""
self._pwm.duty_u16(0)
self._ain1.value(0)
self._ain2.value(0)
self._standby.value(0)
def left(self, speed: float | int = 100):
"""
Turn motor left with a speed (0 - 100%)
"""
self._ain1.value(1)
self._ain2.value(0)
self._standby.value(1)
self._pwm.duty_u16(self.to_u16(speed))
def right(self, speed: float | int = 100):
"""
Turn motor right with a speed (0 - 100%)
"""
self._ain1.value(0)
self._ain2.value(1)
self._standby.value(1)
self._pwm.duty_u16(self.to_u16(speed))
motor1 = HBridge(PWM(Pin(10)), Pin(20), Pin(21), Pin(22))
motor2 = HBridge(PWM(Pin(12)), Pin(25), Pin(26), Pin(27), invert=True) |
Beta Was this translation helpful? Give feedback.
-
It look like HBridge arguments as pin number/names are more shorter/robust and simple in using than Pin/PWM objects arguments.
HBridgeYYY requires more competence from users. |
Beta Was this translation helpful? Give feedback.
-
@sosi-deadeye If TB6612 are different from L298, then there will be different HBridgeTB6612 and HBridgeL298 classes. |
Beta Was this translation helpful? Give feedback.
-
@rkompass I'd prefer to have several simple modules with one class HBridgeXXX inside and similar methods.
|
Beta Was this translation helpful? Give feedback.
-
Last week I developed two H-Bridge drivers: Could you review the README.md and *.py files? Would you be interested in collaborating on work? Thanks a lot. |
Beta Was this translation helpful? Give feedback.
-
Also you may intersted in Add Stepper Motor PWM-Counter driver |
Beta Was this translation helpful? Give feedback.
-
TB6612, L298, L293, L9110, DRV8871, DRV8837, DRV8838, BTS7960 etc.
Let's design HBridgeXXX classes here.
HBridge(discrete components) - motor control #12083
PWM: Reduce inconsistencies between ports. #10817
PWM: Reduce inconsistencies between ports 2. #12084
Beta Was this translation helpful? Give feedback.
All reactions