SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By triath5147
#116363
Hi I just got the PCF8575 board and am trying to use it with Arduino with no luck at all. Does anyone have working code to turn an LED on and off with the pins, So I can mess with it, and learn how to use it and to properly address this chip. I have the address pins all going to ground so the address should be 32 or 0x20 I believe but I can't get it to do anything. Please Help!
By triath5147
#116381
OK I got it to work. Here is the code. So far I can only send the chip data. I am still working on reading from it, but I'm not that far yet.
Code: Select all
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//   Write to a PCF8575 to control the 16 outputs using the I2C bus. The PCF8575 can sink approx. 25ma 
//   but only source approx. 5 ma, so it is best to take your LED's or other devices to ground through
//   the chip instead of feeding them through it. So in my code example the 1's mean that the LED
//   is off, and the 0's mean that the LED is lit.
//
//   12/29/2010 Sonny Schade triath5147@msn.com  Use and have fun. If you make any changes that improve
//                                               this code,Please post it to the community.
///////////////////////////////////////////////////////////////////////////////////////////////////////////




#include <Wire.h>

byte address = 0x20;   // address of PCF8575 with A0-A2 connected to GND "B01000000"
                     
void setup()
{
   Wire.begin();       // join i2c bus 
}

//control the pins 

void loop(){
  
  byte a = B11000000; //controls pins 0 - 7
  byte b = B00110011; //controls pins 10-17
  
  // by changing the 1's and 0's above you can control which pins are on and off. 
  // Remember the chip can sink more than it can source So the 1's are off and the 0's are on.
  
      Wire.beginTransmission(address);   // send the address and the write cmnd
      Wire.send(a);                      // pack the first byte
      Wire.send(b);                      // pack the second byte
      Wire.endTransmission();            // send the data
      

}