Wire1 with PCF8575 on UNO R4 only runs once

The code below is the PCF8575 library Wire2 test using the Arduino UNO R4 WIFI. It works the first time I upload the code, but on subsequent uploads it fails to connect. To recover, it needs to have the USB-C connect unplugged and plugged in again. Then it works the first time again.

I modified the code to use Wire1 because that is what the Quiic connector uses.

Is this something in the code, the Wire library or the R4?

PCF8575_Wire1.ino

//
//    FILE: PCF8575_Wire1.ino
//  AUTHOR: Rob Tillaart
//    DATE: 2021-01-03
// PUPROSE: demo

#include "PCF8575.h"

// adjust addresses if needed
PCF8575 PCF(0x21, &Wire1);

void setup()
{
  Serial.begin(115200);
  Serial.println(__FILE__);
  Serial.print("PCF8575_LIB_VERSION:\t");
  Serial.println(PCF8575_LIB_VERSION);

  if (!PCF.begin())
  {
    Serial.println("could not initialize...");
  }
  if (!PCF.isConnected())
  {
    Serial.println("=> not connected");
    while(1);
  }

  int x = PCF.read16();
  Serial.print("Read ");
  Serial.println(x, HEX);
  delay(1000);
}

void loop()
{
  Serial.println("HLT");
  while (Serial.available() == 0);
  switch (Serial.read())
  {
    case 'H': doHigh(); break;
    case 'L': doLow(); break;
    case 'T': doToggle(); break;
  }
}

void doHigh()
{
  PCF.write(4, HIGH);
  int x = PCF.read16();
  Serial.print("Read ");
  Serial.println(x, HEX);
}

void doLow()
{
  PCF.write(4, LOW);
  int x = PCF.read16();
  Serial.print("Read ");
  Serial.println(x, HEX);
}

void doToggle()
{
  PCF.toggle(4);
  int x = PCF.read16();
  Serial.print("Read ");
  Serial.println(x, HEX);
}

This problem does not exist today. The only thing I can think of is that I rebooted the system this morning.

Consider posting an annotated schematic showing exactly how you have wired it. It sounds like a hardware problem.

gilshultz, although this isn't happening today after a reboot, here is what you were looking for.

The PCF8575 is connected like this:

image

This tells me nothing. Pin numbers, labels, etc are missing as well as showing what wire goes where.

Qwiic connectors and cables by Sparkfun are designed to make it easy to string together I2C devices. The R4 in my project has a qwiic connector and the ICM-20948 IMU device has 2 of them. The PCF device doesn't have Qwiic connectors, it has 5-pin connector like this
image That is connected but the cable with the Qwiic connector on one end and the 4 female Dupont connectors on the other.

You can get more information about Quiic here: Qwiic Connect System - SparkFun Electronics

Here is the updated image showing the connections.

The pictures do not work for me. Try this link: How to Read a Schematic - SparkFun Learn Also realize I probably do not have the same hardware as you do and my things look different.

Good idea, how can we move it to the R4 WIFI forum?

Moved as requested.

1 Like

This issue continues to happen randomly, so please regard it as an open problem.

Thanks.

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