<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: w4ilun</title>
    <description>The latest articles on DEV Community by w4ilun (@w4ilun).</description>
    <link>https://dev.to/w4ilun</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F52787%2Ff2953ac9-ac81-4d21-8802-792c560f5534.jpeg</url>
      <title>DEV Community: w4ilun</title>
      <link>https://dev.to/w4ilun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/w4ilun"/>
    <language>en</language>
    <item>
      <title>Building an IoT badge with ESP8266 + ePaper</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 21:38:15 +0000</pubDate>
      <link>https://dev.to/w4ilun/building-an-iot-badge-with-esp8266-epaper-10m</link>
      <guid>https://dev.to/w4ilun/building-an-iot-badge-with-esp8266-epaper-10m</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.tindie.com/stores/squarofumi/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GG50oG_7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AttOYJtIl92R2aVSp.png" alt="Support Us on Tindie!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’ve recently come across some e-paper display modules and thought they were the coolest thing ever. For those not familiar with e-paper, it’s a display technology similar to what’s used in e-readers (such as the Amazon Kindle).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WRoKKMMi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AzDgkVPau4Wz17rL6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WRoKKMMi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AzDgkVPau4Wz17rL6.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These displays don’t require any power to stay on, it’s only when you need to update the image do you need to give it power. The image on the left shows a high-level concept diagram of how these displays work.&lt;/p&gt;

&lt;p&gt;For battery powered IoT devices, there are many advantages to using these type of displays; you can pretty much shut off everything to preserve battery life and wake up only when you need to perform some action, all while displaying pertinent information to the user.&lt;/p&gt;

&lt;p&gt;So what can you do with an ESP8266, a battery, some buttons, and an ePaper display?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eDi889Rk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/11008/1%2AMLI28vtyl9CjFhhi29M4Jg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eDi889Rk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/11008/1%2AMLI28vtyl9CjFhhi29M4Jg.jpeg" alt="1. Smart Home Remote (Note the 5-way switch, up/down/left/right/center)"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Smart Home Remote (Note the 5-way switch, up/down/left/right/center)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DvvjpoC9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/11008/1%2AltV5Tu1hsKyMMTfO9HdG1g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DvvjpoC9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/11008/1%2AltV5Tu1hsKyMMTfO9HdG1g.jpeg" alt="2. Weather Dashboard"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Weather Dashboard&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YWojY-G1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5504/1%2A3i4Js6116vv6xhCC2Ud6GQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YWojY-G1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5504/1%2A3i4Js6116vv6xhCC2Ud6GQ.jpeg" alt="3. WiFi Manager"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;WiFi Manager&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mHd4qLzg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5504/1%2AcuLt-GF61HapCZMXzWsTPw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mHd4qLzg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5504/1%2AcuLt-GF61HapCZMXzWsTPw.jpeg" alt="4. Display Notifications (IFTTT or other integrations)"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Display Notifications (IFTTT or other integrations)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OQ26tqOg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2306/1%2Ao2exO9VkhtviintDdnDLQw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OQ26tqOg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2306/1%2Ao2exO9VkhtviintDdnDLQw.jpeg" alt="5. Name Tag"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Name Tag&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;…and pretty much anything you can think of. It’s a tiny battery powered computer with WiFi connectivity!&lt;/p&gt;
&lt;h2&gt;
  
  
  Building the badge
&lt;/h2&gt;

&lt;p&gt;These e-paper displays support the SPI protocol, so you’ll need to connect the right wires to the right pins on your microcontroller (the ESP8266 in our case) to drive the display. The display also requires a driving circuit to work, of which you can either get an adapter board for , or build your own. I decided on the latter, as the documentation was sufficient, and I didn’t want messy wires.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iNBQg5wV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AT1EhpMPp16Y66GBY41sk5Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iNBQg5wV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AT1EhpMPp16Y66GBY41sk5Q.png" alt="bunch of diodes, mosfets, and capacitors"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As with many of my recent projects, I usually skip the breadboarding phase and jump straight to designing the PCB on &lt;a href="http://kicad-pcb.org/"&gt;KiCad &lt;/a&gt;(hurrrray for open source software!). While building the driver circuit, I also threw in a coin cell battery + USB charger to make our little badge portable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KfWUMGvb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2An2tj9jjtoKZ9T8ticdMsug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KfWUMGvb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2An2tj9jjtoKZ9T8ticdMsug.png" alt="KiCad :)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5UKqK5on--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ASDURT-hu1YQ9iUbohrx_WQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5UKqK5on--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ASDURT-hu1YQ9iUbohrx_WQ.jpeg" alt="The badge itself is barely larger than the display :)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After double/triple/quadruple checking everything, I sent the design off to a PCB fab to have the boards made…&lt;/p&gt;

&lt;p&gt;The datasheet also thoroughly describes the timing and signals over SPI on how to control the display, but luckily for us, GitHub user &lt;a href="https://github.com/ZinggJM"&gt;ZinggJM&lt;/a&gt; created an Arduino library that abstracts all of that away :)&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/ZinggJM"&gt;
        ZinggJM
      &lt;/a&gt; / &lt;a href="https://github.com/ZinggJM/GxEPD"&gt;
        GxEPD
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A simple E-Paper display library with common base class and separate IO class for Arduino.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;It also leverages the Adafruit-GFX library, so you can use graphics primitives to do your drawing and rendering of images/text.&lt;/p&gt;

&lt;p&gt;After 5 long days, the boards finally arrived!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c4NwsKhZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2880/1%2Agb3YUyZTJOO5yMJET_Y3LQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c4NwsKhZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2880/1%2Agb3YUyZTJOO5yMJET_Y3LQ.jpeg" alt="badgy PCBs!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I used 0805 footprints for most of the components so they’re easier to hand solder, though there was no getting away with the 24 pin FPC connector (drag soldering did the trick)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gzQxSiQx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5504/1%2ALlM7S7zwSLb-qsgPBsk7QQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gzQxSiQx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5504/1%2ALlM7S7zwSLb-qsgPBsk7QQ.jpeg" alt="Yay it works! Charging up the Li-Ion LIR2450 coin cell battery"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the empty pin headers on J1; these are connected to the TX/RX/GPIO0 pins of the ESP8266 and used for programming the chip with a USB-Serial adapter. You can either solder on pin headers and have a permanent programming connector, or you can do what I did and simply pushed pins against the pads to load the OTA firmware once, then you could always upload any new sketches over WiFi (as long as the new sketch doesn’t crash/fail).&lt;/p&gt;

&lt;p&gt;Right now, I’m doing some real world tests on battery life, but based on my calculations I should get about 40 days of battery life in deep sleep mode:&lt;/p&gt;

&lt;p&gt;120 mAh coin cell battery / (60uA regulator + 20uA deepsleep ESP8266) x 0.70 miscellaneous factors = 1050 hours ~= 43 days&lt;/p&gt;

&lt;p&gt;Switching up the battery technology may also extend this a bit further; a 500 mAh LiPo has a similar footprint, and should theoretically offer a 4X battery life.&lt;/p&gt;

&lt;p&gt;All source files will be available on GitHub, feel free to contribute and build your own! If you support Badgy, you can get one today on &lt;strong&gt;&lt;em&gt;&lt;a href="https://www.tindie.com/products/edit/badgy-iot-badge/"&gt;Tindie&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;. Enjoy :)&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/sqfmi"&gt;
        sqfmi
      &lt;/a&gt; / &lt;a href="https://github.com/sqfmi/badgy"&gt;
        badgy
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Home of Badgy - IoT Badge
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>iot</category>
      <category>arduino</category>
      <category>esp8266</category>
      <category>eink</category>
    </item>
    <item>
      <title>Building Your Own Midi Fighter</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 21:30:17 +0000</pubDate>
      <link>https://dev.to/w4ilun/building-your-own-midi-fighter-35of</link>
      <guid>https://dev.to/w4ilun/building-your-own-midi-fighter-35of</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr" rel="noopener noreferrer"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s a Midi Fighter?
&lt;/h2&gt;

&lt;p&gt;A Midi Fighter is a music controller equipped with high quality arcade buttons for a great tactile feel, low latency action, and durability. Every button is also backlit with RGB LEDs, illuminating the translucent buttons with customizable colors and animations.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can you do with a Midi Fighter?
&lt;/h2&gt;

&lt;p&gt;Me? Not much. But check out what other skilled people can do:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ieSzJh4yKmA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Design Process
&lt;/h2&gt;

&lt;p&gt;After spending a few hours on YouTube watching amazing performances by these talented individuals (check out Shawn Wasabi’s &lt;a href="https://www.youtube.com/channel/UCXLrdG_ZVt4US1iV40ytiQQ" rel="noopener noreferrer"&gt;YouTube channel&lt;/a&gt;), I decided I wanted to build my own! There were plenty of DIY projects out there on building a MIDI controller with an Arduino, but most of them lacked LEDs, or were in a larger form factor.&lt;/p&gt;

&lt;p&gt;Designing the enclosure was the first step. I came across a lot of designs that used MDF or Acrylic boards as the mounting plate. I didn’t want any flex when pushing the buttons, and also a premium feel to the end product, so I opted for anodized aluminum plates to form the enclosure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ASpAZpikbBsIThdY6u4TJ4g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ASpAZpikbBsIThdY6u4TJ4g.jpeg" alt="I did some quick design work with Fusion 360 and exported the layout to a DXF file for CNC cutting."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The PCB would be sandwiched between the top and bottom plates, and held together with M3 machine screws; on the 4 corners, aluminum standoffs would provide support and clearance for the arcade buttons, and components on the PCB.&lt;/p&gt;

&lt;p&gt;For the arcade buttons, I chose the Sanwa OBSC 24mm translucent buttons; these are high quality Japanese arcade buttons rated for 15 million presses! They require very little actuation force, and are spring loaded to provide quick feedback. It was also important to choose translucent buttons to let the RGB LEDs shine through :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ABr4X7qQjQFWKMaTi8eFFTw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ABr4X7qQjQFWKMaTi8eFFTw.png" alt="These buttons were pricey but they’re so worth it :)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the PCB, I designed everything using KiCad. The layout wasn’t too complicated as the board was fairly big (~15cmx15cm), so I had plenty of room to route the components. I did spend some extra time on the PCB art and also making sure all the dimensions were correct. The microcontroller is an ATmega32u4, with each of the 16 buttons connected to a GPIO pin. I chose this MCU because it’s the same one as the Arduino Leonardo, and I could take advantage of the many already available libraries.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AFeLCi4CPY3EkUiHfE-Lv3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AFeLCi4CPY3EkUiHfE-Lv3g.png" alt="No PCB design is complete without some artwork :)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2246%2F1%2AbrkGpPpBG9yTgy_y_52gVg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2246%2F1%2AbrkGpPpBG9yTgy_y_52gVg.jpeg" alt="The cluster of mess on the right are the LEDs coupled with bypass capacitors :p"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may have noticed that there are &lt;strong&gt;32 RGB LEDs&lt;/strong&gt; on this board! To provide even lighting without using light pipes, I decided to place two of these LEDs at a diagonal underneath each button. Now because of the layout, the normal sized 5050 Neopixels were too large to fit, so I went with the SK6812 minis which are only 35mm x 35mm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A6VoRO_RnNLtQycfFfv1cSQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A6VoRO_RnNLtQycfFfv1cSQ.png" alt="These are so cute!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Assembly
&lt;/h2&gt;

&lt;p&gt;All the designs were submitted for fabrication and after about 10 days, I received all of the parts:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2A0liCk4yZlEiCNO9U88BoLQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2A0liCk4yZlEiCNO9U88BoLQ.jpeg" alt="Electronics and PCB (Note the coil of SK6812 minis, I bought 200 of them)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2AQLPNqu_ucQH3YK71uDOz0g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2AQLPNqu_ucQH3YK71uDOz0g.jpeg" alt="Close up on the PCB art. I chose ENIG finish to really let the artwork shine (literally)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first thing I wanted to test was to make sure the PCB, the buttons, and the mounting plate were all aligned properly:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2AzEPpUTbiwsLV-mIK7c_MQg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2AzEPpUTbiwsLV-mIK7c_MQg.jpeg" alt="Yay it fits!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2ARBSpPgrMzFzqojmc9D9i4g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2ARBSpPgrMzFzqojmc9D9i4g.jpeg" alt="Top view. I used countersunk aluminum washers with the M3 machine screws."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The buttons were really snug with the mounting holes. In retrospect, I should’ve designed it with a little more wiggle room and not precisely 24mm, as it is now close to impossible to remove the buttons.&lt;/p&gt;

&lt;p&gt;All of the components were then soldered onto the PCB; I didn’t actually have to solder the arcade buttons because the mounting holes had enough friction to keep the pins in contact. Everything was then sandwiched together to form the final device:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2AvBTyB6lf-eHK53Bjgq-uPg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2AvBTyB6lf-eHK53Bjgq-uPg.jpeg" alt="Shiny, shiny buttons!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2Axvwlr38iwz2Chvff3HS0IA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2Axvwlr38iwz2Chvff3HS0IA.jpeg" alt="Corner"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2A4ZagBKo5U9Cds4HWh3TlPQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2A4ZagBKo5U9Cds4HWh3TlPQ.jpeg" alt="Lights On! Better view of the sandwich construction"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2AjJ8Xr0jTHXZC3RPQP8B4LQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2AjJ8Xr0jTHXZC3RPQP8B4LQ.jpeg" alt="Color: RGB(30,10,10) An improvement would be to add a cylindrical housing for each button to avoid light leaking"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2Ar9_J7b7yaBP2jw_WyWH06A.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2Ar9_J7b7yaBP2jw_WyWH06A.jpeg" alt="Lowered the brightness for my camera, these LEDs are bright!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2AFA2OjUDONjthuMkbail71A.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F10666%2F1%2AFA2OjUDONjthuMkbail71A.jpeg" alt="Completed build (Top Right) and all the parts to build one. I bought enough parts to build 5 :)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;The first order of business was to flash the device with the Arduino bootloader, this would allow us to upload our firmware via USB with the Arduino IDE. This can be done using another Arduino as an ISP (in-system programmer). Once this is complete, your device should be recognized by the IDE as an Arduino Leonardo. I’ve included an ISP header on the top right corner of the PCB.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AdeV4rZJLcd1qywvct3nWlw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AdeV4rZJLcd1qywvct3nWlw.png" alt="Follow this guide [https://www.arduino.cc/en/Tutorial/ArduinoISP](https://www.arduino.cc/en/Tutorial/ArduinoISP)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the firmware, I used Adafruit’s &lt;a href="https://github.com/adafruit/Adafruit_NeoPixel" rel="noopener noreferrer"&gt;NeoPixel library&lt;/a&gt; and the &lt;a href="https://www.arduino.cc/en/Reference/MIDIUSB" rel="noopener noreferrer"&gt;MIDIUSB library&lt;/a&gt;. All of the buttons were mapped to a different note, and the LED underneath would change from pink to white when pressed:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Firmware source code and hardware design files are all open source and available on GitHub: &lt;a href="https://github.com/w4ilun/midifighter" rel="noopener noreferrer"&gt;https://github.com/w4ilun/midifighter&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Showtime!
&lt;/h2&gt;

&lt;p&gt;&lt;iframe src="https://player.vimeo.com/video/233169523" width="710" height="399"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;I made the above track with GarageBand, it immediately recognized my Midi Fighter when plugged in; other music creation software e.g. Ableton Live, Traktor, etc. should also be supported.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2212%2F1%2AO80c1jwiS340dcNAZsgMag.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2212%2F1%2AO80c1jwiS340dcNAZsgMag.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;It would be great to have some GUI software that would allow you to easily design LED animations/patterns, as well as configure the button mappings to play different notes. Right now, everything is hardcoded, so any changes would require directly modifying the sketch. This would be a great opportunity to use WebUSB and do everything over a browser :)&lt;/p&gt;

&lt;p&gt;GLHF!&lt;/p&gt;

</description>
      <category>music</category>
      <category>hardware</category>
      <category>midi</category>
      <category>arduino</category>
    </item>
    <item>
      <title>Build a Google Home assistant with Android Things</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 21:26:44 +0000</pubDate>
      <link>https://dev.to/w4ilun/build-a-google-home-assistant-with-android-things-19fa</link>
      <guid>https://dev.to/w4ilun/build-a-google-home-assistant-with-android-things-19fa</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr" rel="noopener noreferrer"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After playing around with &lt;a href="https://dev.to/w4ilun/android-things-getting-to-blinky-3b2m"&gt;Android Things for the first time&lt;/a&gt;, I’ve decided to explore the APIs and try out all the other cool things you could do with this platform. Though blinking an LED was only fun for about 5.2 seconds, that accomplishment prepared me with knowledge to tackle some of the more advanced projects. There are quite a few examples on GitHub, ranging from toggling &lt;a href="https://github.com/androidthings/sample-simplepio" rel="noopener noreferrer"&gt;GPIOs&lt;/a&gt;, &lt;a href="https://github.com/androidthings/sample-bluetooth-audio" rel="noopener noreferrer"&gt;Bluetooth audio&lt;/a&gt;, and even one on &lt;a href="https://github.com/androidthings/sample-tensorflow-imageclassifier" rel="noopener noreferrer"&gt;TensorFlow&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At around the same time, Google announced their &lt;a href="https://aiyprojects.withgoogle.com/" rel="noopener noreferrer"&gt;AIY Voice Ki&lt;/a&gt;t: a DIY AI assistant using a Raspberry Pi. I got super excited and couldn’t wait to build one myself; it looked like a fun little project, and I’ve always wanted to compare Google’s experience with the Amazon Echo’s.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2770%2F1%2AUtMJt1a89jwnwI5b5e_h3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2770%2F1%2AUtMJt1a89jwnwI5b5e_h3g.png" alt="The kit came bundled with issue #57 of The MagPi"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Much to my dismay, the kits were sold out everywhere, and scalpers were selling them for upwards of $90 on eBay :(&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AY7CfklX6tWBTzAB8HZc6PA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AY7CfklX6tWBTzAB8HZc6PA.png" alt="Me: sad"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The kit was essentially a cardboard box with a Voice HAT that connects the button, speaker, and microphones to the Raspberry Pi; the magic was within the &lt;a href="https://developers.google.com/assistant/sdk/overview" rel="noopener noreferrer"&gt;Google Assistant SDK&lt;/a&gt;, which provides the APIs for the voice-based AI interactions.&lt;/p&gt;

&lt;p&gt;Luckily for me, the Google Assistant APIs are supported on Android Things! Would it work on the Edison?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AsPEsGK9fhPtsqAE527KFwA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AsPEsGK9fhPtsqAE527KFwA.gif" alt="The LED on pin 13 blinks when playing an audio response"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2008%2F1%2A6E4n5sTY4NgTv_FxtSjaUw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2008%2F1%2A6E4n5sTY4NgTv_FxtSjaUw.png" alt="speech-to-text captured in the logs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It works! Now let’s see how to put it together…&lt;/p&gt;

&lt;h2&gt;
  
  
  Things You’ll Need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Intel Edison with Arduino Breakout (though any Android Things supported device should work)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.ebay.com/itm/USB-3d-Audio-Sound-Card-Microphone-Headset-Adapter-/152202347054" rel="noopener noreferrer"&gt;USB sound card with mic input&lt;/a&gt; (not needed if your board has audio jacks for in/out)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Speakers (I used my headphones because I don’t have any handy)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.ebay.com/itm/Tube-Hands-Free-Microphone-Lavalier-Lapel-For-SmartPhone-Laptop-PC-Notebook-/152393037334" rel="noopener noreferrer"&gt;Microphone&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Arduino Shield + Button (you could also wire a momentary switch directly to a GPIO pin)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F7680%2F1%2AJAQfkKPgBq7Owi7jWwiDzA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F7680%2F1%2AJAQfkKPgBq7Owi7jWwiDzA.jpeg" alt="The button is connected to IO4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Running Google Assistant on Android Things
&lt;/h2&gt;

&lt;p&gt;The first thing you’ll need to do is to flash Android Things onto your device, you can follow my &lt;a href="https://medium.com/all-technology-feeds/android-things-getting-to-blinky-8c37dd36b259" rel="noopener noreferrer"&gt;previous article&lt;/a&gt; or use the &lt;a href="https://developer.android.com/things/hardware/edison.html" rel="noopener noreferrer"&gt;official guide&lt;/a&gt;. It might be a good idea to at least get to blinky first, so you know that you have a functioning Android Things device.&lt;/p&gt;

&lt;p&gt;Once that’s done, you can then open the Google Assistant sample in Android Studio. You can find the sample code &lt;a href="https://github.com/w4ilun/sample-googleassistant" rel="noopener noreferrer"&gt;**here&lt;/a&gt;, **which I forked from the &lt;a href="https://github.com/androidthings/sample-googleassistant" rel="noopener noreferrer"&gt;official repo&lt;/a&gt;; I’ve made some minor changes to make it work with my setup, namely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Changed the button to activate on high instead of low&lt;/p&gt;

&lt;p&gt;Button.LogicState.&lt;strong&gt;&lt;em&gt;PRESSED_WHEN_HIGH&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mapped button to IO4 (in BoardDefaults.java)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getGPIOForButton&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;getBoardVariant&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;DEVICE_EDISON_ARDUINO:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"IO4"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Default to USB sound card instead of the Voice HAT for the Raspberry Pi
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="no"&gt;AUDIO_USE_I2S_VOICEHAT_IF_AVAILABLE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2978%2F1%2AbpZcUTjERGaFJUsKKq3cjQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2978%2F1%2AbpZcUTjERGaFJUsKKq3cjQ.png" alt="I’m using Android Studio 2.3.2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before you build and deploy onto the device, you’ll also need setup your credentials so your device can use the Google Assistant APIs, and grant permissions via Oauth:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Follow the instructions &lt;a href="https://developers.google.com/assistant/sdk/prototype/getting-started-other-platforms/config-dev-project-and-account" rel="noopener noreferrer"&gt;here&lt;/a&gt; to enable Google Assistant APIs and get your client secret JSON file. You can then rename that file to **client_secret_NNNN.json **to keep it short (if you want to). I also found this &lt;a href="https://aiyprojects.withgoogle.com/voice/#users-guide-1-2--turn-on-the-google-assistant-api" rel="noopener noreferrer"&gt;guide&lt;/a&gt; pretty useful .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy that file over to your projects root directory, then run Google’s oauthlib tool to generate the credentials.json:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;google-auth-oauthlib[tool]
google-oauthlib-tool &lt;span class="nt"&gt;--client-secrets&lt;/span&gt; client_secret_NNNN.json &lt;span class="se"&gt;\&lt;/span&gt;
                     &lt;span class="nt"&gt;--credentials&lt;/span&gt; app/src/main/res/raw/credentials.json &lt;span class="se"&gt;\&lt;/span&gt;
                     &lt;span class="nt"&gt;--scope&lt;/span&gt; https://www.googleapis.com/auth/assistant-sdk-prototype &lt;span class="se"&gt;\&lt;/span&gt;
                     &lt;span class="nt"&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All set! Now click run let the app build and deploy. It should build successfully and you’ll be greeted with:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AsY_v-rq4dZ0q6FpOA1xCsw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AsY_v-rq4dZ0q6FpOA1xCsw.png" alt="woohoo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yay! Except nothing works, because the USB sound card is not connected…what?!&lt;/p&gt;

&lt;p&gt;The Edison Arduino breakout board is setup in a way that there’s a tiny toggle switch between the larger USB-A port and the micro USB port. You can only use one or the other, by moving the toggle switch. Which means you can &lt;strong&gt;either&lt;/strong&gt; use the micro USB port for the ADB shell connection to deploy and debug your application, &lt;strong&gt;or **you can switch and use the larger USB host port for your sound card, **but not both at the same time :(&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Thankfully, the solution is simple: you’ll need to connect a 12V power supply so you can keep the USB host port active for the sound card (i.e. tiny toggle switch facing up). However, you’ll lose the micro USB connection and need to use &lt;a href="https://stackoverflow.com/questions/4893953/run-install-debug-android-applications-over-wi-fi" rel="noopener noreferrer"&gt;ADB shell over Wi-Fi instead&lt;/a&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ adb tcpip 5555
$ adb connect &amp;lt;DEVICE_IP_ADDRESS&amp;gt;:5555
$ adb shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now deploy and run your application again. Your device will start listening when you press the button, and stop when you release it. Your voice query gets sent over via the Google Assistant API, and you get a response almost instantaneously. Neat! Since the service is linked to your Google account, you can even tell it to add events to your Calendar and access other information. Ask for a joke, find out tomorrow’s weather, and when you run out of ideas, check out this &lt;a href="http://www.androidauthority.com/google-home-commands-727911/" rel="noopener noreferrer"&gt;comprehensive list&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Well, that’s it. Again, this has been a lot of fun and it’s great to see how easy it is these days to sprinkle some AI into any project. I still haven’t fully explored the capabilities of my DIY Google Assistant yet, but I think there’s a lot of potential for interesting projects here. I’d love to find out if it can control other IoT products as well, &lt;a href="https://medium.com/@monkeytypewritr/amazon-echo-esp8266-iot-a42076daafa5" rel="noopener noreferrer"&gt;perhaps a spoofed WeMo switch?&lt;/a&gt; :)&lt;/p&gt;

</description>
      <category>android</category>
      <category>googlecloud</category>
      <category>iot</category>
      <category>java</category>
    </item>
    <item>
      <title>Android Things — Getting to Blinky</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 21:21:13 +0000</pubDate>
      <link>https://dev.to/w4ilun/android-things-getting-to-blinky-3b2m</link>
      <guid>https://dev.to/w4ilun/android-things-getting-to-blinky-3b2m</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr" rel="noopener noreferrer"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Android Things brings Android and the mobile development ecosystem to IoT devices. It’s currently in developer preview 4, and has support for a variety of platforms, such as the Raspberry Pi, Intel Edison/Joule, and the NXP pico. You can learn more on the &lt;a href="https://developer.android.com/things/sdk/index.html" rel="noopener noreferrer"&gt;official site&lt;/a&gt;, but in essence, a developer can now use the same Android tools and APIs on IoT devices, including access to Google services, such as Google Drive/Search/Maps/Fit/Firebase/etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Az5pGPntELq-FD7eS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2Az5pGPntELq-FD7eS.png" alt="Android Tings platform architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Having zero Android development experience, this caught my interest and I figured I’d give it a go to see what it takes to get to the “Hello World” of hardware: a blinking LED.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hardware
&lt;/h2&gt;

&lt;p&gt;Android Things currently supports the aforementioned platforms. Naturally, I went with an Intel Edison that I have lying around (many of you may also have one, if you’ve attended one of the many hackathons in the past year :) If you have another supported platform, you could skip the setup section below and follow &lt;a href="https://developer.android.com/things/hardware/developer-kits.html" rel="noopener noreferrer"&gt;https://developer.android.com/things/hardware/developer-kits.html&lt;/a&gt; instead.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AShITe8quFyntm0a4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AShITe8quFyntm0a4.jpg" alt="Follow the assembly guide found here [https://software.intel.com/en-us/node/628221](https://software.intel.com/en-us/node/628221)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Software Setup
&lt;/h2&gt;

&lt;p&gt;We’ll need to download/install a couple of things to get started:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="https://01.org/android-ia/downloads/intel-platform-flash-tool-lite" rel="noopener noreferrer"&gt;Intel Flash Tool Lite&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; (For updating the firmware on the Intel Edison)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="https://developer.android.com/things/preview/download.html" rel="noopener noreferrer"&gt;Android Things System Image&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; (Android Things System Image for your board)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;a href="https://developer.android.com/studio/index.html" rel="noopener noreferrer"&gt;Android Studio&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; (Our IDE and tools for development)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first thing you need to do is to install Android Studio and update to the latest SDK/tools. You’ll need to use these tools later for updating your board and deploying your application. After installing, make sure you have **adb **and **fastboot **in your command prompt.&lt;/p&gt;

&lt;p&gt;Once that’s ready, download the Intel Flash Tool Lite along with the Android Things System Image. You can follow this guide &lt;strong&gt;&lt;em&gt;&lt;a href="https://software.intel.com/en-us/articles/installing-android-things-on-intel-edison-kit-for-arduino" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; for details on how to update the firmware and install Android Things. The &lt;strong&gt;&lt;em&gt;flashall.sh&lt;/em&gt;&lt;/strong&gt; script mentioned in the guide didn’t work for me, so here’s a summary of the steps I took to get the board up and running:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Run the Intel Flash Tool Lite to update the firmware, it should take about 30 seconds, with the board booting into &lt;strong&gt;&lt;em&gt;FASTBOOT MODE&lt;/em&gt;&lt;/strong&gt; if it was successful. You can monitor this from putty or screen terminal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once booted into &lt;strong&gt;&lt;em&gt;FASTBOOT MODE&lt;/em&gt;&lt;/strong&gt;, run the &lt;strong&gt;&lt;em&gt;fastboot&lt;/em&gt;&lt;/strong&gt; tool in a command prompt of your host computer to install the image:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ fastboot \
    flash gpt        partition-table.img \
    flash u-boot     u-boot-edison.bin \
    flash boot_a     boot.img \
    flash boot_b     boot.img \
    flash system_a   system.img \
    flash system_b   system.img \
    flash gapps_a    gapps.img \
    flash gapps_b    gapps.img \
    flash oem_a      oem.img \
    flash oem_b      oem.img \
    set_active a \
    reboot
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Let your device reboot and wait for the adb shell:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ adb wait-**for**-device
$ adb shell
edison:/$
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;…and you’re done! You now have Android Things running on your board!&lt;/p&gt;

&lt;p&gt;You could also connect your board to Wi-Fi (we won’t need to for blinking an LED, but you’ll probably need connectivity for future projects)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;edison: am startservice \
     -n com.google.wifisetup/.WifiSetupService \
     -a WifiSetupService.Connect \
     -e ssid &amp;lt;SSID-name&amp;gt; \
     -e passphrase &amp;lt;SSID-password&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Wait a few seconds then try pinging an IP e.g. 8.8.8.8 to make sure it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating your Android Things app
&lt;/h2&gt;

&lt;p&gt;Follow this &lt;a href="https://developer.android.com/things/training/first-device/index.html" rel="noopener noreferrer"&gt;guide&lt;/a&gt; for creating an Android Things app. The steps are essentially the same as creating a regular Android app, but since I have zero prior experience, I followed this &lt;a href="https://developer.android.com/studio/projects/create-project.html" rel="noopener noreferrer"&gt;guide&lt;/a&gt; for creating my first Android project. You’ll need to target **Android 7.0 (API 24) **and make sure the SDK tools are up to date. Once the project has been created, you’ll need to modify the **build.gradle **and **AndroidManifext.xml **files to configure itself as an Android Things app:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;build.gradle&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;&lt;span class="k"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="o"&gt;...&lt;/span&gt;
        &lt;span class="n"&gt;provided&lt;/span&gt; &lt;span class="s1"&gt;'com.google.android.things:androidthings:0.4-devpreview'&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;AndroidManifest.xml&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;application&lt;/span&gt;
        &lt;span class="na"&gt;android:label=&lt;/span&gt;&lt;span class="s"&gt;"@string/app_name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;uses-library&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"com.google.android.things"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;activity&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;".HomeActivity"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="c"&gt;&amp;lt;!-- Launch activity as default from Android Studio --&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;intent-filter&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;action&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.action.MAIN"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;category&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.category.LAUNCHER"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/intent-filter&amp;gt;&lt;/span&gt;

            &lt;span class="c"&gt;&amp;lt;!-- Launch activity automatically on boot --&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;intent-filter&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;action&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.action.MAIN"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;category&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.category.IOT_LAUNCHER"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;category&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.category.DEFAULT"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/intent-filter&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/activity&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/application&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build and run your project, it should succeed but it won’t be doing much at this point…&lt;/p&gt;

&lt;h2&gt;
  
  
  Interacting with Peripherals
&lt;/h2&gt;

&lt;p&gt;The cool thing about Android Things (ha) is that developers are now able to interact with hardware peripherals in their application. Through the &lt;strong&gt;&lt;em&gt;PeripheralManagerService&lt;/em&gt;&lt;/strong&gt; APIs, you could interact with your device’s GPIO, PWM, I2C, SPI, I2S, and UART, allowing you to communicate with any sensor/actuator using these standard protocols.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3324%2F0%2AdI2GCggktpWkmLCu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3324%2F0%2AdI2GCggktpWkmLCu.png" alt="Example of connecting sensors and displays"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition to the peripheral APIs, Android Things also has the concept of &lt;strong&gt;&lt;em&gt;User-Space Drivers&lt;/em&gt;&lt;/strong&gt;; these drivers are essentially abstractions so you don’t have to worry about the hardware implementation and board configurations when interacting with a peripheral device. You could easily drop in a GPS/Temperature Sensor/Audio Output/OLED Screen/HID driver and use it right away, without worrying about the sensor protocol and any low-level peripheral IO APIs. Check out the &lt;em&gt;**&lt;a href="https://developer.android.com/things/sdk/driver-library.html" rel="noopener noreferrer"&gt;peripheral driver library&lt;/a&gt; *&lt;/em&gt;* to see what’s already supported and how to add your own.&lt;/p&gt;

&lt;p&gt;For now, we’re going to start thee basic Peripheral I/O APIs. Add the following code to your &lt;strong&gt;&lt;em&gt;HomeActivity.java&lt;/em&gt;&lt;/strong&gt; to get a list of available GPIOs on your board (Note: in Android Studio, press Alt+Enter for quick fix, it will import the missing dependencies)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HomeActivity&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Activity&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="no"&gt;TAG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"HomeActivity"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="nd"&gt;@Override&lt;/span&gt;
        &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Bundle&lt;/span&gt; &lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;onCreate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

            &lt;span class="nc"&gt;PeripheralManagerService&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PeripheralManagerService&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;d&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TAG&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Available GPIO: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getGpioList&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build and run, open up the &lt;strong&gt;&lt;em&gt;logcat&lt;/em&gt;&lt;/strong&gt; window and you should see a list of GPIOs:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2162%2F1%2AB9D8o3yLM5mvjx0nRI3riQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2162%2F1%2AB9D8o3yLM5mvjx0nRI3riQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Blinking an LED
&lt;/h2&gt;

&lt;p&gt;Finally! So after setting up your board and installing all the software bits, the last step is to run the code for blinking an LED. You could setup your board like the diagram below, or simple use the on-board LED; both the on-board LED and the external LED are connected to GPIO pin 13:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3516%2F0%2APx9ydia-RxV4jcld.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3516%2F0%2APx9ydia-RxV4jcld.png" alt="There’s an on-board LED connected to pin 13, so you don’t need to if you don’t have one"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Edit your &lt;strong&gt;&lt;em&gt;HomeActivity.java&lt;/em&gt;&lt;/strong&gt; with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HomeActivity&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Activity&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="no"&gt;TAG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"HomeActivity"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="no"&gt;INTERVAL_BETWEEN_BLINKS_MS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="o"&gt;***&lt;/span&gt;&lt;span class="no"&gt;LED_PIN_NAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"IO13"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Handler&lt;/span&gt; &lt;span class="n"&gt;mHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Handler&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Gpio&lt;/span&gt; &lt;span class="n"&gt;mLedGpio&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="nd"&gt;@Override&lt;/span&gt;
        &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Bundle&lt;/span&gt; &lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;onCreate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

            &lt;span class="nc"&gt;PeripheralManagerService&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PeripheralManagerService&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
            &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;d&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TAG&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Available GPIO: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getGpioList&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

            &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;mLedGpio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;openGpio&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;LED_PIN_NAME&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="n"&gt;mLedGpio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setDirection&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Gpio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;DIRECTION_OUT_INITIALLY_LOW&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="n"&gt;mHandler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;post&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mBlinkRunnable&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

            &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IOException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
                &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;e&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TAG&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Error on peripheral"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="nd"&gt;@Override&lt;/span&gt;
        &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;onDestroy&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;onDestroy&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

            &lt;span class="c1"&gt;// Step 4. Remove handler events on close.&lt;/span&gt;
            &lt;span class="n"&gt;mHandler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;removeCallbacks&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mBlinkRunnable&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

            &lt;span class="c1"&gt;// Step 5. Close the resource.&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mLedGpio&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;mLedGpio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;close&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IOException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;e&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TAG&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Error on PeripheralIO API"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="n"&gt;mBlinkRunnable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Runnable&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="nd"&gt;@Override&lt;/span&gt;
            &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Exit if the GPIO is already closed&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mLedGpio&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="c1"&gt;// Step 3. Toggle the LED state&lt;/span&gt;
                    &lt;span class="n"&gt;mLedGpio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setValue&lt;/span&gt;&lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;mLedGpio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

                    &lt;span class="c1"&gt;// Step 4. Schedule another event after delay.&lt;/span&gt;
                    &lt;span class="n"&gt;mHandler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;postDelayed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mBlinkRunnable&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="no"&gt;INTERVAL_BETWEEN_BLINKS_MS&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IOException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                    &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;e&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TAG&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Error on PeripheralIO API"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;};&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what’s happening: We’ve created an instance of &lt;strong&gt;Gpio&lt;/strong&gt;, set it to pin 13 using the &lt;strong&gt;PeripheralManagerService, **set it to output and off initially with **DIRECTION_OUT_INITIALLY_LOW&lt;/strong&gt;, then using the **setValue **method to turn it on/off.&lt;/p&gt;

&lt;p&gt;That’s it! Congratulations on blinking an LED on Android Things!&lt;/p&gt;

&lt;p&gt;If you don’t want to type out these code snippets, you can just head over to &lt;a href="https://developer.android.com/things/sdk/samples.html" rel="noopener noreferrer"&gt;https://developer.android.com/things/sdk/samples.html&lt;/a&gt; to download the complete, ready to run project. It’s all on GitHub and there you could find a lot of additional code samples as well.&lt;/p&gt;

&lt;p&gt;Though still in developer preview, I had a great experience with getting started on Android Things and it was a lot of fun. Feel free to reach out if you have any questions or feedback :)&lt;/p&gt;

</description>
      <category>android</category>
      <category>iot</category>
      <category>java</category>
      <category>helloworld</category>
    </item>
    <item>
      <title>Building your own keyboard (from scratch)</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 20:10:54 +0000</pubDate>
      <link>https://dev.to/w4ilun/building-your-own-keyboard-from-scratch-12g3</link>
      <guid>https://dev.to/w4ilun/building-your-own-keyboard-from-scratch-12g3</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr" rel="noopener noreferrer"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another interest of mine are computer keyboards. I’ve acquired this interest relatively recently, and have spent many hours since perusing /r/MechanicalKeyboards:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3232%2F0%2AcWzjVYfIR7n15eCP.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3232%2F0%2AcWzjVYfIR7n15eCP.jpg" alt="/u/aaron6301"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F4000%2F0%2AZ60rW-ZVlnVxdpTm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F4000%2F0%2AZ60rW-ZVlnVxdpTm.jpg" alt="/u/[fathovercats](https://www.reddit.com/user/fathovercats)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aren’t these beautiful? They come in all sorts of colors, sizes, lights, layouts, switches, and &lt;strong&gt;price&lt;/strong&gt;. And as a tool that I use everyday, it was easy for me to justify my purchases :)&lt;/p&gt;

&lt;p&gt;At the high end, these keyboards are often custom designed and hand assembled: CNC’d aluminum plates, RGB underglow, custom PCB/firmware, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2048%2F0%2Au1-ctn9r67hdTm1a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2048%2F0%2Au1-ctn9r67hdTm1a.jpg" alt="[http://www.gonskeyboardworks.com/](http://www.gonskeyboardworks.com/)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Building one?
&lt;/h2&gt;

&lt;p&gt;As I found out from the /r/MechanicalKeyboard community, there are a lot of members who built their own, and has contributed a lot of their work back to the open source community; from hardware design (e.g. &lt;a href="https://github.com/komar007/gh60" rel="noopener noreferrer"&gt;GH60&lt;/a&gt;) to software/firmware (e.g. &lt;a href="https://github.com/tmk/tmk_keyboard" rel="noopener noreferrer"&gt;TMK&lt;/a&gt;/&lt;a href="https://github.com/qmk/qmk_firmware" rel="noopener noreferrer"&gt;QMK&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Ever since building my &lt;a href="https://medium.com/@monkeytypewritr/building-a-bluetooth-le-lego-controller-web-bluetooth-app-754a9993d511#.c3ocf1i4b" rel="noopener noreferrer"&gt;Lego BLE controller&lt;/a&gt;, I’ve wanted to take on a more advanced project, and this seemed like the perfect one!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hardware&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A keyboard’s hardware is pretty simple: it’s just a bunch of buttons! The challenge lies in that a typical keyboard has about a 100 keys/buttons; most microcontrollers don’t have that many input pins, and it would be a waste to use them all simply to read buttons. The trick is to use a keyboard matrix (e.g. 5 rows x 15 columns) and quickly cycle through each row/column, allowing you to use &lt;em&gt;2n&lt;/em&gt; pins only for a &lt;em&gt;n *x *n&lt;/em&gt; matrix. You can read more about how that works in this excellent &lt;a href="http://blog.komar.be/how-to-make-a-keyboard-the-matrix/" rel="noopener noreferrer"&gt;article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2584%2F1%2A5apsaKutI0lc03KOat5LfQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2584%2F1%2A5apsaKutI0lc03KOat5LfQ.png" alt="Note the 5 way tactile switch I added. It functions as arrow keys or a mouse!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the microcontroller, I chose the popular atmega32u4. It’s got USB support and is also used in the Arduino Pro Micro. The firmware which we will be using later also supports it. The only work that needs to be done is to map our row and column buttons to the microcontroller’s GPIO pins:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2380%2F1%2ApKOXjWUAbqFnz5xGDpw2Hw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2380%2F1%2ApKOXjWUAbqFnz5xGDpw2Hw.png" alt="I took the Arduino Pro Micro schematic, removed the 5V regulator and Tx/RX LEDs, and mapped the GPIO pins"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we have our schematic, now begins the fun part of routing the PCB. In my previous project, I simply used the autoroute feature and let the algorithms do their job. In this design, there were simply too many connections to use that feature, and I wanted a nice clean design (and also throwing in some nice PCB artwork along the way).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2570%2F0%2Al1CsNDzcEt1g3kfW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2570%2F0%2Al1CsNDzcEt1g3kfW.png" alt="Top Layer: Red, Bottom Layer: Blue, Silkscreen: Yellow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I sent in this design to &lt;a href="https://www.seeedstudio.com/fusion_pcb.html" rel="noopener noreferrer"&gt;Seeed studio&lt;/a&gt; and got it made; I chose a black PCB with white silkscreen. In 2 weeks they showed up:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F4000%2F0%2A6wQLYdQOYAlaZzvv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F4000%2F0%2A6wQLYdQOYAlaZzvv.jpg" alt="Nice and shiny :) Though I wished they had an option for a matte black PCB"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Software&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Luckily for me, there’s already a great open source keyboard firmware project out there, &lt;a href="https://github.com/tmk/tmk_keyboard" rel="noopener noreferrer"&gt;TMK&lt;/a&gt;! It already supports a bunch of keyboards and has great documentation on how to customize and compile a build for your own design. The only thing I needed to do was to configure the GPIO pins to the right row and columns and define the &lt;a href="https://github.com/tmk/tmk_keyboard/blob/master/tmk_core/doc/keymap.md" rel="noopener noreferrer"&gt;keymap&lt;/a&gt;, for example:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {&lt;br&gt;
        /* 0: Qwerty&lt;br&gt;
         * ,-----------------------------------------------------------.&lt;br&gt;
         * |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|  \|  `|&lt;br&gt;
         * |-----------------------------------------------------------|&lt;br&gt;
         * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|Backs|&lt;br&gt;
         * |-----------------------------------------------------------|&lt;br&gt;
         * |Contro|  A|  S|  D|  F|  G|  H|  J|  K|  L|Fn1|  '|Enter   |&lt;br&gt;
         * |-----------------------------------------------------------|&lt;br&gt;
         * |Shift   |  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift |Fn0|&lt;br&gt;
         * `-----------------------------------------------------------'&lt;br&gt;
         *       |Gui|Alt  |Space                  |Alt  |Fn2|&lt;br&gt;
         *       `-------------------------------------------'&lt;br&gt;
         */&lt;br&gt;
        KEYMAP(ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSLS,GRV, \&lt;br&gt;
               TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,BSPC, \&lt;br&gt;
               LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   FN1, QUOT,ENT, \&lt;br&gt;
               LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,RSFT,FN0, \&lt;br&gt;
                    LGUI,LALT,          SPC,                RALT,FN2),&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting it all together
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F4000%2F0%2AkDurk8pS1JMGSqWK.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F4000%2F0%2AkDurk8pS1JMGSqWK.jpg" alt="Piccolo for scale :)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After soldering all of the components and compiling the firmware, I flashed the firmware onto the board over USB using dfu-programmer. To my surprise, everything worked on first try! Typing on it was a lot of fun (for about 2 minutes) and I was pretty happy with the results. Though I probably won’t be using this as my daily driver, I definitely learned a lot about PCB design and embedded development.&lt;/p&gt;

&lt;p&gt;You can find all the software and hardware source on my GitHub &lt;a href="https://github.com/w4ilun/pocket-keyboard" rel="noopener noreferrer"&gt;https://github.com/w4ilun/pocket-keyboard&lt;/a&gt;&lt;/p&gt;

</description>
      <category>keyboard</category>
      <category>kicad</category>
      <category>hardware</category>
      <category>embedded</category>
    </item>
    <item>
      <title>Building a Bluetooth LE Lego Controller + Web Bluetooth App</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 20:08:38 +0000</pubDate>
      <link>https://dev.to/w4ilun/building-a-bluetooth-le-lego-controller-web-bluetooth-app-56bg</link>
      <guid>https://dev.to/w4ilun/building-a-bluetooth-le-lego-controller-web-bluetooth-app-56bg</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I’m a big fan of Lego, especially the Technic series. Some of these sets come with &lt;strong&gt;Power Functions&lt;/strong&gt;, which adds motors/servos/lights to the model and lets you control them with an IR remote:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7KzFZWfQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2300/1%2An7stY2FLKxLnlgcdWHMESA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7KzFZWfQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2300/1%2An7stY2FLKxLnlgcdWHMESA.jpeg" alt="2 of my favourite, the excavator and the Mercedes Benz Arocs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;2 of my favourite, the excavator and the Mercedes Benz Arocs&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dUYN71i9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2A0IrompgCrLR5jk2Q.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dUYN71i9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2A0IrompgCrLR5jk2Q.gif" alt="Lego Power Functions"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Lego Power Functions&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not all sets come with a remote, and for each channel you would need an IR receiver; wouldn’t it be cool if you could control everything with your phone over Bluetooth?&lt;/p&gt;

&lt;h2&gt;
  
  
  Power Functions: How Do They Work?
&lt;/h2&gt;

&lt;p&gt;All Lego Power Function connectors have 4 wires; 2 of them carry the +/- 9V from the battery box, while the other 2 provide direction and speed control:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EHIxsift--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2A8T6eAl0Fmz6O47Kx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EHIxsift--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2A8T6eAl0Fmz6O47Kx.jpg" alt="Image source [https://scuttlebots.com/2014/03/02/lego-pf-hacking-wiring/](https://scuttlebots.com/2014/03/02/lego-pf-hacking-wiring/)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The wires C1 &amp;amp; C2 allows you to control to the motors/servos/lights. Drive one of the wires with PWM and the other at ground to control the speed; swapping the input reverses the direction. A great resource to learn more about the Power Function actuators can be found here: &lt;a href="http://www.philohome.com/tech.htm"&gt;http://www.philohome.com/tech.htm&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Concept Diagram
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dTqAcbwz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A4Jsuq6S18czjDLvV2BXKxA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dTqAcbwz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A4Jsuq6S18czjDLvV2BXKxA.jpeg" alt="System Overview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are 3 main components to this build:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A Bluetooth module for sending/receiving commands&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An Arduino to interpret those commands and output PWM signals&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A motor controller that can provide enough current to drive the actuators&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I would normally just wire all of these components together and call it a day, but this time I wanted a cleaner solution and try creating my own PCB…&lt;/p&gt;

&lt;h2&gt;
  
  
  PCB Design and Fabrication
&lt;/h2&gt;

&lt;p&gt;Our build is simple enough that you could hand wire everything and be done with it, but where’s the fun in that? Designing your own PCB is a great learning experience that can be both fun and rewarding; it will also help you down the road as you try to tackle more sophisticated projects. There are quite a few free tools out there that let’s you do that now (e.g. &lt;a href="http://kicad-pcb.org/"&gt;KiCad&lt;/a&gt;, &lt;a href="https://cadsoft.io/"&gt;Eagle&lt;/a&gt;, &lt;a href="https://easyeda.com/"&gt;EasyEDA&lt;/a&gt;, &lt;a href="https://upverter.com/"&gt;Upverter&lt;/a&gt;, etc.), with tons of online resources to learn how.&lt;/p&gt;

&lt;p&gt;I won’t go into details on how to use these tools in this post (YouTube is your friend), but the first step is to turn the concept diagram into a schematic and choosing the right components:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JeSUW_OQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2754/1%2ApYQ9jGSWPBSynHN3RltNoA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JeSUW_OQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2754/1%2ApYQ9jGSWPBSynHN3RltNoA.png" alt="I used EasyEDA for this design (an online editor), but my favourite is KiCad :)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the main Arduino controller, I chose the &lt;strong&gt;&lt;em&gt;&lt;a href="https://www.sparkfun.com/products/12587"&gt;Arduino Pro Micro&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; as I have a few of those around. It also has the right number of GPIO pins we need in a small form factor. I chose the 3.3V variation as our Bluetooth module runs on 2.7V — 3.3V.&lt;/p&gt;

&lt;p&gt;For the Bluetooth LE module, I chose the &lt;strong&gt;&lt;em&gt;&lt;a href="https://www.itead.cc/serial-port-ble-module-master-slave-hm-10.html"&gt;HM-10&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;; it’s based on the CC2541 and can be found for a few dollars on eBay. It has a simple UART interface that simply passes through any data you send to it via its custom Service &amp;amp; Characteristic.&lt;/p&gt;

&lt;p&gt;For the motor controllers I chose the &lt;strong&gt;&lt;em&gt;&lt;a href="https://toshiba.semicon-storage.com/info/docget.jsp?did=10660&amp;amp;prodName=TB6612FNG"&gt;TB6612FNG&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; from Toshiba. I originally wanted to use the popular &lt;a href="https://www.sparkfun.com/products/9479"&gt;L298N&lt;/a&gt; as it’s capable of driving more current. Unfortunately, it is commonly found in the Multiwatt15 package, which is too big for my desired form factor. Each TB6612FNG IC can drive 2 channels, so we’ll need 2 of them total. I also threw in some decoupling capacitors to reduce noise (10uF electrolytic and 0.1uF tantalum).&lt;/p&gt;

&lt;p&gt;Last but not least, we’ll need 4 pin connectors for the Power Function Lego connectors. We could have soldered the wires directly to the board, but I wanted to keep things modular (plus connectors look nicer). I chose the popular JST XH connectors.&lt;/p&gt;

&lt;p&gt;All the above components can be found on &lt;strong&gt;&lt;em&gt;&lt;a href="http://digikey.com"&gt;DigiKey&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; or eBay. I always order extras in case I mess up the soldering (or when I lose those super tiny SMD components).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YGBIlfsw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3716/1%2Axtl8eFhJmLTW6nKNeQ9p9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YGBIlfsw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3716/1%2Axtl8eFhJmLTW6nKNeQ9p9g.png" alt="I was lazy and used the auto-route feature,"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next step is to convert your schematic into a board layout. I chose a 2 layer design and placed the components strategically around the board. The Pro Micro, motor controllers, and connectors go on the top for easy access, while the Bluetooth module goes on the bottom to save space. I also used the auto-route feature so you don’t have to do the routing yourself; I do find, however, that routing your traces manually yields cleaner results. The screenshot above was my first iteration of the design.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dWFYACc7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AkVWfh9kKFsfGa7do.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dWFYACc7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AkVWfh9kKFsfGa7do.png" alt="Top Layer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yXAZW8JT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AXEvZRHtJJogBIwd3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yXAZW8JT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AXEvZRHtJJogBIwd3.png" alt="Bottom Layer (with a Lego man on the silkscreen!)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you are happy with your board layout, you can generate a render of your board. It is a great visual check for any outstanding issues (and it also lets you play around with the design, like adding a Lego man to the silkscreen).&lt;/p&gt;

&lt;p&gt;The final step is to generate Gerber files from your design, and sending it off to PCB fabs! Gerber files are the standard for PCB manufacturing, and they serve as instructions for creating the board (e.g. layout, top/bottom silkscreen, drill holes, vias, etc.); think of it as gcode in 3D printing. There are tons of PCB fabs out there but my favourite is &lt;a href="http://oshpark.com"&gt;OSHpark&lt;/a&gt;; they offer quick turnaround times and they also accept KiCAD/Eagle project files, this means you won’t have to generate/convert Gerber files with them and can directly upload your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DF1dqbQI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/0%2AxpGwTLs03msY_oFA." class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DF1dqbQI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/0%2AxpGwTLs03msY_oFA." alt="Lovely PCBs!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My boards came in 2 weeks after I sent in the designs. I wanted to get a blue PCB like my render, but that costed $10 more :( You can find all of the design files on my GitHub &lt;a href="https://github.com/w4ilun/lego-ble-controller/tree/master/hardware"&gt;https://github.com/w4ilun/lego-ble-controller/tree/master/hardware&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Board Assembly
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--viiKZCas--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/1%2AqIdxQRdTYbkoyQhYg0DRtw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--viiKZCas--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/1%2AqIdxQRdTYbkoyQhYg0DRtw.jpeg" alt="Things you will need"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We only have a few SMD components but they can be tricky to solder if you don’t have steady hands. I used Kester flux and ‘drag soldered’ the SMD components, then did all of the through hole components. An easier alternative would be to use solder paste and put the whole thing in a reflow oven.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WgENT8TQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/1%2Ax2jmRoXFAk1A4E0FJPoxKQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WgENT8TQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/1%2Ax2jmRoXFAk1A4E0FJPoxKQ.jpeg" alt="The tiny pins on the TB6612FNG were a pain! But with lots of flux and sweat, they turned out great :)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wjtEhvrc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/1%2ALrjx_jyeEN-CQ2FVwMMdlw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wjtEhvrc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/1%2ALrjx_jyeEN-CQ2FVwMMdlw.jpeg" alt="Bottom layer, where our Bluetooth module sits"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zxFnVNeX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/1%2AMeKzjDwILKOSI8sOyOpZAA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zxFnVNeX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/1%2AMeKzjDwILKOSI8sOyOpZAA.jpeg" alt="Everything assembled! Before powering it on I did a quick test with my multi-meter to test for shorts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will also need to attach the Lego extension wires to your 4 pin connectors. Make sure you have them in the right orientation by referring to the schematic. You could also solder the extension wires directly to the board without the connectors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VlWuMdn---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AagnsdyCTwmkT-CoMwa6sGw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VlWuMdn---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AagnsdyCTwmkT-CoMwa6sGw.jpeg" alt="Both ends of the Lego extension wires have the same wire/pin layout, but the light gray connectors have no bottom pins"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mnEqB4aT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/1%2AXvHpfNgT0J0oh5ApXe0jLw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mnEqB4aT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3154/1%2AXvHpfNgT0J0oh5ApXe0jLw.jpeg" alt="All connected and ready for testing. Note I don’t have enough Lego extension wires, so I omitted the Channel 4 connector"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Firmware
&lt;/h2&gt;

&lt;p&gt;The firmware is very basic: read some input string from the serial port and turn on/off the appropriate pins accordingly. Every channel requires 3 GPIO pins to control its direction and speed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AWISoIEs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2Axq5oVz710yj_lbnV." class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AWISoIEs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2Axq5oVz710yj_lbnV." alt="I almost forgot to enable the STDBY pin and was wondering why nothing was working :p"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the pin number mappings in the schematic; the code snippet below shows how to turn the motor in one direction at half speed:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;digitalWrite(m1en1, HIGH); //CW or CCW
digitalWrite(m1en2, LOW);
analogWrite(m1pwm, 128); //values can be 0-255
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;For the command protocol, it is simply a string of 4 integer values separated by a &lt;strong&gt;#.&lt;/strong&gt; For example, **128#-255#10#0 **means drive Channel 1 at ~50%, drive Channel 2 at full speed in reverse, drive Channel 3 at 10/255 speed (~4% of max), and brake Channel 4. If a channel is connected to a Lego servo, -255 represents -90 degrees, 0 is center, and 255 represents +90 degrees. Unlike a regular hobby servo, the Lego servo only has 7 steps in each direction, so intermediate values between that range will be ignored (you can learn more about the Lego servo in this YouTube &lt;a href="https://www.youtube.com/watch?v=TPxbbOoX10U"&gt;video&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All together, the firmware is simply an infinite loop that waits for commands from the Bluetooth module via serial, then sets the motor direction and speed for each channel. You can find the firmware code on my GitHub &lt;a href="https://github.com/w4ilun/lego-ble-controller/tree/master/firmware"&gt;https://github.com/w4ilun/lego-ble-controller/tree/master/firmware&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Web Bluetooth App
&lt;/h2&gt;

&lt;p&gt;To control our Lego Power Function motors/servos/lights, we will need to talk to our Bluetooth LE module some how. We can create a native mobile app for iOS/Android, or use one of the Bluetooth LE APIs in Python or Node.JS (such as &lt;a href="https://github.com/sandeepmistry/bleno"&gt;Bleno&lt;/a&gt; by &lt;a href="http://twitter.com/sandeepmistry"&gt;@sandeepmistry&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;For this project, I’ve decided to leverage the cutting edge Web Bluetooth APIs available in Chrome 45+. You will need to first enable this experimental feature under chrome://flags (though this feature is enabled by default in &lt;a href="https://www.chromestatus.com/feature/5264933985976320"&gt;Chrome 56+&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;The cool thing about Web Bluetooth is that it works right from your browser, without needing additional libraries/plugins! It works on both desktop and Android, and you don’t need to download anything extra; simply visit a web page that has Web Bluetooth enabled and you’re presented with option to interact with nearby Bluetooth LE devices. The JavaScript snippet below shows how you can discover devices, connect, discover services/characteristics, and reading/writing to them:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;navigator.bluetooth.requestDevice({ filters: [{ services: [service] }] })
    .then(device =&amp;gt; device.gatt.connect())
    .then(server =&amp;gt; server.getPrimaryService(service))
    .then(service =&amp;gt; service.getCharacteristic(characteristic))
    .then(characteristic =&amp;gt; {
        characteristicInstance = characteristic;
    setInterval(updateSpeed,200); //send commands every 200ms
    return characteristic.writeValue(str2ab("0#0#0#0"));
    })
.catch(error =&amp;gt; { console.log(error); });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The complete code can be found here &lt;a href="https://github.com/w4ilun/lego-ble-controller/blob/master/index.html"&gt;https://github.com/w4ilun/lego-ble-controller/blob/master/index.html&lt;/a&gt;; I’ve also enabled GitHub pages on my repo, so if you built the same controller as I have, you could simply go to &lt;a href="https://w4ilun.github.io/lego-ble-controller/"&gt;https://w4ilun.github.io/lego-ble-controller/&lt;/a&gt; and start controlling your Lego!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tcAYMkT8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2512/1%2AAWTg6jYHeGNAxxgLYmukvw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tcAYMkT8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2512/1%2AAWTg6jYHeGNAxxgLYmukvw.png" alt="I renamed my HM-10 module to “LEGO-BLE” with AT commands, the default name is BT05"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I only created 2 control channels in this interface for testing; to expand on this example, you can add additional UI elements (such as toggle buttons, dials, etc.) and simply map them to the command string (CH1#CH2#CH3#CH4, right now CH3 and CH4 default to 0). You can also use your phone’s accelerometer data as input (e.g. deviceorientation ).&lt;/p&gt;

&lt;h2&gt;
  
  
  Trying It Out
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UZCYgWbp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AgE04R5OacwQNtwtPWMhOFg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UZCYgWbp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AgE04R5OacwQNtwtPWMhOFg.gif" alt="I should build a nice Lego enclosure for the controller board…"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I put together a “car” to test out everything and much to my delight, everything worked perfectly :)&lt;/p&gt;

&lt;p&gt;This learning experience has been a lot of fun and I look forward to improving on this design. In the next iteration I plan to consolidate the Bluetooth LE module and the main microcontroller, and not use the Pro Micro + HM-10 (ESP32 perhaps?).&lt;/p&gt;

&lt;p&gt;You can find everything you need on my &lt;a href="https://github.com/w4ilun/lego-ble-controller"&gt;GitHub&lt;/a&gt;; I still have a few extra PCBs so feel free to reach out and I’d be glad to send you one to try for yourself.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;

</description>
      <category>iot</category>
      <category>lego</category>
      <category>bluetooth</category>
      <category>web</category>
    </item>
    <item>
      <title>Using Web Bluetooth in Chrome to visualize IMU data</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 20:03:04 +0000</pubDate>
      <link>https://dev.to/w4ilun/using-web-bluetooth-in-chrome-to-visualize-imu-data-1g7c</link>
      <guid>https://dev.to/w4ilun/using-web-bluetooth-in-chrome-to-visualize-imu-data-1g7c</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tkMywqSE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ApReO0DkhL9RQcj8MJ0fguA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tkMywqSE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ApReO0DkhL9RQcj8MJ0fguA.gif" alt="[https://github.com/w4ilun/web-bluetooth-curie-imu](https://github.com/w4ilun/web-bluetooth-curie-imu)"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/w4ilun"&gt;
        w4ilun
      &lt;/a&gt; / &lt;a href="https://github.com/w4ilun/web-bluetooth-curie-imu"&gt;
        web-bluetooth-curie-imu
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Arduino/Genuino 101 CurieIMU Web Bluetooth Orientation Visualiser
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;The Web Bluetooth API allows you to interact with Bluetooth LE peripherals from your browser using JavaScript. It’s been available since Chrome 45+, but you’ll have to enable it manually since it’s still an experimental feature. You can check out the API and examples &lt;a href="https://googlechrome.github.io/samples/web-bluetooth/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To start, I combined code examples for the Arduino 101 on using the built-in IMU and Bluetooth LE features; all of the Curie’s IMU readings are sent as notifications over Bluetooth LE by updating the characteristic’s value. The sketch below shows how to do so with the CurieBLE and CurieIMU libraries.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;On the web side, Chrome’s Web Bluetooth APIs were used to detect, connect, and read notifications from a Bluetooth LE peripheral device (our Arduino 101). For security reasons, all of this is enabled only after the user interacts with the page, so the &lt;strong&gt;navigator.bluetooth&lt;/strong&gt; method is called after you click connect. From then on, you can discover the peripherals services and characteristics; we subscribe to these characteristics and receive IMU data in the callback function:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The IMU data (roll, pitch, &amp;amp; yaw) gets updated, and we update them as globals as well in our script; this allows our Processing.js sketch to read from the global scope the IMU data, and update the canvas WebGL rendering.&lt;/p&gt;

&lt;p&gt;Since everything is done in Chrome and no additional server side processing is required, I hosted everything on GitHub pages, so everyone can try it out for themselves &lt;a href="https://w4ilun.github.io/web-bluetooth-curie-imu/"&gt;https://w4ilun.github.io/web-bluetooth-curie-imu/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also find all of the code above on GitHub: &lt;a href="https://github.com/w4ilun/web-bluetooth-curie-imu"&gt;https://github.com/w4ilun/web-bluetooth-curie-imu&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;

</description>
      <category>iot</category>
      <category>web</category>
      <category>bluetooth</category>
      <category>arduino</category>
    </item>
    <item>
      <title>Building an IoT power switch with the ESP8266 (and control it with your Amazon Echo!)</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 19:58:09 +0000</pubDate>
      <link>https://dev.to/w4ilun/building-an-iot-power-switch-with-the-esp8266-and-control-it-with-your-amazon-echo-43db</link>
      <guid>https://dev.to/w4ilun/building-an-iot-power-switch-with-the-esp8266-and-control-it-with-your-amazon-echo-43db</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr" rel="noopener noreferrer"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;*&lt;strong&gt;&lt;em&gt;Cut to the chase, show me the build!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The ESP8266 is an amazing little module that packs WiFi connectivity and Arduino support for a little over $2 (less if you buy in bulk):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AGIIEOGMe1KvdPoNKVFyHnA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AGIIEOGMe1KvdPoNKVFyHnA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I first heard of this module about a year ago and was attracted by its price point and form factor. At the time, there weren’t a lot of system on a module (SOM) options for prototyping that included connectivity; often, you would have to add on an expensive and bulky WiFi/Bluetooth shield to your project.&lt;/p&gt;

&lt;p&gt;The biggest appeal of this module to me however, was the support of &lt;a href="http://nodemcu.com/index_en.html" rel="noopener noreferrer"&gt;NodeMCU&lt;/a&gt;: a LUA runtime on the module, with networking and I/O APIs that makes it very easy to perform common tasks such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;WiFi Config (connecting, setting/saving the SSID, credentials)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Performing HTTP requests, creating an HTTP server&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the hardware I/O (GPIO, I²C, PWM, etc.)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A9p1tRo3-LTC9ULIhnhSmqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A9p1tRo3-LTC9ULIhnhSmqw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was great! I immediately ordered a whole bunch of these (10+) for the many, many IoT projects I thought I would build. I started by building the IoT equivalent of Hello World: Blinking an LED from a browser:&lt;/p&gt;



&lt;p&gt;A few weeks later, while casually browsing through my regular sites, I came across this piece of exciting news:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ACajpKEmpv1LxFalNwCxiTg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ACajpKEmpv1LxFalNwCxiTg.png" alt="[http://hackaday.com/2015/03/28/arduino-ide-support-for-the-esp8266/](http://hackaday.com/2015/03/28/arduino-ide-support-for-the-esp8266/)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;w00t! Arduino support! This meant the module would have access to the vast number of libraries and extensions in the Arduino ecosystem. You could now easily use this module with &lt;a href="https://github.com/knolleary/pubsubclient" rel="noopener noreferrer"&gt;MQTT&lt;/a&gt;, &lt;a href="https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer" rel="noopener noreferrer"&gt;Web Server&lt;/a&gt;, &lt;a href="https://blog.adafruit.com/2015/06/30/updated-neopixel-support-for-esp8266-and-arduino-zero/" rel="noopener noreferrer"&gt;Neopixels&lt;/a&gt;, &lt;a href="https://github.com/firmata/arduino/issues/257" rel="noopener noreferrer"&gt;Firmata&lt;/a&gt; (hence, &lt;a href="http://johnny-five.io/" rel="noopener noreferrer"&gt;Johnny-Five&lt;/a&gt;!), and many, many more.&lt;/p&gt;

&lt;p&gt;Arduino support helped this module gain popularity, and at the same time, the number of board/breakout offerings grew. Most of these boards aim to make development easier by including features like pin breakouts, voltage regulation, reset buttons, USB-Serial converters, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVHVmseLH1gyxbwggTpvv_A.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AVHVmseLH1gyxbwggTpvv_A.jpeg" alt="[https://www.adafruit.com/product/2471](https://www.adafruit.com/product/2471) — with the ESP 12"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2048%2F1%2AtIsNAukjUdci5Ku1yB5sWg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2048%2F1%2AtIsNAukjUdci5Ku1yB5sWg.jpeg" alt="I didn’t buy any of these because I still had 10+ OG ESP8266s, but they look awesome!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was all exciting news, but I honestly had no projects in mind. These awesome little modules were tucked away in my toolbox for the next little while…until my &lt;a href="https://dev.toundefined"&gt;GE Lighting&lt;/a&gt; smart bulbs stopped working :(&lt;/p&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Asq9c2T5XAUWkgqpBBD4mWA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Asq9c2T5XAUWkgqpBBD4mWA.jpeg" alt="The smart home kit I bought. These bulbs use ZigBee with HA profile"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, what to do? I can’t go back to using a mechanical switch (*gasp)! I’ve grown accustomed to shouting at my lights to turn them on/off. Time to dust off those ESP8266's and make something!&lt;/p&gt;

&lt;h2&gt;
  
  
  Building an IoT power switch
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F7680%2F1%2Au1K7iBT1uCQSxue-elUHwQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F7680%2F1%2Au1K7iBT1uCQSxue-elUHwQ.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Bill of Materials (you’ll need these things)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Electronics&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.ebay.com/itm/For-Arduino-ESP8266-WIFI-Wireless-Transceiver-Module-Send-Receive-LWIP-AP-STA-BG-/121841140322" rel="noopener noreferrer"&gt;ESP8266 module&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.ebay.com/itm/24V-380V-40A-250V-SSR-40-DA-Solid-State-Relay-Module-3-32V-DC-To-AC-/121915540741" rel="noopener noreferrer"&gt;Solid State Relay&lt;/a&gt; (no clicking sounds, yay!)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.ebay.com/itm/AC-DC-Power-Supply-Buck-Converter-Step-Down-Module-110V-220V-TO-3-3V-700mA-2-3W-/201620442875" rel="noopener noreferrer"&gt;AC-DC Power Supply 110/220V to 3.3V&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wires (for low voltage DC connections)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hardware&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.homedepot.com/p/1-Gang-12-cu-in-Electrical-Handy-Box-B112HBR/202077374" rel="noopener noreferrer"&gt;Electrical Box&lt;/a&gt; (for all the components)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.homedepot.com/p/Leviton-15-Amp-Duplex-Outlet-White-R52-05320-00W/202066670" rel="noopener noreferrer"&gt;Duplex Outlet&lt;/a&gt; (socket)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.homedepot.com/p/Leviton-1-Gang-Duplex-Outlet-Wall-Plate-White-R52-88003-00W/100025171" rel="noopener noreferrer"&gt;Wall Plate&lt;/a&gt; (to hide everything in the box)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.homedepot.com/p/Axis-6-ft-3-Outlet-Indoor-Extension-Cord-White-45502/206346669" rel="noopener noreferrer"&gt;Extension Cord&lt;/a&gt; (for the socket plug and mains wires)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tools&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Soldering Iron&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Glue gun (for insulating any mains connections, be careful!)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://www.ebay.com/itm/FTDI-FT232RL-USB-to-TTL-Serial-Converter-Adapter-Module-5V-3-3V-For-Arduino-SM-/152164631351" rel="noopener noreferrer"&gt;USB-Serial adapter&lt;/a&gt; (for programming the module)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Jumper Cables/Breadboard&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Programming your ESP8266
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AU_7dOEdX9Fa9WX81PNHlPA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AU_7dOEdX9Fa9WX81PNHlPA.jpeg" alt="Reference: [http://benlo.com/esp8266/esp8266QuickStart.html](http://benlo.com/esp8266/esp8266QuickStart.html)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ll want to start by programming your ESP8266 with a USB-Serial adapter. The other boards out there (such as the NodeMCU dev board) might have the adapter built in, for those you’ll just need to plug it into your USB port.&lt;/p&gt;

&lt;p&gt;With our adapter, connect the pins according to the above diagram using your jumper wires/breadboard. Note the orange line in the above diagram: the pin GPIO0 needs to be pulled to GND during boot in order to flash it, make sure this is done before connecting it to your computer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F7680%2F1%2A_gY8z9mcILprbXPlc4kiKg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F7680%2F1%2A_gY8z9mcILprbXPlc4kiKg.jpeg" alt="messy wires"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ll also want to install the ESP8266 toolchain from the Arduino Boards Manager. Type in “esp8266” and install the latest version:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2116%2F1%2AzlcpGiSqY-WkEjvMN8_JhA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2116%2F1%2AzlcpGiSqY-WkEjvMN8_JhA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once installed, you can browse through the bundled examples and play around with the API; you’ll find examples on HTTP servers, sending/receiving UDP packets, connecting to a network, etc. Our project is built on top of these APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Amazon Echo, UDP/TCP, &amp;amp; WeMo Spoofing
&lt;/h2&gt;

&lt;p&gt;The Amazon Echo is my smart home hub; all the “smart things” in my home can be controlled via voice with the Echo, thanks to the incredible job it has done to integrate with different smart devices on the market.&lt;/p&gt;

&lt;p&gt;The simplest way we can get the Echo to discover and control our ESP8266, is by spoofing as a device supported by the integration, such as a Belkin WeMo switch!&lt;/p&gt;

&lt;p&gt;Device discovery is achieved through UPnP broadcast over UDP, the ESP8266 simply needs to spoof the response to pretend to be a supported device (such as the WeMo)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AdQvNBsoJMswyOP4kMIKY_Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AdQvNBsoJMswyOP4kMIKY_Q.png" alt="Reference: [http://hackaday.com/2015/07/16/how-to-make-amazon-echo-control-fake-wemo-devices/](http://hackaday.com/2015/07/16/how-to-make-amazon-echo-control-fake-wemo-devices/)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The response looks something like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;While browsing through the different sites detailing the protocol and data exchange, I came across this incredible GitHub project that has everything I need: WeMo spoofing with the ESP8266!&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/kakopappa" rel="noopener noreferrer"&gt;
        kakopappa
      &lt;/a&gt; / &lt;a href="https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch" rel="noopener noreferrer"&gt;
        arduino-esp8266-alexa-wemo-switch
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Amazon Alexa  + WeMos switch made with Arduino D1 Mini 
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;**&lt;strong&gt;&lt;em&gt;Update&lt;/em&gt;&lt;/strong&gt;** the author has an updated the repo to support multiple switches!&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/kakopappa" rel="noopener noreferrer"&gt;
        kakopappa
      &lt;/a&gt; / &lt;a href="https://github.com/kakopappa/arduino-esp8266-alexa-multiple-wemo-switch" rel="noopener noreferrer"&gt;
        arduino-esp8266-alexa-multiple-wemo-switch
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      multiple belkin wemos switch emulator using ESP8266
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Looks like my work is done!!! I edited the WiFi credentials to match my home network and gave the code a go. I told my Echo to discover devices and monitored the serial terminal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AcHj2A_7sMtFBBbgPeWoA3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AcHj2A_7sMtFBBbgPeWoA3g.png" alt="you could see a lot of UDP traffic going on"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Did it work? Let’s check the app!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AK3-rNQQOHD2bHAJ4hYrVrQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AK3-rNQQOHD2bHAJ4hYrVrQ.png" alt="w00t! on first try! awesome work @kakopappa!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So it found my ESP8266! The default name for the device is “box”, set by the String &lt;em&gt;device_name&lt;/em&gt; in the code, but I assume it can be named anything (not sure what the rules are, probably best to stay away from symbols and numbers).&lt;/p&gt;

&lt;p&gt;Now let’s try some commands! I hooked up a green LED to GPIO2 and yelled “Echo, box on!”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F7680%2F1%2AMCd2CU9Pwwbc-HtRJ5sd7g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F7680%2F1%2AMCd2CU9Pwwbc-HtRJ5sd7g.jpeg" alt="it worksssssss"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Putting It Together
&lt;/h2&gt;

&lt;p&gt;To create out IoT power switch, we just need to swap out the green LED for our solid state relay, and connect all the wires. Here’s the wiring diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AnaLf9QOR8JYPTNeFEaywYg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AnaLf9QOR8JYPTNeFEaywYg.png" alt="Note: I couldn’t find my relay model in Fritzing, but the Sharp relay has the same connections"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Be careful when working around mains AC! I used my glue gun to insulate all the mains connections (exposed PCB traces, wires, etc.).&lt;/p&gt;

&lt;p&gt;Now stuff everything in your project box and make sure there are no shorts. Screw on the duplex outlet and the wall plate onto the box:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F7680%2F1%2ASobr6ssONoL7z8lR5naZkw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F7680%2F1%2ASobr6ssONoL7z8lR5naZkw.jpeg" alt="Assembled! Looks like a plain ol’ socket (Note: the extension cord wires were not connected in this picture)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. All Done!
&lt;/h2&gt;

&lt;p&gt;The solid state relay is rated for 40A so you could connect this IoT power switch to a lot of different appliances (e.g. a 12,000 BTU air conditioner draws about 10A). Mine’s connected to only 3 LED bulbs, which is well within the relay’s constraints.&lt;/p&gt;

&lt;p&gt;The whole project cost me about $10 and 2 hours of time (thanks to kakopappa’s GitHub project!). Time to make use of my ESP8266 stash!&lt;/p&gt;

</description>
      <category>iot</category>
      <category>alexa</category>
      <category>esp8266</category>
      <category>arduino</category>
    </item>
    <item>
      <title>Control your Intel Edison in Realtime with Websockets (and ngrok)!</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 19:42:33 +0000</pubDate>
      <link>https://dev.to/w4ilun/control-your-intel-edison-in-realtime-with-websockets-and-ngrok-4d9g</link>
      <guid>https://dev.to/w4ilun/control-your-intel-edison-in-realtime-with-websockets-and-ngrok-4d9g</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;First off, I would like to thank &lt;a href="https://medium.com/u/8a9d5e8e66bc"&gt;Nathan Meryash&lt;/a&gt; for his suggestions! In my next few posts, I will describe using different cloud services and technologies for your IoT project.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Following up with &lt;a href="https://dev.to/w4ilun/updated-control-your-intel-edison-in-realtime-with-websockets-l9a"&gt;Control your Intel Edison in Realtime with Websockets!&lt;/a&gt;, this post briefly describes how you could expose your connected device to the public web using &lt;a href="https://ngrok.com/"&gt;ngrok&lt;/a&gt;. This is useful if you would like to be able to control your device from outside of your home network, without having to setup port forwarding and/or DDNS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ngrok.com/"&gt;ngrok&lt;/a&gt; is a service that “exposes a local server behind a NAT or firewall to the internet”. There is no signup required and you get a public URL accessible from the Internet!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mR6CEe4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2400/1%2AYzvuotOQ3ntlxsrdr53XkQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mR6CEe4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2400/1%2AYzvuotOQ3ntlxsrdr53XkQ.png" alt="Image courtesy of ngrok [https://ngrok.com/](https://ngrok.com/)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are 2 additional packages that you would need to install:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install ngrok --save
npm install express-dot-engine --save
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;ngrok&lt;/em&gt;&lt;/strong&gt;: an npm module for using ngrok. It allows you to programmatically create a new ngrok instance URL (e.g. &lt;a href="https://571a6a18.ngrok.io"&gt;https://571a6a18.ngrok.io&lt;/a&gt;) and bind it to your local server IP and port.&lt;/p&gt;

&lt;p&gt;**express-dot-engine: **a lightweight template engine for embedding our ngrok URL into our index.html file&lt;/p&gt;

&lt;p&gt;Here is the new code that has been updated to include the use of ngrok and the &lt;a href="https://github.com/olado/doT"&gt;dot&lt;/a&gt; template engine with Express:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;




&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Then, simply run:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node blinkWithSocketsNgrok.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;…and go to the generated URL from anywhere on the web!&lt;/p&gt;

</description>
      <category>iot</category>
      <category>hardware</category>
      <category>ngrok</category>
      <category>websockets</category>
    </item>
    <item>
      <title>$2 Bluetooth Tags and Tangible UIs for IoT</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 19:34:53 +0000</pubDate>
      <link>https://dev.to/w4ilun/2-bluetooth-tags-and-tangible-uis-for-iot-4bjf</link>
      <guid>https://dev.to/w4ilun/2-bluetooth-tags-and-tangible-uis-for-iot-4bjf</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have a “smart” home. All the lighting in my home is wirelessly connected and I also have a “smart” outlet that lets me turn any appliance on/off that’s connected to it. It was one my first purchases on my quest to “internet all the things” at home.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IVj3PgO---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AxM8UPnvaVtSJNBRYcVfTdw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IVj3PgO---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AxM8UPnvaVtSJNBRYcVfTdw.jpeg" alt="I got a starter pack with 2 of these bulbs and a gateway for $25"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7KmBQqvc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ADk5LRvsjXnn2jZjzXqXIrQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7KmBQqvc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ADk5LRvsjXnn2jZjzXqXIrQ.jpeg" alt="Quirky’s smart outlet. Only 2 of the 4 sockets are “smart”"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Installation was relatively painless and I enjoyed the novelty of being able to control everything through my phone. It lasted about a full week before I found it quite inconvenient that I have to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;pick up my phone&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;unlock my phone&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;load the app&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;find my device&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;…then finally clicking the adorable lightbulb drawing to turn on the lights.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;My “smart” home doesn’t feel so smart when turning on the lights is now 5 steps instead of the flick of a switch. Of course, this is ignoring the fact that I could also set schedules, dim lights, set scenes, and do all of that from anywhere in the world. But for my day to day operation, this experience feels much worse than it’s “dumb”equivalent.&lt;/p&gt;

&lt;p&gt;Interacting with IoT devices has always been an interesting problem to me. A lot of “smart appliances” and connected devices on the market still rely on a smartphone app for controlling and configuring them. While this makes sense for more complex devices that benefit from a rich GUI (e.g. Dropcam), and/or for devices that are highly automated where very little daily interaction is required (e.g. NEST thermostat), it makes less sense for simple devices that are frequently operated.&lt;/p&gt;

&lt;p&gt;That is part of the reason why I love my Amazon Echo; its voice based UI (aka Alexa) was a much better experience when interacting with the smart devices in my home. Now all I have to do is say “Echo, lights off” (I can’t help but feel like Iron Man and J.A.R.V.I.S. every time I do this)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yRVp6-WZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Ai24huA2t1LjAO9-Y86GZzQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yRVp6-WZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Ai24huA2t1LjAO9-Y86GZzQ.jpeg" alt="Though not perfect, its speech recognition abilities are quite impressive"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But sometimes I don’t want to talk. Sometimes I’m far away and I don’t want to yell. Sometimes people are sleeping and I don’t want to make a noise. I missed my simple wall switch that didn’t have any of these problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter the (tangible) button
&lt;/h2&gt;

&lt;p&gt;I did some research to find a solution (and often, the solution is to buy more things) and I came across the &lt;a href="https://flic.io/"&gt;FLIC&lt;/a&gt; button, a small BLE button that you could stick anywhere, and program it to do things.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7dtFIyfm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AgbdSC8zqVAsnK5h4wfP_kw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7dtFIyfm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AgbdSC8zqVAsnK5h4wfP_kw.jpeg" alt="Small bluetooth button that could do so much [https://flic.io/](https://flic.io/)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dIEM01Ab--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AgcJKJ8GDtEh-3oFh5xjsaA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dIEM01Ab--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AgcJKJ8GDtEh-3oFh5xjsaA.jpeg" alt="Take a selfie! Open a door! There’s a button for everything!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This solved my problem! It looks like a well engineered product, and also has a very nice app to complement! With &lt;a href="https://ifttt.com/"&gt;IFTTT&lt;/a&gt; integration, the possibility are endless.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lRkmKxpA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AtV8ko7_9wACqrfbt0be9sA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lRkmKxpA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AtV8ko7_9wACqrfbt0be9sA.png" alt="IFTTT integration. Idea: button to buy more FLIC buttons."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;…but it’s also $35 and I don’t want to pay that price. Don’t get me wrong, I think this price is well justified for all the R&amp;amp;D and design work that has gone into this product (hardware and software). I just couldn’t justify myself buying this particular gadget, given the amount of Arduinos, RPis, Edisons, and BLE/ZigBEE/LoRA/ZWave modules that I had lying around; I wanted to build something.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter the ($2) tangible (BLE) button
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uhcTyrrK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AR_FFTTZNbiQ2f6H6drrVMw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uhcTyrrK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AR_FFTTZNbiQ2f6H6drrVMw.png" alt="I found this on eBay for $2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A quick search on eBay brought me to &lt;a href="http://www.ebay.com/itm/Smart-Finder-Bluetooth-Tracer-Pet-Child-GPS-Locator-Tag-Alarm-Wallet-Key-Tracker-/111918348768"&gt;this&lt;/a&gt; interesting little gadget; a BLE button/tag/tracker device that’s meant to serve as a selfie button, but also doubles as a tag that beeps if your paired phone goes out of range. You could also use it as a keychain, and trigger the tag to beep to find it. The description was loose on details, but at $2 I just had to give it a try.&lt;/p&gt;

&lt;h2&gt;
  
  
  Experimenting with the button
&lt;/h2&gt;

&lt;p&gt;I turned to my favourite BLE library &lt;a href="https://github.com/sandeepmistry/noble"&gt;noble&lt;/a&gt; by &lt;a href="https://twitter.com/sandeepmistry"&gt;@sandeepmistry&lt;/a&gt; to do some service and characteristic discovery (e.g. &lt;strong&gt;noble.startScanning()&lt;/strong&gt;, &lt;strong&gt;peripheral.discoverServices()&lt;/strong&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;GENERIC ATTRIBUTE&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IMMEDIATE ALERT&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TX POWER&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;LINK LOSS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;BATTERY SERVICE&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CUSTOM SERVICE 1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CUSTOM SERVICE 2&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Of which CUSTOM SERVICE 1 was the one that was most interesting to me right now, because it had a characteristic with the &lt;strong&gt;notify&lt;/strong&gt; property. You can subscribe to this characteristic and get notified with the value 0x01 when the button is pressed.&lt;/p&gt;

&lt;p&gt;So after all that, it was just a matter of hooking the characteristic’s notify callback into the APIs that controlled my “smart” home:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--di0KdZ24--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AZHXeF8xVcG4fGgORPHtZUA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--di0KdZ24--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AZHXeF8xVcG4fGgORPHtZUA.gif" alt="sorry about the vertical video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enjoy :)&lt;/p&gt;

</description>
      <category>iot</category>
      <category>ble</category>
      <category>hardware</category>
    </item>
    <item>
      <title>Experimenting with Google’s Cloud Vision API + Intel Edison</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 19:31:38 +0000</pubDate>
      <link>https://dev.to/w4ilun/experimenting-with-google-s-cloud-vision-api-intel-edison-257i</link>
      <guid>https://dev.to/w4ilun/experimenting-with-google-s-cloud-vision-api-intel-edison-257i</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I first learned about Google’s Cloud Vision API at this year’s Google I/O. Though it’s been out in beta since 2015, I had not heard of it, nor had the chance to try it out till today. I came across this blog &lt;a href="https://www.raspberrypi.org/blog/raspberry-pi-cloud-vision-google-io/"&gt;post&lt;/a&gt; and was intrigued by the YouTube demo:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/eve8DkkVdhI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;As always, I have an Intel Edison lying around so I decided to give it a try.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before you begin:
&lt;/h2&gt;

&lt;p&gt;Make sure your Edison has been updated to the latest firmware and has Wi-Fi setup, use the setup/configuration tool found &lt;a href="https://software.intel.com/en-us/iot/hardware/edison/downloads"&gt;here&lt;/a&gt; to do so.&lt;/p&gt;

&lt;p&gt;You will also need a Google Cloud account with the Vision API enabled. Follow these instructions &lt;a href="https://cloud.google.com/vision/docs/quickstart#before_you_begin"&gt;here&lt;/a&gt; to do so before proceeding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things you’ll need:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Intel Edison w/ Arduino Breakout Board (You could also use the mini breakout but you might need a USB adapter to connect a webcam&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logitech C270 Webcam (Any other USB webcam supported by Linux UVC drivers would work too)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Power Supply&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s how it’s all connected:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v5diLuyT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2826/1%2ARTr6qiLtWP7kHiOSlnwmqQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v5diLuyT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2826/1%2ARTr6qiLtWP7kHiOSlnwmqQ.jpeg" alt="Note the position of the tiny switch; it is closer to the big USB port"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s go!
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;For the USB webcam to work, make sure UVC drivers are installed and enabled; you can find instructions &lt;a href="https://github.com/drejkim/edi-cam#installing-the-uvc-driver"&gt;here&lt;/a&gt; on how to do that.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;strong&gt;ffmpeg&lt;/strong&gt;. Git clone the &lt;a href="https://github.com/drejkim/edi-cam"&gt;edi-cam&lt;/a&gt; repository and run the shell script to install ffmpeg:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@edison:~# cd /edi-cam/bin
root@edison:~# ./install_ffmpeg.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;strong&gt;gcloud&lt;/strong&gt;. This is the Google Cloud NodeJS module that allows you to easily use Google Cloud APIs.&lt;/p&gt;

&lt;p&gt;root@edison:~# npm install gcloud&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy over your service account key JSON created during setup (scp/sftp). You can create a new one &lt;a href="https://console.developers.google.com/projectselector/apis/credentials"&gt;here&lt;/a&gt; if you’ve lost it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the code! Copy &amp;amp; Paste this snippet into VIM or transfer the file over:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@edison:~# node capture.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;Here’s the image that was captured by my webcam:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G2k3yDt8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A5ja94TUqiPHiaf_nfPxAZA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G2k3yDt8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A5ja94TUqiPHiaf_nfPxAZA.jpeg" alt="It’s a Hello Kitty Robot!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here’s the returned JSON:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@edison:~# node capture.js

[ { desc: ‘cartoon’, mid: ‘/m/0215n’, score: 85.945672 },

{ desc: ‘machine’, mid: ‘/m/0dkw5’, score: 74.98506900000001 },

{ desc: ‘robot’, mid: ‘/m/06fgw’, score: 69.911 },

{ desc: ‘gadget’, mid: ‘/m/02mf1n’, score: 67.246151 } ]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;…I thought that was pretty cool :)&lt;/p&gt;

&lt;p&gt;The Google Cloud Vision API actually has a lot of other powerful features, including &lt;strong&gt;analyzing emotional facial attributes, text extraction &amp;amp; detection, and detecting any [faces, landmarks, labels, logos, properties]&lt;/strong&gt; in your images.&lt;/p&gt;

&lt;p&gt;Vision capabilities perfectly complement robotic applications (e.g. a drone that tazes you if you’re not smiling, a spray paint bot that corrects graffiti grammar, etc.). I can’t wait to see what kind of cool things people will make with this!&lt;/p&gt;

</description>
      <category>iot</category>
      <category>machinelearning</category>
      <category>ai</category>
      <category>computervision</category>
    </item>
    <item>
      <title>Real time sensor data from the Intel Edison via Websockets</title>
      <dc:creator>w4ilun</dc:creator>
      <pubDate>Sat, 22 Aug 2020 19:23:45 +0000</pubDate>
      <link>https://dev.to/w4ilun/real-time-sensor-data-from-the-intel-edison-via-websockets-4274</link>
      <guid>https://dev.to/w4ilun/real-time-sensor-data-from-the-intel-edison-via-websockets-4274</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;(Note: these posts are migrated from my previous &lt;a href="https://medium.com/@monkeytypewritr"&gt;medium.com&lt;/a&gt; blog)&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s been a while since my last post &lt;a href="https://dev.to/w4ilun/updated-control-your-intel-edison-in-realtime-with-websockets-l9a"&gt;Control your Intel Edison in Realtime with Websockets!&lt;/a&gt; There’s been tons of updates on documentation, tools, and libraries that allow setting up and development a lot easier. Check out the &lt;a href="https://software.intel.com/en-us/iot/hardware/edison/downloads"&gt;downloads&lt;/a&gt; page to get the new installer and latest firmware.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The following tutorial assumes an Intel Edison already updated and setup with connectivity. If you have a fresh out of the box Intel Edison, please follow this &lt;a href="https://software.intel.com/en-us/iot/library/edison-getting-started"&gt;guide&lt;/a&gt; or my previous &lt;a href="https://dev.to/w4ilun/updated-control-your-intel-edison-in-realtime-with-websockets-l9a"&gt;post&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Read sensor data using the UPM repository
&lt;/h3&gt;

&lt;p&gt;UPM is a high level repository for sensors/actuators that uses &lt;a href="https://github.com/intel-iot-devkit/mraa"&gt;MRAA&lt;/a&gt;. Check out the list of supported sensors &lt;a href="http://iotdk.intel.com/docs/master/upm/modules.html"&gt;here&lt;/a&gt;. If the sensor you are using is already supported by UPM, you will save a lot of time by getting a high level interface.&lt;/p&gt;

&lt;p&gt;If the sensor you are using is not found in UPM, feel free to submit an issue or a pull request on Github. You can of course always use &lt;a href="https://github.com/intel-iot-devkit/mraa"&gt;MRAA&lt;/a&gt; to read raw data from your sensor (e.g. via Analog, I²C, SPI, UART, etc.)&lt;/p&gt;

&lt;p&gt;For this tutorial, I will be using the &lt;a href="http://www.seeedstudio.com/depot/Grove-Temperature-Sensor-p-774.html"&gt;temperature sensor&lt;/a&gt; from my &lt;a href="http://www.seeedstudio.com/depot/Grove-starter-kit-plus-Intel-IoT-Edition-for-Intel-Galileo-Gen-2-and-Edison-p-1978.html"&gt;Grove Starter Kit&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mZMAUCqT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Ab2exyH9GCcd84lnR9LD4ow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mZMAUCqT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Ab2exyH9GCcd84lnR9LD4ow.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This temperature sensor uses a thermistor to detect temperature. A thermistor is a device that will change its resistance when the temperature changes. By measuring the voltage output from this sensor with an analog pin, we are able to determine the temperature by looking up the sensor’s datasheet. Luckily for us, UPM has done that for use already. Learn more about thermistors &lt;a href="https://en.wikipedia.org/wiki/Thermistor"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I connected my temperature sensor to analog pin &lt;strong&gt;A0&lt;/strong&gt;, as shown in the picture below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BtrZToq5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/7680/1%2AyYh8gmefhcFN1qIsSMvDcg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BtrZToq5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/7680/1%2AyYh8gmefhcFN1qIsSMvDcg.jpeg" alt="you can connect to any analog pin you like, just make sure you reference it correctly in your code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;UPM supports the Grove Temperature Sensor and also includes example &lt;a href="https://github.com/intel-iot-devkit/upm/blob/master/examples/javascript/grovetemp.js"&gt;code&lt;/a&gt;. I am going to &lt;em&gt;wget&lt;/em&gt; the example code on my Intel Edison and run it:&lt;/p&gt;



&lt;p&gt;…and you should see the following output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8KP96BQ5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AD1LJgCp1dp-KjQF0V3dRiQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8KP96BQ5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AD1LJgCp1dp-KjQF0V3dRiQ.png" alt="it’s quite hot in my room"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look at the code in &lt;strong&gt;grovetemp.js&lt;/strong&gt;, you will see that it is basically instantiating the temperature sensor object and repeatedly calling &lt;strong&gt;temp.value()&lt;/strong&gt; to get the latest temperature reading.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Pushing sensor data via Websockets
&lt;/h3&gt;

&lt;p&gt;Well that was easy :) Now all we have to do is push this data via websockets to a UI, using Socket.IO like the last tutorial:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Put these two files on your Intel Edison and run:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node tempsensorsocket.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Be sure to have express and socket.io installed already, and change the IP address in index.html&lt;/p&gt;

&lt;p&gt;You should be seeing the live temperature data in your browser, try touching the sensor to see the temperature go up :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KlteaNY2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A1frZEtNHPThbQjK3aN1kTg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KlteaNY2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A1frZEtNHPThbQjK3aN1kTg.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In 40 lines of code we were able to stream live temperature sensor data via websockets! This is only possible with great open source libraries like Socket.IO, Express, UPM, and MRAA.&lt;/p&gt;

&lt;p&gt;This tutorial itself serves as a starting point and there are tons of other things you could add on to it. A fancy CSS dashboard? Cloud Analytics? Turning on your AC when it gets too hot? Start the sprinklers?&lt;/p&gt;

&lt;p&gt;What will you make?&lt;/p&gt;

</description>
      <category>iot</category>
      <category>hardware</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
