Skip to content

Ensure readPressure function is executed only if begin returns 1 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2021

Conversation

pennam
Copy link
Contributor

@pennam pennam commented Jul 6, 2021

With some example sketches like https://opla.arduino.cc/opla/module/iot-starter-kit-maker/lesson/02-personal-weather-station the program execution goes on even if carrier.begin() returns an error. If the pressure sensor (or any other sensor of the board) fails to initialize the following reading calls get stuck here

while ((i2cRead(LPS22HB_CTRL2_REG) & 0x01) != 0) {

because the sensor is not responding. On the MKR_WIFI_1010 this will lead to a watchdog infinite reset loop (watchdog is enabled by the IOT library).
Even if the board resets itself the sensor is never initialized correctly, the only thing i found working is to completely power off the board unplugging the usb connector, therefore, in this specific case, the watchdog resets are completely usless.
What i propose is to store the initialization return value and check it into the readPressure funcion avoiding any action if something went wrong during initialization phase and let the user decide when to reset/unplug the board.
If the changes are good i think we could extend them also to:

and maybe some other library...

@pennam pennam marked this pull request as ready for review July 6, 2021 14:14
@pennam pennam requested a review from aentinger July 6, 2021 14:14
@github-actions
Copy link

github-actions bot commented Jul 6, 2021

Memory usage change @ 45a8900

Board flash % RAM for global variables %
arduino:mbed_nano:nano33ble 🔺 +64 - +64 +0.01 - +0.01 🔺 +8 - +8 0.0 - 0.0
Click for full report table
Board examples/ReadPressure
flash
% examples/ReadPressure
RAM for global variables
% examples/ReadPressureImperial
flash
% examples/ReadPressureImperial
RAM for global variables
%
arduino:mbed_nano:nano33ble 64 0.01 8 0.0 64 0.01 8 0.0
Click for full report CSV
Board,examples/ReadPressure<br>flash,%,examples/ReadPressure<br>RAM for global variables,%,examples/ReadPressureImperial<br>flash,%,examples/ReadPressureImperial<br>RAM for global variables,%
arduino:mbed_nano:nano33ble,64,0.01,8,0.0,64,0.01,8,0.0

Copy link
Contributor

@aentinger aentinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a feasible solution, however it would be much better if this would be solved within the Opla demo sketches instead of ignoring the return values.

@pennam
Copy link
Contributor Author

pennam commented Jul 7, 2021

i completely agree, i will try to understand where the demo sketches are hosted to propose a change, however i think we could also merge this to strengthen the library. Thanks.

@aentinger aentinger merged commit 0cc23c4 into arduino-libraries:master Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants