PCF8574 - Driving an LED w/ I2C - Very Dim LED

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:

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

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

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

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

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?

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

perhaps someone could post some basic code which worked aleady.

greetz

woo

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.

/* 
  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.

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?