Author Topic: I2C help with SX1509 I/O expander  (Read 5571 times)

SavvySimian

  • Newbie
  • *
  • Posts: 2
I2C help with SX1509 I/O expander
« on: February 18, 2013, 01:20:34 am »
I am using an SX1509 I/O Expander with the digispark in a project to control multiple LED's independently, and am having trouble getting I2C to output anything on SDA and SCK.  The SX1509 requires communication over I2C and comes with Arduino example code/library intended for an Atmega style arduino.  It uses the Wire.h library as well.

I modified the provided library to use TinyWireM instead of Wire, to attempt to get the ledDriver example code working.  I edited sx1509_library.cpp in the following ways:

Wire.begin() -> TinyWireM.begin()
Wire.write(registerAddress) -> TinyWireM.send(registerAddress)
Wire.read -> TinyWireM.receive
etc - anything .write became .send, and .read became .receive

I was also receiving an error with this line of code in the sx1509_library due to INPUT_PULLUP pinmode not being recognized:
pinMode(pinInterrupt, INPUT_PULLUP);

Which I was able to resolve using this codefix for the wiring.h and wiring_digital.c libraries:
http://code.google.com/p/arduino-tiny/issues/detail?id=69

The sx1509_ledDriver example code will now compile, but no data is sent over SDA or SCK, any help would be appreciated!  :)

SX1509 Board:
https://www.sparkfun.com/products/11502?

Arduino library:
https://github.com/sparkfun/SX1509_IO-Expander/tree/master/Arduino/libraries/SX1509

SavvySimian

  • Newbie
  • *
  • Posts: 2
Re: I2C help with SX1509 I/O expander
« Reply #1 on: February 19, 2013, 01:42:36 am »
If anyone is curious, I solved the problem by pulling up the two I2C pins with a 4.7k resistor.  The good news is Wire.h can be completely replaced with TinyWireM.h with the steps previously used.

barbudor

  • Newbie
  • *
  • Posts: 9
Re: I2C help with SX1509 I/O expander
« Reply #2 on: November 06, 2013, 12:27:01 pm »
While this topic isold, for the sake of anyone who find it by searching : having 4K7 pull-ups on SDA & SCL is part of the I2C standard and is the same on whatever platform.
Just in case it can help anyone.

gogol

  • Sr. Member
  • ****
  • Posts: 398
Re: I2C help with SX1509 I/O expander
« Reply #3 on: November 07, 2013, 02:07:14 am »
Second point:  Wire.h can't be used with the digispark, as the digispark has no built-in I2C (TWI) Interface, like the bigger siblings.
The attinies do have instead an USI (universal serial interface), which can be used as SPI, I2C, serial, one-wire, ...  with the same pins.

While wire uses the hardware TWI interface, tinywire uses the USI.