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
  • Setup
  • Run
  1. 3. Coding
  2. Peripherals
  3. I2C devices

PCA9555

PreviousADS1115NextCAT24C512

Last updated 9 months ago

This chapter will set up your port expander as an input device. If you're using at as an output device, you'll find the

Adding the necessary code for PCA9555 requires two steps:

  • Setup

  • Run

Setup

The setup is done in 2_Board.ino. Set up your , then scroll down to this section:

//PORT EXPANDER PCA9555
#define USING_PCA9555 0
#define PCA9555_I2C_NUMBER 0
uint8_t PCA9555interruptPins [] = {99};
#define PCA9555_OUTPUT 0

USING_PCA0555 is to disable/enable support for this IC. Set it to 1 to enable.

PCA9555_I2C_NUMBER lets to chose between I2C channel 0 or 1 on a RP2040 board. If you're not using a RP2040 board, just leave this at 0.

PCA9555interruptPins is an array where you put in the pin numbers for the pins used for If you have several PCA9555 chips, list all the pins here.

PCA9995_OUTPUT is to set up the port expander as an output device. We're not going to use this if you're using it for switches.

Example: We have two PCA9555 using interrupt pins 10 and 16:

//PORT EXPANDER PCA9555
#define USING_PCA9555 1
#define PCA9555_I2C_NUMBER 0
uint8_t PCA9555interruptPins [] = {10,16};
#define PCA9555_OUTPUT 0

Run

You'll need to get the processor to read your PCA9555 and put the input values into the switch table. This is done with a simple function that you place in 30_Switches.ino together with all your button functions. I recommend placing it at the very top, before anything else.

PCA9555Run()

The function wants to know a couple of things:

  • address: The I2C address of this PCA9555 chip.

  • interruptPin: The pin number of the interrupt pin used for this chip.

  • row: The row at which this port expander will start placing its input data. It will use the first 8 columns on this row, and the first 8 columns on the next row. Example: setting row to "4" means you'll find the expanders inputs on address 4,1 - 4,8 and 5,1 - 5,8 in the switch table.

Now, lets set up the two PCA955 in the example at the top of the page, and use rows 1 to 4 for these. We've wired 8 push buttons and 4 PEC11 encoders to each of them:

  //--------------------------------------
  //---------SWITCHES START HERE----------
  //--------------------------------------
  
  PCA9555Run(0x20,10,1);
  PCA9555Run(0x21,16,3);
  
  pushButton(1,1);
  pushButton(1,2);
  pushButton(1,3);
  pushButton(1,4);
  pushButton(1,5);
  pushButton(1,6);
  pushButton(1,7);
  pushButton(1,8);
  
  PEC11(2,1,false);
  PEC11(2,3,false);
  PEC11(2,5,false);
  PEC11(2,7,false);
  
  pushButton(3,1);
  pushButton(3,2);
  pushButton(3,3);
  pushButton(3,4);
  pushButton(3,5);
  pushButton(3,6);
  pushButton(3,7);
  pushButton(3,8);
  
  PEC11(4,1,false);
  PEC11(4,3,false);
  PEC11(4,5,false);
  PEC11(4,7,false);
  

  //--------------------------------------
  //---------SWITCHES END HERE------------
  //--------------------------------------

	Joystick.setZAxis(rotaryField - 32767);
	Joystick.setYAxis(buttonField - 32767);

	Joystick.sendState();

} //LOOP ENDS HERE

#if (BOARDTYPE == 2)
  void loop()
  {
	#if (LED1COUNT + LED2COUNT + LED3COUNT + LED4COUNT > 0)
		processCommands();
	#endif
  #if(USING_CB1 == 1)
  CB1Oversampling();
  #endif
  }
#endif

documentation here.
I2C channels
interrupt.