Go Down

Topic: PCF8574 - Driving an LED w/ I2C - Very Dim LED (Read 8525 times) previous topic - next topic

Josh

First, thanks for your patience as this is very new to me - and probably a very simple question but I did not know where else to turn.  I'm trying to use an I2C I/O expander (PCF8574) to run some relays, but currently just testing w/ LEDs.  I have the I2C working fine, and the chip seems to be working correctly, except that the LED is extremely dim, and not lighting up much at all.  I had an old RadioShack (I know, it's cheap and lame) meter I was using, but it has stopped functioning so I cant immediately test my volts/amps - but I'm assuming something along the lines of an amps problem?  This is confusing me because the documentation clearly says it should be able to drive LEDs directly:

http://www.nxp.com/pip/PCF8574.html

I simply have the chip setup to the I2C on the arduino, and the output pins on the I/O chip directly tied to some LEDs (actually just one right now), and then to ground.  This is how I know the chip seems to be working fine - as I can barely see the LED lighting up when it is supposed to.  I have tried tying multiple I/O lines into the LED - and it does glow a little brighter - but nowhere near full brightness, and nothing compared to my debug LED on arduino pin 13 and ground.

So, what am I missing?  I'm betting it is some basic electrical circuitry knowledge, that I'm hoping someone here can help me fill.

Thanks,
Josh

Daniel

#1
Mar 04, 2007, 11:53 pm Last Edit: Mar 05, 2007, 12:05 am by Daniel Reason: 1
Hi

that chip can drive LED's directly, but you have to connect them this way:

+5V------+LED-------330Rresistor------P8574pin

(edit: make sure the resistor is at least 330R)

This is called 'sinking' current, rather than 'sourcing' it.

According to the specifications on the datasheet, the 8574 can source ( i.e. give out during high pin state) only 100uA or .1ma, but it can sink (i.e. accept during low pin state) 20 milliamps. That's why your leds were always dim.

You'll need a resistor in series with the LED to limit the current, or the chip and/or LED will blow.


Hope this helps

D



Josh

#2
Mar 05, 2007, 12:28 am Last Edit: Mar 05, 2007, 12:29 am by Josh Reason: 1
And yet so simple when you can read.... Thanks so much for pointing this out to me.  I can now say I understand what that part of the docs say - your a life saver!  Now it is working great!!!

Thanks,
Josh

Daniel

No sweat. It just takes while to learn how to read these things.
In the first circuit I built, I thought the resistor symbol was a misprint on the schematic. Man, that one took a really long time to figure out.

D

woo_oow

#4
Mar 21, 2007, 09:31 pm Last Edit: Mar 21, 2007, 09:34 pm by woo_oow Reason: 1
Hi there,

I try to get this i2c thing working, but without any succes. Im using a pcf 8574a, with some LEDs attached. But nothing  happens.
I've got some basic questions about the i2c protocol:
The adress consist of a 8 bit number, eg 112 or 56, ...? so i use like  "Wire.beginTransmission(112);"?
I dont understand the datasheet  how to write to the ports of the PCF8574, what do i have to write to that device?
http:// http://www.reichelt.de/?SID=208PfrUqwQARQAAH6JtH4852ebc6602248fba4d6fe06e77038d10;ACTION=7;LA=6;OPEN=1;INDEX=0;FILENAME=A300%252FPCF8574%2523PHI.pdf

i see with the oscilloscope that sda and scl are well connected.

perhaps someone could post some basic code which worked aleady.

greetz

woo

rfordh

Here's some code I got working for the PCF8574. I hooked up an LED in series with 5V and a resistor, as Daniel suggested and it blinks.
You will have to change the address for the PCF8574A to B0111000 (with all three address pins tied to ground). The Wire library will take care of the last bit (the R/W) so make sure you leave that out of the address.

Code: [Select]

/*
 Test program for PCF8574 I2C I/O expander
 - Blinks all ports low then high.
 by Ford
*/

#include <Wire.h>

#define expander B0100000  // Address with three address pins grounded.
                          // Note that the R/W bit is not part of this address.

void setup() {
 Wire.begin();
 Serial.begin(9600);
}

void loop() {
 Serial.println("Writing B00000000.");
 expanderWrite(B00000000);
 Serial.print("Read: ");
 Serial.println(expanderRead(), BIN);
 delay(1000);
 Serial.println("Writing B11111111.");
 expanderWrite(B11111111);
 Serial.print("Read: ");
 Serial.println(expanderRead(), BIN);
 delay(1000);
}


void expanderWrite(byte _data ) {
 Wire.beginTransmission(expander);
 Wire.send(_data);
 Wire.endTransmission();
}

byte expanderRead() {
 byte _data;
 Wire.requestFrom(expander, 1);
 if(Wire.available()) {
   _data = Wire.receive();
 }
 return _data;
}


Cheers.

wlewis

#6
Aug 08, 2010, 07:51 pm Last Edit: Aug 08, 2010, 07:54 pm by wlewis Reason: 1
THIS WORKS:


#include <LiquidCrystal.h>
#include <Wire.h>
#include <avr/pgmspace.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int buttons = B00100000;//PCF8574 ID
byte buttonV;//Right,Down,Up,Left,A,B
unsigned long buttonT;
int start;
byte count;

void setup()
{
lcd.begin(20, 4);
Wire.begin();

 Wire.beginTransmission(buttons);
 Wire.send(255);
 Wire.endTransmission();

}

void loop(){

buttonScan();
lcd.setCursor(0,0);

if(((buttonV>>0)&1)==0){lcd.print("0 "); lcd.print(buttonV, BIN); }
if(((buttonV>>1)&1)==0){lcd.print("1 "); lcd.print(buttonV, BIN); }
if(((buttonV>>2)&1)==0){lcd.print("2 "); lcd.print(buttonV, BIN); }
if(((buttonV>>3)&1)==0){lcd.print("3 "); lcd.print(buttonV, BIN); }  
if(((buttonV>>4)&1)==0){lcd.print("4 "); lcd.print(buttonV, BIN); }  
if(((buttonV>>5)&1)==0){lcd.print("5 "); lcd.print(buttonV, BIN); }  
if(((buttonV>>6)&1)==0){lcd.print("6 "); lcd.print(buttonV, BIN); }  
if(((buttonV>>7)&1)==0){lcd.print("7 "); lcd.print(buttonV, BIN); }  
}

void buttonScan(){
 Wire.requestFrom(buttons,1);
 if (Wire.available())
 buttonV = Wire.receive();
}


connections on pcf8574:
SCL 14 --- 10K --- VCC+ (YOU MUST HAVE THESE 10K RESISTORS)
SDA 15 --- 10K --- VCC+                         "
PIN 16 ---- VCC +
PIN 1   ---- GND
     2   ---- GND
     3   ---- GND
PINS 4 - 12 (as follows:)

                             BTN
                            -------
 ie. pin4  ------------        ------------ R 1K ----- + VCC
                                    |
                                    |
                                  GND

when button is pressed current is diverted to ground.

THIS WORKS!

I was unable to upload a schematic.png // hmm.. how do you upload images?




Go Up