Comments: SX1509 I/O Expander Breakout Hookup Guide


Looking for answers to technical questions?

We welcome your comments and suggestions below. However, if you are looking for solutions to technical questions please see our Technical Assistance page.

  • Pat / about 4 years ago / 3

    Hi All. In case anyone is still interested, I have ported the code to run in python on a Raspberry Pi. More details are here:

  • Xoff / about 7 years ago / 2

    Has anyone used an SX1509 pin with a Neopixel?

    Preferably the FastLED library.

  • Member #1592680 / about a year ago / 1

    Hi All, recently I am trying to address multiple I/O expanders as mentioned up to 4 units. But somehow I am unable to configure and read out 0x70 address. The other 3 are well received from the MCU. Is anyone facing the same issue? If so how to overcome this 0x70 address. I will need it all 4 addresses to be used.

  • Member #1657601 / about 3 years ago / 1

    Hey there, 1.) I'm interested in using the SX1509 for a 8x8 button matrix. I have read through the datasheet of the SX1509 to understand how the buttons have to be wired up. I understand the simple row/column layout for the 12 button keypad. But in this setup, multiple button pressed (or buttons being held) will cause problems, correct? Can I just make use of those diodes after each button to prevent this?

    2.) How to deal with latching buttons? Since they are always "on" … can I wire them up in button matrices and make use of the SX1509s keypad engine as well? Is the interrupt only firing on the buttons state change … ?


  • Member #1508428 / about 5 years ago / 1

    Is there a device tree example anyone can provide that defines the sx1509 with the gpio-matrix-keypad driver? I am having a problem where the matrix keypad driver in linux will not start as it cannot map an IRQ with the sx1509 pinctrl driver. Any help would be much appreciated.

  • Member #1486867 / about 5 years ago / 1

    Hello, the advice below for porting SparkFun to raspberry pi seems to be incomplete, or perhaps it has become more involved with the latest version of the SparkFun library. For starters, there are 'byte' types sprinkled throughout the .cpp file and both header files, Wire.h must be replaced with wiringPi.h, remove references to Arduino.h, and a few other obvious steps. But beyond that, I am still seeing a bunch of compile errors. For instance, RPI is missing the constrain() function, and the references to Wire object need to be replaced with equivalent operations for wiringPi (I assume). Not sure if this is the extent of what I need to work through, or if this is just the tip of the iceberg. Am I missing something? has anyone ported the SparkFun library to raspberry pi lately?

    • Pat / about 5 years ago * / 1

      Hi, Late reply, but in case anyone is still wondering: I have successfully ported the library to use on the Raspberry Pi. If anyone is interested, you can find my updated code here. Here is a rough outline of what I have done:

      1. There are a lot of 'byte' types in the source, which I replaced with 'unsigned char' types.

      2. There are a few defines that are taken from the Arduino libraries that need to be replaced in 'SparkFunSX1509.h'. If you are using 'wiringPi.h' you do not need to define some of these.

        #define INPUT               0x00    //in wiringPi.h
        #define OUTPUT              0x01    //in wiringPi.h
        #define INPUT_PULLUP        0x02
        #define ANALOG_OUTPUT       0x03    //To set a pin mode for PWM output
        #define HIGH 0x01       //in wiringPi.h
        #define LOW  0x00       //in wiringPi.h
        //Interrupt Modes
        #define RISING  0x01
        #define FALLING 0x02
        #define CHANGE  0x03
      3. The Arduino function 'constrain' needs to be replaced. I wrote a very simple one as shown below. Note: this function will probably not work as intended for negative constraints, so I need to fix it when I get a chance. I put this in the top of 'SparkFunSX1509.c'

         int constrain(int ValueToConstrain, int LowerLimit, int UpperLimit)
            if(ValueToConstrain < LowerLimit)
                return LowerLimit;
            else if(ValueToConstrain > UpperLimit)
                return UpperLimit;
                return ValueToConstrain;
      4. The six I2C read and write functions at the bottom of 'SparkFunSX1509.c' (readByte, readWord, readBytes, writeByte, writeWord, writeBytes) need to be changed to use the wiringPi library. Note that there is an endianness issue with the wiringPi 'WriteReg16' and 'ReadReg16'. I used two 8-bit writes instead.

  • Member #1269012 / about 6 years ago / 1

    Hi there! I am using 3 of those boards to drive 36 LEDs in my Arduino Fibbonacci clock project. Used 5x shift registers 74HC595 before, but got those for the PWM ability, and I am loving them! I wrote the code, everything works. There is just one thing that bothers me. When powering up, Arduino connects with those boards and lights up all the LEDs with full power. I would really like to avoid it. I have checked the library files for that, cannot find it. If you guys could point me to the line in SparkFunSX1509.cpp that does it so I can // it out, or how to disable that somehow. Would appreciate any help, thanks in advance!! Pat

  • Member #805046 / about 6 years ago / 1

    To use it with the particle photon what I have to do with the code and connecting ?

  • Member #487124 / about 7 years ago * / 1

    "VCC1 and VCC2 Jumpers

    SJ1 and SJ2 on the back-side of the board connect VCC2 and VCC1, respectively, to the 3V3 voltage supply input. So, if you’re delivering 3.3V to the board, each of the I/O banks will operate at 3.3V."

    I believe you mean SJ2 and SJ3 on the back-side of the board connect VCC1 and VCC2 respectively.



  • Steps how to use Sparkfun SX1509 C++ Library on raspberry pi

    you might be facing compilation errors when compiling SX1509 C++ library. Below are the few errors which i faced when compiling and steps to fix them.


    • Install wiringPi on raspberry Pi

    • Download the Sparkfun library from github

    ** To compile **

    • g++ -c sx1509_registers.h SparkFunSX1509.h SparkFunSX1509.cpp -std=gnu++11 -lwiringPi -lpthread


    sx1509_registers.h:142:1: error: ‘uint8_t’ does not name a type uint8_t REG_I_ON[16] = {REG_I_ON_0, REG_I_ON_1, REG_I_ON_2, REG_I_ON_3, ^ sx1509_registers.h:147:1: error: ‘byte’ does not name a type byte REG_T_ON[16] = {REG_T_ON_0, REG_T_ON_1, REG_T_ON_2, REG_T_ON_3, ^

    * Open the file sx1509_registers.h and replace "byte" with "unsigned char"
    * and execute the command above.
    * It should compile successfully and generate an object file "SparkFunSX1509.o" for you.

    **Generate an archive library using "SparkFunSX1509.o" **

    • ar rvs SparkFunSX1509.a SparkFunSX1509.o

    ** Compile the demo file available in the ** github

    * g++ main.cpp -o demo SparkFunSX1509.a -lwiringPi -lpthread -std=gnu++11

    Demo executable is generated now successfully. Now you can run it on raspberry pi and explore more capabilities of SX1509 I/O Expander Breakout board

    • Member #1486867 / about 5 years ago / 1

      See my top-posted comment. The steps above seem to be insufficient, at least with the current version of SparkFun.

  • Member #517633 / about 9 years ago * / 1

    Not clear on how to utilize and make calls if I'm using two or more SX1509 boards.

    Could someone provide a initialization and pin io example when using two or more boards?

    Is it as straightforward as: ...

    const byte SX1509_ADDRESS1 = 0x3E; 
    const byte SX1509_ADDRESS2 = 0x3F; 
    SX1509 io1,io2; 
    if (!io1.begin(SX1509_ADDRESS1))
        while (1)
    if (!io2.begin(SX1509_ADDRESS2))
        while (1)

    ... etc

    • Member #611955 / about 8 years ago / 2

      Great question. I'm eager to hear the answer as well. Anyone?

    • Xoff / about 7 years ago / 1

      It should be as simple as specifying the object:

      SX1509 io1, io2;
      io1.pinMode(SX1509_LED_PIN, OUTPUT);

      Would reference the first created object.

      No reason you can't call them whatever you want, so this should work, too:

      SX1509 demo1;
      demo1.pinMode(SX1509_LED_PIN, OUTPUT);

  • Rick C / about 9 years ago / 1

    the fritzing diagram for the io test is wrong, button is shown connected to pin 0, but the code says 7

  • Member #807740 / about 5 years ago * / 0

    I have had success with the SX1509 interfacing to my Raspberry Pi 2 Model B running Raspbian GNU/Linux 9 (stretch) using cmake (sudo apt-get install cmake) with the type of CMakeLists.txt file found at I have not had to make the "byte" to "unsigned char" changes that Sasi described in the post above to avoid compiler errors. (I use the command cmake . (cmake <space> <dot>) once to set up the compile environment and make to compile the executable.)

    From I adapted the Arduino program keypadInterrupt.ino to implement 4x7 and 8x8 button switch systems using WiringPi interrupt handling. My wires connecting from switches to the SX1509 are longer than they probably should be, so I had to include some code to do some additional debouncing work beyond what the SX1509 library code provides.

If you've found an issue with this tutorial content, please send us your feedback!