DDC
  • Welcome
    • Introduction
    • Supported hardware
  • 1: Project planning
    • Switch inputs
      • Switch table
      • Direct
      • Shift register
      • Port expander
    • Analog inputs
      • External ADC
    • RGB LED
    • Digital outputs
    • PWM / Circuit control
    • EEPROM
    • Processing and memory
  • 2. Wiring
    • Switch inputs
      • Matrix
      • Direct
      • Shift register
      • Port expander
    • Analog
      • Analog switches
      • External ADC
    • RGB LED
    • Digital outputs
    • PWM / Circuit control
    • EEPROM
  • 3. Coding
    • Essentials
      • 02_Board.ino
      • 08_Joystick
      • 10_TableAndAnalog.ino
        • Switch table
        • Analog channels
      • 30_Switches.ino
    • Peripherals
      • RGB LED
        • Firmware control
          • LED functions
          • Color
          • Brightness
          • Presets
        • SimHub control
      • Digital outputs
        • Setup
        • SimHub control
        • Firmware control
      • PWM / Circuit control
        • Setup
        • Calibrate
        • Switch control
        • Trigger control
      • Shift register
      • I2C devices
        • ADS1115
        • PCA9555
        • CAT24C512
    • Advanced
      • Analog inject
      • Conditional coding
        • Triggers
        • Editors
      • Field placement
      • Presets
        • 31_RunningPresets.ino
        • 32_Presets.ino
        • Example
    • Upload
    • Naming the controller
  • 4. Connect to SimHub
    • LED control
    • Controller settings and properties
      • How to connect?
      • How does it work?
      • How to control it?
      • Property list
  • Switch library
    • Pushbutton
    • Function switches
    • Toggle switches
    • Hat switches
    • Car control functions
      • QuickSwitch
      • BrakeMagic
      • ThrottleHold
      • Handbrake
    • Pedals & paddles
      • Brake/throttle
      • Clutch
      • Bite point & launch
      • Filtered curves
      • Shifter
    • Funky switch
      • Directional
      • Center push
    • Encoders
      • rotary2Bit
      • rotary4Bit
      • funkyRotary
      • wildEncoder
      • E18
      • rotaryPulse
      • PEC11
    • Rotary switches
      • rotaryAnalog
      • quickRotary
      • SW1
      • Editing functions
    • Multiswitch complexes
      • Hybrid rotary
      • Multifunction rotary
      • Modded encoder
      • Stacked encoder
    • Preset
    • DDS
    • RGB LED control
    • PWM / Circuit control
    • Utility
  • Fast DDC
    • Buttons and LED
    • 4 encoders, buttons and LED
    • Dual clutches, 4 encoders, buttons and LED
    • Dual clutches, 6 encoders, button matrix and LED
  • CB1
    • Ordering
      • Order together
      • Order yourself
        • 1. Open in EasyEDA
        • 2. Export files
        • 3. Edit Pick&Place
        • 4. Pin headers and jumper
        • 5. Order from JLCPCB
    • Wiring
    • Code
      • Essentials
      • Complete project
      • Settings
    • Circuit
    • Shields
      • Robin
  • Collaboration
Powered by GitBook
On this page
  1. 1: Project planning
  2. Switch inputs

Port expander

PreviousShift registerNextAnalog inputs

Last updated 17 days ago

In contrast to shift registers, a port expander will give you actual general purpose input/output pins. Just like the ones already on the microcontroller board -> they work more or less the same way. In fact, you could use a port expander to drive a chain of shift registers. Or you could wire a button matrix to it. The only supported port expander chip is PCA9555, which is fairly cheap, good quality and has good stock on JLCPCB.

While shift registers work more like a puppet controlled by the master (the microcontroller), the port expander works on its own, and can communicate with the microcontroller over a protocol called I2C. You'll need to connect it to the I2C pins of the microcontroller, and you'll need 1 pin for interrupt, more on that under

Quick comparison between shift register and port expander:

Feature
Shift register (74HC165)
Port expander (PCA9555)

Input/output

Only input

Input and output

Inputs per chip

8

16

Inputs maximum

Unlimited (chain)

128 (8 x PCA9555)

Pullup resistors

Needs external pullup

Included

Components needed for 16 inputs

18

1

Space needed on PCB

Managable amount

Less than half of SR

Processing

Continously

Only when needed

Performance

Good

Good

Price

2 USD for two + resistors

3 USD

Every PCA9555 you add you'll get two rows with eight columns in the switch table. You can decide where in the switch table to put them yourself. Since it requres eight columns, you need to make your switch table at least eight columns wide.

In the example above, there is a 2 x 4 matrix on rows 1 and 2. The PCA9555 is placed on row 3, taking up two full rows with 8 columns. Row 3 representing input pins IO0 0-7 (in practice pins 1-8) and row 4 representing input pins IO1 0-7 (in practice pins 9-16) on the port expander. Lastly, row 5 has been used for some direct wired switches.

You can add up to 8 port expanders to a single I2C line. If you have two I2C lines you can add another 8. However, 8 port expanders are 128 inputs, which is the maximum button count for a Windows controller. So rarely would you need more.

In DDC, the default configuration for the PCA9555 is 16 input pins. You can set up one as an as well, using all 16 pins as output pins - typically for controlling analog LEDs.

output device
wiring.