amc2020:group_n:test
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
amc2020:group_n:test [2020/07/29 11:25] – [Back To Main Page] jonas001 | amc2020:group_n:test [2023/01/05 14:38] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 178: | Line 178: | ||
- | ==== Back To Start of the Page ==== | ||
+ | ===== Links ===== | ||
< | < | ||
- | <span id="test"> | + | |
- | < | + | <a href="https://wiki.eolab.de/doku.php? |
- | <html>< | + | <span style="color:#2E71B8"; onmouseover=" |
+ | ↩ Back to the main page | ||
+ | </ | ||
+ | | ||
+ | | ||
</ | </ | ||
- | ===== DS3231 Code Explanation ===== | ||
< | < | ||
- | | + | |
- | <ol> | + | <span> |
- | <li> | + | <a href="javascript:self.scrollTo(0,0)"; onmouseover=" |
- | As explained before, no external library needs to be included, only the < | + | <span style=" |
- | </ | + | |
- | < | + | </span> |
- | The I2C address of the DS3231 needs to be defined. By default | + | </ |
- | </ | + | </span> |
- | < | + | </center> |
- | When setting the day of the week later, 1 represents Monday, and 7 represents Sunday. To make it more intuitive the days are here defined. | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | As explained in section 2, the alarm register mask bits define the alarm rate. For example, choosing the < | + | |
- | </ | + | |
- | < | + | |
- | The < | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | Here the Arduino pins for the interrupt (< | + | |
- | </ | + | |
- | < | + | |
- | When an interrupt is triggered, the MCU executes the attached interrupt service routine ISR which is defined later. The variable < | + | |
- | < | + | |
- | Configuring a variable as volatile tells the Compiler to load the variable from the RAM instead of the a storage register. This is necessary when the variable can be changed from somewhere else than the code that it is appearing in, for example a concurrently executed function like an ISR. | + | |
- | < | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | In the < | + | |
- | </ | + | |
- | < | + | |
- | The interrupt pin < | + | |
- | </ | + | |
- | < | + | |
- | The pin for the LED needs to be configured as an < | + | |
- | </ | + | |
- | < | + | |
- | Here the later defined function < | + | |
- | </ | + | |
- | < | + | |
- | The function < | + | |
- | </ | + | |
- | < | + | |
- | To attach an interrupt on the Arduino UNO, the function < | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | The main < | + | |
- | </ | + | |
- | < | + | |
- | The < | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | The function < | + | |
- | </ | + | |
- | < | + | |
- | This function does the exact opposite of the previous one. It converts binary coded decimal back to decimal. This is only used for optionally checking if the time set in the DS3231 is correct. | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | The function < | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | As explained before (11), < | + | |
- | </ | + | |
- | < | + | |
- | The method < | + | |
- | </ | + | |
- | < | + | |
- | The method < | + | |
- | </ | + | |
- | < | + | |
- | Now the value for < | + | |
- | </ | + | |
- | < | + | |
- | When all the registers are configured and the DS3231 has a new time set, the I2C transmission is stopped with < | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | Here follows the definition of function < | + | |
- | </ | + | |
- | < | + | |
- | To configure the four registers of alarm 1, it is necessary to convert the seconds, minutes, hours and date/day into BCD format again. However, as can be seen in table 1, the alarm registers also contain the mask bits for the alarm rate which are stored as A1M1 to A1M4 in the MSBs of the four. The Which mask bit is used for which register is determined by the element chosen in the mask bit array (5). | + | |
- | < | + | |
- | The function < | + | |
- | < | + | |
- | This same process is repeated for the minutes hours and days. What changes is the position of the respective mask bit in the mask bit array element; for minutes it is 4, for hours 5 and for days or date 6. | + | |
- | < | + | |
- | The hour format will automatically be 24 hours like in the time register because bit 6 stays always 0 (see table 1). However, when the alarm rate is chosen to be either once a week or once a month, i.e. days/date are matched, that has to be changed in the code. Therefore, the MSB of the array element contains a 0 for matching the date and a 1 for matching the day (table 2). This value is read from the array with another < | + | |
- | </ | + | |
- | < | + | |
- | After configuring the values of the bytes for setting the alarm, another transmission to the RTC is started and the register pointer is set to register < | + | |
- | </ | + | |
- | < | + | |
- | To activate alarm 1 and enable the interrupt output throug the SQW pin, another transmission is started and the register pointer is set to < | + | |
- | </ | + | |
- | < | + | |
- | Then the byte < | + | |
- | B: 0 - turn on the oscillator; 0 - no square wave output; 0 - no temperature conversion command; 1 - square wave frequency setting - 1 square wave frequency setting; 1 -activate interrupt output; 0 - deactivate alarm 2; 1 - activate alarm 1. | + | |
- | <br> | + | |
- | After that, the alarm is set and an interrupt is issued when the respective register entries match. | + | |
- | | + | |
- | < | + | |
- | < | + | |
- | Whenever the alarm is activated, the alarm flag bit in the DS3231 status register is switched to a 1 and needs to be reset manually by changing | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | The last two functions are not used in the sketch but are useful to check whether the DS3231 has a correctly configured time register. The function < | + | |
- | </ | + | |
- | < | + | |
- | Then the I2C transmission is started in slave receiver mode to set the register pointer to the seconds register and the transmission is ended again. | + | |
- | </ | + | |
- | < | + | |
- | Another transmission is started but in the slave transmitter mode using the < | + | |
- | </li> | + | |
- | < | + | |
- | The dereferencing operator, the asterisk *, is used to change the value at the address of the pointer variable, in this case the value for the local variables from the < | + | |
- | </li> | + | |
- | < | + | |
- | < | + | |
- | In the < | + | |
- | </ | + | |
- | </ol> | + | |
- | </font> | + | |
</ | </ | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | Default Link Color RGB: #2E71B8 | ||
+ | |||
+ | < | ||
+ | <div style=" | ||
+ | <img src=" | ||
+ | | ||
+ | <a href=" | ||
+ | | ||
+ | <a href=" | ||
+ | | ||
+ | <a href=" | ||
+ | | ||
+ | < | ||
+ | | ||
+ | <a href=" | ||
+ | | ||
+ | < | ||
+ | | ||
+ | < | ||
+ | | ||
+ | <a href=" | ||
+ | | ||
+ | <a href=" | ||
+ | | ||
+ | <a href=" | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Materials and Methods ===== | ||
+ | |||
+ | ==== Sensors and modules that are used ==== | ||
+ | |||
+ | Further information on the sensors and devices used can be seen in their respective pages: | ||
+ | |||
+ | **[[dht22|DHT-22 Air Temperature and Humidity Sensor]]** | ||
+ | |||
+ | **[[ds18b20|DS18B20 Waterproof Temperature Sensor]]** | ||
+ | |||
+ | **[[SN74HC595N|SN74HC595(N) Shift Register]]** | ||
+ | |||
+ | **[[DS3231RTC|DS3231 Real Time Clock]]** | ||
+ | |||
+ | ==== Programming Deep Sleep and MQTT ==== | ||
+ | |||
+ | **[[amc2020: | ||
+ | |||
+ | **[[amc2020: | ||
+ | |||
+ | ==== Setup of the ESP32 and the Modules ==== | ||
+ | |||
+ | ^{{: | ||
+ | |**//Figure 2//** Graphic on how to set up the ESP32 and the modules and parts.| | ||
+ | |||
+ | ^{{: | ||
+ | |**//Figure 3//** Schematic of the connections between ESP32 and the modules and parts.| | ||
+ | |||
+ | ===== Results ===== | ||
+ | |||
+ | ^ {{: | ||
+ | | **//Figure 4//** Measurement results of the DHT-22 and DS18B20 sensors visualized in Grafana. | ||
+ | |||
+ | |||
+ | |||
+ | {{: | ||
+ | |||
+ |
amc2020/group_n/test.1596014745.txt.gz · Last modified: 2023/01/05 14:38 (external edit)