{"id":407,"date":"2010-10-28T20:55:56","date_gmt":"2010-10-29T01:55:56","guid":{"rendered":"http:\/\/nootropicdesign.com\/projectlab\/?p=407"},"modified":"2018-11-02T09:35:16","modified_gmt":"2018-11-02T14:35:16","slug":"a-halloween-costume-with-source-code","status":"publish","type":"post","link":"https:\/\/nootropicdesign.com\/projectlab\/2010\/10\/28\/a-halloween-costume-with-source-code\/","title":{"rendered":"A Halloween Costume with Source Code"},"content":{"rendered":"<p><strong><em>Difficulty Level = 5<\/em><\/strong>  <a href=\"\/projectlab\/difficulty-levels\/\">[What&#8217;s this?]<\/a><\/p>\n<p>Like many parents, we make hand-made costumes for our kids instead of buying cheaply-made (and expensive) costumes based on licensed characters.  This year, my youngest son wanted to be a robot.  My wife did a great job making the costume, but I just had to add some cool electronics to take it to the next level.  <\/p>\n<p><iframe loading=\"lazy\" width=\"640\" height=\"505\" src=\"https:\/\/www.youtube.com\/embed\/kLOo2hJF7G8\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p>The electronics are nothing fancy &#8212; a simple <a href=\"http:\/\/www.atmel.com:80\/dyn\/products\/product_card.asp?part_id=3175\">Atmel ATtiny13 microcontroller<\/a> that interfaces with two 74HC595 shift registers to light up LEDs randomly.  The technical details are below, but in the process of building this, I was really struck by how electronics and computing are being embedded into everything.  This week I was making a TODO list and one of the items was &#8220;finish source code for robot costume&#8221;.<\/p>\n<p><em>OMG, now the costumes we make have source code.<\/em><\/p>\n<p>This is a great example of how technology is becoming increasingly ubiquitous.  Ten years ago, this would have been far beyond my reach.  But in 2010 I can build this easily.  The microcontroller cost $1.04, the shift register chips are $0.25 each, the resistors are a penny each, and the LEDs probably average $0.20 each.  Definitely less than $5 for everything.<\/p>\n<h3>Technical Details<\/h3>\n<p>Here&#8217;s the schematic:<br \/>\n<div id=\"attachment_404\" style=\"width: 650px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2010\/10\/robotCostumeSchematic.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-404\" src=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2010\/10\/robotCostumeSchematic_sm.png\" alt=\"\" title=\"robotCostumeSchematic_sm\" width=\"640\" height=\"422\" class=\"size-full wp-image-404\" \/><\/a><p id=\"caption-attachment-404\" class=\"wp-caption-text\">Schematic for robot costume circuit<\/p><\/div><\/p>\n<p\/>\n<p\/>\nHere is a closeup of the circuit board.  There is a piece of clear acrylic protecting it.  I ran out of 16 pin IC sockets, so the shift registers are in 20 pin sockets.<br \/>\n<div id=\"attachment_406\" style=\"width: 650px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2010\/10\/robotCostumeCircuit.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-406\" src=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2010\/10\/robotCostumeCircuit-640x480.jpg\" alt=\"\" title=\"robotCostumeCircuit-640x480\" width=\"640\" height=\"480\" class=\"size-full wp-image-406\" srcset=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2010\/10\/robotCostumeCircuit-640x480.jpg 640w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2010\/10\/robotCostumeCircuit-640x480-300x225.jpg 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><p id=\"caption-attachment-406\" class=\"wp-caption-text\">Circuit on front of costume.  ATtiny13 microcontroller and two 74HC595 shift registers.<\/p><\/div><\/p>\n<p\/>\n<p\/>\nAnd finally, the simple source code that runs on the chip.  I use <a href=\"http:\/\/www.obdev.at\/products\/crosspack\/index.html\">CrossPack<\/a> for AVR development.  I use avrdude and a <a href=\"http:\/\/dangerousprototypes.com\/bus-pirate-manual\/\">Bus Pirate<\/a> to upload the code onto the ATtiny13 chip.<\/p>\n<pre class=\"codeblockscroll\">\r\n\/*\r\n * ATtiny13 driving two 74HC595 shift registers\r\n *\r\n * Randomly turns on\/off output pins of the shift\r\n * register ICs.\r\n * A random number of outputs are set high, then\r\n * a random time delay occurs.  Then the cycle\r\n *  repeats.\r\n *\r\n *\/\r\n\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;avr\/io.h&gt;\r\n#include &lt;util\/delay.h&gt;\r\n\r\n#define DATA PB0\r\n#define CLOCK PB1\r\n#define LATCH PB2\r\n\r\nint main(void) {\r\n  int d;\r\n  char n;\r\n  char i;\r\n\r\n  \/\/ set DATA, LATCH and CLOCK pins to OUTPUT\r\n  DDRB |= (1 << DATA);\r\n  DDRB |= (1 << LATCH);\r\n  DDRB |= (1 << CLOCK);\r\n  PORTB = 0;\r\n\r\n  for(;;) {\r\n    \/\/ choose number of LEDs to light up.\r\n    \/\/ n will be between 4 and 16\r\n    n = 4 + (random() % 13);\r\n\r\n    for(i=0;i&lt;16;i++) {\r\n      \/\/ for each LED, probability of it being lit\r\n      \/\/ is n\/16\r\n      if ((random() % 16) <= n) {\r\n\tPORTB |= (1 << DATA);  \/\/ set DATA pin high\r\n      } else {\r\n\tPORTB &#038;= ~(1 << DATA); \/\/ set DATA pin low\r\n      }\r\n\r\n      \/\/ toggle shift register clock pin\r\n      PORTB |= (1 << CLOCK);\r\n      _delay_ms(2);\r\n      PORTB &#038;= ~(1 << CLOCK);\r\n    }\r\n\r\n    \/\/ once we've shifted out all 16 values, toggle\r\n    \/\/ the latch pin.\r\n    PORTB |= (1 << LATCH);\r\n    _delay_ms(2);\r\n    PORTB &#038;= ~(1 << LATCH);\r\n\r\n    \/\/ delay random amount of time between\r\n    \/\/ 100ms and 500ms\r\n    d = 100 + (random() % 400);\r\n    for(i=0;i&lt;d;i++) {\r\n      \/\/ _delay_ms function must be called with a\r\n      \/\/ constant value, not a variable!\r\n      _delay_ms(1);\r\n    }\r\n\r\n  }\r\n  return 0; \/\/ not reached\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Difficulty Level = 5 [What&#8217;s this?] Like many parents, we make hand-made costumes for our kids instead of buying cheaply-made (and expensive) costumes based on licensed characters. This year, my youngest son wanted to be a robot. My wife did a great job making the costume, but I just had to add some cool electronics [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[24,6],"tags":[],"class_list":["post-407","post","type-post","status-publish","format-standard","hentry","category-avr","category-robotics"],"_links":{"self":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/comments?post=407"}],"version-history":[{"count":19,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/407\/revisions"}],"predecessor-version":[{"id":1985,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/407\/revisions\/1985"}],"wp:attachment":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/media?parent=407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/categories?post=407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/tags?post=407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}