{"id":619,"date":"2014-10-16T11:00:16","date_gmt":"2014-10-16T09:00:16","guid":{"rendered":"https:\/\/www.yelloworb.com\/orbblog\/?p=619"},"modified":"2014-10-16T11:18:42","modified_gmt":"2014-10-16T09:18:42","slug":"writing-ram-efficient-arduino-code","status":"publish","type":"post","link":"https:\/\/www.yelloworb.com\/orbblog\/writing-ram-efficient-arduino-code\/","title":{"rendered":"Writing RAM efficient Arduino code"},"content":{"rendered":"<p>Developing the software for the wind stations I often run into problems and random restarts of the Arduino. Soon I realised it was due to that I ran out of RAM, 2k does not last that long, specifically when every debug string you put in consumes RAM. I found out about <a href=\"http:\/\/www.nongnu.org\/avr-libc\/user-manual\/group__avr__pgmspace.html\" target=\"_blank\">PROGMEM<\/a> but I did not find so much more information on how to use it so instead I focused on getting things to work. But now when I re-write the whole communication code I plan to do it right!<\/p>\n<p>So have looked a bit more into it and found the great article <a href=\"http:\/\/gammon.com.au\/progmem\" title=\"Putting constant data into program memory (PROGMEM)\" target=\"_blank\">Putting constant data into program memory (PROGMEM)<\/a> by <a href=\"http:\/\/www.gammon.com.au\" title=\"Nick Gammons web page\" target=\"_blank\">Nick Gammon<\/a>. It explains the whole problem as well as give many practical tips on how to write RAM efficient Arduino code.<\/p>\n<p>And another recommendation is to use the latest Arduino IDE, the <a href=\"http:\/\/arduino.cc\/en\/Main\/Software#toc3\" target=\"_blank\">1.5.8 Beta<\/a>. It uses much newer compiler etc as described in <a href=\"http:\/\/forum.arduino.cc\/index.php?PHPSESSID=nvoa1qig8vkqmu3egqha5uo176&#038;topic=272313.msg1919623#msg1919623\" target=\"_blank\">this post<\/a>. Also when compiling it generates not only information about how much of the storage space you sketch uses but also how much RAM is used at start. Like this:<br \/>\n<code class=\"\" data-line=\"\">Sketch uses 9,412 bytes (30%) of program storage space. Maximum is 30,720 bytes.<br \/>\nGlobal variables use 1,126 bytes (54%) of dynamic memory, leaving 922 bytes for local variables. Maximum is 2,048 bytes.<\/code><br \/>\nRemember that this only indicates the situation at start so do you have functions that use large arrays that will not be shown there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Developing the software for the wind stations I often run into problems and random restarts of the Arduino. Soon I realised it was due to that I ran out of RAM, 2k does not last that long, specifically when every debug string you put in consumes RAM. I found out about PROGMEM but I did [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[67,28],"tags":[],"class_list":["post-619","post","type-post","status-publish","format-standard","hentry","category-arduino","category-software-development"],"_links":{"self":[{"href":"https:\/\/www.yelloworb.com\/orbblog\/wp-json\/wp\/v2\/posts\/619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yelloworb.com\/orbblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yelloworb.com\/orbblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yelloworb.com\/orbblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yelloworb.com\/orbblog\/wp-json\/wp\/v2\/comments?post=619"}],"version-history":[{"count":2,"href":"https:\/\/www.yelloworb.com\/orbblog\/wp-json\/wp\/v2\/posts\/619\/revisions"}],"predecessor-version":[{"id":621,"href":"https:\/\/www.yelloworb.com\/orbblog\/wp-json\/wp\/v2\/posts\/619\/revisions\/621"}],"wp:attachment":[{"href":"https:\/\/www.yelloworb.com\/orbblog\/wp-json\/wp\/v2\/media?parent=619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yelloworb.com\/orbblog\/wp-json\/wp\/v2\/categories?post=619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yelloworb.com\/orbblog\/wp-json\/wp\/v2\/tags?post=619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}