• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Getting the BME280 to run with Deep Sleep coded in

Q&A Forum › Category: ESP32 › Getting the BME280 to run with Deep Sleep coded in
0 Vote Up Vote Down
Jacob George asked 6 years ago

Hello,

I would appreciate some assistance. I have got the BME280 to work, but when I include the Deep Sleep code, the BME280 sensor element does not run. I am attaching a screenshot of the (partial, but relevant) code).

Thank you.

https://imgur.com/a/d6IM4cE

6 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi Jacob.
Can you please answer some question so that I can better understand what is happening?
The sensor fails to initialize or the BME280 readings are not being printed?
Where are you getting the BME280 readings in your code? In the loop()?
Your code goes to deep sleep after reaching the loop(), so your sensor readings will never be printed.
Do you get any errors on the Serial Monitor?
Regards,
Sara
 

0 Vote Up Vote Down
Jacob George answered 6 years ago

The sensor readings are not displayed. The ‘deep sleep’ code runs in the setup function, and the sensor runs in the loop function. Also, if I am using code to display the readings in a web server, where do I run the deep sleep code so that the sensor readings are made and these can be read in the web server?
There is some gibberish in the serial monitor, but it also displays that the deep sleep boot count and the timer wake up and going to sleep instructions. But the sensor reading (obviously) does not display once deep sleep is activated.

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi again.

In a sketch that uses deep sleep, all the code that you want to be executed should go before calling the deep sleep function. Whatever you write after that, won’t be executed because the ESP will be sleeping.

When the ESP32 is in deep sleep mode, the Wi-Fi is off. So, you can’t have a web server running while the ESP32 is in deep sleep.

Alternatively, you can send your sensor readings via MQTT, for example, to another ESP32 that is awake and running the web server.

I hope this helps. Let me know if you have more questions.

Regards,
Sara

0 Vote Up Vote Down
Jacob George answered 6 years ago

Thank you for your prompt replies. Much appreciated. We have got it working by placing the deep sleep code in a function and then calling it in the loop function after the sensor function call. However, while the sensor readings are now being displayed and the deep sleep works accordingly, we do get some gibberish  Here is the link to the image of teh ‘gibberish’.

https://imgur.com/a/RXTfgI0

0 Vote Up Vote Down
Jacob George answered 6 years ago

Can I assume that if we want to include the Web Server elements, these will have to be called as a seperate function before the deep sleep function call in the loop?

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Yes, exactly.
But I’m not sure if it will handle clients properly with a deep sleep code right after it.
Also, the web server would be running just while the ESP32 is awake (which I assume is a short period of time).
The gibberish you get is normal, don’t worry.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.