Integrating an I2C pulse counter on RAK4631

I’m trying to integrate an I2C pulse counter with a RAK4631(RUI3) to send flow readings via lora

Preformatted text

void readFlowRateFromEZO() {
    Wire.beginTransmission(pulseCounterAddress);
    Wire.write("r");
    Wire.endTransmission();
    delay(300); // Wait for the EZO device to respond (adjust delay as needed)
    
    String currentReading = "";
    
    while (Wire.available()) {
      char dataChar = Wire.read();
      currentReading += dataChar; // Append the character to currentReading 
    }

    if (currentReading.length() > 0) {
        flowRateString += currentReading + "\n";
    }

    Serial.print("Current Flow Rate: ");
    Serial.println(currentReading);
    Serial.println("Cumulative Flow Rate Readings:");
    Serial.println(flowRateString);
}

however despite a being read off with an I2C scanner I can’t get the readings out, I’ve tried it with an Arduino and have gotten the results I want. I’m wondering if the issue is due to RUI3 implementation for I2C

Hi Nikko,

What version of RUI3 are you using?
How many bytes will the pulse counter send after the “r” request?
RUI3 has the I2C buffer limited to 32 bytes only. That could be the reason.
Did you try the latest staging version? It has an extended I2C buffer of 64 bytes and it solved my problem with some I2C devices.

What is the max I2C speed of the pulse counter? Did you try to lower the I2C speed with Wire.setClock()?

I’m using 4.1.0, im expecting a 1 byte response,i’ve already set the clock speed to 100k.

image

It looks like you are receiving something, as you set String currentReading =""; and then the Serial.println() prints the question mark. Are you sure the data arriving is a character and not a number?
The printout looks like you get a non-printable character.

Try to read the incoming data in a byte array instead of a string.

uint8_t received[64];
uint8_t index = 0;
while (Wire.available()) {
      received[index] = Wire.read();
      index++;
}

Serial.println("Received data:");
for (int idx = 0, idx < index; idx++)
{
   Serial.printf("%d ",received[idx]);
}
Serial.println("");

Hi Bernd, first off thanks for responding, however, after trying it out I received blank output. By the way i’m using an EZO Flow Pulse counter

image

and this is the result i get from an Arduino:

image