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
}