Connecting a Sparkfun SX1509 Breakout board?

Hey guys,
Trying to get two Sparkfun SX1509 breakout boards connected to a Photon via I2C, to be used as 32 digital inputs. This is my first time using I2C, and I’m therefore a little “noobish” in that department. :wink: I’m using the Atom/Particle Dev.

Here’s what I’ve got so far:

I’ve got the address jumpers configured, so that ExpanderA is 0x3E, and ExpanderB is 0x3F.

SDA is connected to Particle DO
SCK is connected to Particle D1

I’ve put Wire.begin(); inside of void setup()

So I guess my questions are:

  1. What files/libraries do I need to include?
  2. How do I include said libraries using the Atom/Particle Dev (not the web version)?
  3. There is an SX1509 Arduino library, but I’m not sure how to include it?

That should be enough questions for the kickoff post. @peekay123 @ScruffR You guys up for this most-likely simple explanation? :wink:

Thanks so much for any advice!

Only the (ported) SX1509 library is required, since Wire.h is already part of the Particle frame work.
You can download that from GitHub when you click on the GitHub icon next to the library name (once selected) or directly there

You copy the library files alongside your main project file and include the .h file(s) like #include "someFile.h"

See 2.

Great, thanks @ScruffR! Looks like the library files are ported, but the example code files are still Arduino. I’m thereby assuming I just change:

#include <SparkFunSX1509.h>


#include "SparkFunSX1509.h"

And remove any instance of:

#include <Wire.h>

I’m now having issues with my Photon breathing green, which I believe means it’s connected to wifi but not to the cloud? Could this be related to the code in any way? It was doing this last night, so I started flashing simple “Blink” code to it and it seemed to stay connected (breathing cyan). Was I just dreaming up this connection, or could there be something there?


@jeremywmccarter, the example most likely is blocking somewhere, preventing loop() from ending. You have two options: 1) Add SYSTEM_THREAD(ENABLED) in your code before setup(), or 2) Find the spot where the code is blocking and add Particle.process(); as part of what is most likely a while() loop doing the blocking. I suggest 1) as it will allow the system firmware to run independently of the user code. :wink:

1 Like

Thanks @peekay123… I’ll add SYSTEM_THREAD(ENABLED) before my void setup()… but now, how can I get this code to flash when it keeps hanging? When I hit Reset, it gets stuck in the “breathing green” before I can flash to code.

While 1) and 2) usually keep the cloud connection, you might still need to find out why the code gets trapped in a loop for that long and how to get out of it (or not in in the first place).

@jeremywmccarter, you can use Safe Mode - hold SETUP, tap RESET, release SETUP when you see the first magenta flash.

I’m thinking this is where it’s hanging :wink:

  // Call io.begin(<address>) to initialize the SX1509. If it
  // successfully communicates, it'll return 1.
  if (!io.begin(SX1509_ADDRESS))
    Serial.println("Failed to communicate.");
    while (1) ;

That seems to be (at least one) possible cause.
But as said above, what’s causing the hang (aka why does io.begin() not return true)?!?
Is the address wrong?
Are the jumpers set correct?
Are the pull-up resistors still connected? (when using several boards, only one maybe two sets of pull-ups are allowed)

BTW, you can always flash new binaries via USB using Particle CLI.

Thanks for the Safe Mode explanation @ScruffR, that worked.

But you’re right, why isn’t the device communicating? I have two devices connected; one with address 0x3E, one with 0x3F. I’m going to take the 3F out of the circuit for now…

This is my first time ever using I2C, so perhaps I’m just missing something…

Ok, removing the second device fixed it, so at least now I’m communicating.


I’ve got both devices (addresses 0x3E and 0x3F) on the I2C bus, communicating independently (though one at a time, for now). I can read the input values, based on an attachInterrupt… but only when a single input changes (it seems you have to watch only one pin at a time, checking to see if it changes, in order to call the interrupt). My thought is then to do a for loop to cycle through each input, checking for changes.

But that seems cumbersome to me. Shouldn’t the SX1509 chip be able to watch all inputs and pulse !INT when something changes? Or am I asking for too much? :wink:

My code is based on this example from @JohnVidler , though I’ve made a few changes to get it to work with the Particle (and my setup).

To answer that we’d need to do the same thing as you could: Look at the datasheet :wink: