gpiojoyexpension

GPIO Joy Port Expansion Chips

The Raspberry Pi has 17 general use GPIO pins. When this is not enough for your creation, you can use a pin expansion chip.  You can use the MCP port expansion chip for simple output. You can use the PCA port expansion chip for hardware PWM output.

This example shows how to configure a MCP23008 (8 extra pins) and a MCP23017 (16 extra pins) to with a pin base starting at 200.

<GpioConfig>

  <MCPs>

    <MCP>
      <Type>Mcp23008</Type>
      <!-- chip at 0x20-->
      <Address>32</Address>
      <Base>200</Base>
    </MCP>
    <MCP>
      <Type>Mcp23017</Type>
      <!--  chip at 0x21 -->
      <Address>33</Address>
      <Base>208</Base>
    </MCP>

  </MCPs>

  <PinModes>

    <!-- Pin 0 on MCP23008 -->
    <Pin>
      <Number>200</Number>
      <Mode>Output</Mode>
    </Pin>
    <!-- Pin 0 on MCP23017-->
    <Pin>
      <Number>208</Number>
      <Mode>Output</Mode>
    </Pin>

  </PinModes>

</GpioConfig>

This example shows how to configure a PCA9685 chip when using the Adafruit Servo Hat. The first pin  is configured to drive a servo motor forward and backward with the XBox left stick.  The second pin is configured for and simple PWM output on the right stick up.

<GpioConfig>

  <PCAs>

    <PCA>
      <!-- adafruit pwm hat at default address 0x40-->
      <Address>64</Address>
      <Base>300</Base>
      <Frequency>50</Frequency>
    </PCA>

  </PCAs>

  <PinModes>

    <Pin>
      <Name>Servo One</Name>
      <Number>300</Number>
      <Mode>PWMOutput</Mode>
      <Joystick servo="true" direction="1">LeftStickUp</Joystick>
      <Joystick servo="true" direction="-1">LeftStickDown</Joystick>
    </Pin>

    <Pin>
      <Name>Green</Name>
      <Number>301</Number>
      <Mode>PWMOutput</Mode>
      <Joystick>RightStickUp</Joystick>
    </Pin>

  </PinModes>

</GpioConfig>

This example shows how to configure a PCA9685 chip when using the Adafruit Motor Hat with a motor connected to the M4 terminals.

<GpioConfig>

  <PCAs>

    <PCA>
      <!-- adafruit motor hat at default address 0x60-->
      <Address>96</Address>
      <Base>400</Base>
      <Frequency>50</Frequency>
    </PCA>

  </PCAs>

  <PinModes>


    <Pin>
      <Number>407</Number>
      <Mode>PWMOutput</Mode>
    </Pin>

    <Pin>
      <Number>405</Number>
      <Mode>Output</Mode>
    </Pin>

    <Pin>
      <Number>406</Number>
      <Mode>Output</Mode>
    </Pin>

  </PinModes>

  <HBridgeMotors>

    <HBridgeMotor>
      <Name>M4 on Motor Hat</Name>
      <HBridge>407,405,406</HBridge>
      <Joystick direction="-1" scale="0.4">RightTrigger</Joystick>
    </HBridgeMotor>

  </HBridgeMotors>

</GpioConfig>