

The first one will simply hold the number of the pin where we will attach our interruption, so its value is easy to change.Īdditionally, we will declare a Boolean variable that will be used in our interrupt service routine to signal that an interrupt has occurred. Then, we declare some global variables for our program. So, if you are using a NodeMCU, the correct pin mapping is the following:įirst, we need to include the RTC library that allows us to interact with the DS3231 and also the Arduino library that implements the communication with I2C devices ( wire library). If you are using a NodeMCU board, take into consideration that the board pins don’t correspond to the ESP8266 pins (check here the correct mapping). We just need to connect the SCL and SDA pins (I2C) of the DS3231 module to the corresponding pins of the ESP8266.Īdditionally, we need to connect the square wave / alarm pin (SQW) of the DS3231 to the GPIO of the ESP8266 where we want the interrupt to be triggered. In this example, we will be using GPIO13.įigure 2 – Connection diagram between the ESP8266 and the DS3231 module.Īs described in the documentation of the ESP8266 libraries for the Arduino IDE, the default pins for the I2C in the Wire library are pins 4 (SDA) and 5 (SDL). The connection diagram for this tutorial is illustrated in figure 2 and is the same used in the previous DS3231 post. More details about these registers can be seen in the datasheet of the device.įortunately, the RTC library we are considering has simple easy to use classes and methods that abstract from us the more complex details of interfacing with the RTC. Īll of these functionalities are controlled by the internal registers of the DS3231, which we can manipulate via I2C. Nevertheless, both alarms can operate simultaneously. Naturally, only the alarms or the square wave can be activated at each time. These alarms generate active-low interrupts in one of the pins of the DS3231, which is also shared with the configurable square wave output functionality. One of the alarms (alarm one) can operate with a precision of seconds and the other (alarm 2) can operate with a precision of minutes. The DS3231 has two programmable alarms which can operate in different modes.
#Ds3231 use as timer how to
You can check how to install them in this previous tutorial. You can check here how to configure the Arduino IDE to support the ESP8266.įinally, we will use the DS3231 libraries indicated here, which can be installed via library manager of the Arduino IDE. We also assume the use of the ESP8266 libraries for the Arduino IDE. We will use the ESP8266 interrupts to handle the alarm triggering.įor this tutorial, we consider the use of the DS3231 Real Time Clock (described in more detail in this previous post) integrated in an easy to use board, which can be bought at eBay for less than 1 euro. The objective of this post is to explain how to use the DS3231 Real Time Clock to trigger an alarm interruption when the time matches a specified value for the seconds.
