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)... ");
}
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.
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
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).
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.