{"id":341,"date":"2017-03-12T14:19:13","date_gmt":"2017-03-12T18:19:13","guid":{"rendered":"https:\/\/blog.lufamily.ca\/kang\/?p=341"},"modified":"2017-04-03T21:53:22","modified_gmt":"2017-04-04T01:53:22","slug":"raspberry-heaven","status":"publish","type":"post","link":"https:\/\/blog.lufamily.ca\/kang\/2017\/03\/12\/raspberry-heaven\/","title":{"rendered":"Raspberry Heaven"},"content":{"rendered":"<p>Two years ago I started to tinker with the Arduino platform and created a simplistic garage door opener by coupling a fairly inexpensive <a href=\"https:\/\/store.arduino.cc\/product\/A000057\" target=\"_blank\">Leonardo<\/a> board with a even cheaper <a href=\"https:\/\/www.sparkfun.com\/products\/13678\" target=\"_blank\">ESP8266 WiFi<\/a> board. It took quite a bit of work, figuring out how to configure the WiFi with the ESP8266, and struggling with its unreliability. I also wrote a little iOS test app so that I can control the garage door opener with my iPhone.<\/p>\n<p>After numerous hours and a total bill of materials for less than $20, here is a short video on the fruits of my labour about a couple of years ago:<\/p>\n<div class=\"fb-video\" data-allowfullscreen=\"true\" data-href=\"https:\/\/www.facebook.com\/kanglu\/videos\/10152838677770219\/\" style=\"background-color: #fff; display: inline-block;\"><\/div>\n<p>I have been tracking the Raspberry Pi platform for quite sometime, but always found them to be comparably expensive to the Arduino boards, especially all I needed was something to get on my WiFi network, and be able to respond to a remote request to effectively flip the proverbial switch. So when I found out that you can get a <a href=\"http:\/\/www.canakit.com\/raspberry-pi-zero-wireless.html\" target=\"_blank\">Raspberry Pi Zero W<\/a> for $13.45 CAD at <a href=\"http:\/\/www.canakit.com\" target=\"_blank\">CanaKit.com<\/a>, I was pretty excited to give it a try.<\/p>\n<p>I purchased the Pi Zero W as well as the <a href=\"http:\/\/www.canakit.com\/raspberry-pi-3-model-b.html\" target=\"_blank\">Pi 3 Model B<\/a>. Why not?<\/p>\n<p>Spent a good chunk of yesterday to:<\/p>\n<ul>\n<li>Followed the instructions on <a href=\"https:\/\/www.raspberrypi.org\/documentation\/installation\/installing-images\/mac.md\" target=\"_blank\">raspberrypi.org<\/a> to download and copy the image to a 16GB micro SD flash drive.<\/li>\n<li>I needed to ensure that there is an empty file named <span style=\"font-size:120%\"><strong><code>\"ssh\"<\/code><\/strong><\/span>, so that I can ssh to the board remotely from my Mac. I was too lazy to find the keyboard, mouse, and required cables. Thanks to <a href=\"http:\/\/blog.smalleycreative.com\" target=\"_blank\">Michael Smalley<\/a> for providing this <a href=\"http:\/\/blog.smalleycreative.com\/linux\/setup-a-headless-raspberry-pi-with-raspbian-jessie-on-os-x\/\" target=\"_blank\">very helpful page<\/a>.<\/li>\n<li>Configure the WiFi settings with the good instructions provided by <a href=\"https:\/\/davidmaitland.me\/2015\/12\/raspberry-pi-zero-headless-setup\/\" target=\"_blank\">David Maitland<\/a>.<\/li>\n<\/ul>\n<p>After the above, the Pi board just needs power and nothing else, and I was able to establish an ssh session from my Mac to continue on with the configurations.<\/p>\n<ul>\n<li>First I updated the environment.<br \/>\n            <code><br \/>\nsudo apt-get update<br \/>\nsudo apt-get dist-upgrade<br \/>\n            <\/code><\/p>\n<\/li>\n<li>Then installed the Java Developer&#8217;s Kit<br \/>\n            <code><br \/>\nsudo apt-get install oracle-java8-jdk<br \/>\n            <\/code><\/p>\n<\/li>\n<li>Installed Node.js along with Express and wrote a super simple Express app. The instructions by <a href=\"http:\/\/yannickloriot.com\/2016\/04\/install-mongodb-and-node-js-on-a-raspberry-pi\/\" target=\"_blank\">Yannick Loriot<\/a> were really helpful. Did not try to use <code>apt-get<\/code> to install node, because it ended up crashing the board with a kernel panic. That path led to many lost hours.<br \/>\n            <code><br \/>\nwget <a href=\"https:\/\/nodejs.org\/dist\/latest\/node-v7.7.2-linux-armv7l.tar.gz\" target=\"_blank\">https:\/\/nodejs.org\/dist\/latest\/node-v7.7.2-linux-armv7l.tar.gz<\/a><br \/>\nnpm install express --save<br \/>\n            <\/code><\/p>\n<blockquote>\n<div style=\"font-size:70%\">Update 2017-03-14: The <code>armv7l<\/code> apparently only worked for the Pi 3, but for the Pi Zero W, I had to get the <code><a href=\"https:\/\/nodejs.org\/dist\/latest-v7.x\/node-v7.7.3-linux-armv6l.tar.gz\">arm6l<\/a><\/code> version.<\/div>\n<\/blockquote>\n<\/li>\n<li>Installed Samba, so that I can use my editors on my Mac to edit code.<br \/>\n            <code><br \/>\nsudo apt-get install samba<br \/>\n            <\/code><br \/>\nNote that we had to use <strong>smbd<\/strong> to restart the service after configuration.<br \/>\n            <code><br \/>\nsudo systemctl restart smbd.service<br \/>\n            <\/code><\/p>\n<\/li>\n<\/ul>\n<p>Once I have my development environment all setup and that all the networking stack is working properly. I can then start to play with the GPIO pins that came with the Pi. The idea is to provide a simple web service app powered by Node.js and Express to turn on or off or simply toggle a GPIO pin, acting as a switch, which I can hookup to a relay.<\/p>\n<p>I first downloaded the <a href=\"http:\/\/wiringpi.com\" target=\"_blank\">wiringpi<\/a> package.<br \/>\n<code><br \/>\nsudo apt-get install wiringpi<br \/>\n<\/code><br \/>\nI used the above package to get familiar with the GPIO mechanism and play around with it on the BASH command line.<\/p>\n<p>Once I was comfortable with the concept, I wanted to hook it up with the Express app which I did with the <code>onoff<\/code> npm module. I spent this morning creating a simple Swift iOS app, and wired the Pi to the relay.<\/p>\n<p>You can see it all working in the video below. When I press the button on my test app from my iPhone, you&#8217;ll see the red LED blinking denoting a pulse on the switch &#8212; think of this as you press the garage door opener. The yellow wire is the USB cable that is just feeding the board with power. Thrilling!<\/p>\n<div style=\"width: 840px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-341-1\" width=\"840\" height=\"473\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2017\/03\/Prototype.m4v?_=1\" \/><a href=\"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2017\/03\/Prototype.m4v\">https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2017\/03\/Prototype.m4v<\/a><\/video><\/div>\n<p>I am not finished yet. I still have to make the iOS app and web service more secure and switch from the Pi 3 to the Pi Zero, but not this weekend. However, my initial impression of the Raspberry Pi platform is much simpler for me, coming from a software background. My hardware skills are at best rusty from my university days. The micro controller environment of the Arduino platform is also very finicky and more difficult to debug. There is nothing like working with a real operating system with a mature development stack.<\/p>\n<p>I also used my wattage meter to figure out how many watts the system was drawing, and it only peaked at less than 3W. That&#8217;s pretty good!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Two years ago I started to tinker with the Arduino platform and created a simplistic garage door opener by coupling a fairly inexpensive Leonardo board with a even cheaper ESP8266 WiFi board. It took quite a bit of work, figuring out how to configure the WiFi with the ESP8266, and struggling with its unreliability. I &hellip; <a href=\"https:\/\/blog.lufamily.ca\/kang\/2017\/03\/12\/raspberry-heaven\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Raspberry Heaven&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":364,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[49,48,51,50,47,46],"class_list":["post-341","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-door","tag-garage","tag-ios","tag-opener","tag-pi","tag-raspberry"],"jetpack_featured_media_url":"https:\/\/blog.lufamily.ca\/kang\/wp-content\/uploads\/sites\/3\/2017\/03\/IMG_1471.jpg","jetpack_shortlink":"https:\/\/wp.me\/p7V6i8-5v","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts\/341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/comments?post=341"}],"version-history":[{"count":23,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":367,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts\/341\/revisions\/367"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/media\/364"}],"wp:attachment":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/media?parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/categories?post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/tags?post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}