DF2301Q wont fail init

Can anyone with a DF2301q check if the library works correctly for DF2301Q.begin(); in I2C mode
I'm connected via I2C to an ESP32

while( !( DF2301Q.begin() ) ) {
    Serial.println("Communication with device failed, please check connection");
    delay(1000);
 }

it 'never fails' with device plugged in or not, always returns a value of 1, I'd hate to blame the library.....

The library works...
Is it your code? I'm no expert with this library, but is there supposed to be a "!" before the code?

Also, it would help to move this question here.

TBH I dont know if the ! is in error, its the example code i just changed the delay time to remove the long pause

  Serial.begin(115200);

  // Init the sensor
  while( !( DF2301Q.begin() ) ) {
    Serial.println("Communication with device failed, please check connection");
    delay(3000);
  }

And yes maybe moving this would be good, but maybe after confirmation it is possibly the library and not just an issue with the code from the example

also for some odd forum reason i can only post in some areas and not others, IE I can post in hardware, but i cant post in software(!) -this area is one of only a few i can use, so I generally try fb to fix things or spitball ideas before the visiting the forum

The "bang" (exclamation point) is a logical NOT or negation of the value returned by the function in parenthesis.

That is to say, if DF2301Q.begin() returns a "0" for "failed to begin" then this statement will evaluate to true; while( !( DF2301Q.begin() ) ) and you would see the Serial.println("Comms failed.");

int a = 1;
int b = 2;
int c = a + b;

void setup() {
  Serial.begin(115200);

  if (!(c == 3))
    Serial.println("Fail."); // c != 3
  else
    Serial.println("Pass."); // c == 3
}

void loop() {}

Here it is in a function call to look more like your example...

int a = 1;
int b = 2;
int c = a + b;

void setup() {
  Serial.begin(115200);

  if (!(calcC() == 3)) // if the NOT/negatied return of calcC() is 3... 
    Serial.println("Fail."); // c != 3
  else
    Serial.println("Pass."); // c == 3
}

void loop() {}

int calcC() { // returns an int
  c = a + b;
  Serial.print(a);
  Serial.print(" + ");
  Serial.print(b);
  Serial.print(" = ");
  Serial.print(c);
  Serial.print(" ... so !(c == 3)... ");
}

Result:

1 + 2 = 3 ... so !(c == 3)... Fail.

but board plugged in, it does not print 'fail', thats expected and no issue, unplug the board and exactly the same, it does not print 'fail'.... not as expected.

So either the provided example is wrong, or the library call is bugged.

(long pause while I try different code)

Serial.println(DF2301Q.begin());
Serial.println(DF2301Q.begin());
Serial.println(DF2301Q.begin());

I open serial monitor press reset and I get "1" three times, then i unplug the df2301 from the esp32, hit reset again and get three 1's again, now call me odd but I would have expected a zero....

The board is working fine, I just cant verify its connected with the library function.
Documentation seems hard to find, unless its sales documentation

The DFRobot_DF2301Q library seems to "only" (?) check Wire.h for pass/fail... and "wire" is built-in.

bool DFRobot_DF2301Q_I2C::begin()
{
  _pWire->begin();   // Wire.h(I2C)library function initialize wire library
  _pWire->beginTransmission(_deviceAddr);
  _pWire->write(0x00);
  if(0 != _pWire->endTransmission())
    return false;
  return true;
}

Yes I can check if its on the i2c, but that doesnt fix what I think is a broken library example, which is a big no no and oopsie for dfrobot that they need to address.

edit: I have posted in the libraries subgroup as I really feel confident this is a real library issue, and I have also posted onto the dfrobot forum but it seems to have a lot of odd offtopic threads.

I couldn't move this thread to 'libraries' so started a new one, nor can i delete this thread which is now no longer needed ('you dont have permissions to delete this thread')

If you think this topic has not made known an issue worth acknowledging, you may flag it for deletion (in your first post, click the flag, click "something else", add a comment).

@anon42340922 ,

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

Sorry for the dupe this forum is very very hard to navigate and i'll be removing my account and going back to the facebook groups.

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