DASDUINO CONNECT SLEEP MODE
You are a beginner with Dasduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by soldered where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect the module with Dasduino and the basic code. Everything else is left to your imagination.
When we work on a project, we rarely think about the consumption of each of the modules. But, when we need to switch the project to battery power supply, it is clear that the consumption of the modules is crucial. When the project is battery-powered, each mA the module can consume is essential and we constantly look for ways to reduce the consumption. If we work with reduced consumption, it means that the system (project) will work longer on a single charge, which is very important to us. In order to achieve the long-term operation with Dasduino Connect, in this tutorial, we will show you how to “put Connect to sleep” when it is not required to operate (e.g. measure temperature every hour) and how to “wake it up”. For the purposes of “putting Connect to sleep” and “waking it up”, first, we must know about its operation modes, so let us begin with that.
Dasduino Connect has 4 operating modes which differ according to which part of the board is operating and, of course, the consumption, so let us move on with explaining these operating modes.
•The first operating mode is the Normal operating mode, where each part operates and Dasduino Connect does not “sleep”, but rather operates normally, and it is constantly ready, which means that the consumption is at its highest.
•The second operating mode is MODEM-SLEEP and it is the default operating mode which is attainable only when the Dasduino Connect is being connected to the access point. The only thing done when it is in the second operating mode is shutting the WiFi down whenever possible (among the DTIM Beacon intervals which are set within the router).
•The third operating mode is LIGHT-SLEEP mode in which Dasduino Connect shuts the WiFi and the system clock that controls the processor down, so the processor operates, but it does not perform tasks (idle mode). In this operating mode, Dasduino consumes far less than in the MODEM-SLEEP mode.
•The last operating mode, in which we “put Dasduino Connect to sleep” is DEEP-SLEEP mode, using which we shut all the systems down, except for the RTC (real-time clock) and the consumption in this mode is 17uA (3,3 V power supply), i.e. 50 uA (5V with a regulator and pull-up resistors) which is low and acceptable for projects that are battery-supplied. To reduce the consumption to the uA you must remove the CH340 USB driver, along with the battery charger from the board. Make sure to switch the code to the board before removing the CH340 chip, because later it will not be possible.
Power consumption in the normal operating mode and DEEP-SLEEP is shown in the following table (5V power supply).
As we have already mentioned, this is the only operating mode in which the Dasduino Connect “sleeps”, i.e. all of its systems are shut down, except for the RTC (real-time clock) and this mode is the most energy-efficient. It is used when we need to significantly reduce the consumption, and the constant operation of the microcontroller is not required. We also use this operating mode when we have sensors that measure something during specific time intervals and send these data to the Internet (or server). First, we measure the values and send them, then we shut the microcontroller down for some time (in microseconds), for 70 minutes longest, and finally, repeat the process (turn the microcontroller on again, measure, send data and turn it off). For the microcontroller to wake again you must connect pin 16 to the reset pin. Pin 16 has a special function for waking the microcontroller. When the given time has passed, pin 16 is set to LOW and it restarts the microcontroller, so it starts executing the program the same way as when we reset it using the reset button.
Here is a simple code in which we will read the temperature every minute and send it to the Serial monitor. In the code for switching the microcontroller off, we use the ESP.deepSleep() function to which we transmit the time in microseconds (1s= 1000000 us = 1e6).
//including the library for the DHT sensor
//defining to which pin the DHT sensor is connected and which type of sensor is used (DHT11 or DHT22)
#define DHTPIN 4
#define DHTTYPE DHT11
//creating the constructor for the DHT library
//starting serial communication (115200 baud)
//starting the communication with the sensor
//displaying the message that the Croduino is "awake" and the temperature on the Serial monitor
"Croduino is on and reading temperature"
"Turning the Croduino off for one minute"
// turning the Croduino off for 60 seconds