{"id":64,"date":"2017-08-09T10:04:48","date_gmt":"2017-08-09T10:04:48","guid":{"rendered":"http:\/\/www.albertosarullo.com\/blog\/?p=64"},"modified":"2017-08-10T21:48:28","modified_gmt":"2017-08-10T21:48:28","slug":"pieface-game-challenge-lego-arduino-esp8266","status":"publish","type":"post","link":"https:\/\/www.albertosarullo.com\/blog\/pieface-game-challenge-lego-arduino-esp8266","title":{"rendered":"Pieface game: lego + arduino \/ esp8266"},"content":{"rendered":"<p>I am fascinated by videos of happy children that plays with pieface game. I have never had this, so i decided to build myself an adult-sized, low-budget version, based on ESP8266 board.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/Ic-ZiFXPDL0\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<p><em><strong>TODO: VIDEO OF MATCH<\/strong><\/em><\/p>\n<h2>Rule of the game<\/h2>\n<p>Pieface is a 2 player game. Each player push a button repeatedly. The challenge push the button faster than the opponent. When the winner win, the looser received a pie in face.<\/p>\n<p>From a mechanical perspective the pieface game is basically an\u00c2\u00a0<em>orientable<\/em> catapult; the trigger is the difference number of button pressures.<\/p>\n<h2>Parts of System<\/h2>\n<ul>\n<li>2 players<\/li>\n<li>2 buttons<\/li>\n<li>2 rc servos:\n<ul>\n<li>1 direction rc servo<\/li>\n<li>1 unlock mechanism rc servo<\/li>\n<\/ul>\n<\/li>\n<li>1 microcontroller<\/li>\n<li>Springs<\/li>\n<li>Lego technic beam<\/li>\n<li>Spoon<\/li>\n<li>Cream<\/li>\n<li>Battery<\/li>\n<\/ul>\n<h2>Microcontroller<\/h2>\n<p>I choose a NodeMCU board (and Esp8266 powered board) because is cheap, Arduino compatibile and I already have one in my house. In this project I don&#8217;t use wifi, but with a wifi-ready board any upgrade in the wifi direction (i.e. tablet or website) is feasible.<\/p>\n<h2>Wiring<\/h2>\n<p>The wiring of the electronic part is minimal. The two buttons are connected on D4 and D5\u00c2\u00a0(pull-up mode), the command pin of the two rc servos are connected D0 and D1.<\/p>\n<h2>\u00c2\u00a0<a href=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/pieface_esp8266_v2_bb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-65 size-large\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/pieface_esp8266_v2_bb-963x1024.png\" alt=\"Esp8266 pieface servo button\" width=\"640\" height=\"681\" srcset=\"https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/pieface_esp8266_v2_bb-963x1024.png 963w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/pieface_esp8266_v2_bb-282x300.png 282w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/pieface_esp8266_v2_bb-768x817.png 768w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/pieface_esp8266_v2_bb.png 1035w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/h2>\n<p>&nbsp;<\/p>\n<h2>Software \/ Esp8266 code<\/h2>\n<p>The program on the Esp8266 count the delta between button press. This delta guide the direction rc servo (that orient the spoon on the face of one player or another). When the delta reach a limit, the second rc servo unlock the spoon\u00c2\u00a0pouring the cream on the loser.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/ only loop method\r\n\/\/ full code on https:\/\/github.com\/albertosarullo\/pieface-game-diy-arduino-esp8266\r\nvoid loop() \r\n{ \r\n  int rightButtonValue = digitalRead(rightButtonPin);\r\n  int leftButtonValue = digitalRead(leftButtonPin);\r\n    \r\n  if (rightButtonValue &amp;&amp; !oldRightButtonValue) {\r\n    delta = delta + 1;\r\n  }\r\n  if (leftButtonValue &amp;&amp; !oldLeftButtonValue) {\r\n    delta = delta - 1;\r\n  }\r\n\r\n  digitalWrite(LED_BUILTIN, !(leftButtonValue || rightButtonValue));\r\n\r\n  \/\/ min: 55\u00c2\u00b0, max: 125\u00c2\u00b0\r\n  servoPosition.write(90 + delta * 1.7);\r\n  \r\n  if (delta &gt; limit || delta &lt; -limit) {\r\n     launch();\r\n  } else {\r\n     block();\r\n  }\r\n\r\n  oldRightButtonValue = rightButtonValue;\r\n  oldLeftButtonValue  = leftButtonValue;\r\n  \r\n  delay(10);\r\n}\r\n<\/pre>\n<p>For the complete source code visit <a href=\"https:\/\/github.com\/albertosarullo\/pieface-game-diy-arduino-esp8266\">https:\/\/github.com\/albertosarullo\/pieface-game-diy-arduino-esp8266<\/a><\/p>\n<h2>Physical Implementation<\/h2>\n<p>As is often the case in these projects, i choose an iterative approach: design, develop, test.<\/p>\n<h3>Iteration #1 &#8211; Exploration Sketch<\/h3>\n<p>At the beginning i made some sketch on paper to explore different hypothesis\/solution and have an vague idea of the mechanical parts.<\/p>\n<p>I made simple cardboard prototypes not in scale, simply to explore feasibility.<\/p>\n<p>A crucial point is that \u00c2\u00a0the structure is subject to a high force on launch time.<\/p>\n<h3>Iteration #2 &#8211; First Prototype<\/h3>\n<p>In this phase I use a PVC sheet for build the structure, but after the some trial I quickly change my plan, because basically I seemed to waste time cutting non reusable piece of plastic.<\/p>\n<p>So I switch to Lego brick: they are more robust, modular, and guarantee rapid prototype speed.<\/p>\n<p>For the structure, I follow the Hasbro version: a horizontal pivot (spring powered), on which is mounted a vertical pivot (orientation rc servo).<\/p>\n<p><a href=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_rev_0-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-81 \" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_rev_0-1.png\" alt=\"\" width=\"579\" height=\"407\" srcset=\"https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_rev_0-1.png 434w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_rev_0-1-300x211.png 300w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_0.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-66\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_0-1024x768.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_0-1024x768.png 1024w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_0-300x225.png 300w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_0-768x576.png 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-67\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_1-1024x768.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_1-1024x768.png 1024w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_1-300x225.png 300w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_1-768x576.png 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<h3>Iteration #3 &#8211; Second Prototype<\/h3>\n<p>After some trial, i think that the structure need to be changed, because at launch\u00c2\u00a0time, all the springs force is discharged to the servomotor pivot.<\/p>\n<p>So I entirely destroy and rebuild the structure with this features:<\/p>\n<ul>\n<li>The first pivot (orientation rc servo) is horizontal and rotate the spoon on left and right.<\/li>\n<li>The second pivot (spring powered) is horizontal and launch the spoon<\/li>\n<li>The spring can be regulated<\/li>\n<li>The second servo control the launch mechanism<\/li>\n<\/ul>\n<p><a href=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_rev_1-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-82 size-full\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_rev_1-1.png\" alt=\"\" width=\"486\" height=\"308\" srcset=\"https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_rev_1-1.png 486w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_rev_1-1-300x190.png 300w\" sizes=\"auto, (max-width: 486px) 100vw, 486px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-68 size-large\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_2-e1502359562997-1024x672.png\" alt=\"\" width=\"525\" height=\"345\" srcset=\"https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_2-e1502359562997-1024x672.png 1024w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_2-e1502359562997-300x197.png 300w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_2-e1502359562997-768x504.png 768w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/a><\/p>\n<h3>Iteration #4 &#8211; Extras<\/h3>\n<p>Now the system from functional perspective work, but need some extras:<\/p>\n<ul>\n<li>Mount all system on a\u00c2\u00a0polystyrene plan, to make solid and stable<\/li>\n<li>Make some in house test for\n<ul>\n<li>Identifying the trajectory of cream and adjust some variable in code<\/li>\n<li>Establish a reasonable delta between the button press (too small makes the matches too short, too long is not supportable for the forearms of the players)<\/li>\n<\/ul>\n<\/li>\n<li>Create a support for the player chin,\u00c2\u00a0so that the whipped cream hits the nose of the players<\/li>\n<li>User test at my birthday<\/li>\n<\/ul>\n<h2><a href=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-79\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_4-1024x768.png\" alt=\"\" width=\"525\" height=\"394\" srcset=\"https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_4-1024x768.png 1024w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_4-300x225.png 300w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_4-768x576.png 768w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/a> <a href=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-80\" src=\"http:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_5-1024x619.png\" alt=\"\" width=\"525\" height=\"317\" srcset=\"https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_5-1024x619.png 1024w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_5-300x181.png 300w, https:\/\/www.albertosarullo.com\/blog\/wp-content\/uploads\/2017\/08\/lego_pieface_5-768x464.png 768w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/a><\/h2>\n<h2>Future evolution<\/h2>\n<p>My personal challenge is make a mechanical only version, without any electrical parts (no battery dependency, waterproof).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am fascinated by videos of happy children that plays with pieface game. I have never had this, so i decided to build myself an adult-sized, low-budget version, based on ESP8266 board. &nbsp; TODO: VIDEO OF MATCH Rule of the game Pieface is a 2 player game. Each player push a button repeatedly. The challenge &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.albertosarullo.com\/blog\/pieface-game-challenge-lego-arduino-esp8266\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Pieface game: lego + arduino \/ esp8266&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,66,54],"tags":[63,67,57,39],"class_list":["post-64","post","type-post","status-publish","format-standard","hentry","category-arduino","category-diy","category-maker","tag-arduino","tag-diy","tag-esp8266","tag-lego"],"_links":{"self":[{"href":"https:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/posts\/64","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/comments?post=64"}],"version-history":[{"count":0,"href":"https:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}