Sorry for the long title.
I have two sensors, a BH1750 light sensor and DHT11 temperature and humidity sensor running on an esp32 (wroom32). I want to read from the light sensor every second, but I only want to read from the DHT11 every minute. The methods for reading the sensors are separate. I can add a delay(1000) for the light sensor's method, but how can I delay reading from the DHT11 for one minute? I'm new to the platform, but I've looked around the 'net and can't find any similar situations. I also considered interrupts, but that seems impractical as I'm sure reading from sensors involves interrupts, which would make that problematic. So, is this even possible? If so, how do I go about it?
Thanks
Using two sensors, want to read every second from one, but only every minute for the other. How can I do this?
-
- Posts: 9725
- Joined: Thu Nov 26, 2015 4:08 am
Re: Using two sensors, want to read every second from one, but only every minute for the other. How can I do this?
Simple and stupid way: have a counter and increase it every time you read from the light sensor. Then only read the DHT11 (and reset the counter) once the counter reaches 60.
Re: Using two sensors, want to read every second from one, but only every minute for the other. How can I do this?
Thanks for the reply. I tried something similar and what you recommend is also given as an option here:
https://www.digikey.com/en/maker/blogs/ ... o-sketches
I have yet to try your specific idea, but conceptually, it appears to be effectively the same. But I'll try it anyway.
Specifically what happens is that there are no readings from any of the sensors after the initial read, if any value over 30 seconds is used. (30 seconds is not reliable either)
I wonder if it has to do with the sensors. Do I need to 'kickstart' the sensors again? In setup there is a begin() call for each sensor. Should I instead call begin() just before each read?
Time for more empirical study, I guess.
Thanks again.
https://www.digikey.com/en/maker/blogs/ ... o-sketches
I have yet to try your specific idea, but conceptually, it appears to be effectively the same. But I'll try it anyway.
Specifically what happens is that there are no readings from any of the sensors after the initial read, if any value over 30 seconds is used. (30 seconds is not reliable either)
I wonder if it has to do with the sensors. Do I need to 'kickstart' the sensors again? In setup there is a begin() call for each sensor. Should I instead call begin() just before each read?
Time for more empirical study, I guess.
Thanks again.
Re: Using two sensors, want to read every second from one, but only every minute for the other. How can I do this?
Actually, I got it to works using a timer. Not sure what I did wrong before, but I'm getting temp/humidity readings only every 3 minutes, while the lux readings happen every second.
Thanks
Thanks
-
- Posts: 826
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Using two sensors, want to read every second from one, but only every minute for the other. How can I do this?
The url you posted is very avr specific. There are a lot of very useful examples included with the arduino-esp32 board. Here is an esp32 specific example. https://github.com/espressif/arduino-es ... linker.ino
Re: Using two sensors, want to read every second from one, but only every minute for the other. How can I do this?
Thank you, I'll check them out.
Who is online
Users browsing this forum: Majestic-12 [Bot] and 76 guests