adafruit/Adafruit_BME280_Library

Isn't while(1); dangerous ?

rhuss opened this issue · 3 comments

rhuss commented

Sorry if this is a noob question, just started with tinkering, but I think in the example the while(1); loop is quite problematic:

It happened to me that when I tried it with a Wemos LOLIN32 Pro board (an old one, from two years ago), that the board started smoking after some time got very hot when running this example and it didn't detect an I2C device. First I thought that this is common idiom in ESP32 or Arduino coding so that it indeed is translated in a kind of sleep. But now it looks for me that it really just burns CPU cycle, like in any other programming language.

I killed 3 boards that way until I replaced that line with a delay(verylongtimeout).
What's your take on that while(1); idiom, which, btw, I have seen several times in various examples (so I'm really curious what's the reasoning behind this loop).

Sorry again if this is a noob question, feel free to close the issue any time.

  • Arduino board: Wemo Lolin32 Pro (ESP32)

  • Arduino IDE version (found in Arduino -> About Arduino menu): Using plattform.io

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): Upload BME280 example with the sensor being not detected.

That is just a simple infinite loop. You should only get to that if the BME280 is not initialized properly for some reason. The idea is to give you an error message and then stop. It should not cause any issues with hardware. The smoking and getting hot must be something else.

rhuss commented

Thanks, but that does not explain why a while(1); should be different on an ESP32 than on any other system I know which will burn the CPU with 100%.

Try perl -e 'while(1){}' on mac or linux machine (but you probably know that ....

microcontrollers don't work like that, they are always at 100%