/*PCF adress = 0x38configured as output to control the relay*/#define PCF2_output 0x38 // (Relay) PCF8574AN, Address 0x38 with A0-A1-A2 pins grounded.#include <Wire.h>void setup(){ Wire.begin(); Serial.begin(9600);}void loop(){ Wire.beginTransmission(PCF2_output); Wire.write(254); // turn relay 1 on (P0) Wire.endTransmission(); Serial.print("Relay 1: "); Serial.println(HEX); delay(1500); Wire.beginTransmission(PCF2_output); Wire.write(253); // turn relay 2 on (P1) Wire.endTransmission(); Serial.print("Relay 2: "); Serial.println(HEX); delay(1500); Wire.beginTransmission(PCF2_output); Wire.write(251); // turn relay 3 on (P2) Wire.endTransmission(); Serial.print("Relay 3: "); Serial.println(HEX); delay(1500);}
it is just the software what is not working fine.
Have you got pull up resistors?
Are you using the analogue pins 4 & 5 not the digital ones?
Have you got the anode of the LED connected to 5V, cathode to a resistor and resistor to the PCF output pin?
what i want to make is to have full control on each output port.
i want to switch on some pin. this pin must stay on if the code say so.
in the mean time i want have some other pin switched on or off if it is asking in the code.
/*PCF adress = 0x38configured as output to control the relay*/#define PCF2_output 0x38 // (Relay) PCF8574AN, Address 0x38 with A0-A1-A2 pins grounded.#include <Wire.h>byte dat = 0xff;void setup(){ Wire.begin(); Serial.begin(9600); outputData(dat); // all outputs high}void loop(){ // pin 0 togglingfor(int i=0;i<5;i++){ dat ^= 0x1; // toggle output 0 outputData(dat); delay(200);} // pin 0 togglingfor(int i=0;i<5;i++){ dat ^= 0x2; // toggle output 1 outputData(dat); delay(200);} // pin 0 togglingfor(int i=0;i<5;i++){ dat ^= 0x4; // toggle output 2 outputData(dat); delay(200);}}void outputData(byte dat){ Wire.beginTransmission(PCF2_output); Wire.write(dat); // turn relay 3 on (P2) Wire.endTransmission();}