Go Down

Topic: PCF8574AN configured as output for relay (Read 1 time) previous topic - next topic

Midway

what i want to make is to have full control on each output port.

example:
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.

hope u understand, little poor english.

edwin

Grumpy_Mike

Yep sitting on my bench now with one light going on one after the other and after the third light goes off the first comes on again.
With the code directly copied from your post with a copy and paste.

Quote
what i want to make is to have full control on each output port.

You have it?

Quote
i want to switch on some pin. this pin must stay on if the code say so.

That is what your code does.

Quote
in the mean time i want have some other pin switched on or off if it is asking in the code.

Just change the number you send to the port. All the bits with a zero in them will turn on. If you want to change one pin without the other then just toggle that bit.
Hang on I will write you a demo.

Grumpy_Mike

This code flashes each LED in turn and then leaves it in the inverse state.

Code: [Select]
/*
PCF adress = 0x38

configured 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 toggling
for(int i=0;i<5;i++){
  dat ^= 0x1; // toggle output 0
  outputData(dat);
  delay(200);
}
// pin 0 toggling
for(int i=0;i<5;i++){
  dat ^= 0x2; // toggle output 1
  outputData(dat);
  delay(200);
}
// pin 0 toggling
for(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();
}

Midway

thanks for the example, that works fine as i expected.

but the question are still here.

it must switch a relay ON or OFf and not flashing hihi.
just to test the code i have used a LED


Midway

maybe i have a idee,

my Project code is to big and to private to post it here.

maybe i can send it to u by email, where u can see inside the code where to put the relay on and off .

i think this will helpfull and to better understand for u, if u want help me with this


regards,
edwin

Go Up