<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Simple Remote Air Quality Monitor Project Tutorial</title><link>/challenges-projects/project14/betterworld/b/blog/posts/simple-remote-air-quality-monitor-project-tutorial</link><description>Good ventilation improves people&amp;#39;s quality of life. In this tutorial I present how to build a simple air quality monitor to improve your ventilation routines.
It is a simple remote Air Quality monitor with an Arduino Nicla Sense ME board as a sensor </description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Simple Remote Air Quality Monitor Project Tutorial</title><link>https://community.element14.com/challenges-projects/project14/betterworld/b/blog/posts/simple-remote-air-quality-monitor-project-tutorial</link><pubDate>Sat, 28 May 2022 15:41:39 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:215b3e51-db48-4968-8a44-ae20cce2a0fc</guid><dc:creator>javagoza</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;After several days of continuous operation without problems, the monitor crashed yesterday.&lt;br /&gt;I have not been able to identify the reason so for now I have activated the SAM D21 Watchdog Timer (WDT) that restarts the board if it detects 16 seconds without executing the main loop. It is a very long time but it is to be able to give time to the tasks that are executed on the SD card or when setting up the WiFi without complicating the code by clearing the watchdog timer outside the loop() code.&lt;/p&gt;
&lt;p&gt;From the SAM D21 Family Data Sheet.&amp;nbsp;&lt;a href="https://ww1.microchip.com/downloads/en/DeviceDoc/SAM-D21DA1-Family-Data-Sheet-DS40001882G.pdf"&gt;SAM D21 Family Data Sheet (microchip.com)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;quot;The Watchdog Timer (WDT) is a system function for monitoring correct program operation. It makes it possible to&lt;/em&gt;&lt;br /&gt;&lt;em&gt;recover from error situations such as runaway or deadlocked code. The WDT is configured to a predefined time-out&lt;/em&gt;&lt;br /&gt;&lt;em&gt;period, and is constantly running when enabled. If the WDT is not cleared within the time-out period, it will issue a&lt;/em&gt;&lt;br /&gt;&lt;em&gt;system reset. An early-warning interrupt is available to indicate an upcoming watchdog time-out condition.&lt;/em&gt;&lt;br /&gt;&lt;em&gt;The window mode makes it possible to define a time slot (or window) inside the total time-out period during which&lt;/em&gt;&lt;br /&gt;&lt;em&gt;the WDT must be cleared. If the WDT is cleared outside this window, either too early or too late, a system reset will&lt;/em&gt;&lt;br /&gt;&lt;em&gt;be issued. Compared to the normal mode, this can also catch situations where a code error causes the WDT to be&lt;/em&gt;&lt;br /&gt;&lt;em&gt;cleared frequently.&lt;/em&gt;&lt;br /&gt;&lt;em&gt;When enabled, the WDT will run in active mode and all sleep modes. It is asynchronous and runs from a CPU independent clock source. The WDT will continue operation and issue a system reset or interrupt even if the main&lt;/em&gt;&lt;br /&gt;&lt;em&gt;clocks fail.&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;img height="240" src="/resized-image/__size/934x480/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-215b3e51-db48-4968-8a44-ae20cce2a0fc/pastedimage1653751237371v1.png" width="467" alt=" " /&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Set up the WDT&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:d643e830-d9ab-4a65-b50a-8134127ec4a3:type=c_cpp&amp;text=%2F%2F%20Set%20up%20the%20WDT%20to%20perform%20a%20system%20reset%20if%20the%20loop%28%29%20blocks%20for%20more%20than%2016%20seconds%0D%0Avoid%20setupWDT%28%29%20%0D%0A%7B%0D%0A%20%2F%2F%20Set%20up%20the%20generic%20clock%20%28GCLK2%29%20used%20to%20clock%20the%20watchdog%20timer%20at%201.024kHz%0D%0A%20%20REG_GCLK_GENDIV%20%3D%20GCLK_GENDIV_DIV%284%29%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Divide%20the%2032.768kHz%20clock%20source%20by%20divisor%2032%2C%20where%202%5E%284%20%2B%201%29%3A%2032.768kHz%2F32%3D1.024kHz%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20GCLK_GENDIV_ID%282%29%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Select%20Generic%20Clock%20%28GCLK%29%202%0D%0A%20%20while%20%28GCLK-%3ESTATUS.bit.SYNCBUSY%29%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Wait%20for%20synchronization%0D%0A%0D%0A%20%20REG_GCLK_GENCTRL%20%3D%20GCLK_GENCTRL_DIVSEL%20%7C%20%20%20%20%20%20%20%20%20%20%2F%2F%20Set%20to%20divide%20by%202%5E%28GCLK_GENDIV_DIV%284%29%20%2B%201%29%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20GCLK_GENCTRL_IDC%20%7C%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Set%20the%20duty%20cycle%20to%2050%2F50%20HIGH%2FLOW%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20GCLK_GENCTRL_GENEN%20%7C%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Enable%20GCLK2%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20GCLK_GENCTRL_SRC_OSCULP32K%20%7C%20%20%20%2F%2F%20Set%20the%20clock%20source%20to%20the%20ultra%20low%20power%20oscillator%20%28OSCULP32K%29%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20GCLK_GENCTRL_ID%282%29%3B%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Select%20GCLK2%20%20%20%20%20%20%20%20%20%0D%0A%20%20while%20%28GCLK-%3ESTATUS.bit.SYNCBUSY%29%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Wait%20for%20synchronization%0D%0A%0D%0A%20%20%2F%2F%20Feed%20GCLK2%20to%20WDT%20%28Watchdog%20Timer%29%0D%0A%20%20REG_GCLK_CLKCTRL%20%3D%20GCLK_CLKCTRL_CLKEN%20%7C%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Enable%20GCLK2%20to%20the%20WDT%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20GCLK_CLKCTRL_GEN_GCLK2%20%7C%20%20%20%20%20%20%20%2F%2F%20Select%20GCLK2%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20GCLK_CLKCTRL_ID_WDT%3B%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Feed%20the%20GCLK2%20to%20the%20WDT%0D%0A%20%20while%20%28GCLK-%3ESTATUS.bit.SYNCBUSY%29%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Wait%20for%20synchronization%0D%0A%0D%0A%20%20REG_WDT_CONFIG%20%3D%20WDT_CONFIG_PER_16K%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Set%20the%20WDT%20reset%20timeout%20to%2016384%20clock%20cycles%2C%2016%20seconds%0D%0A%20%20while%28WDT-%3ESTATUS.bit.SYNCBUSY%29%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Wait%20for%20synchronization%0D%0A%20%0D%0A%20%20REG_WDT_CTRL%20%3D%20WDT_CTRL_ENABLE%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Enable%20the%20WDT%20in%20normal%20mode%0D%0A%20%20while%28WDT-%3ESTATUS.bit.SYNCBUSY%29%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Wait%20for%20synchronization%0D%0A%7D]&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And inside loop() function&amp;nbsp;notify the WDT by clearing the watchdog timer&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:817524b3-c2a7-418a-ba13-9a7f750e948a:type=text&amp;text=%20%20if%20%28%21WDT-%3ESTATUS.bit.SYNCBUSY%29%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Check%20if%20the%20WDT%20registers%20are%20synchronized%20%20%0D%0A%20%20%20%20REG_WDT_CLEAR%20%3D%20WDT_CLEAR_CLEAR_KEY%3B%20%20%20%20%20%20%20%20%2F%2F%20Clear%20the%20watchdog%20timer%0D%0A%20%20%7D]&lt;/p&gt;
&lt;p&gt;I have uploaded the changes to the Github repository&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/javagoza/Remote-IAQ-Monitor"&gt;https://github.com/javagoza/Remote-IAQ-Monitor&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=23591&amp;AppID=369&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Simple Remote Air Quality Monitor Project Tutorial</title><link>https://community.element14.com/challenges-projects/project14/betterworld/b/blog/posts/simple-remote-air-quality-monitor-project-tutorial</link><pubDate>Fri, 27 May 2022 14:34:03 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:215b3e51-db48-4968-8a44-ae20cce2a0fc</guid><dc:creator>javagoza</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Looking for information about the Arduino Nicla Sense ME I have found a reference to this project.&amp;nbsp;[emoticon:578cee8aac0e41e9bcef50a2f8d281d5]&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="/resized-image/__size/1280x720/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-215b3e51-db48-4968-8a44-ae20cce2a0fc/pastedimage1653661771995v1.png" alt=" " /&gt;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=23591&amp;AppID=369&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>