gpiojoyhbridge

GPIO Joy H-Bridge

An H-Bridge is a circuit that allows you to reverse the direction of the current by changing the polarity of the two ends. This circuit is used to drive an electric motor forward and backwards.

A H-Bridge circuit requires three pins to control. One pin supplies the Pulse Width Modulation (PWM) signal to control the motor speed. The other two pins are set to on or off to change the polarity and control the direction of the motor.

In this example, an H-Bridge is wired up to pin 12 for PWM, and pins 11 and 13 for direction control.  It will be triggered by the right stick to run forwards or reverse.  Set the attribute ‘scale’ to limit the maximum PWM .  Omit the ‘scale’ attribute and the PWM will run at full duty cycle when the stick is at 100%

<GpioConfig>
  <!-- Set the pin modes for pins we will use -->
  <PinModes>
    <Pin>
      <Number>12</Number>
      <Mode>PWMOutput</Mode>
    </Pin>
    <Pin>
      <Number>11</Number>
      <Mode>Output</Mode>
    </Pin>
    <Pin>
      <Number>13</Number>
      <Mode>Output</Mode>
    </Pin>
  </PinModes>
  <!-- Define the HBridge Motors-->
  <HBridgeMotors>
    <HBridgeMotor>
      <Name>Motor</Name>
      <HBridge>12,11,13</HBridge>
      <Joystick direction="1" scale="0.4">RightStickUp</Joystick>
      <Joystick direction="-1" scale="0.4">RightStickDown</Joystick>
    </HBridgeMotor>
  </HBridgeMotors>
</GpioConfig>