<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Maker Archives - ClickedyClick</title>
	<atom:link href="https://gergely.imreh.net/blog/category/maker/feed/" rel="self" type="application/rss+xml" />
	<link>https://gergely.imreh.net/blog/category/maker/</link>
	<description>Life in real, complex and digital.</description>
	<lastBuildDate>Sat, 19 Aug 2023 04:28:05 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Making a USB Mute Button for Online Meetings</title>
		<link>https://gergely.imreh.net/blog/2023/08/making-a-usb-mute-button-for-online-meetings/</link>
					<comments>https://gergely.imreh.net/blog/2023/08/making-a-usb-mute-button-for-online-meetings/#comments</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Sat, 19 Aug 2023 04:28:00 +0000</pubDate>
				<category><![CDATA[Maker]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Seeed Studio]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB HID]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=2801</guid>

					<description><![CDATA[<p>Since Google Meet teases us to add a USB device to controll calls, let's learn how to teach an Arduino clone to act like a phone mute button, and thus ultimately being capable to act like an infinite variety of peripheral devices.</p>
<p>The post <a href="https://gergely.imreh.net/blog/2023/08/making-a-usb-mute-button-for-online-meetings/">Making a USB Mute Button for Online Meetings</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">I use Google Meet every day for (potentially hours of) online meetings at work, so it&#8217;s very easy to notice when things change and for example new features are available. Recently I&#8217;ve found a new &#8220;Call Control&#8221; section in the settings that promised a lot of fun, <a href="https://support.google.com/meet/answer/12562325?hl=en">connecting USB devices to control my calls</a>.</p>



<figure class="wp-block-image size-full is-style-default"><img decoding="async" src="https://gergely.imreh.net/blog/wp-content/uploads/2023/08/Screenshot-2023-08-19-at-07.05.34.png" alt="Screenshot of the Google Meet Settings menu during calls, showing the call control menu and a call-out to connect my USB device." class="wp-image-2803"/><figcaption class="wp-element-caption">Google Meet Settings menu during a call, witht the Call control section</figcaption></figure>



<p class="wp-block-paragraph">As someone who enjoys (or drawn to, or sort-of obscessed with) <a href="https://gergely.imreh.net/blog/category/maker/">hacking on hardware</a>, this was a nice call of action: let&#8217;s cobble together a custom USB button that can do some kind of call control<sup data-fn="7509dd7d-2867-4955-808e-d9bd3a9e8cd4" class="fn"><a href="#7509dd7d-2867-4955-808e-d9bd3a9e8cd4" id="7509dd7d-2867-4955-808e-d9bd3a9e8cd4-link">1</a></sup>: say muting myself in the call, showing mute status, hanging up, etc.</p>



<p class="wp-block-paragraph">This kicked off such a deep rabbit hole that I barely made it back up to the top, but one that seeded a crazy amount of future opportunities. </p>



<span id="more-2801"></span>



<p class="wp-block-paragraph">And as a shortcut, there&#8217;s a <a href="#demo">demo</a> below to showcase where I got to.</p>



<h2 class="wp-block-heading">Finding suitable hardware</h2>



<p class="wp-block-paragraph">This step was harder than I&#8217;ve expected, given that I have drawers and drawers of gadgets, but I&#8217;m likely a bit out of practice, and also out of date. What I was looking for is</p>



<ul class="wp-block-list">
<li>Being able to show up as a USB device (must)</li>



<li>Have built in button (optional) or easy connectivity of buttons without breadboard for now</li>



<li>Have built in LED (optional) or some other way of showing 1 bit of information</li>
</ul>



<p class="wp-block-paragraph">This doesn&#8217;t sound hard, right?</p>



<h3 class="wp-block-heading">ReSpeaker</h3>



<p class="wp-block-paragraph">The first option that came up was Seeed Studio&#8217;s <a href="https://wiki.seeedstudio.com/ReSpeaker_Core/">ReSpeaker Core</a> that I had two of at hand: Arduino Leonardo compatibility, touch sensors for buttons, and an LED ring (the &#8220;Pixel Ring&#8221;). Turns out that they have been <em>discontinued</em> &#8211; which should be fine for now; but also my models are two different <em>pre-release prototypes</em> Seeed gave away for testers. Thus they are not quite like the final version, have different hardware on board here and there, so an experimental experience is expected.</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://gergely.imreh.net/blog/wp-content/uploads/2023/08/respeaker_core_prototypes-1024x572.jpg" alt="Photo of two ReSpeaker Core boards" class="wp-image-2809"/><figcaption class="wp-element-caption">ReSpeaker core samples to work with</figcaption></figure>



<p class="wp-block-paragraph">The earlier prototype only has touch sensors on one side, the pixel ring lights up, but I couldn&#8217;t control it with <a href="https://github.com/respeaker/respeaker_arduino_library">Seeed&#8217;s ReSpeaker Arduino library</a>. The later prototype has two sides of sensors (effectively two buttons), but the lights don&#8217;t seem to work<sup data-fn="17ce950a-5b32-45de-8a5c-2464146a1840" class="fn"><a href="#17ce950a-5b32-45de-8a5c-2464146a1840" id="17ce950a-5b32-45de-8a5c-2464146a1840-link">2</a></sup>. Regardless this </p>



<h3 class="wp-block-heading">Aside: alternatives considered</h3>



<p class="wp-block-paragraph">It was illuminating to see how much abandoned, obsolete, discontinued, or not quite useful hardware boards do I have.</p>



<p class="wp-block-paragraph">One is RFDuino, that I got from <a href="https://www.kickstarter.com/projects/1608192864/rfduino-iphone-bluetooth-40-arduino-compatible-boa/">Kickstarter</a>, I&#8217;m yet to use, and all the project&#8217;s websites have already disappeared &#8211; fortunately not the <a href="https://github.com/RFduino/RFduino">code repo</a>. This would have been a more complex solution anyways, but wireless! Use one RFDuino to expose a USB Telephony device, and communicate wirelessly to another that operates the light and button on battery. Pretty cool. Also, it might not have worked if the chip used cannot do the cruicial &#8220;expose a USB [device]&#8221; part of the plan.</p>



<p class="wp-block-paragraph">Other option that popped up was an <a href="https://store.arduino.cc/products/arduino-nano">Arduino Nano</a> + my own made <a href="https://www.tindie.com/products/imrehg/grovehat-for-arduino-nano/">GroveHat</a> + a <a href="https://wiki.seeedstudio.com/Grove-Button/">Grove Button</a>. Except, the Nano definitely cannot be a custom USB device, so there goes nothing.</p>



<p class="wp-block-paragraph">Besides these, I&#8217;ve found plenty of:</p>



<ul class="wp-block-list">
<li>single board computers (old or obsolete),</li>



<li>FPGAs (never used, and would be a whole different project to implement something on them), and </li>



<li>other microcontrollers that all have interesting specialties, but don&#8217;t tick the mandatory boxes&#8230;</li>
</ul>



<p class="wp-block-paragraph">These boards might not be right for now, but definitely there are projects in store for them (if only thre&#8217;s time).</p>



<p class="wp-block-paragraph">Back to ReSpeaker then&#8230;</p>



<h2 class="wp-block-heading">Plugging in the USB</h2>



<p class="wp-block-paragraph">The next thing is to figure out what&#8217;s really happening when an USB device is plugged in and it shows the operating system that it can do certain things. That is, how does Meet know that there&#8217;s a compatible device to connect to?</p>



<h3 class="wp-block-heading">The USB HID docs</h3>



<p class="wp-block-paragraph">This is answered by the <a href="https://www.usb.org/hid">USB Human Interface Devices (HID)</a> specs &#8212; one that is pretty complicated, has a lot of legacy bits, and need a different kind of mindset. In a nutshell, though, with my current, partial understanding:</p>



<p class="wp-block-paragraph">On connection the device sends a &#8220;report&#8221; to the OS that details on what can it do, including:</p>



<ul class="wp-block-list">
<li>what kind (or kinds!) of device it is?</li>



<li>what functionality of the kind is available in this particular implementation?</li>



<li>what&#8217;s the data layout to pass control information back-and-forth for this implementation?</li>
</ul>



<p class="wp-block-paragraph">In our example, a very minimal setup would would be:</p>



<ul class="wp-block-list">
<li>I&#8217;m a Telephony Device (Usage page <code>0x0B</code>)</li>



<li>I implement a generic &#8220;Phone&#8221; (Usage ID <code>0x01</code>)</li>



<li>I have capability to do a &#8220;Phone Mute&#8221; (Usage ID <code>0x2F</code>)</li>



<li>Here&#8217;s the 1 bit of a 1 byte payload that conveys that phone mute status</li>
</ul>



<figure class="wp-block-image size-large"><img decoding="async" src="https://gergely.imreh.net/blog/wp-content/uploads/2023/08/Screenshot-2023-08-19-at-07.55.31-1024x920.png" alt="Screenshot of the beginning of the Telephony Device section from the HID Usage Tables" class="wp-image-2808"/><figcaption class="wp-element-caption">Getting started with Telephony devices from the HID Usage Tables</figcaption></figure>



<p class="wp-block-paragraph">This course does not take into account other functionality, e.g.</p>



<ul class="wp-block-list">
<li>I can also hang up &#8211; Hook Switch, Usage ID <code>0x20</code>;</li>



<li>I have status LEDs &#8211; that&#8217;s a whole fun of redefining functions on the LED Page <code>0x08</code>;</li>
</ul>



<p class="wp-block-paragraph">and so on. But for the time being this should be enough.</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://gergely.imreh.net/blog/wp-content/uploads/2023/08/Screenshot-2023-08-19-at-06.59.56-1024x924.png" alt="The Call Control usages abd their description from the HID Usage Tables document" class="wp-image-2806"/><figcaption class="wp-element-caption">Call Control functionality for Telefony devices</figcaption></figure>



<h3 class="wp-block-heading">Device implementation</h3>



<p class="wp-block-paragraph">Fortunately we can stand on the shoulders of giants, that is the <a href="https://github.com/NicoHood/HID">Arduino HID Project</a> which implemented a bunch of different devices. And even though a &#8220;phone&#8221; like this is not among them, we can make some reasonable guesses how it would work.</p>



<p class="wp-block-paragraph">Having said that, from a forum post that was also trying to do something similar (but based on the TinyUSB library):</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">HID report descriptor is very difficult thing to come up by oneself. You should google around, or dump report descriptor from existing device to copy/follow it.</p>
<cite><a href="https://github.com/hathach/tinyusb/discussions/667#discussioncomment-392454">hathach @ TinyUSB discussion 667</a></cite></blockquote>



<p class="wp-block-paragraph">Okay, then do not come up with this stuff, instead let&#8217;s look for tools. The USB HID homepage links to the <a href="https://github.com/microsoft/hidtools">Microsoft HID Tools</a> to generate HID reports from a TOML-like language. Except it needs C# and I just wasn&#8217;t ready to dive in a side-quest to install &amp; learn a new toolchain.</p>



<p class="wp-block-paragraph">So being lazy this way, a bit more sleuthing turned up <a href="https://web.archive.org/web/20210614160735/https://blog.noser.com/first-steps-with-an-usb-hid-report/">someone&#8217;s example HID report</a> for a device very close to what I&#8217;m trying to do, hurray!</p>



<p class="wp-block-paragraph">I took this and started to poke around the HID project to see how other devices are implemented. Troubleshooting by using the ReSpeaker&#8217;s touch to adjust screen brightness up / down (as a &#8220;Consumer Device&#8221;) was also pretty neat! In the end I took the system buttons example and run with that one.</p>



<p class="wp-block-paragraph">Having said that, the HID report is really just the interface. The devil is in how to implement actually creating the data packages that passes data according to the report definition. And this is the case when I wish I knew more C++ but copy-paste and some guesswork will have to do.</p>



<figure class="wp-block-image size-large"><img decoding="async" src="https://gergely.imreh.net/blog/wp-content/uploads/2023/08/Screenshot-2023-08-19-at-08.48.30-1024x519.png" alt="Screenshot of the Phone HID report definition code" class="wp-image-2814"/><figcaption class="wp-element-caption">Our minimal viable mute button&#8217;s HID report (<a href="https://github.com/imrehg/HID/blob/1851b68b008111734287f6ce4f894173ad21bb3f/src/MultiReport/Phone.cpp#L26C1-L41C1">source</a>)</figcaption></figure>



<p class="wp-block-paragraph">The current result lives in the &#8220;<a href="https://github.com/imrehg/HID/tree/phone">phone&#8221; branch of my HID Project fork</a>, check for the &#8220;Phone&#8221; bits in &#8220;src/HID-APIs&#8221; and &#8220;MultiReport&#8221; folders, if interested.</p>



<h2 class="wp-block-heading">Minimal viable mute</h2>



<p class="wp-block-paragraph">The implementation from this point on was pretty straightforward &#8211; since we cut back the scope so much&#8230;</p>



<p class="wp-block-paragraph">The code to run on the ReSpeaker then just has to do the following:</p>



<ul class="wp-block-list">
<li>when touching one side, send a report with &#8220;Phone Mute&#8221; on</li>



<li>when touching the other, send a report with &#8220;Phone Mute&#8221; off</li>
</ul>



<p class="wp-block-paragraph">And this is sort of simple<sup data-fn="c40b4257-a075-44fc-aefb-e036c5cb3543" class="fn"><a href="#c40b4257-a075-44fc-aefb-e036c5cb3543" id="c40b4257-a075-44fc-aefb-e036c5cb3543-link">3</a></sup> :</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="870" src="https://gergely.imreh.net/blog/wp-content/uploads/2023/08/arduino-code-for-phone-mute-events-1024x870.png" alt="Screenshot of the Arduino code to send the right mute events" class="wp-image-2821" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2023/08/arduino-code-for-phone-mute-events-1024x870.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2023/08/arduino-code-for-phone-mute-events-500x425.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2023/08/arduino-code-for-phone-mute-events-768x653.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2023/08/arduino-code-for-phone-mute-events.png 1198w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Sending data on touch events in the simplest way</figcaption></figure>



<p class="wp-block-paragraph" id="demo">For the full use case there would be a lot more complexity for both reading and writing data from the host, controlling multiple peripherals (LEDs and buttons) and the whole logic around it. But for now, it&#8217;s good enough for a demo:</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="A custom USB HID mute button for Google Meet" width="580" height="435" src="https://www.youtube.com/embed/Mz-B7sYGLUI?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div><figcaption class="wp-element-caption">A very quick demo</figcaption></figure>



<p class="wp-block-paragraph">The code repository is available on Github at <a href="https://github.com/imrehg/arduino-usb-phone-hid">imrehg/arduino-usb-phone-hid</a>.</p>



<h2 class="wp-block-heading">Notes and Future work</h2>



<h3 class="wp-block-heading">The specs</h3>



<p class="wp-block-paragraph">It&#8217;s great that stuff from 20+ years ago still works mostly the same way. The <a href="https://www.usb.org/sites/default/files/hut1_4.pdf">latest 1.4 version</a> of the HID Tables is nicely formatted, has a lot more device typed defined, but has much less support text. Originally I&#8217;ve read the <a href="https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf">1.12v2 version</a> as that showed up in my search. Back then in 2004 they had an &#8220;examples&#8221; section (see the Telephone at Appendix 10!) which is useful to grok more of the fundamentals. </p>



<p class="wp-block-paragraph">The newer version also has some devices types that looked suitable, but weren&#8217;t really: Generic Desktop Page (<code>0x01</code>) and <code>0xE0-E2</code> Usage IDs for Call Active LED, Call Mute Toggle, and Call Mute LED respectively. These didn&#8217;t seem to work with Meet, so it might be interesting to try implementing a device that does both and try other online call software.</p>



<p class="wp-block-paragraph">I should also have read the spec more before diving into hacking on the HID implementation fork, as there&#8217;s a lot more information in the <a href="https://www.usb.org/document-library/device-class-definition-hid-111">HID Device Class Definition</a>, including how to construct the values for many of the fields (I&#8217;m looking at you &#8220;<code>INPUT (Cnst,Var,Abs)</code>&#8220;). RTFM is and remains a solid advice &#8211; and not just when one thinks there&#8217;s time.</p>



<p class="wp-block-paragraph">Also regarding the specs: some of them I only find in the Internet Archive&#8217;s <a href="https://web.archive.org/">Wayback Machine</a>. If you encounter a good source that should be kept, always add it to the Wayback Machine and preserve it for your future selves and others!</p>



<p class="wp-block-paragraph">This exploration of USB HID pulled on so many threads, and left so much unfinished, that it&#8217;s a fertile ground for the future, even more than most previous projects.</p>



<h3 class="wp-block-heading">More call functionality</h3>



<p class="wp-block-paragraph">The most obvious thing is to implement the whole setup with the buttons. I&#8217;ve tried Hook Switch to hang up a call, that works too. Could add status lights, maybe throw in some &#8220;Active Call&#8221; LEDs, or so on. This requires better understanding how data is sent over the wire for USB and how to handle incoming data. The Arduino examples rarely seem to use the &#8220;Output&#8221; fields (ie. incoming data, output from the host&#8217;s point of view, but maybe <a href="https://github.com/hathach/tinyusb">TinyUSB</a> does ?</p>



<p class="wp-block-paragraph">For this, it would be nice to find a different hardware platform that would make this more seamless (so I can concentrate on the software side more). If that platform would lend itself to be reproduced or made stand alone, that would be even nicer: imaging brining my little call control box that can be used with other computers easily as well&#8230;</p>



<h3 class="wp-block-heading">Implement more USB HID devices</h3>



<p class="wp-block-paragraph">The <a href="https://github.com/NicoHood/HID">Arduino HID project</a> has a bunch of devices implemented, but there are an infinite numbers that could be added. Unfortunately for Arduino it is harder to add more device types as an add-on to this library versus the current &#8220;forked&#8221; approach<sup data-fn="d18cdbdc-1733-40b6-a512-81c55a158ce0" class="fn"><a href="#d18cdbdc-1733-40b6-a512-81c55a158ce0" id="d18cdbdc-1733-40b6-a512-81c55a158ce0-link">4</a></sup>, so new decices should be in the main project, eventually.</p>



<p class="wp-block-paragraph">So far there&#8217;s no Telephony device implemented there and it would be nice to find the right level of abstraction that works. The library doesn&#8217;t implement specific HID table pages, but specific usages or a subset of a usage. Thus like always, the hardest part would likely be setting the right interface (the right specs and &#8220;API&#8221;) for a new device to implement both the HID reports and the functions that manipulate what&#8217;s being sent and when.</p>



<p class="wp-block-paragraph">On the other hand, that does sound like a fun experiment, and I&#8217;d look forward to adding 3D Game Controllers (Game Controls Page <code>0x05</code>), Environmental Sensors (Sensors Page <code>0x20</code>, Usage ID <code>0x30-3B</code>), &#8230; or even a Submarine Simulation Device (Simulation Device page <code>0x02</code>, usage id <code>0x05</code>). These are stuff I go to Hackerspaces for&#8230;</p>



<h3 class="wp-block-heading">WebHID for internet plus USB</h3>



<p class="wp-block-paragraph">While debugging this HID device behaviour, I found also <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API">WebHID</a> that brings such devices to the web. This feature seems to be behind Meet&#8217;s and other phone systems like <a href="https://www.3cx.com/blog/docs/webhid-headset-integration/">3CX</a> expanding USB support outside of the OS and into the browser. And no, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1835412">Firefox does not support it</a>, furthermore <a href="https://mozilla.github.io/standards-positions/#webhid">declined supporting it</a>.</p>



<p class="wp-block-paragraph">Nonetheless it&#8217;s very cool that (if I upskill a bit), I can create a web page that would help me debug such HID development:</p>



<ul class="wp-block-list">
<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/HID/requestDevice">request devices</a> that are filtered in various ways (vendor, product is standard, but usage page and explicit usage is the main key). This is likely what Meet does as well, &#8220;just gimme devices with Telephony usage page (or Phone usage? Need to check exactly) </li>



<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/HIDDevice/collections">read the HID report collections</a> sent by the device, so the results can be debugged, and</li>



<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/HIDInputReportEvent">read device input events</a> that we can then either log for debugging or in an application react to to it</li>
</ul>



<p class="wp-block-paragraph">This opens a lot more mashup opportunities by the dozen.</p>



<h2 class="wp-block-heading">Finally</h2>



<p class="wp-block-paragraph">Unlike most other projects I had where I&#8217;m focused on one specific outcome, this turned out to be more focusing on getting a new toolkit (custom USB devices) up and running, so I can think about a wider <em>types</em> of projects to do. In that sense, this feels a big success, even if I know how little I know about programming outside of my day-to-day environment. But ignorance is not a bliss.</p>



<p class="wp-block-paragraph">And now, going on mute.</p>


<ol class="wp-block-footnotes"><li id="7509dd7d-2867-4955-808e-d9bd3a9e8cd4">Many moons past I used to use a Jabra Evolve 80, that has <a href="https://www.manualslib.com/manual/1021017/Jabra-Evolve-80.html?page=16#manual">a USB accessory</a> controlling call features, so I did have first hand example of what sort of experience I&#8217;d like. <a href="#7509dd7d-2867-4955-808e-d9bd3a9e8cd4-link" aria-label="Jump to footnote reference 1"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/21a9.png" alt="↩" class="wp-smiley" style="height: 1em; max-height: 1em;" />︎</a></li><li id="17ce950a-5b32-45de-8a5c-2464146a1840">I&#8217;ve tried reviewing the <a href="https://github.com/respeaker/get_started_with_respeaker/blob/master/files/RespeakerCorev1.0_Schematic.pdf">hardware schematics</a>, looking into the <a href="https://github.com/respeaker/respeaker_arduino_library/blob/4e04f8c72fa53beeb27dacd8d729a90f79202db7/pixels.cpp">pixel ring control functions</a>, and given that the LEDs seems standard I&#8217;ve also attempted to use the <a href="http://fastled.io/">FastLED library</a> to drive them instead, so far nothing. I still bet on hardware differences from final schematic + my inability to debug it, but it can be faulty hardware just as well. Needs more effort &#8211; in the future. <a href="#17ce950a-5b32-45de-8a5c-2464146a1840-link" aria-label="Jump to footnote reference 2"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/21a9.png" alt="↩" class="wp-smiley" style="height: 1em; max-height: 1em;" />︎</a></li><li id="c40b4257-a075-44fc-aefb-e036c5cb3543">The Arduino code became more &#8220;simple&#8221; once I realised that things set up this way do not need debouncing for the touch sensors. In other cases that would be essential, there&#8217;s sooo much flaky signal to use those terminals as momentary switches or similar. <a href="#c40b4257-a075-44fc-aefb-e036c5cb3543-link" aria-label="Jump to footnote reference 3"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/21a9.png" alt="↩" class="wp-smiley" style="height: 1em; max-height: 1em;" />︎</a></li><li id="d18cdbdc-1733-40b6-a512-81c55a158ce0">At least I don&#8217;t know how nicely extend a library for C++, if that&#8217;s even possible. Keen to learn, though. <a href="#d18cdbdc-1733-40b6-a512-81c55a158ce0-link" aria-label="Jump to footnote reference 4"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/21a9.png" alt="↩" class="wp-smiley" style="height: 1em; max-height: 1em;" />︎</a></li></ol><p>The post <a href="https://gergely.imreh.net/blog/2023/08/making-a-usb-mute-button-for-online-meetings/">Making a USB Mute Button for Online Meetings</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2023/08/making-a-usb-mute-button-for-online-meetings/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Home Automation Mix-and-Match</title>
		<link>https://gergely.imreh.net/blog/2016/04/home-automation-mix-and-match/</link>
					<comments>https://gergely.imreh.net/blog/2016/04/home-automation-mix-and-match/#respond</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Sun, 10 Apr 2016 10:58:52 +0000</pubDate>
				<category><![CDATA[Maker]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Home Assistant]]></category>
		<category><![CDATA[home automation]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Olimex]]></category>
		<category><![CDATA[OLinuXino Lime2]]></category>
		<category><![CDATA[Seeed Studio]]></category>
		<category><![CDATA[Wio Link]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=2245</guid>

					<description><![CDATA[<p>Building a presence alert home automation system with Seeed Studio's Wio Link, Home Assistant, a DD-WRT router, and an Olimex Lime2 ARM server.</p>
<p>The post <a href="https://gergely.imreh.net/blog/2016/04/home-automation-mix-and-match/">Home Automation Mix-and-Match</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This week I got a <a href="http://www.seeedstudio.com/wiki/Wio_Link">Wio Link</a> prototype from a friend at <a href="https://www.seeedstudio.com/">Seeed Studio</a>. It is an <a href="https://en.wikipedia.org/wiki/ESP8266">ESP8266</a>-based little Internet of Things board with 6 Grove connectors for easy device connectivity, wifi networking, and controlled over an app &amp; the Internet. For a quick project I wanted to hook it up with Home Assistant, an open source home automation platform that I read a lot about lately. The main focus was to have a first impression of both parts, and build up some experience for future, more serious projects.</p>
<p>The target solution: <em>light up an LED if a particular person is at home location</em>. Sort of a basic alarm system, though notice that the location of the LED was not mentioned &#8211; it can actually be anywhere in the world, as long as there&#8217;s Internet connectivity.</p>
<p>I&#8217;ve used the <a href="http://www.seeedstudio.com/wiki/Wio_Link">Wio Link</a>, a <a href="http://www.seeedstudio.com/wiki/Grove_-_LED_Socket_Kit">Grove LED light</a>, an <a href="https://www.olimex.com/Products/OLinuXino/A20/A20-OLinuXIno-LIME2/open-source-hardware">Olimex OLinuXino Lime2 board</a> running <a href="http://archlinuxarm.org/">ArchLinux</a> for the server, and a <a href="http://www.buffalotech.com/products/wireless/open-source-dd-wrt/airstation-highpower-n450-gigabit-dd-wrt-wireless-router">Buffalo router</a> with <a href="http://www.dd-wrt.com/site/index">DD-WRT</a> system installed.</p>
<h2>Wio Link</h2>
<p>Wio Link was introduced in <a href="https://www.kickstarter.com/projects/seeed/wio-link-3-steps-5-minutes-build-your-iot-applicat">Seeed&#8217;s Kickstarter campaign</a>, where they have raised more than 8x of their original target. It looks like a neat little board, and was happy to try out when I got my hands on one.</p>
<p>Their <a href="http://www.seeedstudio.com/wiki/Wio_Link">wiki page</a> has quite a bit of information, so it was easy to get started. Connect to power, hold down the configure button till the LED lights up in a &#8220;breathing&#8221; pattern, connect through <a href="https://play.google.com/store/apps/details?id=cc.seeed.iot.ap">their Wio Link app</a>, set up the wireless network settings and so on. Once connected, can define what kind of devices are attached to the board, and it looks like most of <a href="http://www.seeedstudio.com/wiki/Grove_System">Grove devices</a> are represented there. I only had a Grove LED at hand, so added it (&#8220;Generic Digital Output&#8221;), updated it, which created a new firmware and pushed onto the device.</p>
<p><figure id="attachment_2248" aria-describedby="caption-attachment-2248" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/WioLink.png" rel="attachment wp-att-2248"><img decoding="async" class="size-large wp-image-2248" src="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/WioLink-1024x607.png" alt="Wio Link setup process (left to right): add device, update firmware, check status" width="604" height="358" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/WioLink-1024x607.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2016/04/WioLink-500x296.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2016/04/WioLink-768x455.png 768w" sizes="(max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2248" class="wp-caption-text">Wio Link setup process (left to right): add device, update firmware, check status</figcaption></figure></p>
<p>The first update took a couple of minutes, but it&#8217;s pretty straightforward. The device then also has an API link, which brings up a web page with all the options to query, control, and reset the attached accessories (in my case that&#8217;s the one digital output).</p>
<p><span id="more-2245"></span></p>
<p>The API is pretty simple and usable, though definitely not perfect (will come back to this).</p>
<p><a href="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/WioLinkAPI.png" rel="attachment wp-att-2252"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-2252" src="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/WioLinkAPI.png" alt="WioLinkAPI" width="941" height="800" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/WioLinkAPI.png 941w, https://gergely.imreh.net/blog/wp-content/uploads/2016/04/WioLinkAPI-500x425.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2016/04/WioLinkAPI-768x653.png 768w" sizes="auto, (max-width: 941px) 100vw, 941px" /></a></p>
<p>Since manual switching the light on and off worked like the charm, the next step was to enable automatic switching by the presence detection within the home automation system.</p>
<h2>Home Assistant</h2>
<p><a href="http://home-assistant.io/">Home Assistant</a> is an open source home automation system written in Python. There&#8217;s a lot to like about it, and a lot of people are checking it out since a number of other, closed system providers are <a href="https://home-assistant.io/blog/2016/04/05/your-hub-should-be-local-and-open/">shutting down their services</a>. On the other hand, figuring out the configuration to implement the automation steps I came up with is far from trivial&#8230;</p>
<p>Setting up Home Assistant is pretty simple. Create a new directory, add a new virtualenv environment, and install home assistant (I&#8217;ve added some bonus modules that the logs recommended):</p>
<pre class="lang:sh decode:true" title="Home Assistant and bonus modules installation">$ virtualenv env
Using base prefix '/usr'
New python executable in /tmp/env/bin/python3
Also creating executable in /tmp/env/bin/python
Installing setuptools, pip, wheel...done.
$ source env/bin/activate
(env) $ pip install homeassistant
...
(env) $ pip install python-Levenshtein
(env) $ pip install colorlog
(env) $ hass --open-ui</pre>
<p>Next step is adding the actual components (the pieces of the home automation).  I&#8217;ve implemented the Wio Link light as a <a href="https://home-assistant.io/components/switch.command_line/">Command Line Switch</a>. It has two commands for &#8220;on&#8221; and &#8220;off&#8221;, plus an extra for checking the on/off status (this latter is a very nice touch, and works well checking whether the switch took effect). In the <span class="lang:default decode:true crayon-inline">configuration.yaml</span>  file in the <span class="lang:default decode:true crayon-inline ">~/.homeassistant</span>  directory:</p>
<pre class="lang:yaml decode:true" title="Wio Link LED light as a Command Line Switch component">switch:
  platform: command_line
  switches:
    presence_light:
      name: Home Presence Light
      oncmd: "/usr/bin/curl -s -X POST https://iot.seeed.cc/v1/node/GenericDOutD0/onoff/1?access_token=&lt;token&gt;"
      offcmd: "/usr/bin/curl -s -X POST https://iot.seeed.cc/v1/node/GenericDOutD0/onoff/0?access_token=&lt;token&gt;"
      statecmd: "/usr/bin/curl -s https://iot.seeed.cc/v1/node/GenericDOutD0/onoff_status?access_token=&lt;token&gt;"
      value_template: '{{ value_json.onoff == 1 }}'

group:
  remote:
    - switch.home_presence_light</pre>
<p>Here the URLs are coming straight from Wio Link API page, and you have to add your token value and the correct channels instead of <span class="lang:default decode:true crayon-inline ">GenericDOutD0</span>  if you plugged your light into a different connector than me. I&#8217;ve also removed their <span class="lang:default decode:true crayon-inline ">-k</span>  command line parameter (allow insecure SSL connection), and added  <span class="lang:default decode:true crayon-inline ">-s</span>  (silent mode). The last section starting with &#8220;group&#8221; is not really necessary, but could group devices to be controlled together.</p>
<p>Adding the presence detection through DD-WRT is just the same as in their example configuration, obviously add your own parameters.</p>
<pre class="lang:yaml decode:true" title="DD-WRT Presence Detection component config">device_tracker:
  platform: ddwrt
  host: 192.168.x.y
  username: &lt;user&gt;
  password: &lt;password&gt;
  interval: 10</pre>
<p>I don&#8217;t like that username/password is in clear text, so better protect your Home Assistant device and this configuration file!</p>
<p>By the default configuration, after restarting Home Assistant this presence detection module will create a <span class="lang:default decode:true crayon-inline ">known_devices.yaml</span>  file in the <span class="lang:default decode:true crayon-inline ">~/.homeassistant/</span>  directory and add all new devices (see the <a href="https://home-assistant.io/components/device_tracker/">device tracker component page</a> for some more info). Here I had my smartphone, after connecting it to the home network.</p>
<pre class="lang:yaml decode:true" title="Known devices settings">xxxxxxxxxxxx:
  name: HTC One M9
  mac: xx:xx:xx:xx:xx:xx
  picture: http://www.gravatar.com/avatar/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  track: yes
  hide_if_away: no</pre>
<p>That file then can be edited, for example  adding device name, disabling tracking for some discovered devices (eg. the small server running the Home Assistant server itself), and adding an image. I&#8217;ve added an image using a <a href="https://en.gravatar.com/">Gravatar</a> link, where the xxxx section is just the md5 hash of your email, get it by.</p>
<pre class="lang:sh decode:true">echo -n "my@email.com" | md5sum -</pre>
<p>Alternatively, this week&#8217;s update added local file support too, as it was <a href="https://home-assistant.io/blog/2016/04/07/static-website/">discussed in the Home Assistant blog</a>, so files in the <span class="lang:default decode:true crayon-inline">~/.homeassistant/www/</span>  can be linked through the <span class="lang:default decode:true crayon-inline ">http://127.0.0.1/local/</span>  path, so no online link is necessary (but I think Gravatar is a good unified approach).</p>
<p>After all this, the control interface will look something like this (the Sun is added as I had my home&#8217;s longitude/latitude information in the configuration). My icon will show Home/Away status, and clicking the switch on the presence light will trigger the light on the Wio Link.</p>
<p><figure id="attachment_2249" aria-describedby="caption-attachment-2249" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Interface.png" rel="attachment wp-att-2249"><img loading="lazy" decoding="async" class="size-large wp-image-2249" src="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Interface-1024x640.png" alt="Home Assistant control interface: sun, device tracker, and switch" width="604" height="378" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Interface-1024x640.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Interface-500x313.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Interface-768x480.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Interface.png 1280w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2249" class="wp-caption-text">Home Assistant control interface: sun, device tracker, and switch</figcaption></figure></p>
<p>The final step is the automation. This was the hardest step, as the <a href="https://home-assistant.io/getting-started/automation/">Home Assistant automation documentation</a> and their cookbook is pretty shallow, and often feel confusing. In the end, one working result is this pair of rules, which turn the light on when status change to <span class="lang:default decode:true crayon-inline ">home</span> , and turn it off when changes to <span class="lang:default decode:true crayon-inline ">not_home</span>  for that particular device.</p>
<pre class="lang:yaml decode:true" title="Home/Away signalling through automation">automation 1:
  trigger:
    platform: state
    entity_id: device_tracker.xxxxxxxxxxxx
    to: 'home'
  action:
    service: homeassistant.turn_on
    entity_id: group.remote

automation 2:
  trigger:
    platform: state
    entity_id: device_tracker.xxxxxxxxxxxx
    to: 'not_home'
  action:
    service: homeassistant.turn_off
    entity_id: group.remote
</pre>
<p>I&#8217;m sure it can be done differently, but I&#8217;m also just glad it works, as it took quite a few hours of checking documentation, trying things, and reading the <a href="https://github.com/balloob/home-assistant">Home Assistant source code</a> to come up with a working solution.</p>
<p>It functions pretty well, though presence (arriving) is detected quicker than absence (going away), I guess that&#8217;s part of detection method and certain timeouts within DD-WRT.</p>
<h2>Lessons</h2>
<p>I quite like how it all turned out, and I&#8217;ve learned a lot along the way, in the about 5-6 hours it took to pull everything together for the first time.</p>
<p>There will always be <strong>bugs</strong>. When trying to read the Wio Link LED&#8217;s status, first I was trying to implement it as a <a href="https://home-assistant.io/components/binary_sensor.rest/">RESTful Binary Sensor</a>. Took a while to find that that component had a breaking bug. I&#8217;ve made a patch, but haven&#8217;t sent it upstream yet, because Home Assistant makes me fill out so much information before a pull request can be even considered. To make it worthwhile, I&#8217;ll review things and send the fix later.</p>
<p>Not all the Wio Link <strong>API design</strong> is great. In particular, turning the light on/off are empty POST request to two different API endpoints! That&#8217;s not really REST at all. I think the way it should have been is using the same API endpoint (one single URL), and the setting sent over the POST data. Because of peculiarity, I couldn&#8217;t implement the Wio Link control over the <a href="https://home-assistant.io/components/switch.rest/">RESTful Switch</a> component, which requires a single endpoint.</p>
<p>Since the Wio Link can be placed anywhere where there&#8217;s internet connection, this home automation system can incorporate <strong>data from anywhere</strong>, sending or receiving. Can have an <a href="http://www.seeedstudio.com/wiki/Grove_-_LCD_RGB_Backlight">LCD screen</a> miles away that displays metrics from your home. Can incorporate external sensors, actuators, the whole shebang. This makes more of a &#8220;local area&#8221; or even &#8220;wide area&#8221; automation network, not just &#8220;home&#8221;. Let your imagination run amok!</p>
<p>The Home Assistant <strong>documentation</strong> is really lacking for me, and I say that while every component has code samples and there are a lot of cookbook samples around. The problem is that there&#8217;s very little consistency, there&#8217;s no overview, and the options are not documented extensively. There&#8217;s no list of &#8220;these are all the options and possible values&#8221;, and there are no &#8220;these are all the ways you can do this thing&#8221;. In the end, one needs a lot of trial and error and monumental amount of head scratching! (Use the Source, Luke!) All this basically means that Home Assistant is the &#8220;<em>worst documented project that I&#8217;m the most excited about</em>&#8220;. :) Fortunately the <a href="https://github.com/balloob/home-assistant.io">Home Assistant website&#8217;s source</a> is also on Github and can submit updates if I figure out how to explain things better.</p>
<p>Creating automation through triggers, conditions, and actions is probably pretty straightforward at first. I guess it works very well for simple systems, though I wonder how it could be made to scale better. In this <strong>configuration based system</strong>, even just a couple of automation scripts can balloon to pages and pages of code, and possible very little operator understanding how rules possible cross-interact with each other. I don&#8217;t know what model would be better (some kind of state machine definition maybe?), but it would worth thinking about it for the long term of home automation.</p>
<p>There are more <strong>components</strong> defined than I could reasonably ever try in my life, just check the component&#8217;s page!</p>
<p><figure id="attachment_2250" aria-describedby="caption-attachment-2250" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Choices.png" rel="attachment wp-att-2250"><img loading="lazy" decoding="async" class="size-large wp-image-2250" src="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Choices-1024x640.png" alt="Home Assistant components galore" width="604" height="378" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Choices-1024x640.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Choices-500x313.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Choices-768x480.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2016/04/HomeAssistant_Choices.png 1280w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2250" class="wp-caption-text"><a href="https://home-assistant.io/components/">Home Assistant components</a> galore</figcaption></figure></p>
<p>This abundance also means that the number of possible combinations are astronomical. I would wager, though, that the value of those combinations follow a power-low: most of the combinations are not interesting at all, while a relatively small number of combinations are the most useful in general! I guess the <a href="https://home-assistant.io/cookbook/">Cookbook</a> would be a good place to highlight some more &#8220;common use cases&#8221;, not just covering the bases and filling in for the lack of documentation. There are some obviously more useful components, <a href="https://ifttt.com/">IFTTT</a> component on its own can add a ton of functionality, or the RESTful components.</p>
<h2>Future</h2>
<p>I hope, that <strong>more device manufacturers</strong> will create components and generously add it to this lineup. I can&#8217;t see any downside and there&#8217;s just so much upside working with an open source system! Any system integrator that figures out Home Assistant will also have a big competitive advantage in some niches for sure.</p>
<p>I hope, that the <strong>documentation</strong> can be improved in the future and things will be easier to figure out (e.g. how would I update this project above to light up the LED if any one of the tracked devices is present and turn the LED off when all of them are absent?).</p>
<p>The huge number of possible <strong>component combinations</strong> to mix-and-match is also pretty paralyzing too (see the classic <a href="https://www.ted.com/talks/barry_schwartz_on_the_paradox_of_choice?language=en">Paradox of Choice</a>), I have no good &#8220;production-level&#8221; project in mind yet, even though I&#8217;m super excited about many components I&#8217;ve found so far! This particular project worked, because it&#8217;s already something I was thinking about, and could possibly replace <a href="https://gergely.imreh.net/blog/2013/07/electronic-check-in-at-the-taipei-hackerspace/">an existing system in the Taipei Hackerspace</a>!</p>
<p>Have you built something interesting? Would love to hear about it! :)</p>
<p>The post <a href="https://gergely.imreh.net/blog/2016/04/home-automation-mix-and-match/">Home Automation Mix-and-Match</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2016/04/home-automation-mix-and-match/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Scratch Your Robot Itch</title>
		<link>https://gergely.imreh.net/blog/2016/03/scratch-robot-itch/</link>
					<comments>https://gergely.imreh.net/blog/2016/03/scratch-robot-itch/#respond</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Thu, 17 Mar 2016 08:25:18 +0000</pubDate>
				<category><![CDATA[Maker]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[robot]]></category>
		<category><![CDATA[Scratch]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=2220</guid>

					<description><![CDATA[<p>Making a robot prototype dance with Scratch, a visual programming language, through experimental Javascript extensions.</p>
<p>The post <a href="https://gergely.imreh.net/blog/2016/03/scratch-robot-itch/">Scratch Your Robot Itch</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Recently I&#8217;ve been experimenting with the <a href="https://scratch.mit.edu/">Scratch programming language</a>, created by the Lifelong Kindergarten Group at MIT. It&#8217;s a fun environment that uses visual programming: drag-and-drop pieces of code blocks, and control objects on a stage, and the stage itself. It has quite a bit more depth to it, than the expression &#8220;visual programming language&#8221; implies, with it&#8217;s internal messaging system, multitasking, and event-driven approach. While it was originally aimed at creating interactive graphics and animations (see <a href="http://ted.com/talks/mitch_resnick_let_s_teach_kids_to_code">this TEDx talk by Prof. Mitch Resnick</a> on the background), it is now evolving into new territories with the <a href="http://scratchx.org/">Scratch Experimental Extensions</a>.</p>
<p><span id="more-2220"></span></p>
<p>The Experimental Extensions define <a href="https://github.com/LLK/scratchx/wiki">a smallish API</a>, which can be used to create custom programming blocks to be used in Scratch. All it needs is a Javascript file (currently) hosted on Github with a few pre-defined code blocks to unlock any sort of functionality. This creates a possibility to easily tap into any kind of web API or interface any hardware that can be addressed somehow through Javascript. There are <a href="http://scratchx.org/#extensions">a large number of examples</a> already, and I wanted to see how easy or hard it is to create such an extension for a robot that happened to be around <a href="http://www.viatech.com">here at VIA</a>.</p>
<h2>The Robot</h2>
<p>Some of the engineers at VIA have built a small robot using bits and pieces found in the lab: a dual-core ARM-based engineering sample control board, smart battery from another project, some wheels from a commercial robot (Rovio&#8217;s 3-wheel system a few years back), and I think some office supplies.</p>
<p><figure id="attachment_2226" aria-describedby="caption-attachment-2226" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/2016/03/scratch-robot-itch/2016-03-17-15-13-06-min/" rel="attachment wp-att-2226"><img loading="lazy" decoding="async" class="wp-image-2226 size-large" src="https://gergely.imreh.net/blog/wp-content/uploads/2016/03/2016-03-17-15.13.06-min-1024x715.jpg" alt="Hacked-together robot from the lab" width="604" height="422" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2016/03/2016-03-17-15.13.06-min-1024x715.jpg 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2016/03/2016-03-17-15.13.06-min-500x349.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2016/03/2016-03-17-15.13.06-min-768x536.jpg 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2226" class="wp-caption-text">Hacked-together robot from the lab</figcaption></figure></p>
<p>The robot&#8217;s operating system creates an access point (with the Wi-Fi USB stick on the upper right of the picture), and hosts a webpage that can be used to control the <strong>movements</strong> (back/forth/left/right), as well as <strong>streaming video</strong> (or more precisely <a href="https://en.wikipedia.org/wiki/Motion_JPEG">Motion JPEG</a>) from the camera in the front (lower left, the little black square on top of the white sticky pad). Besides the control board, there&#8217;s some voltage converter and battery-control circuits, off-the-shelf pieces by the look of them, with minor modifications (such as an LED to see when the battery is out of power).</p>
<p>It is as hacky as it gets, but all that is needed to have some fun.</p>
<h2>Controlling Through Scratch</h2>
<p>While the built in webpage to control the robot is very handy, and can be used from any device that has a browser (computer, smartphone, I guess could even control it from a <a href="https://gergely.imreh.net/blog/2012/10/laboratory-2-0-a-monitoring-system/">Kindle</a>), it has it&#8217;s limitation: I need to click on buttons to get things done, and nothing can be really automated. Still, the underlying API is a good start to do more interesting things.</p>
<p>The API is very hacky too, and that&#8217;s just fine like that. Looking at the built in webpage, I could see that there are a handful of <a href="http://www.w3schools.com/tags/ref_httpmethods.asp">GET requests</a> to a specific URL to <span class="lang:default decode:true crayon-inline ">move_forward</span> , or <span class="lang:default decode:true crayon-inline">turn_left</span>  or <span class="lang:default decode:true crayon-inline">stop</span> . That&#8217;s straightforward enough, and it does not take more than a couple of minutes to cook up a proof of concept Python script using <a href="https://docs.python.org/2/library/urllib2.html">requests</a> to try these endpoints.</p>
<p>Once that worked, I followed the <a href="https://github.com/LLK/scratchx/wiki">Scratch Extension documentation</a> and some of the examples linked from the site to creating a Javascript module to implement these movement commands.</p>
<p><figure id="attachment_2221" aria-describedby="caption-attachment-2221" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2016/03/ScratchRobot1.png"><img loading="lazy" decoding="async" class="wp-image-2221 size-large" src="https://gergely.imreh.net/blog/wp-content/uploads/2016/03/ScratchRobot1-1024x640.png" alt="Scratch script for robot control" width="604" height="378" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2016/03/ScratchRobot1-1024x640.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2016/03/ScratchRobot1-500x313.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2016/03/ScratchRobot1-768x480.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2016/03/ScratchRobot1.png 1280w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2221" class="wp-caption-text">Example Scratch script to control the robot, samba moves included (click for full size)</figcaption></figure></p>
<p>It didn&#8217;t take too many iterations to add the blocks like &#8220;move forward for X seconds&#8221; and so on for the other movements. I&#8217;ve created a basic project to show how these work, where the robot moves following the directional arrows: forward/backward, and turning with left/right. Figured out that 0.5 turning is about 45°, so the arrow in the screen can sort of follow the direction of the robot in the physical world. For good measure I&#8217;ve also added a complex block of &#8220;samba&#8221; steps (I&#8217;m sorry, haven&#8217;t been doing samba for years, but that&#8217;s what it reminds me of), which is triggered by pressing &#8220;s&#8221; on the keyboard. Here&#8217;s a demo of the robot controlled through Scratch:</p>
<p><iframe loading="lazy" title="Robot control with Scratch" width="580" height="326" src="https://www.youtube.com/embed/TrbbcAt2srY?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<p>The source code naturally is <a href="https://github.com/imrehg/viarobot">available on Github</a>, both the module and an example Scratch project.</p>
<h2>Lessons Learned</h2>
<p>Provided that you have a bit of Javascript knowledge, it&#8217;s super easy to create new scratch extensions. The platform is very quite well thought out and flexible. That code can be so easily included from public sources is very handy. They also make <a href="https://jquery.com/">jQuery</a> available from within the scripts so that helps with simplifying code generally (especially working with web APIs).</p>
<p>The experience also showed me how important is the firmware in the case of hardware control. For example the current firmware on the robot never thought of their API being called outside of the browser, thus I&#8217;ve run into &#8220;<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS">Access-Control-Allow-Origin</a>&#8221; issues. It doesn&#8217;t make things unworkable, but something that needs to be worked around. There are other robots that have extensions available, as well as an extension to control Arduino: that&#8217;s also available only because of a specific firmware, <a href="https://github.com/firmata/arduino">Firmata</a> to create a proper API for controlling the boards.</p>
<p>Since the Javascript modules need to be committed to git, pushed to Github, and the Scratch page reloaded, it helps a lot to run the module through <a href="https://github.com/reid/node-jslint">jslint</a> to catch at least the syntax errors (or have an IDE that can do that for you).</p>
<h2>Future Ideas</h2>
<p>I got enough taste of Scratch to come back for more. There are a couple of ideas that I&#8217;d like to figure out in the future, specific to this robot project and otherwise:</p>
<p>I&#8217;m not using some of the <strong>reserved functions</strong> of Scratch Extension modules,  the <span class="lang:default decode:true  crayon-inline ">_getStatus()</span>  function in particular, that could show whether or not the robot is connected. Should add that functionality to this robot module, though it is not yet clear to me how things should work.</p>
<p>Would be great to be able to bring the <strong>video stream</strong> into Scratch. I see functionality to enable the webcam on the computer, but the modules can&#8217;t control graphics as far as I can tell yet. This would enable a lot of interesting use cases. Especially if coupled with transparent overlays. I can imagine video streams from the robot as a cockpit image, or adding facial expressions to a &#8220;matchstick person&#8221; using a webcam and image processing&#8230;</p>
<p>Scratch is also very good with internationalization (i18n), as it has <strong>translations</strong> in dozens of languages. The current extensions cannot be translated yet, as far as I can tell, so every extension is just single language. It could be interesting, and likely demanding, to add for example <a href="https://en.wikipedia.org/wiki/Gettext">gettext style translations</a> to the extensions, one way  i18n is done in lots of projects these days.</p>
<hr />
<p>Have you used Scratch for any of your projects? Have you made an extension for it or thinking about making one? Would love to hear your experience!</p>
<p>&nbsp;</p>
<p>The post <a href="https://gergely.imreh.net/blog/2016/03/scratch-robot-itch/">Scratch Your Robot Itch</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2016/03/scratch-robot-itch/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Dorothy &#8211; a project for those away from home</title>
		<link>https://gergely.imreh.net/blog/2015/08/dorothy/</link>
					<comments>https://gergely.imreh.net/blog/2015/08/dorothy/#respond</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Mon, 24 Aug 2015 15:42:28 +0000</pubDate>
				<category><![CDATA[Maker]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[Grove]]></category>
		<category><![CDATA[LinkIt One]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=2071</guid>

					<description><![CDATA[<p>I while back I&#8217;ve exchanged some of my points earned from posting projects to a MediaTek LinkIt One on the Hackster.io Store. This is my first project with that, trying to do something different than what I can do with the hardware I (literally) amassed so far. Being an expat and traveller, GPS / location [&#8230;]</p>
<p>The post <a href="https://gergely.imreh.net/blog/2015/08/dorothy/">Dorothy &#8211; a project for those away from home</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I while back I&#8217;ve exchanged some of my points earned from <a href="https://www.hackster.io/imrehg">posting projects</a> to a <a href="https://labs.mediatek.com/site/global/developer_tools/mediatek_linkit/whatis_linkit/index.gsp">MediaTek LinkIt One</a> on the <a href="https://www.hackster.io/store">Hackster.io Store</a>. This is my first project with that, trying to do something different than what I can do with the hardware I (literally) amassed so far. Being an expat and traveller, GPS / location sensing is always a timely topic, so set out to build something around that.</p>
<p>It was a long typhoon day when I started experimenting with the LinkIt one, and and as rainy days go &#8211; I&#8217;ve felt it would be great to know how far am I from home? Of course there&#8217;s a GPS in every single smartphone these days, but a dedicated device can still evoke a different feeling. So the idea for <a href="https://en.wikipedia.org/wiki/The_Wizard_of_Oz_(1939_film)">Dorothy</a> came about.</p>
<h2>Basic version: where are are you?</h2>
<p><figure id="attachment_2074" aria-describedby="caption-attachment-2074" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-07-13.23.10-min.jpg"><img loading="lazy" decoding="async" class="size-large wp-image-2074" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-07-13.23.10-min-1024x576.jpg" alt="Dorothy - Long way from home" width="604" height="340" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-07-13.23.10-min-1024x576.jpg 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-07-13.23.10-min-500x281.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-07-13.23.10-min-768x432.jpg 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2074" class="wp-caption-text">Dorothy &#8211; Long way from home</figcaption></figure></p>
<p>The basic idea is connect the GPS module and a <a href="http://www.seeedstudio.com/wiki/Grove_-_LCD_RGB_Backlight">Grove LCD RGB Backlight</a> screen, and colour-code the distance from home. The LCD speaks I2C, so can directly connect it up to the I2C socket on the LinkIt One.</p>
<p><span id="more-2071"></span></p>
<p><figure id="attachment_2072" aria-describedby="caption-attachment-2072" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LinkitOneSchematics2.png"><img loading="lazy" decoding="async" class="wp-image-2072 size-large" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LinkitOneSchematics2-1024x665.png" alt="Dorothy - version 1" width="604" height="392" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LinkitOneSchematics2-1024x665.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LinkitOneSchematics2-500x325.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LinkitOneSchematics2-768x499.png 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2072" class="wp-caption-text">Dorothy &#8211; version 1</figcaption></figure></p>
<p>The colour coding follows the idea that further away people can feel &#8220;blue&#8221;, while &#8220;green&#8221; is in general a positive colour. Thus at large distances Dorothy should be more blue, while near home more green. Since the distance scales over very large values, logarithmic colouring comes handy:</p>
<ul>
<li>Below a minimum distance 100m be totally green, that is (0, 255, 0) in RGB</li>
<li>Above a maximum distance 10,000km be all blue</li>
<li>Scale between such that the blue value us <em>floor[log10(distance in meters) &#8211; log10(100)]*51.5</em>, and the green value is just <em>255 &#8211; blue</em>.
<ul>
<li>For example, at 1800m the <em>blue = 64 = floor((3.2552 &#8211; 2)*51.5)</em>,</li>
<li>then <em>green = 191 = 255 &#8211; 64</em></li>
</ul>
</li>
</ul>
<p>The text is also changing by the scale: at large distances don&#8217;t have to be too precise, at short distances nicer tho show more, and at all scales use the 16&#215;2 display as fully as possible.</p>
<p>The end result is something like this:</p>
<p><figure id="attachment_2086" aria-describedby="caption-attachment-2086" style="width: 600px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/lcd.gif"><img loading="lazy" decoding="async" class="size-full wp-image-2086" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/lcd.gif" alt="LCD color change by distance" width="600" height="200" /></a><figcaption id="caption-attachment-2086" class="wp-caption-text">LCD color change by distance</figcaption></figure></p>
<p>The distances are calculated using the <a href="https://en.wikipedia.org/wiki/Great-circle_distance#Computational_formulas">Great Circle formulas</a> and 6371km as the Earth&#8217;s radius. The board has of course enough computing power of course to use the more precise Vincenty formula, and the Math library has all relevant functions at hand.</p>
<p>It&#8217;s pretty cool that the LinkIt One comes with the LiPo battery by default, so all of this setup is super portable. Not sure how long the system works on battery, but so far my guess is &#8220;definitely more than 30 minutes&#8221;, probably at least a few times more than that.</p>
<p><figure id="attachment_2075" aria-describedby="caption-attachment-2075" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-07-20.44.44-min.jpg"><img loading="lazy" decoding="async" class="size-large wp-image-2075" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-07-20.44.44-min-1024x576.jpg" alt="Dorothy - On the train" width="604" height="340" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-07-20.44.44-min-1024x576.jpg 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-07-20.44.44-min-500x281.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-07-20.44.44-min-768x432.jpg 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2075" class="wp-caption-text">Dorothy &#8211; On the train</figcaption></figure></p>
<p>Taking Dorothy on the is a perfect use case, here&#8217;s a video too, just for fun &#8211; so don&#8217;t mind the quality too much, no stabilizer for my camera, and this a moving train after all&#8230;</p>
<p>https://www.youtube.com/watch?v=c83YCSIv55I</p>
<p>The home location here is hard-coded into the program flashed onto the board, so to change it, one needs a computer to modify and reflash. That&#8217;s not very handy, so let&#8217;s upgrade things.</p>
<h2>Level up: leave a marker</h2>
<p>One way to make this more useful is having the ability of dropping a marker. Imagine that you are travelling to a new town and want to know during the day how far you are from your lodging. Drop a marker at the lodging when heading out, then later can use the distance as &#8220;breadcrumbs&#8221; going back (realistically &#8211; to augment your map, but still).</p>
<p>For this I needed to add some way to interact with the board &#8211; a touch button! The LinkIt One does not have any Grove digital I/O connector (just an I2C and a Serial), so had to add  <a href="http://www.seeedstudio.com/depot/Base-Shield-V2-p-1378.html">Grove Base Shield</a> into the mix too.</p>
<p><figure id="attachment_2073" aria-describedby="caption-attachment-2073" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LinkitOneSchematics1.png"><img loading="lazy" decoding="async" class="wp-image-2073 size-large" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LinkitOneSchematics1-1024x665.png" alt="Dorothy - version 2" width="604" height="392" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LinkitOneSchematics1-1024x665.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LinkitOneSchematics1-500x325.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LinkitOneSchematics1-768x499.png 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2073" class="wp-caption-text">Dorothy &#8211; version 2</figcaption></figure></p>
<p>First I&#8217;ve tried with a <a href="http://www.seeedstudio.com/wiki/Grove_-_Button">Grove Button</a>, but it seems like some pull-up resistor default setting makes it stuck at &#8220;permanently pressed&#8221; (as <a href="http://www.seeedstudio.com/forum/viewtopic.php?f=42&amp;t=5908">others reported this bug too</a>). I guess there would be some deep software setting that would fix this, but in the meantime I went with a <a href="http://www.seeedstudio.com/wiki/Grove_-_Touch_Sensor">Grove Touch Sensor</a> instead, as it was reported working (it does work!)</p>
<p>Now the logic becomes the following:</p>
<p>After bootup Dorothy looks for GPS satellites. When it finds some, shows the distance from the hard-coded location. Now touching the sensor will save the current location as the home.</p>
<p><figure id="attachment_2078" aria-describedby="caption-attachment-2078" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.26-min.jpg"><img loading="lazy" decoding="async" class="size-large wp-image-2078" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.26-min-1024x715.jpg" alt="Setting a new home location" width="604" height="422" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.26-min-1024x715.jpg 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.26-min-500x349.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.26-min-768x536.jpg 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2078" class="wp-caption-text">Setting a new home location</figcaption></figure></p>
<p>Then of course you&#8217;ll appear instantly &#8220;at home&#8221;. The location info is stored on the internal flash, and so it will survive reboot.</p>
<p><figure id="attachment_2079" aria-describedby="caption-attachment-2079" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.52-min.jpg"><img loading="lazy" decoding="async" class="size-large wp-image-2079" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.52-min-1024x715.jpg" alt="Dorothy - near home" width="604" height="422" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.52-min-1024x715.jpg 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.52-min-500x349.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.52-min-768x536.jpg 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2079" class="wp-caption-text">Dorothy &#8211; near home</figcaption></figure></p>
<p>If starting the board in &#8220;Mass Storage Mode&#8221; (by flipping the appropriate switch near the back of the board), then you can find the saved location data in a file called &#8220;<em>homelocation.log</em>&#8220;. You can also update that file to add a new home location without reflashing (the contents are just decimal longitude &amp; latitude, both followed by a comma, and without any space or new line).</p>
<p>If a location is already saved, touching the sensor will clear the location data and goes back tracking the hard-coded home location (deletes the above mentioned file).</p>
<p><figure id="attachment_2077" aria-describedby="caption-attachment-2077" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.20-min.jpg"><img loading="lazy" decoding="async" class="size-large wp-image-2077" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.20-min-1024x715.jpg" alt="Back to flashed home location" width="604" height="422" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.20-min-1024x715.jpg 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.20-min-500x349.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-23-22.54.20-min-768x536.jpg 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2077" class="wp-caption-text">Back to flashed home location</figcaption></figure></p>
<p>To make sure that it&#8217;s not that easy to mess up the location save, Dorothy checks for a touch sensor on start. If there&#8217;s no touch sensor then the internal pull-up shows a &#8220;HIGH&#8221; value, and in that case turn off the sensor monitoring code. That means no home location save until the board is restarted with a touch sensor attached.</p>
<p>The source code for all this is <a href="https://github.com/imrehg/dorothy">available on Github</a>! It is based on the GPS demo included in the LinkIt One SDK, just heavily modified.</p>
<h2>Future</h2>
<p>It was an interesting first project with this board. Probably Dorothy will stop here, most other changes I can think of are more &#8220;complications&#8221; than &#8220;improvements&#8221;, so probably not worth doing at this stage. I&#8217;d love to hear suggestions, though!</p>
<p>For the board so far my impression is quite positive, even though there are some difficult issues remaining:</p>
<ul>
<li>there&#8217;s no Linux support for the SDK (only Windows and Mac), though I guess it&#8217;s more of a choice than a fundamental problem. The only parts of the SDK that is probably not available for Linux is the firmware flasher &#8211; which does not work for me on Windows anyways. The IDE is based on Arduino so that should be fine, the compiler is gcc (I think) so that&#8217;s fine too&#8230;.</li>
<li>the <a href="http://labs.mediatek.com/site/global/developer_tools/mediatek_linkit/api_references/Core_Digital.gsp">SDK documentation</a> is quite patchy. Can&#8217;t use the API docs by themselves as not everything is explained. For many things I have to look at the examples directly, and even then it&#8217;s more trial &amp; error</li>
<li>the hardware bugs like the over-eager pull-up are annoying (and harder to debug than software bugs)</li>
</ul>
<p>But there are other stuff that makes me want to try more things out:</p>
<ul>
<li>onboard SD card is cool (even if cannot be used in the same time as the internal flash)</li>
<li>onboard audio, WiFi, Bluetooth are also very cool</li>
<li>the battery is very useful, will try to measure how long it can last and build some projects around that.</li>
</ul>
<p>From LinkIt One&#8217;s messaging I see they want it to be the ultimate prototyping platform for Wearables and IoT. I don&#8217;t think it&#8217;s the ultimate one, but definitely a very handy tool.</p>
<p>And this was a fun project. My homesickness has abated a bit too, which is nice. :)</p>
<p>The post <a href="https://gergely.imreh.net/blog/2015/08/dorothy/">Dorothy &#8211; a project for those away from home</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2015/08/dorothy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>My first non-trivial hardware: PCIeDuino</title>
		<link>https://gergely.imreh.net/blog/2015/08/pcieduino/</link>
					<comments>https://gergely.imreh.net/blog/2015/08/pcieduino/#comments</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Fri, 21 Aug 2015 14:17:10 +0000</pubDate>
				<category><![CDATA[Maker]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[hardware design]]></category>
		<category><![CDATA[open hardware]]></category>
		<category><![CDATA[Tindie]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=1993</guid>

					<description><![CDATA[<p>Just a bit more than a year ago I&#8217;ve started to work on a hardware idea as a challenge &#8211; a mini-PCIe form factor Arduino clone, the PCIeDuino.  The inspiration was working with a bunch of embedded boards, especially the VIA VAB-600 Springboard, that had a mini-PCIe connector, but not that many accessories that can [&#8230;]</p>
<p>The post <a href="https://gergely.imreh.net/blog/2015/08/pcieduino/">My first non-trivial hardware: PCIeDuino</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Just a bit more than a year ago I&#8217;ve started to work on a hardware idea as a challenge &#8211; a mini-PCIe form factor <a href="https://www.arduino.cc/">Arduino</a> clone, the <a href="https://www.tindie.com/products/imrehg/pcieduino/">PCIeDuino</a>.  The inspiration was working with a bunch of embedded boards, especially the <a href="http://www.viaembedded.com/en/boards/pico-itx/vab-600/">VIA VAB-600 Springboard</a>, that had a mini-PCIe connector, but not that many accessories that can go in there. (Disclaimer, I work at VIA at the moment, though this wasn&#8217;t a work project). I thought it would be cool to put an embedded-grade microcontroller on these boards, mostly to expand the I/O capabilities.</p>
<h2>Idea</h2>
<p><figure id="attachment_2034" aria-describedby="caption-attachment-2034" style="width: 720px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="size-large wp-image-2034" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LabBook1-min-1024x715.jpg" alt="The original PCIeDuino sketch in my lab book" width="720" height="503" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LabBook1-min-1024x715.jpg 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LabBook1-min-500x349.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/LabBook1-min-768x536.jpg 768w" sizes="auto, (max-width: 720px) 100vw, 720px" /><figcaption id="caption-attachment-2034" class="wp-caption-text">The original PCIeDuino sketch in my lab book</figcaption></figure></p>
<p>Looking at the mini-PCIe specs, the connector has mandatory USB 2.0 lines so communication was solved. The area available, roughly 5.1 x 3.0 cm, is not too bad  -more than how big the <a href="https://www.arduino.cc/en/Main/ArduinoBoardNano">Arduino Nano</a> is in comparison. The biggest challenge probably was that there are only 3.3V power lines available, and most example designs use 5V power supply.</p>
<p><span id="more-1993"></span></p>
<p>Fortunately Arduino is released under quite permissive <a href="https://creativecommons.org/licenses/by-sa/3.0/">Creative Commons CC-BY-SA</a> license, which means whoever makes an Arduino clone, also has to release it under the same license. This gave a lot of interesting designs to scout and learn from.</p>
<p>The original plan was using a similar Bill of Materials as the Nano, based around the <a href="http://www.atmel.com/devices/atmega328p.aspx">ATmega328P</a>, but two things happened to change it. First, I&#8217;ve changed my mind that I didn&#8217;t want to use the FTDI FT232 chip they used for USB-to-UART conversion. Second, my clever electronics friend Niko figured out that the tiny bit more advanced <a href="http://www.atmel.com/devices/atmega328p.aspx">ATmega32U4</a> microcontroller would also work at 3.3V and since it speaks USB natively, could cut a bunch of components (that&#8217;s always good). The trade-off is a bit of clock speed (running at 8MHz), but that&#8217;s acceptable.</p>
<h2>Design</h2>
<p>I did find clone with these parameters (3.3V power and ATmega32U4), the <a href="https://www.sparkfun.com/products/12587">SparkFun Pro Micro 3.3V</a>.  Took that basic design, replaced some components, added a Power LED,  and broke out the pins differently. Done in <a href="http://www.kicad-pcb.org/">KiCad</a>, the result is this PCIeDuino design below (or check the <a href="https://github.com/moonpunchorg/pcieduino/blob/master/pcieduino.pdf">PDF version)</a>.</p>
<p><figure id="attachment_2055" aria-describedby="caption-attachment-2055" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/pcieduino_schematic.png"><img loading="lazy" decoding="async" class="size-large wp-image-2055" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/pcieduino_schematic-1024x724.png" alt="PCIeDuino Schematic (click for full size)" width="604" height="427" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/pcieduino_schematic-1024x724.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/pcieduino_schematic-500x354.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/pcieduino_schematic-768x543.png 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2055" class="wp-caption-text">PCIeDuino Schematic (click for full size)</figcaption></figure></p>
<p>The next step was fitting all these components onto a mini-PCIe card. The board size was sketched in detail in the specs, though somehow all the dimensions were described in a way that it was quite inconvenient for making a board outline. Nothing that an hour of math cannot fix&#8230;</p>
<p><figure id="attachment_2061" aria-describedby="caption-attachment-2061" style="width: 641px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/miniPCIe_full.png"><img loading="lazy" decoding="async" class="size-full wp-image-2061" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/miniPCIe_full.png" alt="Full sized mini-PCIe card dimensions" width="641" height="400" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/miniPCIe_full.png 641w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/miniPCIe_full-500x312.png 500w" sizes="auto, (max-width: 641px) 100vw, 641px" /></a><figcaption id="caption-attachment-2061" class="wp-caption-text">Full sized mini-PCIe card dimensions</figcaption></figure></p>
<p>Actually, had to do the board layout twice, because for the first prototype (that I actually got printed) somehow had a crystal footprint that doesn&#8217;t correspond to any available 8Mhz crystal that I needed &#8211; so had to start again a bit. I took that chance to reorganize the board bit, and that extra round of design did a lot of good to the quality! More logical layout, better component grouping, simplified arrangement.</p>
<p>The biggest challenge at this stage was wiring the output pins. That part was done with a few tries of autorouting with <a href="https://github.com/nikropht/FreeRouting/">FreeRouting</a>. The idea being that it&#8217;s a low frequency, small board so likely not too demanding design-wise, and getting it printed is more important that fine-tuning it to death. The USB line was hand-matched, though, and the LEDs were arranged to face the same way for easier mounting, so not all just auto-optimize.</p>
<p>The tape-out happened in May, about 9 months after getting started (and about 4 months downtime in between). The resulting board looks like this:</p>
<p><figure id="attachment_2056" aria-describedby="caption-attachment-2056" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/seeed_20150524_top_small_functional_white.png"><img loading="lazy" decoding="async" class="size-large wp-image-2056" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/seeed_20150524_top_small_functional_white-1002x1024.png" alt="Functional Diagram (click to enlarge)" width="604" height="617" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/seeed_20150524_top_small_functional_white-1002x1024.png 1002w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/seeed_20150524_top_small_functional_white-489x500.png 489w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/seeed_20150524_top_small_functional_white-768x785.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/seeed_20150524_top_small_functional_white.png 1164w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2056" class="wp-caption-text">Functional Diagram (click to enlarge)</figcaption></figure></p>
<p>I&#8217;ve submitted the board to <a href="http://www.seeedstudio.com/service/index.php?r=pcb">Seeed Studio&#8217;s Fusion PCB service</a>, and got it back in about 2 weeks. In the meantime the components were ordered from <a href="http://www.mouser.tw/Home.aspx">Mouser</a>, the parts for 10 boards (equal to the number of PCBs printed)  just being above the minimum threshold for free shipping.</p>
<h2>Alive</h2>
<p>Then came the assembly &#8211; hand soldered surface mount components can be really frustrating, but I really got to like them by now. If only my left hand was better (I&#8217;m right handed &#8211; solder in right hand, tweezers supposed to be in left). The assembly took about 1 hour altogether.</p>
<p><figure id="attachment_2057" aria-describedby="caption-attachment-2057" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/PCIeDuino_magnifying.jpg"><img loading="lazy" decoding="async" class="size-large wp-image-2057" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/PCIeDuino_magnifying-1024x576.jpg" alt="Under the magnifying glass (early prototype)" width="604" height="340" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/PCIeDuino_magnifying-1024x576.jpg 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/PCIeDuino_magnifying-500x281.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/PCIeDuino_magnifying-768x432.jpg 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2057" class="wp-caption-text">Under the magnifying glass (early prototype)</figcaption></figure></p>
<p>Now it&#8217;s time for waking the board up. Fortunately SparkFun&#8217;s <a href="https://github.com/sparkfun/SF32u4_boards">Pro Micro firmware</a> fits nicely onto the PCIeDuino too. Using an <a href="https://learn.adafruit.com/usbtinyisp/overview">USBTinyISP</a> clone (from eBay), a bunch of <a href="http://www.mouser.tw/Search/ProductDetail.aspx?R=0922-0-15-20-75-14-11-0virtualkey57510000virtualkey575-922015">pogo pins</a>, and the ISP headers on the board I could flash the firmware.</p>
<p>Plug it into the the embedded board and powering up, the blinking D13 LED showed that everything should be pretty close to alright!</p>
<p><figure id="attachment_2058" aria-describedby="caption-attachment-2058" style="width: 604px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/PCIeDuino_spark.jpg"><img loading="lazy" decoding="async" class="wp-image-2058 size-large" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/PCIeDuino_spark-1024x576.jpg" alt="The spark of life" width="604" height="340" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/PCIeDuino_spark-1024x576.jpg 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/PCIeDuino_spark-500x281.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/PCIeDuino_spark-768x432.jpg 768w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2058" class="wp-caption-text">The spark of life &#8211; PCIeDuino in a Springboard</figcaption></figure></p>
<p>Since then I&#8217;ve assembled altogether 7 of the boards (still takes about 1 hour each by hand, but I&#8217;m getting better). Had a few failures, but now I also know how to diagnose those issues better.</p>
<p>(If curious, so far had &#8220;magic smoke&#8221;, cold joint, shorted microcontroller pins, and now a board with a short somewhere that triggered the fuse. Ah, the learning!)</p>
<h2>Advanced</h2>
<p>Now the <a href="https://www.tindie.com/products/imrehg/pcieduino/">PCIeDuino is available on Tindie</a> (whenever I have a bit of time to assemble more). It a great experience trying to make a compelling maker project that other people want to use too! Having better documentation, more explanation, better software, better communication, and actually going out finding people who are interested in this could be pretty much full time work!</p>
<p>I got my first <a href="http://hackaday.com/2015/07/24/arduino-pci-express/">Hackaday feature</a> too, not that it was a great article, but the discussion was very illuminating and helped me to polish my own idea regarding this project.</p>
<p>All the <a href="https://github.com/moonpunchorg/pcieduino">KiCAd source and Gerber files</a> are available on Github with CC-BY-SA license, so others can take this design to places too!</p>
<h2>Future</h2>
<p>The PCIeDuino is still very much a prototype project, more suitable probably for advanced users who are not put off when not every path is well worn out. I have to test it a lot more too, and <strong>find interesting use cases</strong>!</p>
<p>It looks like that the SparkFun <strong>firmware</strong> is not very well maintained, and it could be useful to look for alternatives. <a href="https://github.com/Optiboot/optiboot">Optiboot</a> seems to be interesting, but it also needs some work for the ATmega32U4 chip. Software support is super important, though, so this got to be a high priority improvement.</p>
<p>The original idea was to use this on embedded boards, that are mostly ARM systems. It should also be easy to use, Arduino IDE compatible project. The problem is, that the two parts are at odds with each other. The <strong>Arduino IDE doesn&#8217;t quite work well on ARM</strong> yet, so it&#8217;s mostly command line operation at the moment. Not a breaking change, but still a fail that needs to be remedied somehow.</p>
<p>The board is designed to conform to the mini-PCIe board specs. It fulfills the full-sized board variation&#8217;s requirements: the board outline, 1.0mm PCB thickness, connector pins,  mounting, keep out zones, &#8230;. It does not do the beveled cut at the connector (45º bevel cut needed, but seems to work regardless). To help other people to design mini-PCIe boards, I&#8217;ve put together a <strong>bare board starter kit</strong> in KiCad, <a href="https://github.com/moonpunchorg/baseboards">available on Github</a>, which includes the connector schematic, board outline, pin placement, and top-end mounting holes. Would be good to make a half-sized board variation design as well in the future, though at the moment it&#8217;s not a priority (pull requests welcome!)</p>
<p><figure id="attachment_2069" aria-describedby="caption-attachment-2069" style="width: 604px" class="wp-caption aligncenter"><a href="https://github.com/moonpunchorg/baseboards"><img loading="lazy" decoding="async" class="size-large wp-image-2069" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/baseboard-1024x671.png" alt="Mini PCIe baseboard in KiCad (click for source)" width="604" height="396" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/baseboard-1024x671.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/baseboard-500x327.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/baseboard-768x503.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/baseboard.png 1139w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2069" class="wp-caption-text">Mini PCIe baseboard in KiCad (click for source)</figcaption></figure></p>
<p>This project also gave me a lot of <strong>ideas for future devices</strong>: similar mini-PCIe designs with ATXmega or ARM Cortex-M microcontrollers, and other Arduino clones with special functionality, e.g. built around the <a href="http://www.atmel.com/devices/ATMEGA2564RFR2.aspx">ATmega2564RF2</a> for  <a href="https://en.wikipedia.org/wiki/IEEE_802.15.4">802.15.4</a> mesh networking&#8230; But first, take this design to its full potential&#8230;</p>
<p>If you like this idea, check out the <a href="https://www.tindie.com/products/imrehg/pcieduino/">PCIeDuino on Tindie</a>, and would love to hear any kind of feedback or comment too! There&#8217;s a lot to improve, even if this is really the most complex electronics design I made so far&#8230; Now back to the drawing board and to soldering!</p>
<p>The post <a href="https://gergely.imreh.net/blog/2015/08/pcieduino/">My first non-trivial hardware: PCIeDuino</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2015/08/pcieduino/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Is there an Uncanny Valley for hardware projects?</title>
		<link>https://gergely.imreh.net/blog/2015/08/maker-uncanny-valley/</link>
					<comments>https://gergely.imreh.net/blog/2015/08/maker-uncanny-valley/#comments</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Thu, 20 Aug 2015 06:02:18 +0000</pubDate>
				<category><![CDATA[Maker]]></category>
		<category><![CDATA[Thinking]]></category>
		<category><![CDATA[hardware design]]></category>
		<category><![CDATA[hardware startup]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=2048</guid>

					<description><![CDATA[<p>The concept of the Uncanny Valley comes from robotics, its hypothesis says that when humanoid robots move and feel almost, but not completely like the real thing, they can be more off-putting than the robots that have less human likeness. Working on quite a few hardware projects these days, I started to wonder (okay, say [&#8230;]</p>
<p>The post <a href="https://gergely.imreh.net/blog/2015/08/maker-uncanny-valley/">Is there an Uncanny Valley for hardware projects?</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The concept of the <a href="https://en.wikipedia.org/wiki/Uncanny_valley">Uncanny Valley</a> comes from robotics, its hypothesis says that when humanoid robots move and feel almost, but not completely like the real thing, they can be more off-putting than the robots that have less human likeness.</p>
<p>Working on quite a few hardware projects these days, I started to wonder (okay, say it out loud: worry), that there&#8217;s an uncanny valley for hardware projects as well. My theory goes such that hardware projects that are almost, but not completely professional can be more off-putting (or underwhelming) than less advanced, clearly maker projects and prototypes.</p>
<p><span id="more-2048"></span></p>
<p><figure id="attachment_2049" aria-describedby="caption-attachment-2049" style="width: 700px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="wp-image-2049 size-full" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/MakerUncannyValley.png" alt="Uncanny Valley sketch" width="700" height="400" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/MakerUncannyValley.png 700w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/MakerUncannyValley-500x286.png 500w" sizes="auto, (max-width: 700px) 100vw, 700px" /><figcaption id="caption-attachment-2049" class="wp-caption-text">The hardware project Uncanny Valley sketch</figcaption></figure></p>
<p>To give a few examples of cases that I feel might fall into this uncanny valley:</p>
<ul>
<li>a gadget that moved on to more advanced, <strong>surface-mount components, but they are hand-soldered</strong> (instead of done with a reflow oven). Functionality is the same (hopefully), but the visual appearance is always a bit less organized</li>
<li>a project that has <strong>very detailed documentation, but not quite a complete manual</strong>, leaving just enough uncertainty to possibly frustrate some semi-advanced users</li>
<li><strong>packaging / invoice done nicely but not as good or clear or standardized</strong> as e.g. a Mouser order (just as an example), going overboard with what to include or not going far enough (quick start guide, any help, disclaimers, policies &#8211; are they needed, and if yes, in what depth to cover the topic?)</li>
<li><strong>communication is more polished but still fall short</strong> of professional customer service in clarity, or hitting the right tone, or being too corporate-y (or too little), taking just a bit too much time to reply to questions, and so on&#8230;.</li>
</ul>
<p>I guess many of these issues arise around the time when makers want to start earning a few buck with their work, and not everyone is prepared to cross this region of professionalism. But if there&#8217;s a valley, you&#8217;d better stay on the low side, or fight through to the upside with plenty of effort.</p>
<p>If there&#8217;s a valley like that, I guess it&#8217;s still a good problem to have, and platforms like <a href="https://www.tindie.com">Tindie</a> (the indie hardware marketplace) do a good job of throwing people into the deep end into these issues. I myself trying to figure out whether I&#8217;m in there yet (and whether I&#8217;m making progress). I might just be overthinking this&#8230;</p>
<p>So what do you think, is there such an Uncanny valley for hardware? If there is, have you experienced and survived it? (any advice if you did?;)</p>
<p><strong>Edit (2015 Aug 28)</strong>: this post got a surprise mention on <a href="http://www.theamphour.com/264-the-cost-of-doing-business/">The Amp Hour</a> podcast where <a href="https://twitter.com/Chris_Gammell">Chris Gammell</a> of <a href="https://contextualelectronics.com/">Contextual Electronics</a> and <a href="https://twitter.com/eevblog/">Dave Jones</a> of <a href="http://www.eevblog.com/">EEVblog</a> discuss all things electronics. Glad they (pretty strongly) disagreed, that means I&#8217;m overthinking it for the lack of experience (compared to them for sure). The part about this is between 5:00-15:00, but the whole podcast is good! (And I&#8217;m fan of their sites too:) Cheers~</p>
<p>The post <a href="https://gergely.imreh.net/blog/2015/08/maker-uncanny-valley/">Is there an Uncanny Valley for hardware projects?</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2015/08/maker-uncanny-valley/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>A window to IRC with Edison and Resin</title>
		<link>https://gergely.imreh.net/blog/2015/08/a-window-to-irc-with-edison-and-resin/</link>
					<comments>https://gergely.imreh.net/blog/2015/08/a-window-to-irc-with-edison-and-resin/#comments</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Sat, 01 Aug 2015 15:26:07 +0000</pubDate>
				<category><![CDATA[Maker]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Intel Edison]]></category>
		<category><![CDATA[IRC]]></category>
		<category><![CDATA[Resin.io]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=1995</guid>

					<description><![CDATA[<p>Displaying the chatter on IRC for those who are not online themselves. A cloud IoT project.</p>
<p>The post <a href="https://gergely.imreh.net/blog/2015/08/a-window-to-irc-with-edison-and-resin/">A window to IRC with Edison and Resin</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>After trying <a href="https://resin.io">Resin.io</a> briefly with <a href="https://gergely.imreh.net/blog/2015/05/resin_io_somastream/">a SomaFM Streaming Application</a>, I was eager to experiment more with their cloud deployment platform. Maybe some new hardware, maybe some more complex project&#8230; In the end, it became a little bit of both: here&#8217;s MrEdison, and portable IRC chat display based on Intel Edison.</p>
<p><figure id="attachment_1997" aria-describedby="caption-attachment-1997" style="width: 550px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-01-21.34.28.jpg"><img loading="lazy" decoding="async" class="size-large wp-image-1997" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-01-21.34.28-1024x576.jpg" alt="Checking out the chatter on the #ubuntu channel" width="550" height="309" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-01-21.34.28-1024x576.jpg 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-01-21.34.28-500x281.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/2015-08-01-21.34.28-768x432.jpg 768w" sizes="auto, (max-width: 550px) 100vw, 550px" /></a><figcaption id="caption-attachment-1997" class="wp-caption-text">Checking out the chatter on the #ubuntu channel</figcaption></figure></p>
<p>The idea came from the fact that we have an IRC channel for the <a href="https://taipeihack.org">Taipei Hackerspace</a>, <a href="https://taipeihack.org/#irc">#taipeihack on Freenode</a>, just it is not very well (or rather: at all) frequented by people. I wanted to break that channel out of the computer, and put a physical window to it in the &#8216;space, so people can see what&#8217;s going on, and hopefully want to get on too!</p>
<p><span id="more-1995"></span></p>
<p>Here is it in action:</p>
<p><iframe loading="lazy" title="MrEdison: IRC channel monitoring demo" width="580" height="326" src="https://www.youtube.com/embed/8BpqkYePXUw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<h2>Hardware</h2>
<p>For this I&#8217;ve used parts that were pretty much lying around in the Hackerspace:</p>
<ul>
<li>an <a href="https://www-ssl.intel.com/content/www/us/en/do-it-yourself/edison.html">Intel Edison</a>, then added&#8230;</li>
<li>an Android Breakout Board,</li>
<li>a <a href="http://www.seeedstudio.com/wiki/Grove_-_Base_Shield_V1.3">Grove Base Shield</a></li>
<li>a <a href="http://www.seeedstudio.com/wiki/Grove_-_LCD_RGB_Backlight">Grove RGB-LCD</a> (that is controlled over the I2C lines)</li>
<li>a <a href="http://www.seeedstudio.com/wiki/Grove_-_Red_LED">Grove LED</a> (on one of the digital pins)</li>
</ul>
<p><figure id="attachment_2006" aria-describedby="caption-attachment-2006" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/MrEdisonSchematic.png"><img loading="lazy" decoding="async" class="wp-image-2006 size-medium" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/MrEdisonSchematic-500x444.png" alt="MrEdison Schematic" width="500" height="444" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/MrEdisonSchematic-500x444.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/MrEdisonSchematic.png 593w" sizes="auto, (max-width: 500px) 100vw, 500px" /></a><figcaption id="caption-attachment-2006" class="wp-caption-text">MrEdison Schematic</figcaption></figure></p>
<p>I&#8217;ve started a new project in the Resin.io interface based on Edison. Downloaded their image (and <a href="http://docs.resin.io/#/pages/installing/gettingStarted-Edison.md">checked out getting started guide</a>), flashed it onto the board through the Android breakout board, and it was ready to get some code on (well, kinda).</p>
<h2>Software</h2>
<p>In the docs I&#8217;ve found that there&#8217;s <a href="http://docs.resin.io/#/pages/configuration/resin-base-images.md#i386-intel-edison">a specific docker starter container</a> made by the Resin team for Python code, and that looked like a good point to start off from.</p>
<p>First I was thinking using the default <a href="https://github.com/intel-iot-devkit/mraa">mraa library</a> that Intel provides for the low level I/O, but fortunately also found <a href="https://github.com/intel-iot-devkit/upm">UPM</a>, a higher level library that already supports a lot of sensors and I/O &#8211; including the RGB-LCD! That saves a lot of time indeed, and has both Python and Node.js API for quicker code (besides the base C++).</p>
<p>Mraa is already installed on the base image, but UPM had to be added manually to the Dockerfile.</p>
<p>The base function of the code is crystallized out as:</p>
<ul>
<li>connect to a specified IRC server and join a specific channel</li>
<li>listen to the messages there</li>
<li>on the LCD display the messages as:
<ul>
<li>first line shows the user that posted</li>
<li>second line is the message posted, if longer than the width of the LCD then scroll it</li>
<li>to quickly distinguish between people, assign different colours to the different users</li>
</ul>
</li>
<li>blink the LED on new messages</li>
<li>keep doing this&#8230;</li>
</ul>
<p>Straightforward enough?</p>
<p><figure id="attachment_1996" aria-describedby="caption-attachment-1996" style="width: 360px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/MrEdisonAnimation.gif"><img loading="lazy" decoding="async" class="size-full wp-image-1996" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/MrEdisonAnimation.gif" alt="MrEdison at work" width="360" height="202" /></a><figcaption id="caption-attachment-1996" class="wp-caption-text">MrEdison at work</figcaption></figure></p>
<p>I&#8217;ve used the <a href="https://pypi.python.org/pypi/irc">irc</a> library in Python to create a simple IRC bot that listens to the channel and does the required I/O. Needed some code digging (because it&#8217;s not too &#8212; khm &#8212; well documented), for example to enable SSL connection for the bot part of the code (for using <a href="https://freenode.net/irc_servers.shtml">port 7070 on Freenode</a>). In the end indeed &#8220;use the source, Luke!&#8221;, as they write and it worked out.</p>
<p>The I/O part needed to be parallelized too, there used some part of the multiprocessing library that I haven&#8217;t used before (<a href="https://docs.python.org/2/library/multiprocessing.html#the-process-class">Process</a>), and some data sharing: the display can run and scroll the text, while the bot can notify the display&#8217;s process when it needs to show something new. Same for notifying the LED, when it needs to blink.</p>
<p>For doing different colours for the different usernames I use hashing: run the username through <a href="https://en.wikipedia.org/wiki/SHA-2">SHA256</a>, and use the 1st, 2nd, 3rd bytes of the resulting has as Red/Green/Blue for the backlight colour.</p>
<p>Here&#8217;s the code in Python (2.x):</p>
<pre class="lang:python decode:true  ">import hashlib
username = "MrEdison"
h = hashlib.sha256()
h.update(username)
ColorR = int(h.hexdigest()[0:2], 16)
ColorG = int(h.hexdigest()[2:4], 16)
ColorB = int(h.hexdigest()[4:6], 16)
# (ColorR, ColorG, ColorB) = (115, 126, 15) or #737EF</pre>
<p>the result:</p>
<p><figure id="attachment_2015" aria-describedby="caption-attachment-2015" style="width: 550px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="size-full wp-image-2015" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/colours550.gif" alt="Example colours" width="550" height="400" /><figcaption id="caption-attachment-2015" class="wp-caption-text">Example colours</figcaption></figure></p>
<p>Works pretty well!</p>
<p>The bot&#8217;s settings (server name, port, channel, nickname) are all set through the Resin.io control panel as environment variables.</p>
<p>Environmental variables used at the moment:</p>
<ul>
<li>SERVER: the IRC server used, defaults to <strong>irc.freenet.net</strong></li>
<li>PORT: port used, has to be SSL-enabled, defaults to <strong>6697</strong></li>
<li>CHANNEL: which channel to connect to, together with all the hashes, defaults to <strong>#mredison</strong></li>
<li>NICK: nick to choose, no authentication yet, defaults to <strong>mredison</strong></li>
<li>TIMEZONE: what timezone to display updates in standard <a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">tz database notation</a>, defaults to <strong>UTC</strong></li>
</ul>
<p><figure id="attachment_1998" aria-describedby="caption-attachment-1998" style="width: 550px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/ResinMrEdison.png"><img loading="lazy" decoding="async" class="size-large wp-image-1998" src="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/ResinMrEdison-1024x640.png" alt="Settings through environment variables in the Resin.io interface" width="550" height="344" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2015/08/ResinMrEdison-1024x640.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/ResinMrEdison-500x313.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/ResinMrEdison-768x480.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2015/08/ResinMrEdison.png 1280w" sizes="auto, (max-width: 550px) 100vw, 550px" /></a><figcaption id="caption-attachment-1998" class="wp-caption-text">Settings through environment variables in the Resin.io interface</figcaption></figure></p>
<p>This makes it quite flexible, can let the bot/setup monitor any channel on any network, though at the moment needs SSL-enabled server, but that&#8217;s easy enough to change if someone wants to run the code and don&#8217;t care about security&#8230; :P</p>
<p>For testing I was using mostly the #ubuntu and ##linux channels, as they seems to be pretty chatty!</p>
<h2>Experience</h2>
<p>It was a bit bumpy process, like most experimental works. First I&#8217;ve run into some <a href="http://talk.resin.io/t/i2c-crashes-cant-use-e-g-lcd-rgb/100">Edison/Docker related strangeness</a> that messed with the I/O. Solved by <a href="https://github.com/shaunmulligan/">Shaun</a> from Resin, the trick being needing to mount the debugfs before running my code, so the kernel can configure things correctly:</p>
<pre>mount -t debugfs nodev /sys/kernel/debug</pre>
<p><strong>Edit (8/1):</strong> This in the end wasn&#8217;t enough, had to go back to the <a href="http://www.emutexlabs.com/project/215-intel-edison-gpio-pin-multiplexing-guide">Edison GPIO Pin Muxing Guide</a>, and turned their <em>Example 4: Configure IO18/IO19 for I2C connectivity</em> guide into a pretty hard core, but probably well commented <a href="https://github.com/taipeihackerspace/mredison/blob/33f6a61e474fae87c7c2770282ecca7d5fe9f0c4/gpio_setup.sh">bash script</a> to set up I2C, which is called on start. Seems to work out!</p>
<p>There was also some issue with the bot timing out in a strange way and losing connection. I was about to rewrite the whole code in Node.js, but tried a quick client test first. Turns out that I was testing on port 6697 (which is I read the default SSL port), and that has some connection issues. After I&#8217;ve switched to 7070, all of that disappeared, and the connection seems pretty solid (no timeout so far).</p>
<p>There are some bugs that remain, though:</p>
<ul>
<li>Unicode handling is non-existent, so those posts can pretty much mess up the display</li>
<li>There can be race conditions using the display, not the best threading code probably&#8230;</li>
<li>At bootup, the LCD display is borked, but after adjusting the environment variables (without reboot), things sort themselves out! Maybe need to tweak the startup script and add some delay between the steps?</li>
</ul>
<p>Otherwise it&#8217;s working pretty well, the colour changes are fun, the text is readable, so I guess mission is accomplished!</p>
<p>The <a href="https://github.com/taipeihackerspace/mredison">source code is on Github</a>, and to set up your own version of this, just create a new Edison project, flash the system, clone the source code and push it to your application, finally define the environment variables SERVER, PORT, CHANNEL, NICK as they are suitable for you, and enjoy!</p>
<h2>Future</h2>
<p>It would be probably good to create an enclosure for this setup, to hold the parts together more securely. Then drop it in the Hackerspace and set it up to listen to our IRC channel &#8211; and get chatting.</p>
<p>It&#8217;s probably unlikely that I&#8217;ll change much on it in the future, most I can think of is adding some more bells &amp; whistles (or rather, literally a buzzer:), but that might be too much. The code works well enough, but pull requests are accepted!</p>
<p>I&#8217;m mostly just glad that the idea worked out, and the project is done. Now I can actually move onto another one (there are way too many projects on the waiting list, driving me nuts)&#8230;.</p>
<p>What&#8217;s your take on IRC? Do you use it? Would this project be useful for you somehow?</p>
<p><em>This project is also <a href="https://www.hackster.io/imrehg/standalone-irc-channel-monitoring">written up on hackster.io</a>.</em></p>
<p>The post <a href="https://gergely.imreh.net/blog/2015/08/a-window-to-irc-with-edison-and-resin/">A window to IRC with Edison and Resin</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2015/08/a-window-to-irc-with-edison-and-resin/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Solar powered Tibetan prayer wheel circuit</title>
		<link>https://gergely.imreh.net/blog/2014/09/tibetan-prayer-wheel-circuit/</link>
					<comments>https://gergely.imreh.net/blog/2014/09/tibetan-prayer-wheel-circuit/#comments</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Sat, 13 Sep 2014 02:09:48 +0000</pubDate>
				<category><![CDATA[Maker]]></category>
		<category><![CDATA[circuit]]></category>
		<category><![CDATA[disassembly]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[repair]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=1814</guid>

					<description><![CDATA[<p>There are all kinds of toys and fun gadgets around the house for most people that might work or be broken, but either way most people wouldn&#8217;t know how do they work inside. For example take this solar powered Tibetan prayer wheel. There are many of these out there, and found one at home lying [&#8230;]</p>
<p>The post <a href="https://gergely.imreh.net/blog/2014/09/tibetan-prayer-wheel-circuit/">Solar powered Tibetan prayer wheel circuit</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>There are all kinds of toys and fun gadgets around the house for most people that might work or be broken, but either way most people wouldn&#8217;t know how do they work inside. For example take this solar powered Tibetan prayer wheel. There are <a title="Google image search: solar tibetan prayer wheel" href="https://www.google.com.tw/search?q=solar+tibetan+prayer+wheel&amp;safe=off&amp;tbm=isch">many of these</a> out there, and found one at home lying around as well. It didn&#8217;t seem to work, and thought why not take apart to take a look?</p>
<p><figure id="attachment_1819" aria-describedby="caption-attachment-1819" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/tibetanprayerwheel.jpg"><img loading="lazy" decoding="async" class="size-medium wp-image-1819" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/tibetanprayerwheel-500x333.jpg" alt="Solar powered Tibetan prayer wheel" width="500" height="333" /></a><figcaption id="caption-attachment-1819" class="wp-caption-text">Solar powered Tibetan prayer wheel</figcaption></figure></p>
<p>The inside of this Tibetan prayer wheels is pretty straightforward: taking off the bottom cover out come two ballast stones, and drivebox with a solar panel hanging off it. The drivebox is connected to the prayer wheel outside via a rectangular shaft to turn it.<span id="more-1814"></span></p>
<p><figure id="attachment_1824" aria-describedby="caption-attachment-1824" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly1.jpg"><img loading="lazy" decoding="async" class="size-medium wp-image-1824" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly1-500x333.jpg" alt="All the parts of the solar power prayer wheel laid out" width="500" height="333" /></a><figcaption id="caption-attachment-1824" class="wp-caption-text">The prayer wheel in disassembled form</figcaption></figure></p>
<p>The drivebox contains an electronic circuit and a couple of cogwheels to turn the DC solar power into motion somehow. Originally the solar panel was not detached from the circuit board as it seems above, just after messing around with it for a while it came off&#8230;</p>
<h3>Electronics</h3>
<p>The circuit has only a handful of components and they looked reasonably intact (some surface corrosion on the capacitors and lot of grime on the transistors, but nothing that seems to be a showstopper). The round black thing on the right is a spool of thin, enamel coated wires  &#8211; a custom inductor. The wires were spun in both directions, so it is actually two inductors intertwined.  The transistors are <a title="2SC945 transistor datasheet" href="http://www.micropik.com/PDF/2sc945.pdf">C945</a> according to their marking (or 2SC945 in it&#8217;s full name, as I&#8217;ve been told). The two lines leaving the photo to the left connect to the solar panel.</p>
<p><figure id="attachment_1825" aria-describedby="caption-attachment-1825" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly2.jpg"><img loading="lazy" decoding="async" class="wp-image-1825 size-medium" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly2-500x375.jpg" alt="Closeup of the circuit board from above" width="500" height="375" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly2-500x375.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly2-768x576.jpg 768w, https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly2.jpg 1000w" sizes="auto, (max-width: 500px) 100vw, 500px" /></a><figcaption id="caption-attachment-1825" class="wp-caption-text">The circuit board inside (top view)</figcaption></figure></p>
<p>The bottom of the circuit. From here it can be reverse engineered to see how does it actually work. The enamel coated wires were freaky to have a lot of extra length after their soldering point and been all over the circuit. Probably that would be good to cut short to make sure they don&#8217;t cause any shorts in the future&#8230; The resistors were desoldered so I can check their component value, the capacitor values were read off their housing, the inductor I didn&#8217;t touch this time, so their value is an outstanding question&#8230;</p>
<p><figure id="attachment_1826" aria-describedby="caption-attachment-1826" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly3.jpg"><img loading="lazy" decoding="async" class="wp-image-1826 size-medium" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly3-500x375.jpg" alt="Closeup of the circuit board from below" width="500" height="375" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly3-500x375.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly3-768x576.jpg 768w, https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly3.jpg 1000w" sizes="auto, (max-width: 500px) 100vw, 500px" /></a><figcaption id="caption-attachment-1826" class="wp-caption-text">The circuit board inside (bottom view)</figcaption></figure></p>
<p>To figure out what the circuit does, it  helps to transcribe the diagram into schematic well. Then I messed up the legs of the transistors in the up-down flipping multiple times, so the circuit came out all wrong. Fortunately <a title="Solar powered Tibetan prayer wheel circuit issue on Reddit AskElectronics" href="http://www.reddit.com/r/AskElectronics/comments/2fpugw/solar_powered_tibetan_prayer_wheel_circuit_issue/">JohnnyThree at Reddit AskElectronics</a> helped (may he be blessed with lot of karma!:), not just to correctly transcribe the circuit but arrange the components so that it shows what the circuit really is: a variation on an <a title="Astable multivibrator on Wikipedia" href="http://en.wikipedia.org/wiki/Multivibrator#Astable_multivibrator">astable multivibrator</a>.</p>
<p><figure id="attachment_1816" aria-describedby="caption-attachment-1816" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/PrayerWheelScreenshot.png"><img loading="lazy" decoding="async" class="wp-image-1816 size-medium" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/PrayerWheelScreenshot-500x319.png" alt="The circuit schematic of the solar powered tibetan prayer wheel" width="500" height="319" /></a><figcaption id="caption-attachment-1816" class="wp-caption-text">The reverse engineered circuit schematic</figcaption></figure></p>
<p>I fixed up the circuit in <a title="KiCAD homepage" href="http://www.kicad-pcb.org/">KiCAD</a> (good learning experience as well, and go open source!). The difference between the regular astable multivibrator and this circuit is C3 capacitor between the base and collector of Q2 (according to JohnnyThree it&#8217;s to curb RF interference), and using inductors L1 and L2 instead of pure resistors.</p>
<p>Here are some additional resources if anyone&#8217;s interested:</p>
<ul>
<li><a title="PDF version of Solar Powered Tibetan Prayer Wheel Schematics" href="https://gergely.imreh.net/supplements/prayer-wheel/prayer_wheel.pdf">Schematics in PDF format</a></li>
<li><a title="KiCAD/eeschema version of the solar powered tibetan prayer wheel schematic" href="https://gergely.imreh.net/supplements/prayer-wheel/prayer_wheel.sch">KiCAD/eeschema schematic</a> and <a title="Eeschema component library cache for the solar powered Tibetan prayer wheel" href="https://gergely.imreh.net/supplements/prayer-wheel/prayer_wheel-cache.lib">component library</a></li>
</ul>
<p>Been checking some of the components separately as well when trying to figure out what was going wrong. The solar panel has <a title="Poor light type amorphous silicon solar cell at VIMUN" href="http://www.vimun.cn/en/ProductInfo.asp?pid=18">VIMUN SC-5528</a> marking on it, which would make it a 1.5V poor light type amorphous silicon solar cell. This would make a lot of sense for home electronics, poor light is basically every light. When using my smartphone&#8217;s flash as a light, I could drive it up to 2.9V output at full power, but normally was much less.</p>
<p>Since the solar panel&#8217;s connections came off the board after a while, I resoldered them, and could measure with a multimeter that the circuit does something. When connected, the voltage across solar panel maxed out around 1.VV, and the voltage across either of the inductors seemed to be oscillating between 0.3V and 1.0V with a period of about 5s. Not sure if this is any useful, just noted.</p>
<p>When I&#8217;ve put the wheel with the magnets attached back in place over the coil, it was moving a bit back and forth with the 5s period. I thought maybe the device is back to normal after reattaching the solar panel and time to reassemble.</p>
<h3>Reassembly</h3>
<p>It was time to check out whether the setup was actually working and put everything back together. The wheels were pretty hard to test when not held at their place by the drivebox&#8217;s top.</p>
<p><figure id="attachment_1827" aria-describedby="caption-attachment-1827" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly4.jpg"><img loading="lazy" decoding="async" class="wp-image-1827 size-medium" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly4-500x333.jpg" alt="Partial mechanical assembly of the prayer wheel drive box" width="500" height="333" /></a><figcaption id="caption-attachment-1827" class="wp-caption-text">The drive box with the magnetic wheel.</figcaption></figure></p>
<p>Before I&#8217;ve put the cogwheels back to the box, I&#8217;ve counted their gear ratios. The magnetic wheel has 10 teeth, the middle wheel has 70 / 12 teeth (in / out), and the final has 70 teeth again. That would mean a (70/10) × (70/12) = 7 × 5 = 35 gear ratio, I guess. The teeth on one wheel seemed not symmetric which ends up forcing the prayer wheel to only turn in one direction.</p>
<p><figure id="attachment_1828" aria-describedby="caption-attachment-1828" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly5.jpg"><img loading="lazy" decoding="async" class="wp-image-1828 size-medium" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly5-500x333.jpg" alt="Fully assembled prayer wheel drive box" width="500" height="333" /></a><figcaption id="caption-attachment-1828" class="wp-caption-text">All the wheels in place with the lid still off</figcaption></figure></p>
<p>After putting the box back together, I&#8217;ve tried illuminating the solar panel with the flashlight again and see what happens. With a little initial turn the square drive shaft (is that what the thing is called, by the way?) it did start to rotate by itself pretty well! We are on the right track.</p>
<p><figure id="attachment_1829" aria-describedby="caption-attachment-1829" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly6.jpg"><img loading="lazy" decoding="async" class="wp-image-1829 size-medium" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly6-500x333.jpg" alt="The drivebox closed up" width="500" height="333" /></a><figcaption id="caption-attachment-1829" class="wp-caption-text">The box closed up</figcaption></figure></p>
<p>The biggest difficulty putting the parts back into the box was keeping the ballast stones from dropping on the solar panel and crashing it. A little careful handling and everything&#8217;s back in place.</p>
<p><figure id="attachment_1830" aria-describedby="caption-attachment-1830" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly7.jpg"><img loading="lazy" decoding="async" class="wp-image-1830 size-medium" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/09/pw_assembly7-500x333.jpg" alt="Drivebox reinserted into the prayer wheel housing" width="500" height="333" /></a><figcaption id="caption-attachment-1830" class="wp-caption-text">The drive box reinserted into the housing, with the ballast stones and the solar panel still outside</figcaption></figure></p>
<p>Finally I could test the whole assembly. Looks like the essential ingredients are sufficient light and an initial push. Not sure if the need for the initial push is intended or just a side-effect, but it actually mimics very well the existing physical Tibetan prayer wheels where one has to set them in motion, and the intention does count for the religious purposes. Though as a note, if the light is strong enough (full blast flashlight from up close), the wheel does start by itself and goes into pretty fast spin!</p>
<p>The prayer wheel part of the assembly has a lot more inertia than the driveshaft on its own, and this it the wheel turns slower than I&#8217;ve seen in the earlier test, and stops much quicker when the light is cut off.</p>
<p><iframe loading="lazy" title="Solar Powered Tibetan Prayer Wheel" width="580" height="326" src="https://www.youtube.com/embed/oH5jmLEdZQ8?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<p>In the video I test the wheel out, kickstarting it, blocking the light to see if it is really operating from the solar panel or just the initial kick keep it moving&#8230;. So far so good!</p>
<h3>Future</h3>
<p>A couple of things I can think of as future work with this gadget:</p>
<ul>
<li>Simulate the circuit in SPICE to understand the effect of the extra capacitor and the inductors</li>
<li>Figure out whether it can it be fixed up to use less light? At the moment it&#8217;s not that easy to find a place around the house with sufficient natural light to make it work.</li>
<li>Figure out if the friction on the wheels be reduced to make them turn easier / longer?</li>
<li>What else could I hack this circuit to do?</li>
</ul>
<p>And then again, what other gadget to take apart next time?</p>
<p>The post <a href="https://gergely.imreh.net/blog/2014/09/tibetan-prayer-wheel-circuit/">Solar powered Tibetan prayer wheel circuit</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2014/09/tibetan-prayer-wheel-circuit/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>Navspark: Arduino for GPS, GLONASS, and Beidou</title>
		<link>https://gergely.imreh.net/blog/2014/05/navspark-beidou/</link>
					<comments>https://gergely.imreh.net/blog/2014/05/navspark-beidou/#comments</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Sun, 18 May 2014 14:21:16 +0000</pubDate>
				<category><![CDATA[Maker]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[beidou]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[indiegogo]]></category>
		<category><![CDATA[navspark]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=1759</guid>

					<description><![CDATA[<p>Unboxing Navspark, a GPS and Beidou satellite positioning enabled Arduino compatible device, and using it to identify the Beidou satellites visible above.</p>
<p>The post <a href="https://gergely.imreh.net/blog/2014/05/navspark-beidou/">Navspark: Arduino for GPS, GLONASS, and Beidou</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I&#8217;m very much into satellite navigation as previous projects might show (<a title="My IT travel pack" href="https://gergely.imreh.net/blog/2014/04/my-it-travel-pack/">my IT travel pack</a>, <a title="StartupBus rolling again" href="https://gergely.imreh.net/blog/2012/03/startupbus-rolling-again/">StartupBus tracking</a>, <a title="GPS satellite tracks animation " href="https://www.youtube.com/watch?v=kp09W5El52U">GPS satellite tracking</a>). Because of this I was very excited to see an <a title="Navspark Indiegogo page" href="https://www.indiegogo.com/projects/navspark-arduino-compatible-with-gps-gnss-receiver">Indiegogo project for Navspark</a>, an Arduino compatible GPS, GLONASS, and Beidou receiver. I guess everyone knows <a title="GPS Wikipedia page" href="http://en.wikipedia.org/wiki/Global_Positioning_System">GPS</a>, <a title="GLONASS Wikipedia page" href="http://en.wikipedia.org/wiki/GLONASS">GLONASS</a> is the equivalent Russian satellite network, and <a title="Beidou Wikipedia page" href="http://en.wikipedia.org/wiki/Beidou_navigation_satellite_system">Beidou</a> is the same for China.</p>
<p>I have signed up to support it for two main reasons: it&#8217;s a Taiwanese project (<a title="Skytraq homepage" href="http://www.skytraq.com.tw/">Skytraq</a>, the company behind Navspark is in in Hsinchu city in Taiwan), and I haven&#8217;t seen anything about Beidou before.</p>
<p>They barely made the campaign, but it&#8217;s not for the lack of quality. There were a lot of updates during and afterwards as well as the project was developing. Those were good behind the scenes information, got to see what parts of hardware development are more troublesome than others.</p>
<h2>The Navspark board</h2>
<p><figure id="attachment_1763" aria-describedby="caption-attachment-1763" style="width: 500px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="wp-image-1763 size-full" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/05/navspark1.jpg" alt="Navspark unboxing: board, antenna, pins" width="500" height="333" /><figcaption id="caption-attachment-1763" class="wp-caption-text">Navspark unboxing: board, antenna, pins</figcaption></figure></p>
<p>The rewards just shipped this week, and since for this campaign I&#8217;m a &#8220;local&#8221;, I got it pretty early. I got my Navspark GPS/Beidou (BD) version in a big envelope, together with an antenna, some pin and a jumper.</p>
<p><span id="more-1759"></span></p>
<p>The size of the board is about the same as the <a title="Arduino Nano homepage" href="http://arduino.cc/en/Main/arduinoBoardNano">Arduino Nano</a>, but not pin-compatible. Navspark&#8217;s pins are multiplexed, and multifunctional.</p>
<p><figure id="attachment_1768" aria-describedby="caption-attachment-1768" style="width: 500px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="size-full wp-image-1768" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/05/pinout1.jpg" alt="Detailed Navspark pinout with pin functions" width="500" height="530" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2014/05/pinout1.jpg 500w, https://gergely.imreh.net/blog/wp-content/uploads/2014/05/pinout1-472x500.jpg 472w" sizes="auto, (max-width: 500px) 100vw, 500px" /><figcaption id="caption-attachment-1768" class="wp-caption-text">Navspark pinout from the User Manual</figcaption></figure></p>
<p>When I first tried to set it up, I&#8217;ve run into some issues. The <a title="Navspark community" href="http://www.navspark.com.tw/">Navspark community site</a> has a lot of information and many tools. I started at the <a title="Navspark resources " href="http://navspark.mybigcommerce.com/resources/">resources page</a>, downloading the User Manual and the customized Arduino IDE made for Navspark. First the IDE didn&#8217;t want to run on my 64bit Linux, but they figured it out and <a title="64bit Linux issue update" href="http://www.navspark.com.tw/forum/64bit-linux-issue">posted an update</a>. Then flashing the code to the board failed with a mysterious error message, but they got that one working as well in the <a title="Navspark flashing error fix" href="http://www.navspark.com.tw/forum/navspark-imege-failure-error-code-4">next update</a>. This all took about a day, after which I could happily develop with my brand new board, awesome!</p>
<h2>Beidou</h2>
<p>When I chose my reward during the campaign, I went for the GPS/Beidou version because my HTC Butterfly already has GLONASS reception, and wanted to try something new. Beidou is an interesting because it just wants to be regional, as opposed to GPS, GLONASS, and the European Galileo positioning network that are all going global. Being regional then it can  use geostationary satellites, and fewer than the other networks.</p>
<p>When I was thinking what should be my first project, I thought I use Navspark to take a look at the Beidou satellites, how do they behave.</p>
<p><figure id="attachment_1764" aria-describedby="caption-attachment-1764" style="width: 500px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="size-full wp-image-1764" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/05/navspark2.jpg" alt="Antenna hanging out of the window" width="500" height="333" /><figcaption id="caption-attachment-1764" class="wp-caption-text">Antenna hanging out of the window</figcaption></figure></p>
<p>I&#8217;ve tried the antenna, and it worked (naturally) better being outside, I hung it up on the little balcony outside of my window. Compiled the &#8220;demo_how_to_extract_gps_info&#8221; sketch, and flashed it.</p>
<p>I needed a few tries to start receiving data from the board, but that&#8217;s just because my memory was rusty of all the tools needed under Linux to get and to understand GPS/positioning data. Reminded myself how to use gpsd, and gpsmon, but those understood only the GPS part.</p>
<h3>Sidetrack: NMEA</h3>
<p>When I started to use gpscat, to just split all the &#8220;NMEA sentences&#8221; (or fragments of data) from the receiver, everything started to make more sense. The NMEA sentences have a 3-letter identifier, what data should be in that sentence. For example the GGA sentence has the location information, while the GSV sentence lists detailed satellite info, or ZDA lists the date and time.</p>
<p>In front of that 3-letter identifier, though there&#8217;s 2 more letters, which I didn&#8217;t pay attention before, but now it makes sense: those can be used to denote which positioning network the data is coming from. When I looked at the logs, I&#8217;ve seen for example &#8220;GPGSV&#8221;, and &#8220;BDGSV&#8221; sentences &#8211; both are detailed satellite data, but one from the GPS (&#8220;GP&#8221;) satellites, while  the other from the Beidou (&#8220;BD&#8221;) satellites. I&#8217;ve seen also &#8220;GN&#8221; as 2-letter identifier, so that&#8217;s probably GLONASS. Since this receiver does not have that function, no actual data shows up in those sentences.</p>
<p>There&#8217;s a lot of <a title="Google search for NMEA sentences" href="https://www.google.com.tw/search?&amp;q=nmea+sentences">NMEA sentence information online</a>, for more details. As an example, here&#8217;s a sentence that lists the first 4 of the Beidou satellites found by the receiver:</p>
<p><code>$BDGSV,2,1,05,203,59,206,34,208,58,181,42,201,56,140,44,204,00,000,34*6D</code></p>
<p>Without going into too much detail, here&#8217;s what&#8217;s inside this line:</p>
<p>&#8220;203&#8221;, &#8220;208&#8221;, &#8220;201&#8221;, and &#8220;204&#8221; are the pseudo-random number generator  (PRN) code of 4 different satellites, basically a way to identify them. For the GPS network, <a title="PRN list for GPS" href="http://en.wikipedia.org/wiki/List_of_GPS_satellites#Cross_reference_of_PRNs_to_satellite_blocks">PRN goes from 1-32</a>, so anything above that is something else. GLONASS has reserved the <a title="GLONASS numbers" href="http://webcache.googleusercontent.com/search?q=cache:91Tjzf2C0FAJ:www.microsurvey.com/helpdesk/index.php%3F_m%3Dknowledgebase%26_a%3Dviewarticle%26kbarticleid%3D268+&amp;cd=2&amp;hl=en&amp;ct=clnk&amp;gl=tw">numbers between 66-85</a> (will have to check this with my Butterfly). These 200+ numbers are again a different network, the Beidou satellites (though I haven&#8217;t found any source yet that spells them out directly).</p>
<p>The 3 numbers after each PRN code is the &#8220;elevation&#8221; (degree over the horizon), &#8220;azimuth&#8221; (horizontal direction in degrees), and signal-to-noise ratio (SNR) of the reception. For example satellite 203 has from my location elevation 59<span style="color: #545454;">°, direction 206° (south-by-south-west), and SNR of 34. The satellite 204 has 0 for elevation and azimuth, meaning it hasn&#8217;t been figured out by the system yet.</span></p>
<h3>Recording</h3>
<p>I&#8217;ve used gpscat to record some (so far about 8 hours) of satellite tracking data, all the NMEA sentences coming out of Navspark. When plugged in, the receiver showed up at /dev/ttyUSB0, and the incoming data stream was correctly received and logged with the command:</p>
<p><code>gpscat -s 115200N1 /dev/ttyUSBx &gt; navspark.log</code></p>
<p>Here the &#8220;-s&#8221; command sets a speed (baud rate) for the USB-serial connection to 115200 bits per second. The &#8220;N1&#8221; part sets No Parity, 1 stop bit, which is usually the case.. Sometime I could communicate without this setting, but often the wrong baud rate was detected, so I guessed that this receiver likes the highest speed that usually occurs (this 115200 baud rate). Finally, all the output is directed into the &#8220;navspark.log&#8221;file.</p>
<p>The 8 hours of data adds up to about 15Mb text, and I&#8217;ve written a Python script to extract the GPS and Beidou satellite location data. Another python script is used to visualize the tracks on the sky above with <a href="http://matplotlib.org/">Matplotlib</a>. The scripts used can be found in the <a title="Navspark supplementary files" href="/supplements/navspark-beidou/">supplementary files section</a>.</p>
<p>First the GPS tracks. This is quite familiar, fast lines across the sky.</p>
<p><figure id="attachment_1775" aria-describedby="caption-attachment-1775" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/05/gps_tracks.png"><img loading="lazy" decoding="async" class="size-medium wp-image-1775" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/05/gps_tracks-500x375.png" alt="Plot of recorded GPS satellite paths " width="500" height="375" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2014/05/gps_tracks-500x375.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2014/05/gps_tracks-768x576.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2014/05/gps_tracks.png 800w" sizes="auto, (max-width: 500px) 100vw, 500px" /></a><figcaption id="caption-attachment-1775" class="wp-caption-text">GPS tracks on a polar plot. Azimuth on the circular axis, elevation on the radial axis. Filtered for satellites with more than 3000 records. Legend lists satellite PRN, and number of records in parentheses.</figcaption></figure></p>
<p>On the image 0<span style="color: #545454;">° is North, 180° is South, and so on. The centre of the image is right above my location, while the edge of the circle is on the horizon. The satellites are filtered to only show the ones with more than 3000 records, but it&#8217;s still a big mess. This is definitely not my greatest plot ever, but it more or less does the job.</span></p>
<p>Then I&#8217;ve plotted the Beidou tracks too. Similar filter is applied, except for the satellite with PRN 209, that I included as well with fewer records. The tracks look like this:</p>
<p><figure id="attachment_1778" aria-describedby="caption-attachment-1778" style="width: 500px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2014/05/bd_tracks.png"><img loading="lazy" decoding="async" class="wp-image-1778 size-medium" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/05/bd_tracks-500x375.png" alt="Path of the Beidou satellites plotted similarly as the GPS satellites." width="500" height="375" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2014/05/bd_tracks-500x375.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2014/05/bd_tracks-768x576.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2014/05/bd_tracks.png 800w" sizes="auto, (max-width: 500px) 100vw, 500px" /></a><figcaption id="caption-attachment-1778" class="wp-caption-text">Beidou satellite tracks, recorded in the same time frame.</figcaption></figure></p>
<p>The thing that should stand out is not that there are fewer tracks (of course, since there are fewer Beidou satellites), but that there are two very distinct behaviour.</p>
<p>Satellites 201, 203 and 204 stay pretty much at the same place (geostationary orbit), while 206, 207, 208, 209, 210 are tracing out a path.</p>
<p>Now trying to match this information up with the <a title="List of Beidou satellites " href="http://en.wikipedia.org/wiki/Beidou_Navigation_Satellite_System#List_of_satellites_.28as_of_December_2012.29">list of satellites on the Beidou Wikipedia page</a>, I get the following conclusions:</p>
<p>PRN 201, 203, and 204 should correspond to Compass-G1, Compass-G3, and Compass-G4 geostationary satellites. I haven&#8217;t double-checked where their location should be visible from here, but their East-West ordering in the group is correct according to this hypothesis. If that&#8217;s so, there still should be a PRN 205 (Compass-G5 although might not be visible from here), and no PRN 202 (Compass-G2 is not functioning). Not sure what number the latest geostationary Compass-G6 should have, because PRN 206 is already in use.</p>
<p>PRN 206, 207, and 208 seem to be on the same loop (the three colours adding up to a single loop-of-8). Then these could very well be the Compass-IGSO1, -IGSO2, and -IGSO3 satellites which fly a geosynchronous orbit at &#8220;118°E with inclination 55°&#8221;. Not sure yet how that orbit should look like, but the position of their loop compared to the geostationary satellites looks promising.</p>
<p>PRN 209 and 210 also seem to be of the same loop, so probably Compass-IGSO4, and -IGSO5, on a geosynchronous orbit &#8220;95°E with inclination 55°&#8221;.</p>
<p>It&#8217;s pretty cool that from a mere few hours of recording we can identify all the Beidou satellites.</p>
<p>An extra mystery</p>
<p>If I check the GPS tracks closely, there are two satellites with code 42 and 50 that don&#8217;t look GPS, but geostationary. A bit of search into what they might be showed that they are are the pair of <a title="Multi-functional Satellite Augmentation System" href="http://en.wikipedia.org/wiki/Multi-functional_Satellite_Augmentation_System">Multi-functional Satellite Augmentation System </a>birds from Japan, to supplement the GPS network. 42 and 50 are their NMEA code, which is equal to PRN-87, so I might have been misusing the &#8220;PRN code&#8221; terminology, but maybe not too much.</p>
<p>There&#8217;s one more satellite with PRN 193 that is out of ordinary. That shows up in a <a title="QZSS Research at UNSW" href="http://www.gmat.unsw.edu.au/snap/publications/glennon2011a.pdf">document</a> as <a title="Quasi-Zenith Satellite System" href="http://en.wikipedia.org/wiki/Quasi-Zenith_Satellite_System">Quasi-Zenith Satellite System</a> SV 1 bird. That system is for time transfer, and also to further improve GPS over Japan.</p>
<p>It&#8217;s interesting that this receiver can find them. And I guess the Japanese space program does worth to take a deeper look at!</p>
<h2>What to do next?</h2>
<p>This is a good first experiment, because there are a lot of questions answered, while almost as many new questions popped up. Already have more ideas what to do than time to do it.</p>
<ul>
<li>Should compare the position accuracy of this receiver and one of the other USB GPS receivers I have. Not totally fair, because they kinda have a more complete antenna, but maybe under open sky it would work.</li>
<li>Figure out how GPS and Beidou satellites are used together to get a location. Are they? Or separately?</li>
<li>Try out the other Navspark functions, which there are many! The examples show ADC, timestamping, SPI, two-wire, 400KHz PWM output. It&#8217;s also running on higher frequency (100MHz?) and more program memory (1Mb?) than Arduino.</li>
<li>Try other programs now playing with GPS, for example gpredict (orbital prediction and tracking). If they don&#8217;t have support for Beidou, maybe can try add to them?</li>
<li>Find my <a title="Orbital Mechanice for Engineering Students on Goodreads" href="https://www.goodreads.com/book/show/2534162.Orbital_Mechanics_for_Engineering_Students">Orbital Mechanics for Engineering Students</a> book, and get learning!</li>
</ul>
<p>What would <strong>you</strong> like to do with such hard core geo-positioning tool?</p>
<p>The post <a href="https://gergely.imreh.net/blog/2014/05/navspark-beidou/">Navspark: Arduino for GPS, GLONASS, and Beidou</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2014/05/navspark-beidou/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Personal phone server, or Can you hear me now?</title>
		<link>https://gergely.imreh.net/blog/2014/03/can-you-hear-me-now/</link>
					<comments>https://gergely.imreh.net/blog/2014/03/can-you-hear-me-now/#comments</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Tue, 18 Mar 2014 09:41:02 +0000</pubDate>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[Maker]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[hackerspace]]></category>
		<category><![CDATA[iax]]></category>
		<category><![CDATA[sip]]></category>
		<category><![CDATA[voip]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=1712</guid>

					<description><![CDATA[<p>Experience setting up my own Voice-over-IP phone network, with the aim to have one good way to communicate from desktop &#038; smartphone, over wifi &#038; 3G.</p>
<p>The post <a href="https://gergely.imreh.net/blog/2014/03/can-you-hear-me-now/">Personal phone server, or Can you hear me now?</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Ever since someone donated an IP phone to the <a title="Taipei Hackerspace" href="http://tpehack.no-ip.biz">Taipei Hackerspace</a>, I&#8217;m trying to find time to set up an internal phone network between the hackerspace members. It should be fun to make our own infrastructure. Recently did some research, and started with it. Since if I get into something then I dive deep for a while, this was an intense week. This post is to summarize where I have got in this time</p>
<h2>Asterisk &amp; FreePBX</h2>
<p>A bit of searching turned up <a title="Asterisk homepage" href="http://www.asterisk.org/">Asterisk</a>, a PBX (&#8220;private branch exchange&#8221; aka telephone network) software. It looked interesting because it came with <a title="A brief history of Asterisk" href="https://wiki.asterisk.org/wiki/display/AST/A+Brief+History+of+the+Asterisk+Project">a story</a>: a guy building something awesome because he doesn&#8217;t know that it was supposed to be difficult. It&#8217;s also open source from the start, with a successful <a title="Digium" href="http://www.digium.com/">company</a> build on top of the project.</p>
<p>Also found, that there&#8217;s a graphical control panel called <a title="FreePBX home" href="http://www.freepbx.org/">FreePBX</a> that makes using the all-command-line-and-config-files Asterisk easier to use. Both projects had a seemingly very detailed wiki, long track record, and strong following that made it worth checking them out.</p>
<h3>The Server</h3>
<p>Judging from the <a title="Installing FreePBX on Ubuntu 12.04 Server (Precise Pangolin)" href="http://wiki.freepbx.org/pages/viewpage.action?pageId=1409028">original install instructions</a> on the FreePBX wiki, it looked like installing Asterisk &amp; FreePBX is a complex (or rather many-step) process. Didn&#8217;t want to litter my own computer with broken installation artefacts, so enter <a title="VirtualBox home" href="https://www.virtualbox.org/">VirtualBox</a>. Using a virtual machine makes it easy to wipe and restart.</p>
<p>There&#8217;s a dedicated, preinstalled FreePBX distro based on CentOS, but had enough of CentOS for a while. Instead I just took Ubuntu 12.04.3 as a base, and FreePBX 2.11 and Asterisk 11 from the wiki. The install instructions were clear enough, though occasionally there were small differences needing a fix. Nothing major, but had to play around. After 5-6 reinstalls with increasing experience I got the basic functionality working, calls placed between and such, but the performance and sound quality wasn&#8217;t really that good. After thinking what could I improve, decided to take the next step: get out of the virtual machine, and up the version numbers (I&#8217;m <a title="ArchLinux About page" href="https://www.archlinux.org/about/">Arch Linux</a> user with a reason, living on the bleeding edge).</p>
<p>Enter <a title="DigitalOcean" href="https://www.digitalocean.com/">DigitalOcean</a>, a hosting provider that I used for other projects before (cheap, fast with SSD, good service). Set up a machine (aka &#8220;droplet&#8221;) in their Singaporean center (since that&#8217;s probably the closest one to Taiwan). I chose the 1Gb memory instance, because from experience with VirtualBox Asterisk+FreePBX maxed out at around that with a few test accounts.</p>
<p>Upping the version numbers I went with FreePBX 12.0 (from git) and Asterisk 12.1.1 (from download), both are testing versions. Asterisk had an extra dependency of libjansson-dev compared to version 11, didn&#8217;t check if any of the earlier dependencies are not required anymore.</p>
<p><figure id="attachment_1717" aria-describedby="caption-attachment-1717" style="width: 500px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="size-full wp-image-1717" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/03/Asterisk.jpg" alt="The information control panel of FreePBX." width="500" height="380" /><figcaption id="caption-attachment-1717" class="wp-caption-text">FreePBX interface for Asterisk</figcaption></figure></p>
<p>Got the whole system working (after a few droplet wipes), and played with the installation with a bit more confidence. From initial experience, Asterisk is a bit like the Linux Kernel. It&#8217;s modular, complex, focus on reliability, and the &#8220;<a title="Menuselect on the Asterisk wiki" href="https://wiki.asterisk.org/wiki/display/AST/Using+Menuselect+to+Select+Asterisk+Options">make menuselect</a>&#8221; is a familiar environment after years of &#8220;<a title="Menuconfig on Wikipedia" href="http://en.wikipedia.org/wiki/Menuconfig">make menuconfig</a>&#8221; compiling my own kernel. On the other hand, FreePBX is a bit like WordPress. It has its own auto-updater (just like updating plugins in WordPress), loads and loads of menus, focuses on configuration and tries not to let any faulty module take down the system (found quite a few buggy behaviour, so that&#8217;s a good idea). The Kernel and WordPress are two familiar environments, so felt home here too somehow.</p>
<p>Asterisk has a bunch of vocabulary that I&#8217;m so far barely familiar with, and lots of functionality that I haven&#8217;t had a chance to test yet. FreePBX has a lot of functionality too, and still it&#8217;s a bit difficult for me to tell where does an Asterisk function (module, resource?) end and one FreePBX function (plugin?) start. The fact is that I got to feel excited about programmable phone routing (with Lua), fax-to-pdf, hotel style wake-up calls, voicemail recording, call tracing, speaking time, simple conference talks, intercom functionality, regardless from whether it&#8217;s a module or a plugin&#8230;</p>
<p><span style="line-height: 1.5em;">Some additional server notes: voicemail requires email out for notification, I set that up with <a title="Mandrill homepage" href="https://mandrill.com/">Mandrill</a> and <a title="Can I configure Postfix to send through Mandrill?" href="http://help.mandrill.com/entries/23060367-Can-I-configure-Postfix-to-send-through-Mandrill-">postfix</a>. For such testing it might not be important, but good to secure the server at least a bit with <a title="fail2ban wiki" href="http://www.fail2ban.org/wiki/index.php/Main_Page">fail2ban</a> and <a title="ufw on the community wiki" href="https://help.ubuntu.com/community/UFW">ufw</a> (Uncomplicated Firewall), and probably other things I don&#8217;t do well yet. Just sayin&#8217;.</span></p>
<h3>Accounts / Extensions</h3>
<p>Accounts on  the server are the extensions on which someone (or something), a numerical value. The vocabulary and concepts are also new to me, so it took a while to understand how things supposed to interoperate. Asterisk has a bunch of different kinds of extensions, of which I have tried two main ones: SIP and IAX.</p>
<h4>SIP</h4>
<p>SIP stands for <a title="Session Initiation Protocol on Wikipedia" href="http://en.wikipedia.org/wiki/Session_Initiation_Protocol">Session Initiation Protocol</a>. As far as I see it is basically a messaging protocol, to set up a connection between two parties, and also provide some other services, for example presence information (Online, Away, Busy&#8230;.), messaging, and what not. The actual data of the call (voice or video) is trhough RTP (<a title="Real-time Transport Protocol on Wikipedia" href="http://en.wikipedia.org/wiki/Real-time_Transport_Protocol">Real-time Transport Protocol</a>).</p>
<p>The voice data in the transmission is compressed with one of the many codecs available:</p>
<ul>
<li>ulaw and alaw (<a title="G.711 on Wikipedia" href="http://en.wikipedia.org/wiki/G.711">G.711</a>) are a pair of the standard codecs, okay quality, one of the basic one to have in any client</li>
<li><a title="Speex on Wikipedia" href="http://en.wikipedia.org/wiki/Speex">speex</a> is a variable bitrate codec, haven&#8217;t used that much</li>
<li>gsm is lower bitrate, but lower quality too (think of crappy cell phone reception voice)</li>
<li><a title="G.722 on Wikipedia" href="http://en.wikipedia.org/wiki/G.722">G.722</a> is a hi-def (HD) voice codec, really good! I think beats Skype, and on par with a good Google Hangout quality,</li>
<li><a title="G.729 on Wikipedia" href="http://en.wikipedia.org/wiki/G.729">G.729</a> is a non-free codec, shows up here and there, but haven&#8217;t had a chance to try it, this is the other HD codec that I&#8217;ve seen recommended</li>
</ul>
<p>In testing, this was some of the learning curve, how to set up clients, and also the server that they can communicate with each other. Who choses the codec (caller, callee, server)? How to prioritize the codecs in different clients? What does it look like (or sounds like) when there&#8217;s a problem in this area? How to debug and fix?</p>
<p>Asterisk 12 has two different SIP channels or components: their classic library (chan_sip), and a rewritten one (<a title="PJSIP homepage" href="http://www.pjsip.org/">chan_pjsip</a>). The latter one is a standalone library that can be used for other purposes as well. SIP usually works on UDP, while PJSIP can do UDP/TCP/WebSockets too, and feels stable and fast. Definitely would use that if I have to choose between these two. Still, it is in test phase (both in Asterisk and FreePBX), so not without headaches.</p>
<p>There are bunch of different clients that I tried:</p>
<p>On Linux:</p>
<ul>
<li><a title="Ekiga homepage" href="http://ekiga.org/">Ekiga</a> is nice, simple, can sign into multiple accounts in multiple networks. Presence information, well integrated into the desktop with notifications and such. Does not seem to be able to handle non-standard SIP ports (which will be an issue further down)</li>
<li><a title="Linphone homepage" href="http://www.linphone.org/">Linphone</a> is really multiplatform (Linux, Win, OSX, smartphones&#8230;), but it was crashing on me quite a bit, doesn&#8217;t integrate into the desktop (no notification just sound on call), and can be confusing with the lot of settings (the control panel looks a mess). Can handle non-standard ports too.</li>
<li><a title="SFLPhone homepgae" href="http://sflphone.org/">SFLPhone</a> is good, works pretty well, simple, and can do IAX communication besides SIP.</li>
</ul>
<p>On Android:</p>
<ul>
<li><a title="Android SIP configuration" href="http://www.voipvoip.com/android/sip.html">Android</a> actually has full SIP handling capabilities built in for a while now (under &#8220;internet phone&#8221;). That would be awesome, if there were more information how to set up and use, but in theory a SIP account can be fully integrated into the system.</li>
<li><a title="CSIPSimple on the Play Store" href="https://play.google.com/store/apps/details?id=com.csipsimple">CSIPSimple</a> really impressed me, probably the best working client I found. Integrates with the system (calls are handled as &#8216;calls&#8217; with all the icons, history, and so on), good sound quality (can use the G.722 codec) and so on.</li>
<li>SipDroid, VIMPhone, LinPhone&#8230;. these other clients, don&#8217;t even remember them, all of them fell short somehow</li>
<li><a title="Zoiper home" href="http://www.zoiper.com/">Zoiper</a> stands out as well, not just because it&#8217;s multiplatform, but because it&#8217;s pretty much the only one I found that can do both SIP and IAX. The Android system integration is not as close as CSIPSimple, but quite okay.</li>
</ul>
<p>One of (the many) good thing about SIP that it is well known and pretty well supported. If there&#8217;s a &#8220;softphone&#8221; (phone in software), it&#8217;s quite likely to have SIP communication capabilities.</p>
<p>The bad thing about SIP though that it is well known and pretty well resented by the phone service providers. Many of those providers block SIP messages on their network, or sabotage the connection in some other way. On my own cell phone / 3G provider&#8217;s network, I couldn&#8217;t connect to Asterisk. In the forums some suggested that changing the port number that Asterisk listens on for SIP connections can solve things &#8211; and indeed after moving away from 5060/5061 to somewhere else, I could connect. The celebration was short lived, though because even though the calls now can reach the destination, RTP communication (the part that actually transports voice) was still broken. I don&#8217;t want to use VPN all the time (though might need to soon), and want to keep moving parts and settings to the minimum if I want others in the Hackerspace to join this network as well, thus SIP looks like a no-go because of the phone companies (darn).</p>
<h4>IAX</h4>
<p>Looking around, I found another type of channel, using the IAX (Inter-Asterisk eXchange) protocol. The bad thing about it that it is much less supported, but in turn it is not blocked by the phone companies either (since they don&#8217;t know about it).</p>
<p>Using SFLPhone and Zoiper I could successfully talk over 3G! Still it is not all good, the devil is in the details.</p>
<p><figure id="attachment_1713" aria-describedby="caption-attachment-1713" style="width: 281px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="size-full wp-image-1713" src="https://gergely.imreh.net/blog/wp-content/uploads/2014/03/zoiper.jpg" alt="Phone interface showing incoming call from IAX test user" width="281" height="500" /><figcaption id="caption-attachment-1713" class="wp-caption-text">Zoiper incoming call on Android</figcaption></figure></p>
<ul>
<li>It&#8217;s good that no need for custom ports</li>
<li>It&#8217;s bad that the IAX channel seems to be more unstable on Asterisk (or maybe I messed up my install after a while?): some extensions have trouble logging on for a while until the server is restarted; the wakeup-calls plugin misbehaved with IAX extension.</li>
<li>The less support also means less choice in clients. The ones I found cannot do G.722 so no HD voice anymore</li>
<li>Has a security setting (requirecalltoken) that not all clients support, not sure if there are any implications.</li>
</ul>
<p>It&#8217;s also good, that Asterisk can route incoming SIP calls onto IAX extensions (i.e. the caller doesn&#8217;t have to care what technology the callee is using). On the note of routing, I could set things up such that outside calls can be routed into the system. E.g. every hackerspace could have their own Asterisk server and interoperate to call members at other spaces &#8211; sounds like a lot of work and might not worth it, but it also sounds awesome.</p>
<p><span style="font-size: 1.5em; line-height: 1.5em;">Summary &amp; Future</span></p>
<p>I had a lot of fun playing with Asterisk. On the surface phone networks are familiar to everyone, but going deeper both makes things more confusing and opens my eyes how many possibilities there are for making something useful.<span style="line-height: 1.5em;"> </span></p>
<p>There are a lot of things that I thought about, but haven&#8217;t tried yet:</p>
<ul>
<li>Programmable dialplans (&#8220;what happens when a call is received&#8221;), <a title="Lua Dialpans" href="https://wiki.asterisk.org/wiki/display/AST/Lua+Dialplan+Configuration">via Lua</a>. Lua is an <a title="Language of the Month: Lua, part 2" href="https://gergely.imreh.net/blog/2011/07/language-of-the-month-lua-part-2/">awesome language</a> and probably a lot more large piece of software has it embedded (since that&#8217;s one of its strength)</li>
<li>Could script a lot more too via the <a title="AGI technical introduction" href="http://www.rdegges.com/a-technical-introduction-to-the-asterisk-gateway-interface-agi/">Asterisk Gateway Interface</a> (AGI).</li>
<li>There are a bunch of other protocols and acronyms in Asterisk, for example <a title="SRTP on Wikipedia" href="http://en.wikipedia.org/wiki/Secure_Real-time_Transport_Protocol">Secure Real-Time Protocol</a> (SRTP) and <a title="ZRTP on Wikipedia" href="http://en.wikipedia.org/wiki/ZRTP">ZRTP</a>, that could worth figuring out for a deeper understanding and security</li>
<li>There&#8217;s an <a title="Asterisk on Rasberry Pi" href="http://www.raspberry-asterisk.org/">Asterisk on Raspberry Pi</a> project that looks interesting (if nothing else then how do they lower the memory usage below the RPi&#8217;s &lt;512MB?). Since Asterisk can be used with multiple servers in a network, the RPi can provide one kind of service (e.g. <a title="GSM Dongle setup for Asterisk on Rasberry Pi" href="http://www.raspberry-asterisk.org/documentation/gsm-voip-gateway-with-chan_dongle/">GSM gateway</a>) while other servers with more resources do other stuff</li>
<li>Using physical phones in the network, for example traditional phone network to come into the server, and IP Phone to ring out.  Maybe setting up fax endpoint (and sending it out as PDF or printing it). Basically anything that is working on the threshold between physical and digital.</li>
<li>Should check out how the likes of <a title="Line" href="http://line.me/">Line</a>, <a title="Voxer home" href="https://voxer.com/">Voxer</a>, and <a title="Viber homepage" href="http://www.viber.com/">Viber</a> are doing VoIP on Android, do they have any interoperability?</li>
<li>How about <a title="Twillio" href="http://www.twilio.com/">Twillio</a>, can their system be a similar PBX on a much larger scale?</li>
</ul>
<p>The funny thing is that looks like the original IP phone that started this whole adventure does not work with Asterisk. Never mind, it will be good for another project.</p>
<p>The post <a href="https://gergely.imreh.net/blog/2014/03/can-you-hear-me-now/">Personal phone server, or Can you hear me now?</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2014/03/can-you-hear-me-now/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Object Caching 7/237 objects using APC
Page Caching using Disk: Enhanced 
Lazy Loading (feed)

Served from: gergely.imreh.net @ 2026-09-03 09:46:31 by W3 Total Cache
-->