{"id":198,"date":"2013-05-29T17:23:04","date_gmt":"2013-05-29T17:23:04","guid":{"rendered":"http:\/\/cto.dyalog.com\/?p=198"},"modified":"2014-07-10T14:06:51","modified_gmt":"2014-07-10T14:06:51","slug":"fun-with-apl-on-the-raspberry-pi-without-a-robot","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2013\/05\/fun-with-apl-on-the-raspberry-pi-without-a-robot\/","title":{"rendered":"Fun with APL on the Raspberry Pi (without a Robot)"},"content":{"rendered":"<p>The official release of Dyalog APL for the Raspberry Pi now looks as if it going to happen on Friday! In preparation for this, we have been working on some examples to demonstrate things you can do on your Pi <em><strong>without<\/strong><\/em> a set of wheels attached &#8211; like making lights blink!<\/p>\n<iframe loading=\"lazy\"  id=\"_ytid_71881\"  width=\"584\" height=\"329\"  data-origwidth=\"584\" data-origheight=\"329\"  src=\"https:\/\/www.youtube.com\/embed\/ztLIQgszE1s?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"autoplay; encrypted-media\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe>\n<p>&nbsp;<\/p>\n<h2>Quick2Wire Interface Boards<\/h2>\n<p>It is possible to connect input and output devices directly to your Pi. However, we have elected to do our experiments using the interface boards from Quick2Wire &#8211; to be precise the &#8220;<a title=\"Port Expander Combo in the Quick2wire store\" href=\"http:\/\/store.quick2wire.com\/combo-kit-port-expander-11.html\" target=\"_blank\">Port Expander Combo<\/a>&#8220;, which protects you from damaging your Pi by making wiring\/soldering mistakes, and makes a number of interfaces more easily accessible. The photo below shows the\u00a0<a title=\"Quick2wire: Make your own bar LED board\" href=\"http:\/\/quick2wire.com\/2013\/01\/make-your-own-bar-led-board\/\" target=\"_blank\">LED bar<\/a>\u00a0used in the above video, attached to the combo:<\/p>\n<div id=\"attachment_199\" style=\"width: 490px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/pi-with-quick2wire-boards.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-199\" class=\" wp-image-199 \" title=\"Raspberry Pi with Quick2wire expansion and bar LED boards\" alt=\"pi-with-quick2wire-boards\" src=\"http:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/pi-with-quick2wire-boards.jpg\" width=\"480\" height=\"302\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/pi-with-quick2wire-boards.jpg 750w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/pi-with-quick2wire-boards-300x189.jpg 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2013\/05\/pi-with-quick2wire-boards-475x300.jpg 475w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><p id=\"caption-attachment-199\" class=\"wp-caption-text\">Raspberry Pi with Quick2wire expansion and bar LED boards<\/p><\/div>\n<h2>The LED Pattern Generation Language (LEDPGL)<\/h2>\n<p>The Bar LED has 8 controllable LED&#8217;s. APL is actually a neat language for generating boolean patterns, for example:<\/p>\n<pre><code class=\"language-apl\">      3\u21911    \u235d \"3 take 1\"\r\n1 0 0\r\n      8\u23743\u21911 \u235d \"8 reshape 3 take 1\"\r\n1 0 0 1 0 0 1 0\r\n      \u00af1\u233d8\u23743\u21911 \u235d \"negative 1 rotate\" of the above\r\n0 1 0 0 1 0 0 1 \r\n      \u236a\u00af1 \u00af2 \u00af3\u233d\u00a8\u22828\u23743\u21911 \u235d \"columnise the neg 1, 2 and 3 rotations...\"\r\n 0 1 0 0 1 0 0 1\r\n 1 0 1 0 0 1 0 0\r\n 0 1 0 1 0 0 1 0<\/code><\/pre>\n<p>Once you get into the habit of working with APL, you quickly learn to create small, functional &#8220;Embedded Domain Specific Notations&#8221; to work with your data. The <a title=\"LEDPGL Namespace (GitHub)\" href=\"https:\/\/github.com\/APLPi\/libi2c-com\/blob\/master\/examples\/LEDPGL.dyalog\" target=\"_blank\">LEDPGL namespace<\/a> contains a small &#8220;pattern generation language&#8221;, which allows expressions like:<\/p>\n<pre><code class=\"language-apl\">       LEDPGL.(0 4 shift 4 \/ 1 0)\r\n 1 1 1 1 0 0 0 0   0 0 0 0 1 1 1 1\r\n       LEDPGL.(show 0 4 shift 4 \/ 1 0)\r\n \u2395\u2395\u2395\u2395....\r\n ....\u2395\u2395\u2395\u2395<\/code><\/pre>\n<p>Finally, the namespace contains a Demo function which takes a time interval in seconds as its argument (or 0 to use the &#8220;show&#8221; method to display the patterns in the session log). This is what was used to create the video at the top of this post:<\/p>\n<pre><code class=\"language-apl\">       LEDPGL.Demo 0.1\r\n 0 4 shift 4\/1 0 \u235d Left Right\r\n cycle 4 4\/1 0   \u235d Barber pole\r\n 4 cycle 8 repeat head 4 \u235d Ripple\r\n binary \u2373256             \u235d Counter\r\n mirror cycle head 4     \u235d Halves-in\r\n 6 repeat 3 repeat x\u2228 reverse x\u2190mirror cycle head 4 \u235d Half-flip\r\n 12 repeat \u00af1\u2193x,1\u2193reverse x\u2190mirror cycle head 4     \u235d Out-In-Out<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>LED Morse Code<\/h2>\n<p>The <a title=\"Quick2wire store: Interface Board\" href=\"http:\/\/store.quick2wire.com\/raspberrypi-interface-board.html\" target=\"_blank\">Quick2wire expansion board<\/a>\u00a0(largest, closest board to the Pi in the first picture) has a single LED mounted, which can be controlled via GPIO. Our first example, which is included in the &#8220;Getting Started&#8221; guide which is included with Dyalog APL for the Pi &#8211; and\u00a0<a title=\"Dyalog APL GPIO samples on GitHub\" href=\"https:\/\/github.com\/APLPi\/GPIO\" target=\"_blank\">available on GitHub<\/a>\u00a0&#8211; is an encoder for Morse Code. For example, the video below was generated by passing a character vector containing the only morse message that most people would be able to read:<\/p>\n<pre><code class=\"language-apl\">GPIO.Morse 'SOS'<\/code><\/pre>\n<iframe loading=\"lazy\"  id=\"_ytid_89645\"  width=\"584\" height=\"329\"  data-origwidth=\"584\" data-origheight=\"329\"  src=\"https:\/\/www.youtube.com\/embed\/xKBS0gtSDQ8?enablejsapi=1&autoplay=0&cc_load_policy=0&iv_load_policy=1&loop=0&modestbranding=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"autoplay; encrypted-media\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe>\n","protected":false},"excerpt":{"rendered":"<p>The official release of Dyalog APL for the Raspberry Pi now looks as if it going to happen on Friday! In preparation for this, we have been working on some examples to demonstrate things you can do on your Pi &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2013\/05\/fun-with-apl-on-the-raspberry-pi-without-a-robot\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,12,9],"tags":[],"class_list":["post-198","post","type-post","status-publish","format-standard","hentry","category-apl-language","category-cto","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=198"}],"version-history":[{"count":21,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/198\/revisions"}],"predecessor-version":[{"id":463,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/198\/revisions\/463"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}