adafruit / Adafruit_BME280_Library

Arduino Library for BME280 sensors
Other
339 stars 306 forks source link

Isn't while(1); dangerous ? #71

Closed rhuss closed 4 years ago

rhuss commented 4 years ago

Sorry if this is a noob question, just started with tinkering, but I think in the example the while(1); loop is quite problematic: https://github.com/adafruit/Adafruit_BME280_Library/blob/616c7290e4a1bf863021506fe8367e924881cc80/examples/bme280test/bme280test.ino#L54

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.

caternuson commented 4 years ago

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 4 years ago

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 ....

ladyada commented 4 years ago

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