Offline
Newbie
Karma: 0
Posts: 22
I just want to learn more :)
|
 |
« on: February 14, 2013, 04:17:51 pm » |
i use the output P0/P1/P2 ect... to switch independent the output, a relay and must stay ON untill this is asking in some code to switch it OFF. for the test i made this example, but it will not work good, it is like flashing loop light. any software example help would be great. /* 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>
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); }
|
|
|
|
« Last Edit: February 14, 2013, 04:21:55 pm by Midway »
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 278
Posts: 25585
Solder is electric glue
|
 |
« Reply #1 on: February 14, 2013, 04:28:08 pm » |
You can only sink 25mA of current on an output how have you got your relay wired? Have you used a transistor to drive it. There is probably not enough current to hold your relay in if you have wired it directly.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
I just want to learn more :)
|
 |
« Reply #2 on: February 14, 2013, 04:31:56 pm » |
i am just test it now with some LED (20mA), and this is also not working!
dont worry the relay wiring, this is drived by some transistor, and or optocouplers ect ect,,,,
it is just the software what is not working fine.
|
|
|
|
« Last Edit: February 14, 2013, 04:44:53 pm by Midway »
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 278
Posts: 25585
Solder is electric glue
|
 |
« Reply #3 on: February 14, 2013, 04:49:59 pm » |
it is just the software what is not working fine. It looks fine to me. 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?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
I just want to learn more :)
|
 |
« Reply #4 on: February 14, 2013, 05:28:07 pm » |
Have you got pull up resistors? yes, offcourse. Are you using the analogue pins 4 & 5 not the digital ones? Im use on the arduino uno the pins located near the reset button, marked with SDA/SCL. so not use pin 3 and 4. Have you got the anode of the LED connected to 5V, cathode to a resistor and resistor to the PCF output pin? yes, i hope the attachment is here u can see the diagram i quickly made. i have also tried some other LED's with same voltage and less mA. but same result.
|
|
|
|
« Last Edit: February 14, 2013, 05:42:53 pm by Midway »
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 278
Posts: 25585
Solder is electric glue
|
 |
« Reply #5 on: February 14, 2013, 06:00:08 pm » |
Ok I'll try your code on my system but it might take 24 hours to get back to you as I am seprated from my system at the moment.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
I just want to learn more :)
|
 |
« Reply #6 on: February 14, 2013, 06:05:58 pm » |
ok, thanks.
i ll wait any result.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
I just want to learn more :)
|
 |
« Reply #7 on: February 15, 2013, 03:13:08 pm » |
anybody else a idee how to manage a PCF ?
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 278
Posts: 25585
Solder is electric glue
|
 |
« Reply #8 on: February 15, 2013, 03:54:23 pm » |
OK, so I downloaded your code and as expected it works perfectly. The three LEDs come on one after the other. So what ever is your problem it is not the code.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
I just want to learn more :)
|
 |
« Reply #9 on: February 15, 2013, 03:56:03 pm » |
it is like flashing loop light.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
I just want to learn more :)
|
 |
« Reply #10 on: February 15, 2013, 04:00:06 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 278
Posts: 25585
Solder is electric glue
|
 |
« Reply #11 on: February 15, 2013, 04:04:29 pm » |
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. what i want to make is to have full control on each output port. You have it? i want to switch on some pin. this pin must stay on if the code say so. That is what your code does. 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.
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 278
Posts: 25585
Solder is electric glue
|
 |
« Reply #12 on: February 15, 2013, 04:10:24 pm » |
This code flashes each LED in turn and then leaves it in the inverse state. /* 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(); }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
I just want to learn more :)
|
 |
« Reply #13 on: February 15, 2013, 04:16:11 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
I just want to learn more :)
|
 |
« Reply #14 on: February 15, 2013, 04:20:05 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
|