Seeeduino Xiao and PCF8574

so if I had a mind left to lose, I would have lost it by now.
I can not get the pcf8574 to work on anything. right now im using the seeeduino Xiao. I have also tried a pro micro, and I have a nRF52832 that I plan on using.

None of them want to work for me.

I have found numerous tutorials on line using one of two libraries.
xreef PCF8574 Library

RobTillaard PCF8574

below is the code I have been working.

#include "Arduino.h"
#include "PCF8574.h"

PCF8574 pcf8574(0x20);


void setup() {
  Serial.begin(115200);
//  while the serial stream is not open, do nothing:
  while (!Serial) ;  
  pcf8574.pinMode(P0, OUTPUT);
  pcf8574.pinMode(P1, INPUT);
  Serial.println("Hi");
  Serial.println("Init pcf8574...");
  if (pcf8574.begin()){
    Serial.println("OK");
  }else{
    Serial.println("KO");
  }
 }

void loop() {
  digitalWrite(P0, HIGH);
  delay(1000);
  digitalWrite(P0, LOW);
  delay(1000);
}

Hi
Did you make sure the PCF8574 address is really 0x20?
Run I2Cscanner and see what address it prints.

If I2C does not work out of the box
the first thing to use is a I2C-scanner

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

void setup() {
  Wire.begin();

  Serial.begin(9600);
  while (!Serial); // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop() {
  int nDevices = 0;

  Serial.println("Scanning...");

  for (byte address = 1; address < 127; ++address) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    byte error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address, HEX);
      Serial.println("  !");

      ++nDevices;
    } else if (error == 4) {
      Serial.print("Unknown error at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  } else {
    Serial.println("done\n");
  }
  delay(2000); // Wait 5 seconds for next scan
}

Next step is to use the pre-configured IO-pins

The library has a variant in the constructor for ESP32 / ESP8266
it might be nescessary for a Seeeduino XIAO too to specify the IO-pins

#if defined (ESP8266) || defined(ESP32)
bool PCF8574::begin(uint8_t dataPin, uint8_t clockPin, uint8_t val)

best regards Stefan

TBC your code print KO, that is you aren’t even seeing the device?

Yeah we hear that. Welcome to the community!

a7

I did a quoogling and found this

best regards Stefan

Thats not correct!

pcf8574.digitalWrite(P0, HIGH);

But check the examples!

yep that would be a problem. :crazy_face:

Fixed that one, but still no beans
Also you guys are quick! Thanks. working on the rest of the tips. figured I would fix the easiest first.

#include "Arduino.h"
#include "PCF8574.h"

PCF8574 pcf8574(0x20);


void setup() {
  Serial.begin(115200);
//  while the serial stream is not open, do nothing:
  while (!Serial) ;  
  pcf8574.pinMode(P0, OUTPUT);
  pcf8574.pinMode(P1, INPUT);
  Serial.println("Hi");
  Serial.println("Init pcf8574...");
  if (pcf8574.begin()){
    Serial.println("OK");
  }else{
    Serial.println("KO");
  }
 }

void loop() {
  pcf8574.digitalWrite(P0, HIGH);
  delay(1000);
  pcf8574.digitalWrite(P0, LOW);
  delay(1000);
}

Yes I did do that. Just ran it again for sanity sake too.

I2C device found at address 0x20  !
done

Scanning...
I2C device found at address 0x20  !
done

Scanning...
I2C device found at address 0x20  !
done

Scanning...
I2C device found at address 0x20  !
done

so from what I was reading on the closed issues, there are some microcontrollers that are not responding with the bool value.

This Issue

What exact type of PCF8574-device/board are you using?
plain chip or some kind of board?
With a plain chip are you using pullup-resistors?
Does the board have pullup-resistors?

Did you take a look into the datasheet?

There is a schematic with the typical application

best regards Stefan

It is a board

PCF8574

im pretty sure those are two resisters on the front of the board.But I could be wrong. I usually am.

I have tried both methods and neither work for me :frowning:

#include "Arduino.h"
#include "PCF8574.h"

//PCF8574 pcf8574(0x20);
PCF8574 pcf8574(0x20, 4, 5);

void setup() {
  Serial.begin(115200);
//  while the serial stream is not open, do nothing:
  while (!Serial) ;  
  pcf8574.pinMode(P0, OUTPUT);
  pcf8574.pinMode(P1, INPUT);
  Serial.println("Hi");
  Serial.println("Init pcf8574...");
  if (pcf8574.begin()){
    Serial.println("OK");
  }else{
    Serial.println("KO");
  }
 }

void loop() {
  pcf8574.digitalWrite(P0, HIGH);
  delay(1000);
  pcf8574.digitalWrite(P0, LOW);
  delay(1000);
}

Yes looks like resistors.

this

means if you really use a ESP8266 or a ESP32-board the constant is defined and in case of that
it is using this variant. But with any onther boards it is using it not
What you could have done right with the first post and should do now is posting a

easy-to-see-connections-picture

easy-to-see-connections-picture means your wiring must be clearly recognisable by just seeing the picture. Remember other users are not sitting next to you to have a look at the real thing they only have the picture.

Best option to do this is taking the picture from vertical above
or to add Text after taking the picture.
and

no

fritzing-pseudo-schematic!
a handdrawn schematic is 10 times better than a fritzing-picture
Fritzing is wiring by "looks-like" which is the opposite of wiring by understanding it really

If you don't have a 24 MHz 8 channel logic analyser this is the right time to buy one.
Price $10. Such a device can visualise the signals of IO-pins at high time-resoultion
It is used with a software sigrok pulseview which can even analyse the data that is sended /received

best regards Stefan

A handy tool. I have a "real" logic analyser, but I got one of these just to give it a spin. Besides coming with a defective cable which I quickly discovered through careful tests kept me tearing hair for quite some time, it works to spec.

I think it would work for most of what I ever did with the real one.

Pulseview works OK, so does the Saleae software. If you are new to it, a bit of a learning curve but not too bad. The things you will see!

Anyway, are you powering everything at 3.3 volts? I don't think the I2C bus wuold work if the processor was at 3.3 and the device at 5 volts, but just in case I ask.

a7

ugh im not allowed to upload images. but here is a link to the image.

Image

I was not using the 3.3v, but I am now!

Logic Analyzer ordered. now I guess I have to figure that out lol.

Great news! I got the PCF8574 working on the Pro Micro. Im not a complete idiot!

Thanks to the logic analyzer! I found that using Wire.h the seeeduino will scan, but using the library, nothing happens. So I am thinking that the library is not compatible with the Seeeduino.

Someone please correct me if I am wrong.

quote from posting +14:

the code there uses the library

#include <Wire.h>

This means the library wire.h can be used with a seeeduino XIAO

This is not snapchat or WhatsApp with smalltalk
this is the arduino-user-forum

If somebody shall help you you have to provide more info
post a picture of your actual wiring
post your actual code
with this method
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

Thank you for all your help. The library did not support the board. Now I know!

I will see if I can close this now.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.