{"id":651,"date":"2011-07-04T17:23:27","date_gmt":"2011-07-04T09:23:27","guid":{"rendered":"http:\/\/www.rocketscream.com\/blog\/?p=651"},"modified":"2017-11-07T15:39:57","modified_gmt":"2017-11-07T07:39:57","slug":"lightweight-low-power-arduino-library","status":"publish","type":"post","link":"https:\/\/www.rocketscream.com\/blog\/2011\/07\/04\/lightweight-low-power-arduino-library\/","title":{"rendered":"Lightweight Low Power Arduino Library"},"content":{"rendered":"<p>We have just release the 1st revision of our low power library for Arduino. <!--more-->This is a simple and easy to use library that has the following features:<\/p>\n<ul>\n<li>Supports all sleeping mode of ATmega328P:\n<ul>\n<li>Idle.<\/li>\n<li>ADC reduction mode.<\/li>\n<li>Power save.<\/li>\n<li>Power down.<\/li>\n<li>Standby.<\/li>\n<li>Extended standby.<\/li>\n<\/ul>\n<\/li>\n<li>Selectable sleep duration:\n<ul>\n<li>15 ms, 30 ms, 60 ms, 120 ms, 250 ms, 500 ms, 1 s, 2 s, 4 s, 8 s, and forever (wake up using other resources) through on chip 125 kHz Watchdog timer. Using sleeping forever duration, the Watchdog timer module is not in use and will further reduce the current consumption by approximately 4\u00a0\u00b5A.<\/li>\n<\/ul>\n<\/li>\n<li>Option to shutdown Analog to Digital Converter (ADC) module to further reduce current consumption.<\/li>\n<li>Option to disable Brownout Detector (BOD) module to further reduce current consumption by approximately 17 \u00b5A. BOD module cannot be disabled through software in idle and ADC noise reduction mode. It can only be disabled through fuse setting in these 2 modes.<\/li>\n<li>Option to shutdown Timer 2 module in idle, ADC noise reduction, power save, \u00a0and extended standby mode. Timer 2 is used by the core of Arduino for PWM operation.<\/li>\n<li>Option to shutdown Timer 0, Timer 1, USART0, TWI, and SPI module in idle mode.<\/li>\n<\/ul>\n<p>We didn&#8217;t add any wake up functionality except using the Watchdog timer module to allow certain amount of sleep duration as we think other wake up resources (interrupt on pins, TWI address match, ADC conversion complete, SPI serial transfer complete, EEPROM ready) are closely bind to the external peripheral or interface it is connected to. For example, an external RTC chip with it&#8217;s clock output pin connected to pin 2 of the Arduino board. In this case, the library should not know what this external interrupt signal means to the system (timer or counter for time stamping or other usage). Therefore, we\u00a0omit them out (at least for now).\u00a0But, rest assured examples are included (more will be added from time to time) to demonstrate the usage of the library with external peripheral and interface.<\/p>\n<p>Please bear in mind that, most of the Arduino boards (official and also compatible) that is currently available in market (except some brilliant design from\u00a0<a title=\"JeeLabs\" href=\"http:\/\/http:\/\/jeelabs.com\/\" target=\"_blank\" rel=\"noopener\">JeeLabs<\/a> and <a title=\"Wiblocks\" href=\"http:\/\/wiblocks.luciani.org\/\" target=\"_blank\" rel=\"noopener\">Wiblocks<\/a>,\u00a0but there might be more out there that we are not aware of) are not low power by design. Low power design requires both hardware and software implementation. Our Mini Ultra 8 MHz (Arduino compatible) board is designed to be low power and is basically the testing platform for this library. Using the library on any Arduino boards (official or compatible) may and may not yield the best result.<\/p>\n<p>Using our Mini Ultra 8 MHz (we are assembling an army of them right now using our <a title=\"Reflow Oven Controller Shield (Arduino Compatible)\" href=\"http:\/\/www.rocketscream.com\/shop\/reflow-oven-controller-shield-arduino-compatible\" target=\"_blank\" rel=\"noopener\">reflow oven controller shield<\/a>) and revision 1.0 of the library yields the following current consumption measurement result. The board is being powered by a Li-Ion 3.7 V battery running at 8 MHz with 3.3 V. The on board regulator of the Mini Ultra 8 MHz consumes about <a title=\"Current Measurement\" href=\"http:\/\/www.rocketscream.com\/blog\/2011\/04\/26\/mini-ultra-8-mhz-current-consumption-part-2\/\" target=\"_blank\" rel=\"noopener\">1.6 \u00b5A of quiescent current<\/a>.<\/p>\n<table>\n<thead>\n<tr>\n<th scope=\"col\">Mode<\/th>\n<th scope=\"col\">WDT<\/th>\n<th scope=\"col\">ADC<\/th>\n<th scope=\"col\">BOD<\/th>\n<th scope=\"col\">T2<\/th>\n<th scope=\"col\">T1<\/th>\n<th scope=\"col\">T0<\/th>\n<th scope=\"col\">SPI<\/th>\n<th scope=\"col\">USART0<\/th>\n<th scope=\"col\">TWI<\/th>\n<th scope=\"col\">Current<\/th>\n<\/tr>\n<\/thead>\n<tfoot>\n<tr>\n<td colspan=\"11\">\n<p style=\"text-align: left;\"><span style=\"color: #008000;\">Timer 1 &amp; Timer 2 not in use<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"color: #3366ff;\">Timer 2 not clock asynchronously from an external 32.768 kHz crystal \u00a0(lower consumption can be further achieved)<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tfoot>\n<tbody>\n<tr>\n<td>Idle<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>3648.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Idle<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>3643.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Idle<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td><span style=\"color: #008000;\">*<\/span><\/td>\n<\/tr>\n<tr>\n<td>Idle<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td><span style=\"color: #008000;\">*<\/span><\/td>\n<\/tr>\n<tr>\n<td>Idle<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>3618.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Idle<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>927.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Idle<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>832.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Idle<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>789.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Idle<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>687.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>ADC Noise Reduction<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>651.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>ADC Noise Reduction<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>646.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>ADC Noise Reduction<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td><span style=\"color: #008000;\">*<\/span><\/td>\n<\/tr>\n<tr>\n<td>ADC Noise Reduction<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>Off<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>584.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Power Down<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>1.7 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Power Down<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>18.6 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Power Down<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>110.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Power Down<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>113.9 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Power Save<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>1.7 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Power Save<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td><span style=\"color: #3366ff;\">416.0 \u00b5A<\/span><\/td>\n<\/tr>\n<tr>\n<td>Power Save<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td><span style=\"color: #3366ff;\">435.0 \u00b5A<\/span><\/td>\n<\/tr>\n<tr>\n<td>Power Save<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td><span style=\"color: #3366ff;\">527.0 \u00b5A<\/span><\/td>\n<\/tr>\n<tr>\n<td>Power Save<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td><span style=\"color: #3366ff;\">531.0 \u00b5A<\/span><\/td>\n<\/tr>\n<tr>\n<td>Standby<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>201.7 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Standby<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>218.5 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Standby<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>309.9 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Standby<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>313.9 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Extended Standby<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>202.2 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Extended Standby<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>416.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Extended Standby<\/td>\n<td>Off<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>436.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Extended Standby<\/td>\n<td>Off<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>527.0 \u00b5A<\/td>\n<\/tr>\n<tr>\n<td>Extended Standby<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>On<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>&#8211;<\/td>\n<td>531.0 \u00b5A<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In idle mode, the IO clock is available for general IO modules usage. Therefore, you need to pull any unused pins low in output mode to reduce the overall current consumption.<\/p>\n<p>In power save mode, Timer 2 can be clocked asynchronously from an external 32.768 kHz crystal to achieve very low current consumption. However, this will require the removal of the external 8 MHz resonator (or crystal in other board variants) to facilitate the low frequency crystal. This will require the ATmega328 to run on its internal 8 MHz on chip RC oscillator in normal operation. But, this will affect time critical modules such as millis, PWM and higher baud rate USART communication as the accuracy of the on chip RC oscillator is limited and is affected pretty much by the operating voltage and temperature. We have some prototype work on running a 32.768 kHz crystal asynchronously which can be seen <a title=\"Ultra\" href=\"http:\/\/www.rocketscream.com\/blog\/2010\/08\/13\/hello-world\/\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>Here&#8217;s a sample code snapshot on how to use the library.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &quot;LowPower.h&quot;\r\n\r\nvoid setup()\r\n{\r\n    \/\/ No setup is required for this library\r\n}\r\n\r\nvoid loop()\r\n{\r\n    \/\/ Sleep for 8 s with ADC module and BOD module off\r\n    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);\r\n    \/\/ Do something here\r\n    \/\/ Example: read sensor, log data, transmit data\r\n}\r\n<\/pre>\n<p>The library is available on our <a title=\"GitHub\" href=\"https:\/\/github.com\/rocketscream\/Low-Power\" target=\"_blank\" rel=\"noopener\">GitHub\u00a0repository<\/a>. Comments and opinions are greatly appreciated! We hope you find this library useful for your application. Take care and happy tinkering.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have just release the 1st revision of our low power library for Arduino.<\/p>\n","protected":false},"author":1,"featured_media":752,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[57,4],"tags":[151,27,7],"class_list":["post-651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-libraries","category-news","tag-arduino","tag-library","tag-low-power"],"_links":{"self":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/comments?post=651"}],"version-history":[{"count":113,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/posts\/651\/revisions"}],"predecessor-version":[{"id":7154,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/posts\/651\/revisions\/7154"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/media\/752"}],"wp:attachment":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/media?parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/categories?post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/tags?post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}