[SOLVED] problem with a PCF8574 I/O Expander

Hello

I am trying to use a PCF8574 I/O expander with an Arduino Uno
The wiring is very simple (see the attached picture).
The program is pasted later in this post
When I run this program, the yellow led is kept off (it should blink), but the led 13 (the led on the Uno board) blinks. If you look at the program, you'll see this means that the function Wire.endTransmission() returns 2, ie "received NACK on transmit of address "

I double-checked the connections, I replaced the PCF8574, I succeeded in controlling a led with pins A4 and A5 (checking the eventuality of a pb with the Arduino).

I there anything I does not undestand ?

Thanks for your help !

the program:

#include <Wire.h>

int x=0;
byte y=255;
int led = 13;

void setup()
{
   Wire.begin();
   pinMode(led, OUTPUT);     

}

void loop()
{
  Wire.beginTransmission(32);     //Begin the transmission to PCF8574
  Wire.write(y);                          //Send 255, this should put on the big yellow led
  int status = Wire.endTransmission();         //End the Transmission
  if ( status == 2 )                     // If error 2
  {
    digitalWrite(led, HIGH);      // led in arduino board is on
  }    
  delay(2000);                           // wait 2 s
  digitalWrite(led, LOW);         // led off
  delay(200);                             // wait .2s
  
  Wire.beginTransmission(32);  
  Wire.write(x);             // send 0, this should put the big yellow led off
  Wire.endTransmission();
  if ( status == 2 )
  {
    digitalWrite(led, HIGH);
  }    
  delay(2000); 
  digitalWrite(led, LOW);
  delay(200);
}

Are you sure you have a PCF8574 and not a PCF8574A?

Use an I2C scanner program and see what address it picks up.

Also you have no pull up resistors on the I2C lines.

Hi
Thanks for your help, my IC is a PCF8574AF, so the correct address was 0x38 (decimal 56)
I just had to modify the program, replacing 32 with 56, and it works well now
Thanks again !

Grumpy_Mike:
Are you sure you have a PCF8574 and not a PCF8574A?

Use an I2C scanner program and see what address it picks up.

Also you have no pull up resistors on the I2C lines.

Even i too have same problem, that endtransmission is throwing error 2.

where do i get I2C Scanned program for confirming the I2C slave address.

annesivaram:
Even i too have same problem, that endtransmission is throwing error 2.

where do i get I2C Scanned program for confirming the I2C slave address.

This page is very good: http://lmgtfy.com/?q=arduino+i2c+port+scanner

1 Like