I2C sensor working on Uno R3, not R4 WiFi

I am trying to use a Sensirion flow sensor (uses I2C). It works perfectly with an Uno R3 but gives an error with the Uno R4 WiFi.

This is the sensor: Smart sensor solutions

I've tried two versions of the code.
One is a script I received directly from them located here: https://github.com/Sensirion/arduino-liquid-flow-snippets/blob/master/SF06/example_15_simple_measurement_SLF3x/example_15_simple_measurement_SLF3x.ino

This script only uses the Wire.h library.

A second is the "exampleUsage" script present in their library and core GitHub - Sensirion/arduino-i2c-sf06-lf: Sensirion Liquid Flow I2c drivers for Arduino.

The error on the R4 happens at the very start:

#include <Wire.h> // Arduino library for I2C

const int ADDRESS = 0x08; // Sensor I2C Address
const float SCALE_FACTOR_FLOW = 500.0; // Scale Factor for flow rate measurement
const float SCALE_FACTOR_TEMP = 200.0; // Scale Factor for temperature measurement
const char *UNIT_FLOW = " ml/min"; //physical unit of the flow rate measurement
const char *UNIT_TEMP = " deg C"; //physical unit of the temperature measurement

// -----------------------------------------------------------------------------
// Arduino setup routine, just runs once:
// -----------------------------------------------------------------------------
void setup() {
  int ret;

  Serial.begin(9600); // initialize serial communication
  Wire.begin();       // join i2c bus (address optional for master)

  do {
    // Soft reset the sensor
    Wire.beginTransmission(0x00);
    Wire.write(0x06);
    ret = Wire.endTransmission();
    if (ret != 0) {
      Serial.println("Error while sending soft reset command, retrying...");
      delay(500); // wait long enough for chip reset to complete
    }
  } while (ret != 0);

  delay(50); // wait long enough for chip reset to complete
}

Serial output repeats: "Error while sending soft reset command, retrying..." when on the R4 WiFi. However, when on the Uno R3, the whole script manages to run and I get sensor values.

About the sensor connections (4):
SDA A4
SCL A5
VDD 3v3
GND GND

The R4 board does not have any pull up resistors on it try adding some. I2C will not work without them on the R4.

1 Like

Thanks for the response!

At this link, they reference the connections:

What are pull up resistors? How do I determine the resistance needed?

Thanks

Resistors that are used to make the normal, un-driven state of the bus a logic high.

You require a current of 2 to 4mA, so the calculation is always the same depending on the voltage of the bus.

For a 3V3 bus use 1.8K, for a 5V bus use 4.7K.

1 Like

Thank you. I assume I add this 1.8K resistance in the 3V3 line between the sensor and the Arduino?

I was looking at this conversation here which seems to suggest in the R4 we can only use the 5V line? Problem? using Arduino Uno R4 Minima and I2C - #9 by geirandersen

No. A pull up resistor is added between the I2C line A4 and the bus drive voltage. There should be another on A5 and the bus drive voltage.

This is wrong.

I'm looking into how pull up resistors are connected (new to this) based on what you've described is it:

A. Create a 1.8Kohm 'short' between A4 and 3V3 and a separate one between A5 and 3V3?
B. Attach a 1.8Kohm between A4 and the sensor SDA pin and a separate one between A5 and sensor SCL pin?

Short? A short circuit has no resistance so this makes no sense.

Here is what I did when I wanted to drive a 3V3 device from a R4 Arduino.

Yes

2 Likes

Thank you! I'll let you know once this works!

actually, the R4 does have internal pull up resistors.
Simply modify the blink example to

void loop() {
  pinMode(A5, INPUT_PULLUP);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  pinMode(A5, INPUT);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

and connect a low-current LED to A5 and GND and it will flash (0.25 mA).
But you are right: the internal resistor is way too big. 20 kOhms, too much for I2C.

Yes BUT only to 5V. To run the bus at any other voltage, like 3V3 then you need pull up resistors to that voltage.

Correct.

However, I would describe the internal resistors as being "way too small".

I know the resistor value is bigger but when we talk about a pull up resistor it is normal to talk about how "hard" they pull. That means the current they can supply. So hence the 30 to 50 KΩ of the internal pull up resistors, don't pull hard enough.

Finally got a chance to get back into lab. The 1K8 pullup resistors worked!
Thanks for your help Grumpy_Mike!

Your vast welcome, glad you got it working.

2 posts were split to a new topic: PN532 works on the Uno R3 but not on Uno R4