<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by w4ilun on Medium]]></title>
        <description><![CDATA[Stories by w4ilun on Medium]]></description>
        <link>https://medium.com/@monkeytypewritr?source=rss-b5931d74fca5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*eozUCR44u4D_OpAr.jpeg</url>
            <title>Stories by w4ilun on Medium</title>
            <link>https://medium.com/@monkeytypewritr?source=rss-b5931d74fca5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 19:51:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@monkeytypewritr/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building an E-Ink Air Quality Monitor w/ Home Assistant Integration]]></title>
            <link>https://medium.com/@monkeytypewritr/building-an-e-ink-air-quality-monitor-w-home-assistant-integration-b9a5602e2e7b?source=rss-b5931d74fca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9a5602e2e7b</guid>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[air-quality]]></category>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[w4ilun]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 03:10:07 GMT</pubDate>
            <atom:updated>2026-02-18T03:10:07.354Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9J6MA92CxpsZqaQRD1oiAQ.png" /></figure><p>I’ve been spending a lot more time indoors lately, and have been more conscious about the air quality in my home. Jumping down the rabbit hole, I learned a little about the different metrics for measuring air quality:</p><ul><li>VOC index (chemicals in household/cleaning products, off-gassing, e.g. formaldehyde)</li><li>CO2 (the air we breath out, a good measure of ventilation)</li><li>NOx index (vehicle exhaust, gas-burning appliances such as stoves)</li><li>PM 1/2.5/10 (particulate matter in the air we breath e.g. cooking, dust, pollen, wildfires)</li></ul><p>I then went on to Amazon to look for a product that could measure all of the above, be reasonably price, had a cool looking form factor, and integrated nicely with my Home Assistant setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*yH2gd1L2YVNQALbb3gc65g.png" /><figcaption>Nothing really stood out or had all the features I wanted.</figcaption></figure><p>Nothing immediately caught my eye or checked all the boxes, so I went on to see what it took to build my own. I already had too many unfinished projects, so I didn’t want to spend too much time on a custom/complex solution i.e. no custom PCBs, just hand wiring, and only a few parts; I wanted something I could put together in a few days.</p><h3>MVP</h3><p>After some Googling, I came across the <a href="https://sensirion.com/sen6x-air-quality-sensor-platform">Sensirion’s SEN6x sensor</a>; it combined all of the sensors I needed in a compact form factor, so I only needed to wire up a microcontroller and a display, it was perfect for this project. The entire design was then centered around this sensor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*PuPyzDqvs_xfseKF" /><figcaption>A nice integrated compact solution, at a price</figcaption></figure><p>I wanted to keep the form factor small, and didn’t want a big bright LCD screen that would keep me up at night, so I chose an 1.54&quot; e-ink screen; it was reasonably priced and just big enough to be legible. There were many e-ink modules to choose from, but in the end I chose <a href="https://www.aliexpress.us/item/3256806104827483.html">WeAct Studio’s module</a> because it included a wiring harness that would simplify the wiring. I also needed a tiny microcontroller with Wi-Fi that integrated nicely with Home Assistant (i.e. ESPHome support), and the <a href="https://www.seeedstudio.com/Seeed-XIAO-ESP32C3-p-5431.html">Seeed Xiao ESP32-C3</a> was something I already had in my parts bin.</p><p>Having picked out all the parts, I just needed to wire it all together:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*Dirx0gYR9zB1XNiOphlz6Q.png" /><figcaption>1.54&quot; E-Ink Display w/ 200x200 resolution.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dvaOWOdExzJFGdn9yioL6A.png" /><figcaption>I just picked the most convenient pins to wire up the display and sensor to the ESP32-C3</figcaption></figure><p>The display is connected to the ESP32-C3 over SPI, while the SEN66 sensor is connected over I2C. Since the SEN66 had 2 sets of VCC/GND pins that are connected together, I was able to use them to power the display and not have to crowd the 3V3/GND pads on the ESP32-C3.</p><p>I wrote a quick sanity check Arduino sketch to make sure everything was working: an I2C scan found the SEN66 at 0x6B, and I was able to show “Hello World” on the e-ink display.</p><h3>Enclosure Design</h3><p>With the electronics now “working”, the next thing I needed to do was to stuff everything into an enclosure. I wanted something minimalistic that didn’t take up too much desk space, and had an industrial aesthetic to it. The <a href="https://sensirion.com/search/downloads?q=SEN6x">SEN6x downloads page</a> provided assembly guidelines and reference design CAD files that I used as a starting point for my design.</p><p>I simply stacked the display on top of the SEN66 sensor, wedged the ESP module in the middle, and added a front grill for style points. Everything is held together by 4 x M2.5 screws from the front.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x2g8vFb0PnzUdiLPeikOJQ.png" /><figcaption>The front grill can be further customized to your liking</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jvi5Fq0EP8JaSqS14sDzzA.png" /><figcaption>Blocky rectangle, no chamfer or filet edges (except on the grill)</figcaption></figure><h3>Firmware</h3><p>Sensirion already provided an <a href="https://github.com/Sensirion/arduino-i2c-sen66">Arduino library</a> for the SEN6x, so reading from the sensor was straightforward by calling:</p><pre>sensor.startContinuousMeasurement();<br>sensor.readMeasuredValues(_pm1, _pm2, _pm4, _pm10, _hum, _temp, _voc, _nox, _co2);</pre><p>The <a href="https://github.com/ZinggJM/GxEPD2">GxEPD2</a> library provided all the drawing primitives for the e-ink display (it supports the 1.54&quot; display used here and many more). I <a href="https://lopaka.app/">designed a simple UI</a> to display all the sensor readings, and added a little smiley/frowny face to represent good/bad air quality:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L39Bi2ssRYnmdBNvn10Ztw.png" /><figcaption>I love the blocky pixel font ORG_01</figcaption></figure><p>Using both libraries, I was able to string together a minimal Arduino firmware that read from the sensor and rendered the readings on the display. This was sufficient as a standalone device, but I also needed to add support for ESPHome to integrate with my Home Assistant setup. At the time of writing, ESPHome did not have native support for SEN6x sensors (PR in review), and it wasn’t straight forward to port over my UI as a display component + lambdas. The solution was to create an <a href="https://esphome.io/components/external_components/">external component</a> to port over the C++ code from my minimal sketch, and publish the sensor data at regular intervals:</p><pre>    // Publish to Home Assistant sensors<br>    if (this-&gt;temperature_sensor_ != nullptr)<br>      this-&gt;temperature_sensor_-&gt;publish_state(temperature);<br>    if (this-&gt;humidity_sensor_ != nullptr)<br>      this-&gt;humidity_sensor_-&gt;publish_state(humidity);<br>    if (this-&gt;co2_sensor_ != nullptr)<br>      this-&gt;co2_sensor_-&gt;publish_state(static_cast&lt;float&gt;(co2));<br>    if (this-&gt;voc_sensor_ != nullptr)<br>      this-&gt;voc_sensor_-&gt;publish_state(voc_index);<br>    if (this-&gt;nox_sensor_ != nullptr)<br>      this-&gt;nox_sensor_-&gt;publish_state(nox_index);<br>    if (this-&gt;pm_1_0_sensor_ != nullptr)<br>      this-&gt;pm_1_0_sensor_-&gt;publish_state(pm1p0);<br>    if (this-&gt;pm_2_5_sensor_ != nullptr)<br>      this-&gt;pm_2_5_sensor_-&gt;publish_state(pm2p5);<br>    if (this-&gt;pm_4_0_sensor_ != nullptr)<br>      this-&gt;pm_4_0_sensor_-&gt;publish_state(pm4p0);<br>    if (this-&gt;pm_10_0_sensor_ != nullptr)<br>      this-&gt;pm_10_0_sensor_-&gt;publish_state(pm10p0);if (this-&gt;temperature_sensor_ != nullptr)</pre><p>You can also expose all the configuration variables in the __init__.py file so that they can be configured in the YAML e.g. I2C/SPI pins, update interval, bad air quality thresholds, etc.</p><pre>  update_interval: 60s<br>  time_id: ntp_time<br>  # I2C pins (SEN66)<br>  i2c_sda: 10<br>  i2c_scl: 9<br>  # SPI pins (e-paper GDEH0154D67)<br>  epd_mosi: 7<br>  epd_sclk: 6<br>  epd_cs: 5<br>  epd_dc: 4<br>  epd_rst: 3<br>  epd_busy: 2<br>  # Display settings<br>  display_rotation: 0   # 0=vertical_up, 1=horizontal_left, 2=vertical_down, 3=horizontal_right<br>  use_fahrenheit: false<br>  # Air quality thresholds for &quot;good&quot; face indicator<br>  aq_co2_max: 1000<br>  aq_voc_max: 150<br>  aq_nox_max: 1<br></pre><h3>ESPHome + HA Integration</h3><p>After creating the external component and adding it to my Github repo, I was able to point the YAML to it and have ESPHome Builder build a custom firmware for my device with the WiFi credentials and API keys needed to integrate with my HA setup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*XO60p3bE2rMhuHjpFf9I4w.png" /><figcaption>Validated the YAML, built the firmware, and flashed it through the browser</figcaption></figure><p>It took a few seconds to connect, then hurray 🎉🎉🎉I can see my sensor readings on HA :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*kPr3FeblJYq69Lut8dkFmQ.png" /></figure><h3>Do-It-Yourself</h3><p>Everything is fully open source as usual, you can find the 3D CAD files, firmware, and wiring diagrams on my GitHub <a href="https://github.com/w4ilun/aqaio">https://github.com/w4ilun/aqaio</a></p><p>Total Cost: ~$68</p><ul><li>SEN66 sensor module — $44.26</li><li>Seeed Xiao ESP32-C3 — $4.99</li><li>1.54&quot; E-paper Display — $8.47</li><li>Miscellaneous (M2.5 screws, 3D printing filament, wires, shipping, etc.) — ~$10</li></ul><p>Happy Building!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9a5602e2e7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an IoT badge with ESP8266 & ePaper]]></title>
            <link>https://medium.com/@monkeytypewritr/esp8266-iot-badge-epaper-c6ef25bdd521?source=rss-b5931d74fca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6ef25bdd521</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[badges]]></category>
            <dc:creator><![CDATA[w4ilun]]></dc:creator>
            <pubDate>Fri, 29 Dec 2017 05:38:32 GMT</pubDate>
            <atom:updated>2025-06-18T01:41:21.849Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building an IoT badge with ESP8266 + ePaper</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rl0reorzczFP0cSxAVyHEw.jpeg" /><figcaption>Hello, my name is badgy! I’m an ePaper IoT badge with a 5-way joystick!</figcaption></figure><p>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).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*zDgkVPau4Wz17rL6.gif" /></figure><p>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.</p><p>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.</p><p>So what can you do with an ESP8266, a battery, some buttons, and an ePaper display?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MLI28vtyl9CjFhhi29M4Jg.jpeg" /><figcaption>1. Smart Home Remote (Note the 5-way switch, up/down/left/right/center)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ltV5Tu1hsKyMMTfO9HdG1g.jpeg" /><figcaption>2. Weather Dashboard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3i4Js6116vv6xhCC2Ud6GQ.jpeg" /><figcaption>3. WiFi Manager</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cuLt-GF61HapCZMXzWsTPw.jpeg" /><figcaption>4. Display Notifications (IFTTT or other integrations)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o2exO9VkhtviintDdnDLQw.jpeg" /><figcaption>5. Name Tag</figcaption></figure><p>…and pretty much anything you can think of. It’s a tiny battery powered computer with WiFi connectivity!</p><h3>Building the badge</h3><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*T1EhpMPp16Y66GBY41sk5Q.png" /><figcaption>bunch of diodes, mosfets, and capacitors</figcaption></figure><p>As with many of my recent projects, I usually skip the breadboarding phase and jump straight to designing the PCB on <a href="http://kicad-pcb.org/">KiCad </a>(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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*n2tj9jjtoKZ9T8ticdMsug.png" /><figcaption>KiCad :)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*SDURT-hu1YQ9iUbohrx_WQ.jpeg" /><figcaption>The badge itself is barely larger than the display :)</figcaption></figure><p>After double/triple/quadruple checking everything, I sent the design off to a PCB fab to have the boards made…</p><p>The datasheet also thoroughly describes the timing and signals over SPI on how to control the display, but luckily for us, GitHub user <a href="https://github.com/ZinggJM">ZinggJM</a> created an Arduino library that abstracts all of that away :)</p><p><a href="https://github.com/ZinggJM/GxEPD">ZinggJM/GxEPD</a></p><p>It also leverages the Adafruit-GFX library, so you can use graphics primitives to do your drawing and rendering of images/text.</p><p>After 5 long days, the boards finally arrived!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gb3YUyZTJOO5yMJET_Y3LQ.jpeg" /><figcaption>badgy PCBs!</figcaption></figure><p>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)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LlM7S7zwSLb-qsgPBsk7QQ.jpeg" /><figcaption>Yay it works! Charging up the Li-Ion LIR2450 coin cell battery</figcaption></figure><p>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).</p><p>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:</p><p>120 mAh coin cell battery / (60uA regulator + 20uA deepsleep ESP8266) x 0.70 miscellaneous factors = 1050 hours ~= 43 days</p><p>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.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6ef25bdd521" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Your Own Midi Fighter]]></title>
            <link>https://medium.com/@monkeytypewritr/building-your-own-midi-fighter-406948137f8f?source=rss-b5931d74fca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/406948137f8f</guid>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[midi]]></category>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[music]]></category>
            <dc:creator><![CDATA[w4ilun]]></dc:creator>
            <pubDate>Sun, 10 Sep 2017 07:41:42 GMT</pubDate>
            <atom:updated>2017-09-11T03:26:30.720Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qAraVnTUeioD9Hl-COWvew.jpeg" /></figure><h3>What’s a Midi Fighter?</h3><p>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.</p><h3>What can you do with a Midi Fighter?</h3><p>Me? Not much. But check out what other skilled people can do:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FieSzJh4yKmA%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DieSzJh4yKmA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FieSzJh4yKmA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/18b664ab82c426d13a2c1aacc09f67a0/href">https://medium.com/media/18b664ab82c426d13a2c1aacc09f67a0/href</a></iframe><h3>Design Process</h3><p>After spending a few hours on YouTube watching amazing performances by these talented individuals (check out Shawn Wasabi’s <a href="https://www.youtube.com/channel/UCXLrdG_ZVt4US1iV40ytiQQ">YouTube channel</a>), 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.</p><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*SpAZpikbBsIThdY6u4TJ4g.jpeg" /><figcaption>I did some quick design work with Fusion 360 and exported the layout to a DXF file for CNC cutting.</figcaption></figure><p>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.</p><p>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 :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*Br4X7qQjQFWKMaTi8eFFTw.png" /><figcaption>These buttons were pricey but they’re so worth it :)</figcaption></figure><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*FeLCi4CPY3EkUiHfE-Lv3g.png" /><figcaption>No PCB design is complete without some artwork :)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*brkGpPpBG9yTgy_y_52gVg.jpeg" /><figcaption>The cluster of mess on the right are the LEDs coupled with bypass capacitors :p</figcaption></figure><p>You may have noticed that there are <strong>32 RGB LEDs</strong> 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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*6VoRO_RnNLtQycfFfv1cSQ.png" /><figcaption>These are so cute!</figcaption></figure><h3>Assembly</h3><p>All the designs were submitted for fabrication and after about 10 days, I received all of the parts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0liCk4yZlEiCNO9U88BoLQ.jpeg" /><figcaption>Electronics and PCB (Note the coil of SK6812 minis, I bought 200 of them)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QLPNqu_ucQH3YK71uDOz0g.jpeg" /><figcaption>Close up on the PCB art. I chose ENIG finish to really let the artwork shine (literally)</figcaption></figure><p>The first thing I wanted to test was to make sure the PCB, the buttons, and the mounting plate were all aligned properly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zEPpUTbiwsLV-mIK7c_MQg.jpeg" /><figcaption>Yay it fits!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RBSpPgrMzFzqojmc9D9i4g.jpeg" /><figcaption>Top view. I used countersunk aluminum washers with the M3 machine screws.</figcaption></figure><p>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.</p><p>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:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vBTyB6lf-eHK53Bjgq-uPg.jpeg" /><figcaption>Shiny, shiny buttons!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xvwlr38iwz2Chvff3HS0IA.jpeg" /><figcaption>Corner</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ZagBKo5U9Cds4HWh3TlPQ.jpeg" /><figcaption>Lights On! Better view of the sandwich construction</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jJ8Xr0jTHXZC3RPQP8B4LQ.jpeg" /><figcaption>Color: RGB(30,10,10) An improvement would be to add a cylindrical housing for each button to avoid light leaking</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r9_J7b7yaBP2jw_WyWH06A.jpeg" /><figcaption>Lowered the brightness for my camera, these LEDs are bright!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FA2OjUDONjthuMkbail71A.jpeg" /><figcaption>Completed build (Top Right) and all the parts to build one. I bought enough parts to build 5 :)</figcaption></figure><h3>Code</h3><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*deV4rZJLcd1qywvct3nWlw.png" /><figcaption>Follow this guide <a href="https://www.arduino.cc/en/Tutorial/ArduinoISP">https://www.arduino.cc/en/Tutorial/ArduinoISP</a></figcaption></figure><p>For the firmware, I used Adafruit’s <a href="https://github.com/adafruit/Adafruit_NeoPixel">NeoPixel library</a> and the <a href="https://www.arduino.cc/en/Reference/MIDIUSB">MIDIUSB library</a>. All of the buttons were mapped to a different note, and the LED underneath would change from pink to white when pressed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23bfe95e78fe20fd9285edc2f784b5fe/href">https://medium.com/media/23bfe95e78fe20fd9285edc2f784b5fe/href</a></iframe><p>Firmware source code and hardware design files are all open source and available on GitHub: <a href="https://github.com/w4ilun/midifighter">https://github.com/w4ilun/midifighter</a></p><h3>Showtime!</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F233169523&amp;dntp=1&amp;url=https%3A%2F%2Fvimeo.com%2F233169523&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F654432553_640.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="640" height="360" frameborder="0" scrolling="no"><a href="https://medium.com/media/db1dced1511e86ed6eb9cab80da8a8b5/href">https://medium.com/media/db1dced1511e86ed6eb9cab80da8a8b5/href</a></iframe><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O80c1jwiS340dcNAZsgMag.png" /></figure><h3>Next Steps</h3><p>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 :)</p><p>GLHF!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=406948137f8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Google Home assistant with Android Things]]></title>
            <link>https://medium.com/@monkeytypewritr/build-a-google-home-assistant-with-android-things-f3ea46c10084?source=rss-b5931d74fca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3ea46c10084</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[intel-edison]]></category>
            <category><![CDATA[google-home]]></category>
            <dc:creator><![CDATA[w4ilun]]></dc:creator>
            <pubDate>Sat, 08 Jul 2017 06:30:32 GMT</pubDate>
            <atom:updated>2017-07-12T02:56:32.225Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rLToXBX6juOTY_tPG9cK3g.png" /></figure><p>After playing around with <a href="https://medium.com/all-technology-feeds/android-things-getting-to-blinky-8c37dd36b259">Android Things for the first time</a>, 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 <a href="https://github.com/androidthings/sample-simplepio">GPIOs</a>, <a href="https://github.com/androidthings/sample-bluetooth-audio">Bluetooth audio</a>, and even one on <a href="https://github.com/androidthings/sample-tensorflow-imageclassifier">TensorFlow</a>.</p><p>At around the same time, Google announced their <a href="https://aiyprojects.withgoogle.com/">AIY Voice Ki</a>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UtMJt1a89jwnwI5b5e_h3g.png" /><figcaption>The kit came bundled with issue #57 of The MagPi</figcaption></figure><p>Much to my dismay, the kits were sold out everywhere, and scalpers were selling them for upwards of $90 on eBay :(</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*Y7CfklX6tWBTzAB8HZc6PA.png" /><figcaption>Me: sad</figcaption></figure><p>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 <a href="https://developers.google.com/assistant/sdk/overview">Google Assistant SDK</a>, which provides the APIs for the voice-based AI interactions.</p><p>Luckily for me, the Google Assistant APIs are supported on Android Things! Would it work on the Edison?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*sPEsGK9fhPtsqAE527KFwA.gif" /><figcaption>The LED on pin 13 blinks when playing an audio response</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*6E4n5sTY4NgTv_FxtSjaUw.png" /><figcaption>speech-to-text captured in the logs</figcaption></figure><p>It works! Now let’s see how to put it together…</p><h3>Things You’ll Need</h3><ul><li>Intel Edison with Arduino Breakout (though any Android Things supported device should work)</li><li><a href="http://www.ebay.com/itm/USB-3d-Audio-Sound-Card-Microphone-Headset-Adapter-/152202347054">USB sound card with mic input</a> (not needed if your board has audio jacks for in/out)</li><li>Speakers (I used my headphones because I don’t have any handy)</li><li><a href="http://www.ebay.com/itm/Tube-Hands-Free-Microphone-Lavalier-Lapel-For-SmartPhone-Laptop-PC-Notebook-/152393037334">Microphone</a></li><li>Arduino Shield + Button (you could also wire a momentary switch directly to a GPIO pin)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JAQfkKPgBq7Owi7jWwiDzA.jpeg" /><figcaption>The button is connected to IO4</figcaption></figure><h3>Running Google Assistant on Android Things</h3><p>The first thing you’ll need to do is to flash Android Things onto your device, you can follow my <a href="https://medium.com/all-technology-feeds/android-things-getting-to-blinky-8c37dd36b259">previous article</a> or use the <a href="https://developer.android.com/things/hardware/edison.html">official guide</a>. It might be a good idea to at least get to blinky first, so you know that you have a functioning Android Things device.</p><p>Once that’s done, you can then open the Google Assistant sample in Android Studio. You can find the sample code <a href="https://github.com/w4ilun/sample-googleassistant"><strong>here</strong></a><strong>,</strong> which I forked from the <a href="https://github.com/androidthings/sample-googleassistant">official repo</a>; I’ve made some minor changes to make it work with my setup, namely:</p><ul><li>Changed the button to activate on high instead of low</li></ul><pre>Button.LogicState.<strong><em>PRESSED_WHEN_HIGH</em></strong></pre><ul><li>Mapped button to IO4 (in BoardDefaults.java)</li></ul><pre><strong>public static </strong>String getGPIOForButton() {<br>    <strong>switch </strong>(<em>getBoardVariant</em>()) {<br>        <strong>case <em>DEVICE_EDISON_ARDUINO</em></strong>:<br>            <strong>return &quot;IO4&quot;</strong>;</pre><ul><li>Default to USB sound card instead of the Voice HAT for the Raspberry Pi</li></ul><pre>AUDIO_USE_I2S_VOICEHAT_IF_AVAILABLE = false</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bpZcUTjERGaFJUsKKq3cjQ.png" /><figcaption>I’m using Android Studio 2.3.2</figcaption></figure><p>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:</p><ul><li>Follow the instructions <a href="https://developers.google.com/assistant/sdk/prototype/getting-started-other-platforms/config-dev-project-and-account">here</a> to enable Google Assistant APIs and get your client secret JSON file. You can then rename that file to <strong>client_secret_NNNN.json</strong> to keep it short (if you want to). I also found this <a href="https://aiyprojects.withgoogle.com/voice/#users-guide-1-2--turn-on-the-google-assistant-api">guide</a> pretty useful .</li><li>Copy that file over to your projects root directory, then run Google’s oauthlib tool to generate the credentials.json</li></ul><pre>pip install google-auth-oauthlib[tool]<br>google-oauthlib-tool --client-secrets client_secret_NNNN.json \<br>                     --credentials app/src/main/res/raw/credentials.json \<br>                     --scope https://www.googleapis.com/auth/assistant-sdk-prototype \<br>                     --save</pre><p>All set! Now click run let the app build and deploy. It should build successfully and you’ll be greeted with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*sY_v-rq4dZ0q6FpOA1xCsw.png" /><figcaption>woohoo</figcaption></figure><p>Yay! Except nothing works, because the USB sound card is not connected…what?!</p><p>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 <strong>either</strong> use the micro USB port for the ADB shell connection to deploy and debug your application, <strong>or </strong>you can switch and use the larger USB host port for your sound card, <strong>but not both at the same time :(</strong></p><p>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 <a href="https://stackoverflow.com/questions/4893953/run-install-debug-android-applications-over-wi-fi">ADB shell over Wi-Fi instead</a>:</p><pre>$ adb tcpip 5555<br>$ adb connect &lt;DEVICE_IP_ADDRESS&gt;:5555<br>$ adb shell</pre><p>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 <a href="http://www.androidauthority.com/google-home-commands-727911/">comprehensive list</a>.</p><p>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, <a href="https://medium.com/@monkeytypewritr/amazon-echo-esp8266-iot-a42076daafa5">perhaps a spoofed WeMo switc</a>h? :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3ea46c10084" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Things — Getting to Blinky]]></title>
            <link>https://medium.com/all-technology-feeds/android-things-getting-to-blinky-8c37dd36b259?source=rss-b5931d74fca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c37dd36b259</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[w4ilun]]></dc:creator>
            <pubDate>Sun, 28 May 2017 01:32:17 GMT</pubDate>
            <atom:updated>2017-05-28T01:32:17.522Z</atom:updated>
            <content:encoded><![CDATA[<h3>Android Things — Getting to Blinky</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*-zngZt9QKntm-FBlBqumwQ.png" /><figcaption><a href="https://developer.android.com/things/index.html">https://developer.android.com/things/index.html</a></figcaption></figure><p>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 <a href="https://developer.android.com/things/sdk/index.html">official site</a>, 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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*z5pGPntELq-FD7eS.png" /><figcaption>Android Tings platform architecture</figcaption></figure><p>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.</p><h3>Hardware</h3><p>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 <a href="https://developer.android.com/things/hardware/developer-kits.html">https://developer.android.com/things/hardware/developer-kits.html</a> instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/0*ShITe8quFyntm0a4.jpg" /><figcaption>Follow the assembly guide found here <a href="https://software.intel.com/en-us/node/628221">https://software.intel.com/en-us/node/628221</a></figcaption></figure><h3>Software Setup</h3><p>We’ll need to download/install a couple of things to get started:</p><ol><li><a href="https://01.org/android-ia/downloads/intel-platform-flash-tool-lite"><strong>Intel Flash Tool Lite</strong></a> (For updating the firmware on the Intel Edison)</li><li><a href="https://developer.android.com/things/preview/download.html"><strong>Android Things System Image</strong></a> (Android Things System Image for your board)</li><li><a href="https://developer.android.com/studio/index.html"><strong>Android Studio</strong></a> (Our IDE and tools for development)</li></ol><p>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 <strong>adb </strong>and <strong>fastboot </strong>in your command prompt.</p><p>Once that’s ready, download the Intel Flash Tool Lite along with the Android Things System Image. You can follow this guide <a href="https://software.intel.com/en-us/articles/installing-android-things-on-intel-edison-kit-for-arduino"><strong>here</strong></a><strong> </strong>for details on how to update the firmware and install Android Things. The <strong>flashall.sh </strong>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:</p><ol><li>Run the Intel Flash Tool Lite to update the firmware, it should take about 30 seconds, with the board booting into <strong>FASTBOOT MODE</strong> if it was successful. You can monitor this from putty or screen terminal.</li><li>Once booted into <strong>FASTBOOT MODE</strong>, run the <strong>fastboot </strong>tool in a command prompt of your host computer to install the image:</li></ol><pre>$ fastboot \<br>    flash gpt        partition-table.img \<br>    flash u-boot     u-boot-edison.bin \<br>    flash boot_a     boot.img \<br>    flash boot_b     boot.img \<br>    flash system_a   system.img \<br>    flash system_b   system.img \<br>    flash gapps_a    gapps.img \<br>    flash gapps_b    gapps.img \<br>    flash oem_a      oem.img \<br>    flash oem_b      oem.img \<br>    set_active a \<br>    reboot</pre><p>3. Let your device reboot and wait for the adb shell:</p><pre>$ adb wait-<strong>for</strong>-device<br>$ adb shell<br>edison:/$</pre><p>…and you’re done! You now have Android Things running on your board!</p><p>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)</p><pre>edison: am startservice \<br>     -n com.google.wifisetup/.WifiSetupService \<br>     -a WifiSetupService.Connect \<br>     -e ssid &lt;SSID-name&gt; \<br>     -e passphrase &lt;SSID-password&gt;</pre><p>Wait a few seconds then try pinging an IP e.g. 8.8.8.8 to make sure it works.</p><h3>Creating your Android Things app</h3><p>Follow this <a href="https://developer.android.com/things/training/first-device/index.html">guide</a> 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 <a href="https://developer.android.com/studio/projects/create-project.html">guide</a> for creating my first Android project. You’ll need to target <strong>Android 7.0 (API 24) </strong>and make sure the SDK tools are up to date. Once the project has been created, you’ll need to modify the <strong>build.gradle </strong>and <strong>AndroidManifext.xml </strong>files to configure itself as an Android Things app:</p><p><strong>build.gradle</strong></p><pre>dependencies {<br>    ...<br>    provided &#39;com.google.android.things:androidthings:0.4-devpreview&#39;<br>}</pre><p><strong>AndroidManifest.xml</strong></p><pre>&lt;application<br>    android:label=&quot;@string/app_name&quot;&gt;<br>    &lt;uses-library android:name=&quot;com.google.android.things&quot;/&gt;<br>    &lt;activity android:name=&quot;.HomeActivity&quot;&gt;<br>        &lt;!-- Launch activity as default from Android Studio --&gt;<br>        &lt;intent-filter&gt;<br>            &lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;<br>            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;/&gt;<br>        &lt;/intent-filter&gt;<br><br>        &lt;!-- Launch activity automatically on boot --&gt;<br>        &lt;intent-filter&gt;<br>            &lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;<br>            &lt;category android:name=&quot;android.intent.category.IOT_LAUNCHER&quot;/&gt;<br>            &lt;category android:name=&quot;android.intent.category.DEFAULT&quot;/&gt;<br>        &lt;/intent-filter&gt;<br>    &lt;/activity&gt;<br>&lt;/application&gt;</pre><p>Build and run your project, it should succeed but it won’t be doing much at this point…</p><h3>Interacting with Peripherals</h3><p>The cool thing about Android Things (ha) is that developers are now able to interact with hardware peripherals in their application. Through the <strong>PeripheralManagerService </strong>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dI2GCggktpWkmLCu.png" /><figcaption>Example of connecting sensors and displays</figcaption></figure><p>In addition to the peripheral APIs, Android Things also has the concept of <strong>User-Space Drivers</strong>; 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 <a href="https://developer.android.com/things/sdk/driver-library.html"><strong>peripheral driver library</strong></a><strong> </strong>to see what’s already supported and how to add your own.</p><p>For now, we’re going to start thee basic Peripheral I/O APIs. Add the following code to your <strong>HomeActivity.java </strong>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)</p><pre>public class HomeActivity extends Activity {<br>    private static final String TAG = &quot;HomeActivity&quot;;<br><br>    @Override<br>    protected void onCreate(Bundle savedInstanceState) {<br>        super.onCreate(savedInstanceState);<br><br>        PeripheralManagerService service = new PeripheralManagerService();<br>        Log.d(TAG, &quot;Available GPIO: &quot; + service.getGpioList());<br>    }<br>}</pre><p>Build and run, open up the <strong>logcat</strong> window and you should see a list of GPIOs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9D8o3yLM5mvjx0nRI3riQ.png" /></figure><h3>Blinking an LED</h3><p>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:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Px9ydia-RxV4jcld.png" /><figcaption>There’s an on-board LED connected to pin 13, so you don’t need to if you don’t have one</figcaption></figure><p>Edit your <strong>HomeActivity.java </strong>with the following code:</p><pre><strong>public class </strong>HomeActivity <strong>extends </strong>Activity {<br>    <strong>private static final </strong>String <strong><em>TAG </em></strong>= <strong>&quot;HomeActivity&quot;</strong>;<br>    <strong>private static final int <em>INTERVAL_BETWEEN_BLINKS_MS </em></strong>= 1000;<br>    <strong>private static final </strong>String <strong><em>LED_PIN_NAME </em></strong>= <strong>&quot;IO13&quot;</strong>;<br><br>    <strong>private </strong>Handler <strong>mHandler </strong>= <strong>new </strong>Handler();<br><br>    <strong>private </strong>Gpio <strong>mLedGpio</strong>;<br><br>    @Override<br>    <strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>        <strong>super</strong>.onCreate(savedInstanceState);<br><br>        PeripheralManagerService service = <strong>new </strong>PeripheralManagerService();<br>        Log.<em>d</em>(<strong><em>TAG</em></strong>, <strong>&quot;Available GPIO: &quot; </strong>+ service.getGpioList());<br><br>        <strong>try</strong>{<br>            <strong>mLedGpio </strong>= service.openGpio(<strong><em>LED_PIN_NAME</em></strong>);<br>            <strong>mLedGpio</strong>.setDirection(Gpio.<strong><em>DIRECTION_OUT_INITIALLY_LOW</em></strong>);<br>            <strong>mHandler</strong>.post(<strong>mBlinkRunnable</strong>);<br><br>        }<strong>catch</strong>(IOException e){<br>            Log.<em>e</em>(<strong><em>TAG</em></strong>, <strong>&quot;Error on peripheral&quot;</strong>, e);<br>        }<br><br>    }<br><br>    @Override<br>    <strong>protected void </strong>onDestroy() {<br>        <strong>super</strong>.onDestroy();<br><br>        <em>// Step 4. Remove handler events on close.<br>        </em><strong>mHandler</strong>.removeCallbacks(<strong>mBlinkRunnable</strong>);<br><br>        <em>// Step 5. Close the resource.<br>        </em><strong>if </strong>(<strong>mLedGpio </strong>!= <strong>null</strong>) {<br>            <strong>try </strong>{<br>                <strong>mLedGpio</strong>.close();<br>            } <strong>catch </strong>(IOException e) {<br>                Log.<em>e</em>(<strong><em>TAG</em></strong>, <strong>&quot;Error on PeripheralIO API&quot;</strong>, e);<br>            }<br>        }<br>    }<br><br>    <strong>private </strong>Runnable <strong>mBlinkRunnable </strong>= <strong>new </strong>Runnable() {<br>        @Override<br>        <strong>public void </strong>run() {<br>            <em>// Exit if the GPIO is already closed<br>            </em><strong>if </strong>(<strong>mLedGpio </strong>== <strong>null</strong>) {<br>                <strong>return</strong>;<br>            }<br><br>            <strong>try </strong>{<br>                <em>// Step 3. Toggle the LED state<br>                </em><strong>mLedGpio</strong>.setValue(!<strong>mLedGpio</strong>.getValue());<br><br>                <em>// Step 4. Schedule another event after delay.<br>                </em><strong>mHandler</strong>.postDelayed(<strong>mBlinkRunnable</strong>, <strong><em>INTERVAL_BETWEEN_BLINKS_MS</em></strong>);<br>            } <strong>catch </strong>(IOException e) {<br>                Log.<em>e</em>(<strong><em>TAG</em></strong>, <strong>&quot;Error on PeripheralIO API&quot;</strong>, e);<br>            }<br>        }<br>    };<br>}</pre><p>Here’s what’s happening: We’ve created an instance of <strong>Gpio</strong>, set it to pin 13 using the <strong>PeripheralManagerService, </strong>set it to output and off initially with <strong>DIRECTION_OUT_INITIALLY_LOW</strong>, then using the <strong>setValue </strong>method to turn it on/off.</p><p>That’s it! Congratulations on blinking an LED on Android Things!</p><p>If you don’t want to type out these code snippets, you can just head over to <a href="https://developer.android.com/things/sdk/samples.html">https://developer.android.com/things/sdk/samples.html</a> 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.</p><p>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 :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c37dd36b259" width="1" height="1" alt=""><hr><p><a href="https://medium.com/all-technology-feeds/android-things-getting-to-blinky-8c37dd36b259">Android Things — Getting to Blinky</a> was originally published in <a href="https://medium.com/all-technology-feeds">All Technology Feeds(Powered by Algoworks)</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building your own keyboard (from scratch)]]></title>
            <link>https://medium.com/@monkeytypewritr/building-your-own-keyboard-from-scratch-bd0638c40850?source=rss-b5931d74fca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd0638c40850</guid>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[mechanical-keyboards]]></category>
            <category><![CDATA[pcb]]></category>
            <category><![CDATA[keyboard]]></category>
            <dc:creator><![CDATA[w4ilun]]></dc:creator>
            <pubDate>Wed, 15 Mar 2017 04:44:10 GMT</pubDate>
            <atom:updated>2017-04-09T23:01:17.910Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*loCuO5dJZUmIX7mG." /></figure><p>Another interest of mine are computer keyboards. I’ve acquired this interest relatively recently, and have spent many hours since perusing /r/MechanicalKeyboards:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cWzjVYfIR7n15eCP.jpg" /><figcaption>/u/aaron6301</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z60rW-ZVlnVxdpTm.jpg" /><figcaption>/u/<a href="https://www.reddit.com/user/fathovercats">fathovercats</a></figcaption></figure><p>Aren’t these beautiful? They come in all sorts of colors, sizes, lights, layouts, switches, and <strong>price</strong>. And as a tool that I use everyday, it was easy for me to justify my purchases :)</p><p>At the high end, these keyboards are often custom designed and hand assembled: CNC’d aluminum plates, RGB underglow, custom PCB/firmware, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u1-ctn9r67hdTm1a.jpg" /><figcaption><a href="http://www.gonskeyboardworks.com/">http://www.gonskeyboardworks.com/</a></figcaption></figure><h3>Building one?</h3><p>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. <a href="https://github.com/komar007/gh60">GH60</a>) to software/firmware (e.g. <a href="https://github.com/tmk/tmk_keyboard">TMK</a>/<a href="https://github.com/qmk/qmk_firmware">QMK</a>).</p><p>Ever since building my <a href="https://medium.com/@monkeytypewritr/building-a-bluetooth-le-lego-controller-web-bluetooth-app-754a9993d511#.c3ocf1i4b">Lego BLE controller</a>, I’ve wanted to take on a more advanced project, and this seemed like the perfect one!</p><p><strong>Hardware</strong></p><p>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 <em>2n</em> pins only for a <em>n </em>x<em> n</em> matrix. You can read more about how that works in this excellent <a href="http://blog.komar.be/how-to-make-a-keyboard-the-matrix/">article</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5apsaKutI0lc03KOat5LfQ.png" /><figcaption>Note the 5 way tactile switch I added. It functions as arrow keys or a mouse!</figcaption></figure><p>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:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKOXjWUAbqFnz5xGDpw2Hw.png" /><figcaption>I took the Arduino Pro Micro schematic, removed the 5V regulator and Tx/RX LEDs, and mapped the GPIO pins</figcaption></figure><p>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).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l1CsNDzcEt1g3kfW.png" /><figcaption>Top Layer: Red, Bottom Layer: Blue, Silkscreen: Yellow</figcaption></figure><p>I sent in this design to <a href="https://www.seeedstudio.com/fusion_pcb.html">Seeed studio</a> and got it made; I chose a black PCB with white silkscreen. In 2 weeks they showed up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6wQLYdQOYAlaZzvv.jpg" /><figcaption>Nice and shiny :) Though I wished they had an option for a matte black PCB</figcaption></figure><p><strong>Software</strong></p><p>Luckily for me, there’s already a great open source keyboard firmware project out there, <a href="https://github.com/tmk/tmk_keyboard">TMK</a>! 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 <a href="https://github.com/tmk/tmk_keyboard/blob/master/tmk_core/doc/keymap.md">keymap</a>, for example:</p><pre>const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {<br>    /* 0: Qwerty<br>     * ,-----------------------------------------------------------.<br>     * |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|  \|  `|<br>     * |-----------------------------------------------------------|<br>     * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|Backs|<br>     * |-----------------------------------------------------------|<br>     * |Contro|  A|  S|  D|  F|  G|  H|  J|  K|  L|Fn1|  &#39;|Enter   |<br>     * |-----------------------------------------------------------|<br>     * |Shift   |  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift |Fn0|<br>     * `-----------------------------------------------------------&#39;<br>     *       |Gui|Alt  |Space                  |Alt  |Fn2|<br>     *       `-------------------------------------------&#39;<br>     */<br>    KEYMAP(ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSLS,GRV, \<br>           TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,BSPC, \<br>           LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   FN1, QUOT,ENT, \<br>           LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,RSFT,FN0, \<br>                LGUI,LALT,          SPC,                RALT,FN2),</pre><h3>Putting it all together</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kDurk8pS1JMGSqWK.jpg" /><figcaption>Piccolo for scale :)</figcaption></figure><p>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.</p><p>You can find all the software and hardware source on my GitHub <a href="https://github.com/w4ilun/pocket-keyboard">https://github.com/w4ilun/pocket-keyboard</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd0638c40850" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Bluetooth LE Lego Controller + Web Bluetooth App]]></title>
            <link>https://medium.com/@monkeytypewritr/building-a-bluetooth-le-lego-controller-web-bluetooth-app-754a9993d511?source=rss-b5931d74fca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/754a9993d511</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[lego]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[bluetooth]]></category>
            <dc:creator><![CDATA[w4ilun]]></dc:creator>
            <pubDate>Sun, 25 Dec 2016 05:34:12 GMT</pubDate>
            <atom:updated>2016-12-28T04:47:51.765Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m a big fan of Lego, especially the Technic series. Some of these sets come with <strong>Power Functions</strong>, which adds motors/servos/lights to the model and lets you control them with an IR remote:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7stY2FLKxLnlgcdWHMESA.jpeg" /><figcaption>2 of my favourite, the excavator and the Mercedes Benz Arocs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/0*0IrompgCrLR5jk2Q.gif" /><figcaption>Lego Power Functions</figcaption></figure><p>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?</p><h3>Power Functions: How Do They Work?</h3><p>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:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/0*8T6eAl0Fmz6O47Kx.jpg" /><figcaption>Image source <a href="https://scuttlebots.com/2014/03/02/lego-pf-hacking-wiring/">https://scuttlebots.com/2014/03/02/lego-pf-hacking-wiring/</a></figcaption></figure><p>The wires C1 &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: <a href="http://www.philohome.com/tech.htm">http://www.philohome.com/tech.htm</a></p><h3>Concept Diagram</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*4Jsuq6S18czjDLvV2BXKxA.jpeg" /><figcaption>System Overview</figcaption></figure><p>There are 3 main components to this build:</p><ol><li>A Bluetooth module for sending/receiving commands</li><li>An Arduino to interpret those commands and output PWM signals</li><li>A motor controller that can provide enough current to drive the actuators</li></ol><p>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…</p><h3>PCB Design and Fabrication</h3><p>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. <a href="http://kicad-pcb.org/">KiCad</a>, <a href="https://cadsoft.io/">Eagle</a>, <a href="https://easyeda.com/">EasyEDA</a>, <a href="https://upverter.com/">Upverter</a>, etc.), with tons of online resources to learn how.</p><p>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:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pYQ9jGSWPBSynHN3RltNoA.png" /><figcaption>I used EasyEDA for this design (an online editor), but my favourite is KiCad :)</figcaption></figure><p>For the main Arduino controller, I chose the <a href="https://www.sparkfun.com/products/12587"><strong>Arduino Pro Micro</strong></a> 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.</p><p>For the Bluetooth LE module, I chose the <a href="https://www.itead.cc/serial-port-ble-module-master-slave-hm-10.html"><strong>HM-10</strong></a>; 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; Characteristic.</p><p>For the motor controllers I chose the <a href="https://toshiba.semicon-storage.com/info/docget.jsp?did=10660&amp;prodName=TB6612FNG"><strong>TB6612FNG</strong></a> from Toshiba. I originally wanted to use the popular <a href="https://www.sparkfun.com/products/9479">L298N</a> 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).</p><p>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.</p><p>All the above components can be found on <a href="http://digikey.com/"><strong>DigiKey</strong></a><strong> </strong>or eBay. I always order extras in case I mess up the soldering (or when I lose those super tiny SMD components).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xtl8eFhJmLTW6nKNeQ9p9g.png" /><figcaption>I was lazy and used the auto-route feature,</figcaption></figure><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/0*kVWfh9kKFsfGa7do.png" /><figcaption>Top Layer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/0*XEvZRHtJJogBIwd3.png" /><figcaption>Bottom Layer (with a Lego man on the silkscreen!)</figcaption></figure><p>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).</p><p>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 <a href="http://oshpark.com/">OSHpark</a>; 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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xpGwTLs03msY_oFA." /><figcaption>Lovely PCBs!</figcaption></figure><p>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 <a href="https://github.com/w4ilun/lego-ble-controller/tree/master/hardware">https://github.com/w4ilun/lego-ble-controller/tree/master/hardware</a></p><h3>Board Assembly</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qIdxQRdTYbkoyQhYg0DRtw.jpeg" /><figcaption>Things you will need</figcaption></figure><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x2jmRoXFAk1A4E0FJPoxKQ.jpeg" /><figcaption>The tiny pins on the TB6612FNG were a pain! But with lots of flux and sweat, they turned out great :)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lrjx_jyeEN-CQ2FVwMMdlw.jpeg" /><figcaption>Bottom layer, where our Bluetooth module sits</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MeKzjDwILKOSI8sOyOpZAA.jpeg" /><figcaption>Everything assembled! Before powering it on I did a quick test with my multi-meter to test for shorts</figcaption></figure><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*agnsdyCTwmkT-CoMwa6sGw.jpeg" /><figcaption>Both ends of the Lego extension wires have the same wire/pin layout, but the light gray connectors have no bottom pins</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvHpfNgT0J0oh5ApXe0jLw.jpeg" /><figcaption>All connected and ready for testing. Note I don’t have enough Lego extension wires, so I omitted the Channel 4 connector</figcaption></figure><h3>Firmware</h3><p>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:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*xq5oVz710yj_lbnV." /><figcaption>I almost forgot to enable the STDBY pin and was wondering why nothing was working :p</figcaption></figure><p>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:</p><pre>digitalWrite(m1en1, HIGH); //CW or CCW<br>digitalWrite(m1en2, LOW);<br>analogWrite(m1pwm, 128); //values can be 0-255</pre><p>For the command protocol, it is simply a string of 4 integer values separated by a <strong>#.</strong> For example, <strong>128#-255#10#0 </strong>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 <a href="https://www.youtube.com/watch?v=TPxbbOoX10U">video</a>.</p><p>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 <a href="https://github.com/w4ilun/lego-ble-controller/tree/master/firmware">https://github.com/w4ilun/lego-ble-controller/tree/master/firmware</a></p><h3>Web Bluetooth App</h3><p>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 <a href="https://github.com/sandeepmistry/bleno">Bleno</a> by <a href="http://twitter.com/sandeepmistry">@sandeepmistry</a>).</p><p>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 <a href="https://www.chromestatus.com/feature/5264933985976320">Chrome 56+</a>)</p><p>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:</p><pre>navigator.bluetooth.requestDevice({ filters: [{ services: [service] }] })<br>    .then(device =&gt; device.gatt.connect())<br>    .then(server =&gt; server.getPrimaryService(service))<br>    .then(service =&gt; service.getCharacteristic(characteristic))<br>    .then(characteristic =&gt; {<br>        characteristicInstance = characteristic;<br>	setInterval(updateSpeed,200); //send commands every 200ms<br>  	return characteristic.writeValue(str2ab(&quot;0#0#0#0&quot;));<br>    })<br>.catch(error =&gt; { console.log(error); });</pre><p>The complete code can be found here <a href="https://github.com/w4ilun/lego-ble-controller/blob/master/index.html">https://github.com/w4ilun/lego-ble-controller/blob/master/index.html</a>; I’ve also enabled GitHub pages on my repo, so if you built the same controller as I have, you could simply go to <a href="https://w4ilun.github.io/lego-ble-controller/">https://w4ilun.github.io/lego-ble-controller/</a> and start controlling your Lego!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWTg6jYHeGNAxxgLYmukvw.png" /><figcaption>I renamed my HM-10 module to “LEGO-BLE” with AT commands, the default name is BT05</figcaption></figure><p>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 ).</p><h3>Trying It Out</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*gE04R5OacwQNtwtPWMhOFg.gif" /><figcaption>I should build a nice Lego enclosure for the controller board…</figcaption></figure><p>I put together a “car” to test out everything and much to my delight, everything worked perfectly :)</p><p>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?).</p><p>You can find everything you need on my <a href="https://github.com/w4ilun/lego-ble-controller">GitHub</a>; 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.</p><p>Enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=754a9993d511" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Web Bluetooth in Chrome to visualize IMU data]]></title>
            <link>https://medium.com/@monkeytypewritr/web-bluetooth-arduino-101-e8bffefb7068?source=rss-b5931d74fca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8bffefb7068</guid>
            <category><![CDATA[web-bluetooth]]></category>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[w4ilun]]></dc:creator>
            <pubDate>Sun, 09 Oct 2016 05:04:27 GMT</pubDate>
            <atom:updated>2016-10-09T05:04:27.869Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*pReO0DkhL9RQcj8MJ0fguA.gif" /><figcaption><a href="https://github.com/w4ilun/web-bluetooth-curie-imu">https://github.com/w4ilun/web-bluetooth-curie-imu</a></figcaption></figure><p>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 <a href="https://googlechrome.github.io/samples/web-bluetooth/">here</a>.</p><p>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.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdb673941826404af9bddbae6c1d6e4c/href">https://medium.com/media/fdb673941826404af9bddbae6c1d6e4c/href</a></iframe><p>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 <strong>navigator.bluetooth</strong> 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:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21769628401fb5a86f76c7dac98391a1/href">https://medium.com/media/21769628401fb5a86f76c7dac98391a1/href</a></iframe><p>The IMU data (roll, pitch, &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.</p><p>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 <a href="https://w4ilun.github.io/web-bluetooth-curie-imu/">https://w4ilun.github.io/web-bluetooth-curie-imu/</a></p><p>You can also find all of the code above on GitHub: <a href="https://github.com/w4ilun/web-bluetooth-curie-imu">https://github.com/w4ilun/web-bluetooth-curie-imu</a></p><p>Enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8bffefb7068" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an IoT power switch with the ESP8266 (and control it with your Amazon Echo!)]]></title>
            <link>https://medium.com/@monkeytypewritr/amazon-echo-esp8266-iot-a42076daafa5?source=rss-b5931d74fca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a42076daafa5</guid>
            <category><![CDATA[amazon-echo]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[esp8266]]></category>
            <dc:creator><![CDATA[w4ilun]]></dc:creator>
            <pubDate>Fri, 23 Sep 2016 02:05:50 GMT</pubDate>
            <atom:updated>2017-09-14T18:20:45.724Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="#4b34"><strong>*Cut to the chase, show me the build!</strong></a></p><p>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):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*GIIEOGMe1KvdPoNKVFyHnA.png" /></figure><p>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.</p><p>The biggest appeal of this module to me however, was the support of <a href="http://nodemcu.com/index_en.html">NodeMCU</a>: a LUA runtime on the module, with networking and I/O APIs that makes it very easy to perform common tasks such as:</p><ul><li>WiFi Config (connecting, setting/saving the SSID, credentials)</li><li>Performing HTTP requests, creating an HTTP server</li><li>Use the hardware I/O (GPIO, I²C, PWM, etc.)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/150/1*9p1tRo3-LTC9ULIhnhSmqw.png" /></figure><p>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:</p><h3>wai lun on Twitter</h3><p>Got firmware updated and HTTP example running on my #ESP8266 with @NodeMCU #IoT Awesome!!! http://t.co/BJ2ouHmLUj</p><p>A few weeks later, while casually browsing through my regular sites, I came across this piece of exciting news:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*CajpKEmpv1LxFalNwCxiTg.png" /><figcaption><a href="http://hackaday.com/2015/03/28/arduino-ide-support-for-the-esp8266/">http://hackaday.com/2015/03/28/arduino-ide-support-for-the-esp8266/</a></figcaption></figure><p>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 <a href="https://github.com/knolleary/pubsubclient">MQTT</a>, <a href="https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer">Web Server</a>, <a href="https://blog.adafruit.com/2015/06/30/updated-neopixel-support-for-esp8266-and-arduino-zero/">Neopixels</a>, <a href="https://github.com/firmata/arduino/issues/257">Firmata</a> (hence, <a href="http://johnny-five.io/">Johnny-Five</a>!), and many, many more.</p><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*VHVmseLH1gyxbwggTpvv_A.jpeg" /><figcaption><a href="https://www.adafruit.com/product/2471">https://www.adafruit.com/product/2471</a> — with the ESP 12</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tIsNAukjUdci5Ku1yB5sWg.jpeg" /><figcaption>I didn’t buy any of these because I still had 10+ OG ESP8266s, but they look awesome!</figcaption></figure><p>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 <a href="https://medium.com/u/6b79e0dd4e18">GE Lighting</a> smart bulbs stopped working :(</p><h3>wai lun on Twitter</h3><p>My GE Link bulb is acting weird, how can this be fixed @GELighting #gelink ? https://t.co/K5eVMNcc0x</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*sq9c2T5XAUWkgqpBBD4mWA.jpeg" /><figcaption>The smart home kit I bought. These bulbs use ZigBee with HA profile</figcaption></figure><p>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&#39;s and make something!</p><h3>Building an IoT power switch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u1K7iBT1uCQSxue-elUHwQ.jpeg" /></figure><h3>1. Bill of Materials (you’ll need these things)</h3><p><strong>Electronics</strong></p><ul><li><a href="http://www.ebay.com/itm/For-Arduino-ESP8266-WIFI-Wireless-Transceiver-Module-Send-Receive-LWIP-AP-STA-BG-/121841140322">ESP8266 module</a></li><li><a href="http://www.ebay.com/itm/24V-380V-40A-250V-SSR-40-DA-Solid-State-Relay-Module-3-32V-DC-To-AC-/121915540741">Solid State Relay</a> (no clicking sounds, yay!)</li><li><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">AC-DC Power Supply 110/220V to 3.3V</a></li><li>Wires (for low voltage DC connections)</li></ul><p><strong>Hardware</strong></p><ul><li><a href="http://www.homedepot.com/p/1-Gang-12-cu-in-Electrical-Handy-Box-B112HBR/202077374">Electrical Box</a> (for all the components)</li><li><a href="http://www.homedepot.com/p/Leviton-15-Amp-Duplex-Outlet-White-R52-05320-00W/202066670">Duplex Outlet</a> (socket)</li><li><a href="http://www.homedepot.com/p/Leviton-1-Gang-Duplex-Outlet-Wall-Plate-White-R52-88003-00W/100025171">Wall Plate</a> (to hide everything in the box)</li><li><a href="http://www.homedepot.com/p/Axis-6-ft-3-Outlet-Indoor-Extension-Cord-White-45502/206346669">Extension Cord</a> (for the socket plug and mains wires)</li></ul><p><strong>Tools</strong></p><ul><li>Soldering Iron</li><li>Glue gun (for insulating any mains connections, be careful!)</li><li><a href="http://www.ebay.com/itm/FTDI-FT232RL-USB-to-TTL-Serial-Converter-Adapter-Module-5V-3-3V-For-Arduino-SM-/152164631351">USB-Serial adapter</a> (for programming the module)</li><li>Jumper Cables/Breadboard</li></ul><h3>2. Programming your ESP8266</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*U_7dOEdX9Fa9WX81PNHlPA.jpeg" /><figcaption>Reference: <a href="http://benlo.com/esp8266/esp8266QuickStart.html">http://benlo.com/esp8266/esp8266QuickStart.html</a></figcaption></figure><p>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.</p><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_gY8z9mcILprbXPlc4kiKg.jpeg" /><figcaption>messy wires</figcaption></figure><p>You’ll also want to install the ESP8266 toolchain from the Arduino Boards Manager. Type in “esp8266” and install the latest version:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zlcpGiSqY-WkEjvMN8_JhA.png" /></figure><p>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.</p><h3>3. Amazon Echo, UDP/TCP, &amp; WeMo Spoofing</h3><p>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.</p><p>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!</p><p>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)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*dQvNBsoJMswyOP4kMIKY_Q.png" /><figcaption>Reference: <a href="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/</a></figcaption></figure><p>The response looks something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be2bd5fe17f2f8bf7dfe78b0c86ee173/href">https://medium.com/media/be2bd5fe17f2f8bf7dfe78b0c86ee173/href</a></iframe><p>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!</p><p><a href="https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/blob/master/sinric.ino">kakopappa/arduino-esp8266-alexa-wemo-switch</a></p><p><strong>**Update** </strong>the author has an updated the repo to support multiple switches!</p><p><a href="https://github.com/kakopappa/arduino-esp8266-alexa-multiple-wemo-switch">kakopappa/arduino-esp8266-alexa-multiple-wemo-switch</a></p><p>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:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*cHj2A_7sMtFBBbgPeWoA3g.png" /><figcaption>you could see a lot of UDP traffic going on</figcaption></figure><p>Did it work? Let’s check the app!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*K3-rNQQOHD2bHAJ4hYrVrQ.png" /><figcaption>w00t! on first try! awesome work @kakopappa!</figcaption></figure><p>So it found my ESP8266! The default name for the device is “box”, set by the String <em>device_name</em> 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).</p><p>Now let’s try some commands! I hooked up a green LED to GPIO2 and yelled “Echo, box on!”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCd2CU9Pwwbc-HtRJ5sd7g.jpeg" /><figcaption>it worksssssss</figcaption></figure><h3>4. Putting It Together</h3><p>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:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*naLf9QOR8JYPTNeFEaywYg.png" /><figcaption>Note: I couldn’t find my relay model in Fritzing, but the Sharp relay has the same connections</figcaption></figure><p>Be careful when working around mains AC! I used my glue gun to insulate all the mains connections (exposed PCB traces, wires, etc.).</p><p>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:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sobr6ssONoL7z8lR5naZkw.jpeg" /><figcaption>Assembled! Looks like a plain ol’ socket (Note: the extension cord wires were not connected in this picture)</figcaption></figure><h3>5. All Done!</h3><p>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.</p><p>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!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a42076daafa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Control your Intel Edison in Realtime with Websockets (and ngrok)!]]></title>
            <link>https://medium.com/@monkeytypewritr/control-your-intel-edison-in-realtime-with-websockets-and-ngrok-529d50ac3fd3?source=rss-b5931d74fca5------2</link>
            <guid isPermaLink="false">https://medium.com/p/529d50ac3fd3</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[ngrok]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[intel-edison]]></category>
            <dc:creator><![CDATA[w4ilun]]></dc:creator>
            <pubDate>Wed, 06 Jul 2016 02:04:00 GMT</pubDate>
            <atom:updated>2016-07-06T02:04:00.938Z</atom:updated>
            <content:encoded><![CDATA[<p><em>First off, I would like to thank </em><a href="https://medium.com/u/8a9d5e8e66bc"><em>Nathan Meryash</em></a><em> for his suggestions! In my next few posts, I will describe using different cloud services and technologies for your IoT project.</em></p><p>Following up with <a href="https://medium.com/p/f16e49b2b2c8"><strong>Control your Intel Edison in Realtime with Websockets!</strong></a><strong>,</strong> this post briefly describes how you could expose your connected device to the public web using <a href="https://ngrok.com/"><strong>ngrok</strong></a>. 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.</p><p><a href="https://ngrok.com/"><strong>ngrok</strong></a> 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!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YzvuotOQ3ntlxsrdr53XkQ.png" /><figcaption>Image courtesy of ngrok <a href="https://ngrok.com/">https://ngrok.com/</a></figcaption></figure><p>There are 2 additional packages that you would need to install:</p><pre>npm install ngrok --save<br>npm install express-dot-engine --save</pre><p><strong>ngrok: </strong>an npm module for using ngrok. It allows you to programmatically create a new ngrok instance URL (e.g. <a href="https://571a6a18.ngrok.io/">https://571a6a18.ngrok.io</a>) and bind it to your local server IP and port.</p><p><strong>express-dot-engine: </strong>a lightweight template engine for embedding our ngrok URL into our index.html file</p><p>Here is the new code that has been updated to include the use of ngrok and the <a href="https://github.com/olado/doT">dot</a> template engine with Express:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8976780880eb0e43ccd597ad72216e18/href">https://medium.com/media/8976780880eb0e43ccd597ad72216e18/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b78abfddd87353d327995172e97261ba/href">https://medium.com/media/b78abfddd87353d327995172e97261ba/href</a></iframe><p>Then, simply run:</p><pre>node blinkWithSocketsNgrok.js</pre><p>…and go to the generated URL from anywhere on the web!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=529d50ac3fd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>