I2C Interface Tutorial
I2C Interface Tutorial
I2C Interface Tutorial
January 2014
Undergraduate Program
Instructor: Waqar S. Qureshi, Matthew N. Dailey
5. When the communication is complete, the master issues a STOP condition indicating that everything
is done.
#include<Wire.h>
#define PCF8574 B00100000
//PCF8574 ID code
#define PCF8574A B00111000 //PCF8574A ID code
//input
byte inpRead;
byte inpBuff = 0x0F;
//Don't care LED port
void setup(){
Wire.begin();
Assignment
Write Arduino program to run four LEDs by using the first PCF8574-IC which its address {A2,A1,A0} is
{0,0,0}. When the button is pressed, all LEDs are blinked in every 1 second. The button is connected at P0
pins of the second PCF8574-IC which its address {A2,A1,A0} is {0,0,1}. The given code is not complete,
you need to finish.
//PCF8574 ID code
//1st-PCF8574A ID code (A0=0, A1=0, A2=0);
//2nd-PCF8574A ID code (A0=1, A1=0, A2=0);
void setup(){
Wire.begin();
}
void loop(){
inpRead = ReadInput(PCF8574A2); //read input from 2nd-PCF8574
inpBuff = inpRead&0x01;
//check P0 Pin
if(inpBuff==0){
//button is pressed
WriteOutput(PCF8574A, (~out2)|0x0F);
out2 = ~out2;
delay(1000);
}
else{
//Run LED
for(int i=0; i<4;i++)
{
WriteOutput(PCF8574A, ~out[i]|0x0F);
delay(250);
}
}
}
Result and Conclusion:
References
http://www.lammertbies.nl/comm/info/I2C-bus.html
http://startingelectronics.com/beginners/start-electronics-now/tut18-two-wire-arduino-knight-rider
http://blog.littlebirdelectronics.com/tutorial-arduino-and-the-i2c-bus
http://hobbybotics.com/projects/hobbybotics-pcf8574a-i2c-io-expander
http://www.totalphase.com/support/kb/10037/#theory