{"id":613,"date":"2013-08-29T18:05:54","date_gmt":"2013-08-29T16:05:54","guid":{"rendered":"http:\/\/paluweb.nl\/?p=613"},"modified":"2013-08-29T18:12:19","modified_gmt":"2013-08-29T16:12:19","slug":"work-in-progress-programming-the-canopy","status":"publish","type":"post","link":"https:\/\/www.paluweb.nl\/?p=613","title":{"rendered":"Work in progress: Programming the Canopy"},"content":{"rendered":"<p><BR><\/p>\n<blockquote><p>As I get closer to actually filling the paludarium with water, plants and eventually animals, I need to put a lot of focus on the electronics. The lighting armature on top, or as I like to call it, the Canopy is fully electronic. Without electronics the lights won&#8217;t even go on&#8230; High time to put some work into the Canopy to upgrade this piece of hardware to version 2.0.<\/p><\/blockquote>\n<p><BR><br \/>\n<strong>First things first: Getting the code compiling again<\/strong><\/p>\n<p>Inside the Canopy I have 12 Atmel AVR controllers (ATtiny2013&#8217;s). These tiny controllers have been programmed in three flavors: LED, HALOGEN and FAN units. You guessed it, each type of controller has its own code. Luckily I programmed a single code, and when compiling this code I can tell the code which type it is supposed to compile. These little AVR controllers are programmed in C:<\/p>\n<p><HR><P STYLE=\"font-size: 7pt;\">#include &#8220;main.h&#8221;<br \/>\n#include &#8220;serial.h&#8221;<br \/>\n#include &#8220;timer.h&#8221;<!--more--><br \/>\n#include &#8220;pwm.h&#8221;<br \/>\n#include &#8220;eeprom.h&#8221;<BR><br \/>\nint main (void)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;for (;;)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/* Set initial levels of the hardware outputs *\/<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outp(0xFF, PORTB); \/* All input lines pullup, outputs push TTL to high *\/<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outp(0xe3, PORTD); \/* All input lines pullup, outputs push TTL to high except DigExp *\/<BR><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/* Init of hardware: I\/O directions *\/<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outp(0x1C, DDRB); \/* PB0-7 are all inputs except PB2,3,4 *\/<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outp(0x3e, DDRD); \/* PD0-7 are all inputs except PD5=OC0B and PD1=TX, also PD2-PD4 *\/<BR><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/* Init the modules *\/<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitEEPROM();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitSerial();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitPWM();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitTimer();\t\/* incorporates sei(); call to globally enable interrupts *\/<BR><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (1)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n}<HR><\/p>\n<p><em>Code snippet. This is the main() function where all stuff gets initialized<\/em><\/p>\n<p>No I will not bore you with all of the code here \ud83d\ude42<\/p>\n<p>This old code that I have for these controllers has proven to be pretty stable. Yet I need to change some minor things, and add or change some features. After a short while I got the compiling environment (an antique version 6 of the <a href=\"https:\/\/www.imagecraft.com\/devtools_AVR.html\" title=\"Imagecraft AVR compiler\" target=\"_blank\">ImageCraft AVR compiler<\/a>) up and running again. I could now compile the code again. At my first attempt, I compiled the most complex code, the LED version. Compilation was a success, device was 98% percent full&#8230; I&#8217;d better not find NEW features cause they&#8217;d never fit. If you think these controllers only have 2KB of flash (yes 2 KILObytes, 2048 bytes and not Megabytes or Gigabytes), 98% is pretty darn full. Still, it works so I&#8217;m not complaining.<br \/>\n<BR><br \/>\n<strong>Programming the ATtiny2313&#8217;s<\/strong><\/p>\n<p>As nice as compiling may sound, the compiled code had to be actually programmed into the chips. For that, you need a programmer. Time to dive into my box of old projects, and there it was: The glorious AVR programmer for ATmega32 and ATtiny2313 chips:<\/p>\n<div id=\"attachment_615\" style=\"width: 510px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/paluweb.nl\/wp-content\/uploads\/2013\/08\/IMG_3453.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-615\" src=\"http:\/\/paluweb.nl\/wp-content\/uploads\/2013\/08\/IMG_3453.jpg\" alt=\"My good old programmer for Atmel Mega32 and Attiny2313 chips\" width=\"500\" height=\"334\" class=\"size-full wp-image-615\" srcset=\"https:\/\/www.paluweb.nl\/wp-content\/uploads\/2013\/08\/IMG_3453.jpg 500w, https:\/\/www.paluweb.nl\/wp-content\/uploads\/2013\/08\/IMG_3453-300x200.jpg 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><p id=\"caption-attachment-615\" class=\"wp-caption-text\">My good old programmer for Atmel Mega32 and Attiny2313 chips<\/p><\/div>\n<p>Yes it is no high-tech. Ok it is somewhat oldish. Ok ok, it is totally oldskool. Is that a USB port? Yes, but I only use USB to power the thing. The large connector in front is actually a PC parallel port connection. I had to search in order to find a PC that still has a parallel port. Why not upgrade to a USB programmer? Uhmmm basically because this one still works \ud83d\ude1b<\/p>\n<p>I had an old version of Claudio Lanconelli&#8217;s <a href=\"http:\/\/www.lancos.com\/prog.html\" title=\"Claudio's PonyProg software\" target=\"_blank\">PonyProg<\/a> that I used to shoot the chips. After some testing I managed to read, write and erase the ATtiny2313 chips. <\/p>\n<p><strong>Mission accomplished!<\/strong> I now can alter the code, reprogram the 12 chips in the Canopy and start playing around. On to the next-of-many things to get going.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I get closer to actually filling the paludarium with water, plants and eventually animals, I need to put a lot of focus on the electronics. The lighting armature on top, or as I like to call it, the Canopy &hellip; <a href=\"https:\/\/www.paluweb.nl\/?p=613\">Read more <span class=\"meta-nav\">&raquo;<\/span><\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[17,8,3],"tags":[141,143,146,144,142,147,148,149,145],"class_list":["post-613","post","type-post","status-publish","format-standard","hentry","category-automation","category-lighting","category-paludarium","tag-atmel","tag-atmel-avr","tag-atmel-programmer","tag-attiny2313","tag-avr","tag-avr-programmer","tag-parallel-port","tag-parallel-port-programmer","tag-ponyprog"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.paluweb.nl\/index.php?rest_route=\/wp\/v2\/posts\/613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.paluweb.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.paluweb.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.paluweb.nl\/index.php?rest_route=\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.paluweb.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=613"}],"version-history":[{"count":30,"href":"https:\/\/www.paluweb.nl\/index.php?rest_route=\/wp\/v2\/posts\/613\/revisions"}],"predecessor-version":[{"id":644,"href":"https:\/\/www.paluweb.nl\/index.php?rest_route=\/wp\/v2\/posts\/613\/revisions\/644"}],"wp:attachment":[{"href":"https:\/\/www.paluweb.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.paluweb.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.paluweb.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}