<?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>Mykola Bilokonsky</title>
	<atom:link href="http://mykola.bilokonsky.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://mykola.bilokonsky.net</link>
	<description>Independent Technologist</description>
	<lastBuildDate>Tue, 12 Jul 2011 01:10:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Apture added</title>
		<link>http://mykola.bilokonsky.net/2011/06/apture-added/</link>
		<comments>http://mykola.bilokonsky.net/2011/06/apture-added/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 18:46:18 +0000</pubDate>
		<dc:creator>mykola</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apture]]></category>
		<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://mykola.bilokonsky.net/?p=30</guid>
		<description><![CDATA[Just a quick note to say that I&#8217;ve added apture support to this blog. Apture is a super smart web service designed to transparently overlay context onto keywords. It&#8217;s smart enough to know what words people are interested in learning more about by keeping track of what words people highlight so that they can copy+google [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note to say that I&#8217;ve added apture support to this blog. Apture is a super smart web service designed to transparently overlay context onto keywords. It&#8217;s smart enough to know what words people are interested in learning more about by keeping track of what words people highlight so that they can copy+google them. You&#8217;ll see Apture links scattered throughout the blog, hover over any of them for more information!</p>
]]></content:encoded>
			<wfw:commentRss>http://mykola.bilokonsky.net/2011/06/apture-added/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WWDC 2011 Prediction: Apple Acquires Twitter?</title>
		<link>http://mykola.bilokonsky.net/2011/06/wwdc-2011-prediction-apple-acquires-twitter/</link>
		<comments>http://mykola.bilokonsky.net/2011/06/wwdc-2011-prediction-apple-acquires-twitter/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 14:48:44 +0000</pubDate>
		<dc:creator>mykola</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[wwdc]]></category>

		<guid isPermaLink="false">http://mykola.bilokonsky.net/?p=27</guid>
		<description><![CDATA[I could be way off base here, but I suspect that Steve Jobs is about to announce the acquisition of Twitter by Apple. I don&#8217;t have access to any private info or anything, but here&#8217;s why I think this might be true. Twitter has a lot to offer Apple Twitter has been behaving strangely lately, [...]]]></description>
			<content:encoded><![CDATA[<p>I could be way off base here, but I suspect that Steve Jobs is about to announce the acquisition of Twitter by Apple. I don&#8217;t have access to any private info or anything, but here&#8217;s why I think this might be true.<br />
<span id="more-27"></span></p>
<h2>Twitter has a lot to offer Apple</h2>
<ul>
<li>Twitter has been behaving strangely lately, creating <a href="http://mashable.com/2011/06/01/twitter-photo-services/">their own media hosting service</a> and telling devs that they should <a href="http://www.technobuffalo.com/internet/social-networking/read-my-beak-no-new-twitter-clients/">think twice before investing time in the creation of new Twitter clients</a>. These represent a major change in tone &#8211; only a few short months ago, Twitter was everyone&#8217;s favorite public API. Now they seem to be fortifying. Why?</li>
<li>Apple is rumored to be integrating Twitter deeply into their next offering of iOS, which Steve Jobs will be announcing later today. As in, <a href="http://www.macrumors.com/2011/06/03/more-claims-of-deep-twitter-integration-in-ios-5/">very deeply</a>. But why would Apple take a neutral third-party and build them into the core of their super-tightly-controlled walled garden? Jobs isn&#8217;t the sort who spends a lot of time relying on other people/companies &#8211; it would surprise me, honestly, if iOS had twitter built in but Apple had no control over Twitter.</li>
<li>Finally, there&#8217;s simply the matter of the gaping hole in Apple&#8217;s offerings. They do hardware well, they do media well, they do software well &#8211; but it&#8217;s no secret that they <a href="http://www.apple.com/itunes/ping/">suck at social</a>. Social Media is not going away, so if Apple wants to be a relevant player in that field they have two choices. They can create a working, usable and popular social media tool &#8211; or they can buy one. This one just makes sense to me &#8211; especially when you realize how perfect Twitter + iPhone are for each other.</li>
</ul>
<p>It&#8217;s that last point that honestly makes me believe this to be true. Twitter is not just any social media service &#8211; it&#8217;s the one that&#8217;s been most embraced by the tech-savvy minimalist. It lacks the clutter of facebook, and it lacks the fragmentation of the geo/social space. It&#8217;s simple, it&#8217;s easy, and (as long as the servers are up) it just works &#8211; it&#8217;s practical an Apple offering already.</p>
<h2>Apple has a lot to offer Twitter</h2>
<p>The other side of the coin is, why would Twitter want to get into bed with Apple?</p>
<ul>
<li>Money.</li>
<li>Expansion &#8211; if Twitter goes native on every iOS device and every Mac, and gets promoted by Apple, their install base is going to go through the roof. They&#8217;re already THE social media company in elite tech circles &#8211; this could be just the move they need to go truly mainstream.</li>
<li>Resources &#8211; if they get built into Apple&#8217;s iCloud service, which is presumably going to have some of the most powerful (and most stable) servers currently running then we&#8217;ll see a lot less of the fail whale.</li>
</ul>
<h2>Conclusions</h2>
<p>What do you think? Am I crazy? I guess we&#8217;ll find out in a few hours!</p>
]]></content:encoded>
			<wfw:commentRss>http://mykola.bilokonsky.net/2011/06/wwdc-2011-prediction-apple-acquires-twitter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Brief Update</title>
		<link>http://mykola.bilokonsky.net/2011/06/brief-update/</link>
		<comments>http://mykola.bilokonsky.net/2011/06/brief-update/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 20:58:32 +0000</pubDate>
		<dc:creator>mykola</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://mykola.bilokonsky.net/?p=25</guid>
		<description><![CDATA[Very little in the way of blog updates the past few months, been up to my ears in a few things. Work is finally starting to slow down, though, so I&#8217;m hoping I&#8217;ll have more time to post. In the meantime, here is a brief rundown of stuff I&#8217;ve been playing with (and will hopefully [...]]]></description>
			<content:encoded><![CDATA[<p>Very little in the way of blog updates the past few months, been up to my ears in a few things. Work is finally starting to slow down, though, so I&#8217;m hoping I&#8217;ll have more time to post.</p>
<p>In the meantime, here is a brief rundown of stuff I&#8217;ve been playing with (and will hopefully soon be blogging about):</p>
<p>1) Living without an IDE &#8211; a lot of folks seem to have a great time coding all kinds of stuff using TextMate, without the clunkiness of an eclipse-based IDE. I&#8217;m looking to explore this option, and I&#8217;ll let you know what I think. This ties into the next few points, because my latest interests live outside of any IDEs -</p>
<p>2) Node.JS &#8211; if you haven&#8217;t heard about Node.JS you&#8217;ve been living under a rock. Node is server-side javascript, bringing that lovely (ech!) JS syntax to the server. Why is this cool? Because like AS3, it relies on the Observer Pattern to handle asynchronous requests. Instead of spawning a new thread and blocking, like most other server-side languages, Node uses an Event system with async callbacks to juggle lots and lots of stuff at the same time. Plus, it&#8217;s JavaScript. Say what you will about it, it&#8217;s pretty slick to be able to handle scripting, web server and front-end coding in the same language. </p>
<p>3) Using JavaScript with Socket.IO to replace Python as my go-to Arduino interface language. If I&#8217;m going to learn one stack inside and out, it seems like JavaScript is the stack to learn. If I&#8217;m doing everything else in JS, why keep Python around when I can use Node just as easily?</p>
<p>4) Back in the Flash world, a big project I&#8217;ve been working on for a few months is approaching launch-readiness. It&#8217;s my first Flex 4 application, and I have some thoughts about that. Generally speaking, I haven&#8217;t really enjoyed it &#8211; but I&#8217;m not sure yet if that&#8217;s my fault or Flex&#8217;s. Much to think about.</p>
<p>5) Finally, this summer I&#8217;ll be rolling out my first iOS application. Stay tuned for rants and thoughts on the subject.</p>
<p>As always, the best way to keep up with me is on Twitter, where you can always find me quickly as <a href="http://www.twitter.com/mykola">@mykola</a>. Drop me a line!</p>
<p>Last thing &#8211; I&#8217;ve implemented Google&#8217;s &#8220;+1&#8243; feature here. If a blog post is useful or interesting, please consider hitting the +1 button to let me and others know!</p>
]]></content:encoded>
			<wfw:commentRss>http://mykola.bilokonsky.net/2011/06/brief-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Public APIs: The True Battlefield of the Platform Wars (and a proposed solution)</title>
		<link>http://mykola.bilokonsky.net/2011/03/public-apis-the-true-battlefield-of-the-platform-wars-and-a-proposed-solution/</link>
		<comments>http://mykola.bilokonsky.net/2011/03/public-apis-the-true-battlefield-of-the-platform-wars-and-a-proposed-solution/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 21:37:06 +0000</pubDate>
		<dc:creator>mykola</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[APIHub]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[lendle]]></category>
		<category><![CDATA[tweetdeck]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://mykola.bilokonsky.net/?p=23</guid>
		<description><![CDATA[A few interesting stories this week have compelled me to flesh out an idea I&#8217;ve been having for a while. Details below the fold, but here&#8217;s the gist: as the web continues to evolve, we get more and more services that deal with lots of information and these services are currently in the habit of [...]]]></description>
			<content:encoded><![CDATA[<p>A few interesting stories this week have compelled me to flesh out an idea I&#8217;ve been having for a while. Details below the fold, but here&#8217;s the gist: as the web continues to evolve, we get more and more services that deal with lots of information and these services are currently in the habit of putting out public APIs. However, these companies also control these APIs and they are able to change or even disable them at will &#8211; which is fine, legally, but creates huge problems for any other companies that are relying on those APIs.</p>
<p>As the web moves forward I can only suspect that this problem is going to become more common, not less &#8211; and so I have at least a vague hint of an idea for how we can go about solving it. I&#8217;m curious for your thoughts!</p>
<p><span id="more-23"></span></p>
<h2>The Context &#8211; Public APIs changed or revoked</h2>
<ul>
<li><a href="http://www.businessinsider.com/amazon-lendle-2011-3">Amazon kills Lendle&#8217;s API access</a> &#8211; Apropos of nothing, Amazon one day decided to shut down the API access of popular up-and-coming kindle lending service <a href="http://lendle.me">Lendle</a>. Nobody is arguing that Amazon isn&#8217;t allowed to do this &#8211; it&#8217;s their API and they are within their rights to do whatever they want with it. The problem is, where does this leave a service like Lendle? They were providing enormous utility for lots and lots of users and never violated any of Amazon&#8217;s policies.</li>
<li><a href="http://www.technobuffalo.com/blog/internet/social-networking/read-my-beak-no-new-twitter-clients/">Twitter threatens third-party client devs</a>. This also came almost entirely out of nowhere &#8211; apparently, now that Twitter has decided they want to turn a profit they&#8217;re gunning for anyone who is creating &#8220;unofficial&#8221; twitter apps &#8211; and this presumably includes things like TweetDeck, Destroy Twitter etc. Again, Twitter is within their rights &#8211; but the general consensus seems to be that this is a dick move. I&#8217;m certainly not about to launch a startup that uses Twitter&#8217;s API &#8211; even if I had been planning to, this would kill those plans</li>
</ul>
<p>You&#8217;re kidding yourself if you don&#8217;t think we&#8217;re going to be seeing more of this in the future. I&#8217;m not even going to mention Facebook, whose API has been in such a state of flux for so long that writing code against it requires phenomenal patience and deep pockets on the part of any client interested in doing so.</p>
<h2>The Complication: Companies Need This Freedom</h2>
<p>And you know what? A company should be allowed to make sweeping changes to a public API, whether these are changes that cause it to work differently than it did yesterday or changes that make it a violation of ToS for someone to continue doing something that was legal yesterday. These companies own these APIs and if we somehow insist that they never change the way they implement them then the only recourse these companies could have is to remove public APIs altogether. I totally understand that.</p>
<h2>The Consequences: Startups Suffer</h2>
<p>But then, look at companies like Lendle which take advantage of these APIs to do truly interesting, unique or useful things. I can only assume Lendle co-founder <a href="http://www.twitter.com/jcroft">Jeff Croft</a> woke up one morning and spit out his coffee as he opened his inbox.  &#8220;Oh, okay, so my company that has been getting all of this press and succeeding wildly is suddenly unable to provide the service around which it&#8217;s based. Now what?&#8221;</p>
<p>That&#8217;s enough to scare me out of putting any serious effort into a startup that relies on a third-party API. I could wake up one morning and realize that an API I had been relying on is no longer available, and now what do I tell my users?</p>
<p>Here&#8217;s where a lot of people simply say &#8220;Well, them&#8217;s the ropes. You knew the risks going in and that&#8217;s just how this works.&#8221;</p>
<p>And that&#8217;s true, but I think we can do better.</p>
<h2>What a Solution Could Look Like</h2>
<p>I&#8217;d like to see a third party emerge that serves as a sort of API Hub. This third party (let&#8217;s call them the API Hub) negotiates with anyone who offers a public API. They basically provide a service whereby this API Provider can register a &#8220;stable and permanent&#8221; API. That&#8217;s not saying that they will stop working on API updates or whatever &#8211; it just means that they will have to version them moving forward, and every version that goes through the API hub needs to be supported independently.</p>
<p>The API Hub in turn sells stable API access to developers. Why would a developer pay for API access instead of using the free public API being offered by the initial provider? They don&#8217;t have to. They are free to build their company on whatever the most recent public API offered by the provider happens to be, and for testing and for getting off the ground this is a perfectly viable strategy. But when they are ready to launch and have enough users that they want to make a stab at stability it&#8217;ll be worth their while to pay for access.</p>
<p>Would this work? Would people buy into this? I think it&#8217;s worth a shot, because money talks. If every serious twitter client out there was paying for the privilege of using a stable API then that&#8217;s going to be a nontrivial source of income for Twitter, I would think, right? Or am I being naive? And if an API Provider is being paid to provide a stable API then suddenly there&#8217;s a much greater incentive for developers to use that API, so this could provide a competitive advantage.</p>
<p>Is that enough to get someone like Twitter or Amazon to sign on? Obviously a big part of it would depend on how the contracts were structured, where the teeth are so to speak. But it&#8217;s at least worth thinking about, right?</p>
<p>I&#8217;m genuinely interested in your thoughts. Does something like this already exist? Is it working? Why/Why not? What are the flaws here? Do you provide an API? Your opinion is the one I&#8217;ve been exposed to the least, how would you feel about participating in something like this? Does it ask you to sign away too much? Is it reasonable? What would make this more compelling for you?</p>
]]></content:encoded>
			<wfw:commentRss>http://mykola.bilokonsky.net/2011/03/public-apis-the-true-battlefield-of-the-platform-wars-and-a-proposed-solution/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>2011 Adobe Community Professional</title>
		<link>http://mykola.bilokonsky.net/2011/01/2011-adobe-community-professional/</link>
		<comments>http://mykola.bilokonsky.net/2011/01/2011-adobe-community-professional/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 22:43:13 +0000</pubDate>
		<dc:creator>mykola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mykola.bilokonsky.net/?p=16</guid>
		<description><![CDATA[Just a quick note to say that I learned last evening that my application to become an Adobe Community Professional this year was accepted. The idea now that the resources and contacts that come along with that will help me to create more and better content, so hold me to it! :)]]></description>
			<content:encoded><![CDATA[<p>Just a quick note to say that I learned last evening that my application to become an Adobe Community Professional this year was accepted. The idea now that the resources and contacts that come along with that will help me to create more and better content, so hold me to it! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://mykola.bilokonsky.net/2011/01/2011-adobe-community-professional/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I Love flash.utils.Dictionary, and you should too!</title>
		<link>http://mykola.bilokonsky.net/2011/01/why-i-love-flash-utils-dictionary-and-you-should-too/</link>
		<comments>http://mykola.bilokonsky.net/2011/01/why-i-love-flash-utils-dictionary-and-you-should-too/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 20:59:43 +0000</pubDate>
		<dc:creator>mykola</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Caching in Flash]]></category>
		<category><![CDATA[Classes]]></category>
		<category><![CDATA[Dictionary]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flash.utils.Dictionary]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://mykola.bilokonsky.net/?p=20</guid>
		<description><![CDATA[One of the unsung heroes of readable AS3 code is the native Dictionary class. A Dictionary is just a container for key/value pairs, much like Object. In fact, a lot of people don&#8217;t realize just how useful Dictionary is. The assumption, easy to make, is that it&#8217;s better to use Object because then you don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>One of the unsung heroes of readable AS3 code is the native <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Dictionary.html">Dictionary</a> class. A Dictionary is just a container for key/value pairs, much like Object. In fact, a lot of people don&#8217;t realize just how useful Dictionary is. The assumption, easy to make, is that it&#8217;s better to use Object because then you don&#8217;t have to import anything.</p>
<p>The cool thing about Dictionary, though, is that you can use non-string keys. In fact, you can pass a reference to ANYTHING and use that as a key. Below are a few examples of how Dictionary lets you write clean, readable code. You can do all of this stuff without Dictionary, but you&#8217;re going to be writing more lines of code. I&#8217;ve got three examples below, in increasing order of abstraction. We&#8217;ll step through using interactive elements such as Buttons as Dictionary keys, then we&#8217;ll use Functions, and finally we&#8217;ll use Classes. This is really, really useful.<br />
<span id="more-20"></span></p>
<h2>Metrics and Analytics &#8211; using interactive elements in your application as keys in a Dictionary</h2>
<p>Anyone who does Flash in the advertising world will be familiar with this &#8211; the client wants every single click to be tracked, which means you need to go through and put unique tracking codes into all of your click handlers. Then the client changes their tracking mechanism and you have to go through and find all of your button handlers and change the codes, and various nightmares ensue. </p>
<p>Well, good news! Dictionary can really help you out here. Here&#8217;s a very simple example of what I mean:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #3f5fbf;">/* note: passing &quot;true&quot; to the Dictionary constructor tells it to use weak keys - meaning that if the dictionary is the only reference to an object, it's available for GC. */</span>
<span style="color: #6699cc; font-weight: bold;">var</span> trackingCodes<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> 
trackingCodes<span style="color: #000000;">&#91;</span>button1<span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;this is the tracking code for button 1&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
trackingCodes<span style="color: #000000;">&#91;</span>button2<span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;this is the tracking code for button 2, etc&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
button1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> buttonHandler<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
button2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> buttonHandler<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> buttonHandler<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	TrackingManager<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">track</span><span style="color: #000000;">&#40;</span>trackingCodes<span style="color: #000000;">&#91;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">currentTarget</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">// logic here to handle click</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Really simple example, but you see what&#8217;s going on, right? The Tracking Code gets associated with the actual button instance. Any time you have a reference to the button you can get a reference to the tracking code &#8211; and e.currentTarget counts as a reference to the button. </p>
<p>If your application is more complex &#8211; for instance, a full-on MVC based web application, with lots of different views &#8211; this can still help you. Set up a Tracking class and give it a static dictionary and two static functions:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">protected</span> static <span style="color: #6699cc; font-weight: bold;">var</span> trackingCodes<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> registerButton<span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">,</span> t<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	trackingCodes<span style="color: #000000;">&#91;</span><span style="color: #004993;">b</span><span style="color: #000000;">&#93;</span> = t<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">track</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	tracking <span style="color: #004993;">code</span> = trackingCodes<span style="color: #000000;">&#91;</span><span style="color: #004993;">b</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">// logic here to do something with that tracking code.</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Then in your views you simply register your buttons in a constructor or init function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">Tracking<span style="color: #000066; font-weight: bold;">.</span>registerButton<span style="color: #000000;">&#40;</span>button1<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;button 1 tracking code&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
Tracking<span style="color: #000066; font-weight: bold;">.</span>registerButton<span style="color: #000000;">&#40;</span>button2<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;button 2 tracking code&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Finally, on click to your button you just pass a reference to e.currentTarget to Tracking.track(). Simple, effective, and it allows you to organize your tracking codes in large blocks so you can easily make changes and no longer have to waste time looking for each button handler.</p>
<h2>Caching &#8211; using Functions as keys in a Dictionary</h2>
<p>This one came up recently on Twitter. Here&#8217;s the problem: you have some relatively expensive functions that only have to get called once. You want to set up a system that&#8217;ll either call your expensive function (the first time) or return a stored value from that function on every subsequent call. The good news? Since Functions are first class Citizen-Objects in Flash, you can use them as Dictionary keys. Here&#8217;s an example of what I mean:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> cache<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> calculateExpensiveNumberOne<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// lots of messy code.</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> calculateExpensiveNumberTwo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// lots of messy code</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> numberOne<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>cache<span style="color: #000000;">&#91;</span>calculateExpensiveNumberOne<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		cache<span style="color: #000000;">&#91;</span>calculateExpensiveNumberOne<span style="color: #000000;">&#93;</span> = calculateExpensiveNumberOne<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">return</span> cache<span style="color: #000000;">&#91;</span>calculateExpensiveNumberOne<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> numberTwo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>cache<span style="color: #000000;">&#91;</span>calculateExpensiveNumberTwo<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		cache<span style="color: #000000;">&#91;</span>calculateExpensiveNumberTwo<span style="color: #000000;">&#93;</span> = calculateExpensiveNumberTwo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">return</span> cache<span style="color: #000000;">&#91;</span>calculateExpensiveNumberTwo<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Simple, right? By the way, the ability to pass references to functions around is REALLY useful. Don&#8217;t be afraid of it. This is how callbacks work, and it opens a door to the wide world of functional programming.</p>
<h3>Class Management &#8211; using Classes as keys in a Dictionary</h3>
<p>If you&#8217;ve ever implemented the Singleton pattern, the previous example probably looked a bit familiar to you. Just to drive the point home, let&#8217;s remember that Classes are also Objects in Flash. You can build, for instance, a factory class that returns singleton instances of the requisite classes using a very similar pattern to the one we used above. For instance, let&#8217;s create a SampleSingletonManager class like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> testing
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Dictionary</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SampleSingletonManager
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> instances<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> getInstance<span style="color: #000000;">&#40;</span><span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>instances<span style="color: #000000;">&#91;</span><span style="color: #004993;">c</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				instances<span style="color: #000000;">&#91;</span><span style="color: #004993;">c</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">c</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">return</span> instances<span style="color: #000000;">&#91;</span><span style="color: #004993;">c</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Then, in our main class, let&#8217;s do this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> testing<span style="color: #000066; font-weight: bold;">.</span>SampleSingletonManager<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TestThing <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TestThing<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>SampleSingletonManager<span style="color: #000066; font-weight: bold;">.</span>getInstance<span style="color: #000000;">&#40;</span><span style="color: #004993;">Sprite</span><span style="color: #000000;">&#41;</span> == SampleSingletonManager<span style="color: #000066; font-weight: bold;">.</span>getInstance<span style="color: #000000;">&#40;</span><span style="color: #004993;">Sprite</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #009900; font-style: italic;">// returns true</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>SampleSingletonManager<span style="color: #000066; font-weight: bold;">.</span>getInstance<span style="color: #000000;">&#40;</span><span style="color: #004993;">Sprite</span><span style="color: #000000;">&#41;</span> === SampleSingletonManager<span style="color: #000066; font-weight: bold;">.</span>getInstance<span style="color: #000000;">&#40;</span><span style="color: #004993;">Sprite</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #009900; font-style: italic;">// returns true</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Again, a very simple example &#8211; obviously this isn&#8217;t enforcing any kind of singleton on your instances, and I have the return type set to Object &#8211; but I hope I&#8217;ve made my point. If you want to take this further, you can structure your singletons to require the SingletonManager to pass an instance of itself, or of a private enforce that can only come from inside SingletonManager. Then you return an Interface type that your various Singletons all implement and BAM.</p>
<p>Dictionary is incredibly useful &#8211; being able to use non-string Keys can lead to some very interesting patterns and can go a long way towards helping to write logical, readable code. There are, of course, some downsides to using Dictionary &#8211; it&#8217;s slower than Object or Array, and you can&#8217;t strictly type the keys or values the way you can with a Vector. However, I&#8217;ve used it to great effect on a wide variety of projects and I hope these simple examples get some of your wheels turning.</p>
<p>Please feel free to comment if you agree/disagree/have questions with any of the examples!</p>
]]></content:encoded>
			<wfw:commentRss>http://mykola.bilokonsky.net/2011/01/why-i-love-flash-utils-dictionary-and-you-should-too/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>2010 In Review</title>
		<link>http://mykola.bilokonsky.net/2010/12/2010-in-review/</link>
		<comments>http://mykola.bilokonsky.net/2010/12/2010-in-review/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 21:16:08 +0000</pubDate>
		<dc:creator>mykola</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Robotics]]></category>
		<category><![CDATA[VEX]]></category>
		<category><![CDATA[2010]]></category>
		<category><![CDATA[2011]]></category>
		<category><![CDATA[consulting]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[robotics]]></category>

		<guid isPermaLink="false">http://mykola.bilokonsky.net/?p=19</guid>
		<description><![CDATA[Just a quick post to wrap up my year. Work 2010 was incredibly exciting for me. A year ago, I was working full-time at a digital advertising agency doing Flash production. It wasn&#8217;t a bad job, but I wasn&#8217;t thrilled about agency life and in April I decided to finally take the plunge and go [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick post to wrap up my year.</p>
<h2>Work</h2>
<p>2010 was incredibly exciting for me. A year ago, I was working full-time at a digital advertising agency doing Flash production. It wasn&#8217;t a bad job, but I wasn&#8217;t thrilled about agency life and in April I decided to finally take the plunge and <a href="http://www.prettysmartstudios.com">go into business for myself</a> &#8211; and honestly, I haven&#8217;t looked back. I prefer the consulting lifestyle over the salaried lifestyle in almost every way, and it&#8217;s allowed me to cast an incredibly wide net in terms of extracurricular activities and side projects. Having a <a href="http://www.twitter.com/stoltesawa">girlfriend</a> who is also a talented designer made this something of a no-brainer for us, and it&#8217;s been great to be able to collaborate on large projects working to meet our own deadlines. Some of my consulting has been done on-site, as has some of hers &#8211; but our most exciting projects are the ones we&#8217;re working on secretly. Hopefully in 2011 we&#8217;ll have some cool stuff to share!</p>
<h2>Activities</h2>
<p>As far as extracurriculars and side projects go, I took over running the <a href="http://www.columbusdigital.org"/>Columbus Digital</a> Adobe User Group, provided technical feedback on not one but two books from O&#8217;Reilly Press (<a href="http://oreilly.com/catalog/9780596805616/">The Flex 4 Cookbook</a> and <a href="http://www.adobe.com/content/dam/Adobe/en/devnet/flex/pdfs/flex4_getting_started.pdf">Getting Started with Flex 4</a>), and went to my first industry conference (<a href="http://riaunleashed.com">RIAUnleashed</a>). I also submitted a talk to 2011&#8242;s Flash and the City.</p>
<p>Additionally I&#8217;ve become much more active on Twitter (hit me up at <a href="http://www.twitter.com/mykola">@mykola</a>) and I&#8217;ve started updating this blog with almost alarming regularity (this is what, like, my fifth post this year? That&#8217;s huge for me!)</p>
<h2>Technology</h2>
<p>2010 was going to be the year I switched to an Android phone. I mean, come on &#8211; I&#8217;m a Flash developer. I&#8217;m supposed to hate Apple and Steve Jobs, especially after that Flash stunt he pulled! So in July, I put a bullet in my trusty iPhone 3G and bought an HTC Evo 4G.</p>
<p>I returned it inside of a month. I know this is a highly polarized field right now, and I don&#8217;t want to make any enemies &#8211; but I hated almost everything about the Android platform as a user. Inconsistent UI, a convoluted phone OS (&#8220;Oh, no, you should download the process manager to let you know what&#8217;s running!&#8221; &#8211; really?), a terrible app store experience. You name it, going down the list I felt like Apple simply cares more about providing a great user experience &#8211; and so I&#8217;m back on an iPhone. Maybe I&#8217;ll switch in 2011 &#8211; but honestly, Android has a lot of cleaning up to do before they can begin to compete with Apple&#8217;s user experience. </p>
<p>I also picked up an iPad this year. I like it okay, but honestly the novelty wore off quickly. I&#8217;m just not entirely clear what I&#8217;m supposed to do with it. Right now it kinda just lives in the bathroom, which is a constant source of amusement for guests. Still, I suspect I&#8217;ll buy an iPad 2 this coming year. </p>
<h2>Robotics</h2>
<p>2010 is the year I bought my first (four) Arduino microcontrollers. This has been an incredible way to spend my downtime, and I&#8217;ve learned so much I can&#8217;t stand it. Currently I&#8217;m working on developing a custom stack for robotics projects &#8211; it looks something like this:</p>
<ul>
<li>Robot Structure &#8211; <strong>VEX</strong> frame, with VEX motors and wheels etc. It&#8217;s a bit like Lego &#8211; everything is designed to fit together nicely.</li>
<li>Microcontroller &#8211; This is going to be <strong>Arduino</strong>. It doesn&#8217;t take that much effort to make the VEX components play nice with the Arduino, and the existing support out there for open-source hardware projects using the Arduino system is fantastic.</li>
<li>Communications &#8211; Right now I&#8217;m using <strong>Python</strong> to handle my serial communications, because it works so nicely. I can rig up my serial connection using USB, BlueTooth or XBee and it doesn&#8217;t make any difference &#8211; Python is able to read/write with like 2 lines of code. That said, I still haven&#8217;t resolved the difficulties I&#8217;ve been having integrating python into the final layer of my stack&#8230;</li>
<li>User Interface &#8211; <strong>Adobe AIR</strong>. This is a no-brainer &#8211; it&#8217;s incredibly easy to build amazingly detailed user interfaces using the Flash Platform, and I&#8217;m almost able to get complete integration between my Python layer and my AIR layer. I&#8217;m confident that with a bit more tweaking I&#8217;ll have it down.</li>
</ul>
<p>So yeah, that&#8217;s that. Vex -> Arduino -> Python -> AIR creates a <strong>VAPA Robotics Stack</strong>. If I can iron out the kinks, I&#8217;m going to have an incredible project to show off in a few months!</p>
<h2>Looking Forward</h2>
<p>2010 was a great year for me &#8211; I&#8217;m expecting 2011 to be even better. I&#8217;m going to keep learning, keep playing and keep doing cool stuff. Please reach out to me on Twitter of any of this sounds interesting to you, I love to talk shop! </p>
<p>In 2011, my largest focus is going to be on completing my robotics stack &#8211; my big goal for the year is to present at Adobe MAX 2011, controlling a variety of cool &#8216;bots from a Flash-built interface. It&#8217;s much easier than you probably think, and it&#8217;s incredibly satisfying! Like I said, I have a few kinks to work out &#8211; but it&#8217;s 80% of the way there, and I&#8217;d love to get other people to join in!</p>
<p>So, from me &#8211; Happy New year, and I&#8217;ll see you all in 2011!</p>
]]></content:encoded>
			<wfw:commentRss>http://mykola.bilokonsky.net/2010/12/2010-in-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling a VEX motor with an Arduino Microcontroller</title>
		<link>http://mykola.bilokonsky.net/2010/12/controlling-a-vex-motor-with-an-arduino-microcontroller/</link>
		<comments>http://mykola.bilokonsky.net/2010/12/controlling-a-vex-motor-with-an-arduino-microcontroller/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 21:45:55 +0000</pubDate>
		<dc:creator>mykola</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Robotics]]></category>
		<category><![CDATA[VEX]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[Arduino Microcontroller]]></category>
		<category><![CDATA[Control VEX with Arduino]]></category>
		<category><![CDATA[Replace VEX Microcontroller]]></category>
		<category><![CDATA[VEX Motor]]></category>
		<category><![CDATA[VEX Servo]]></category>

		<guid isPermaLink="false">http://mykola.bilokonsky.net/?p=17</guid>
		<description><![CDATA[I&#8217;ve been tinkering with some hardware I recently got my paws on, a VEX starter kit. Designed for education, VEX includes a whole host of equipment beyond their microcontroller &#8211; they have structural components, sensors, motors, servos etc and all of it is designed to plug into their microcontroller. Since it&#8217;s hard-wired into me to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been tinkering with some hardware I recently got my paws on, a <a href="http://www.google.com/products/catalog?q=VEX+Starter+Kit&#038;um=1&#038;ie=UTF-8&#038;cid=4939754482240867169&#038;ei=t_YcTd_-OseYnAf_rvzNDg&#038;sa=X&#038;oi=product_catalog_result&#038;ct=result&#038;resnum=1&#038;ved=0CB8Q8wIwAA#">VEX starter kit</a>. Designed for education, VEX includes a whole host of equipment beyond their microcontroller &#8211; they have structural components, sensors, motors, servos etc and all of it is designed to plug into their microcontroller.</p>
<p>Since it&#8217;s hard-wired into me to do things the hard way, I decided to see if it was possible to control VEX components with an Arduino microcontroller. A bit of googling shows that it can be done, but I didn&#8217;t find any good step-by-step guides &#8211; so I thought I&#8217;d write one. This isn&#8217;t a comprehensive guide to powering all things VEX through an Arduino &#8211; but follow along and I&#8217;ll show you how to control a VEX motor using an Arduino, which is pretty cool.<br />
<span id="more-17"></span></p>
<h2>VEX Motors are Servos!</h2>
<p>First of all: VEX motors don&#8217;t operate like standard motors &#8211; they have three wires, not just two, so you can&#8217;t just plug &#8216;em into an Ardumoto and hope for the best. Instead, you have to know that these motors are servos. The black wire is ground, the orange wire is power and the white wire is designed to carry signal. When we wire this up, we&#8217;re going to power the motor independently of the Arduino board &#8211; we&#8217;ll get to why in a bit. The important thing to note here is that you control this guy by creating a Servo object in your Arduino code, and then passing it a value. If you send &#8220;90&#8243; the motor just kinda sits there. If you pass 0 it spins one way, if you pass 180 it spins the other way &#8211; the closer to 90 you are in either direction, the slower the spin. Cool?</p>
<h2>Powering a VEX Motor to work with your Arduino board</h2>
<p>If you just wire this up to your USB-powered arduino unit you&#8217;ll be in for a big disappointment &#8211; it seems like the arduino is not capable of outputting enough power to drive the motor. Fortunately, the signal wire doesn&#8217;t need as much energy as the motor itself, so the solution is fairly simple. You can solder this too, but these instructions are for a breadboard:</p>
<div id="attachment_18" class="wp-caption alignleft" style="width: 310px"><a href="http://mykola.bilokonsky.net/wp-content/uploads/2010/12/photo.jpg"><img src="http://mykola.bilokonsky.net/wp-content/uploads/2010/12/photo-300x224.jpg" alt="Proper wiring: Black wire from 9v battery to both black wire on VEX and Arduino Ground. Red wire from battery to orange wire on VEX and Arduino VIN. White wire on VEX Motor to PWM output on Arduino board." title="VEX Motor controlled by Arduino" width="300" height="224" class="size-medium wp-image-18" /></a><p class="wp-caption-text">Proper wiring: Black wire from 9v battery to both black wire on VEX and Arduino Ground. Red wire from battery to orange wire on VEX and Arduino VIN. White wire on VEX Motor to PWM output on Arduino board.</p></div>
<ol>
<li>Get a 9v battery with one of those connectors that sits on top and has red and black wires coming out. The connectors are really cheap, it was like 3 bucks for a bag of &#8216;em at Radio Shack.</li>
<li>Connect the two battery cables to two different rows on your breadboard.</li>
<li>From the row that has your red wire, run a wire to the Arduino board&#8217;s &#8220;VIN&#8221; pin and run a wire to your motor&#8217;s Orange cable.</li>
<li>From the row that has your black wire, run a wire to the Arduino board&#8217;s &#8220;Ground&#8221; pin and run a wire to your motor&#8217;s Black cable.</li>
<li>Finally, connect the white pin on your motor to a PWM output on your Arduino board. I used Pin 5.</li>
</ol>
<p>What we&#8217;re actually doing here is powering the motor independently of the board &#8211; both the motor and the board are getting energy from the battery, but the motor is getting the full 9v from the battery rather than the 5v it would get if you were powering it from the arduino board directly. From reading the various forum threads it sounds like some people actually put a capacitor between the motor&#8217;s white wire and your Arduino&#8217;s PWM output &#8211; I haven&#8217;t had any issues doing it this way, but if you get erratic behavior you can try that.</p>
<h2>Arduino Code</h2>
<p>This is the easiest part, once you understand the rest. You&#8217;re going to use Arduino&#8217;s native &#8220;Servo&#8221; class. You attach it to your PWM pin, then you send a value. Really, really easy. Here&#8217;s a sample sketch that&#8217;ll get your motor turning:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;Servo.h&quot;</span>
&nbsp;
Servo motor<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  motor.<span style="color: #202020;">attach</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  motor.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Where to now?</h2>
<p>Once you have this part down you&#8217;re in a good position to take advantage of the various equipment that VEX lets you use. Stay tuned for a post soon that&#8217;ll have me driving a VEX robot around using easy-to-make Arduino components.</p>
]]></content:encoded>
			<wfw:commentRss>http://mykola.bilokonsky.net/2010/12/controlling-a-vex-motor-with-an-arduino-microcontroller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe AIR, NativeProcess and Python &#8211; Introduction</title>
		<link>http://mykola.bilokonsky.net/2010/11/adobe-air-nativeprocess-and-python-introduction/</link>
		<comments>http://mykola.bilokonsky.net/2010/11/adobe-air-nativeprocess-and-python-introduction/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 19:20:08 +0000</pubDate>
		<dc:creator>mykola</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[NativeProcess]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://mykola.bilokonsky.net/?p=14</guid>
		<description><![CDATA[Right now, if you want to handle input and output between Arduino and Adobe Flash/AIR, the recommended best practice is to use a program like SerProxy to listen to your serial input, turn it into socket data and publish it to local host. Inside of Flash, then, you treat it as a socket server &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Right now, if you want to handle input and output between Arduino and Adobe Flash/AIR, the recommended best practice is to use a program like <a href="http://www.lspace.nildram.co.uk/freeware.html">SerProxy</a> to listen to your serial input, turn it into socket data and publish it to local host. Inside of Flash, then, you treat it as a socket server &#8211; you listen for socket data, and respond in kind.</p>
<p>It works, but it&#8217;s not pretty. You need to have access to the right ports, and you have to run a third-party application with its own config file to make it work. Additionally, I&#8217;ve never once been able to get it working on a mac &#8211; I know I&#8217;m not the only one, either. There&#8217;s some weird shit going on there. </p>
<p>I decided to see if it was possible to get the same results using the new <a href="http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/desktop/NativeProcess.html">NativeProcess API</a> in Adobe AIR 2. Read on for the details!</p>
<p><span id="more-14"></span></p>
<h2>Overview &#8211; Selecting a Language</h2>
<p>So, before we get started let&#8217;s define the problem as specifically as possible. We have a device, in this case an Arduino Microcontroller, that&#8217;s reading and writing to a serial port on the computer. Our challenge is to allow our Flash application, running in AIR, to interact with it. Flash, however, has no direct access to serial port data &#8211; even with the expanded AIR runtime that stuff is still sandboxed away. So we know right out of the box that we&#8217;re going to need an additional language to handle transport between the serial port and AIR.</p>
<p>My challenge is this: I&#8217;m a flash guy. I can comfortably scan other languages, but I don&#8217;t know the Java or Python or C API&#8217;s or syntaxes as well as I probably should. So I need to pick a language that&#8217;ll make this as easy as possible to implement. I first looked at the source of SerProxy to see if I could repurpose the existing code there &#8211; but it frankly scared me a little bit. C can be an intimidating thing to look at, and when there are 15 files full of one-or-two-character-long method names and system calls I have to assume that there&#8217;s going to be an easier way. The advantage is, there are no dependencies &#8211; once you have your program written, you can compile it down to an executable on any system, and that&#8217;s pretty neat. Still, though &#8211; too scary for now, I want to be up and running quickly.</p>
<p>So I looked into Java &#8211; and that made a bit more sense, but there seem to be issues with the libraries required for native serial IO and the documentation in the tutorials was a bit long. I wanted something simple. Bookmark the Java pages for future reference, but keep looking.</p>
<p>So I looked into python, and apparently serial IO can be handled with about two lines of code, both legible and logical. The downside is that the user needs to have Python installed, and in addition needs to have the PySerial library installed. This is a minor pain in the ass, but it&#8217;s not that big a deal &#8211; anyone who is going to be using my code should be able to at least install python and pyserial, fine. Plus, Python runs on any operating system as long as you have the python interpreter installed. So, Python it is. </p>
<h2>Setup</h2>
<p>Really simple. Open your AIR IDE of choice, create a new Flex project. My MXML is below, it&#8217;s all one file &#8211; paste that in there. Then right click the src folder and add a new file, call it &#8220;ThreadedSerialInterface.py&#8221; &#8211; the code that will go in here is below, as well. That&#8217;s it. The nice thing about AIR is that it will actually bundle your script in with your AIR application, so there&#8217;s no need to worry about running multiple programs the way you have to now, with SerProxy.</p>
<h2>The Python Script</h2>
<p>I know that I want to be able to write a script which is going to remain open in the background until I tell it to close. While open, this script needs to be able to do two things &#8211; accept any data coming out of the serial port and print it to stdout, and accept any data coming in from stdin and write it out to the serial port. Simple enough, but these are two distinct processes &#8211; so I googled around a bit and decided to implement these processes as two threads within my python script. Here&#8217;s the script as I currently have it, with the caveat that I am NOT a python developer and all of this is either made up as I went along or cribbed from helpful folks on <a href="http://stackoverflow.com/questions/4044293/python-noob-silly-question-works-in-python-interpreter-not-from-cli">Stack Overflow</a>. So, here&#8217;s my current script:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">sys</span> <span style="color: #ff7700;font-weight:bold;">import</span> argv, stdin
<span style="color: #ff7700;font-weight:bold;">from</span> serial <span style="color: #ff7700;font-weight:bold;">import</span> Serial
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">threading</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">try</span>:
    baudRate = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>argv<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    serialPort = argv<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ValueError</span>:
    <span style="color: #808080; font-style: italic;">#some nice default</span>
    baudRate = <span style="color: #ff4500;">9600</span>
    serialPort = argv<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#support paths with spaces. Windows maybe?</span>
serialPort = <span style="color: #483d8b;">' '</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>serialPort<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> serialPort:
    exit<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Please specify a serial port&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;opening connection to %r@%i ...&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>serialPort, baudRate<span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
ser = Serial<span style="color: black;">&#40;</span>serialPort, baudRate, timeout=<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>    
&nbsp;
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> readerThread<span style="color: black;">&#40;</span><span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, threadID, name<span style="color: black;">&#41;</span>:
        <span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">threadID</span> = threadID
        <span style="color: #008000;">self</span>.<span style="color: black;">name</span> = name
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
       <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
           <span style="color: #ff7700;font-weight:bold;">if</span> ser.<span style="color: black;">inWaiting</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
               <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;[R]&quot;</span> + ser.<span style="color: #dc143c;">readline</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> writerThread<span style="color: black;">&#40;</span><span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span><span style="color: black;">&#41;</span>: 
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, threadID, name<span style="color: black;">&#41;</span>:
        <span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">threadID</span> = threadID
        <span style="color: #008000;">self</span>.<span style="color: black;">name</span> = name
    <span style="color: #ff7700;font-weight:bold;">def</span> run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
            <span style="color: #008000;">input</span> = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;[W}Give Me Input!&quot;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;[W]You input %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">input</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            ser.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #008000;">input</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
thread1 = readerThread<span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, <span style="color: #483d8b;">&quot;readerThread&quot;</span><span style="color: black;">&#41;</span>
thread2 = writerThread<span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, <span style="color: #483d8b;">&quot;writerThread&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
thread1.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
thread2.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>A few notes: I&#8217;ve appended &#8220;[R]&#8221; and &#8220;[W]&#8221; to outputs from my Reader and Writer threads, respectively. This lets me easily separate them in my AIR app, which is helpful for knowing what I&#8217;m looking at.</p>
<p>So what&#8217;s going on in this script? I instantiate an instance of pySerial&#8217;s serial class, called &#8220;ser&#8221;, and I tell it to connect to the serial port and baud rate specified as arguments when I run this script. Simple enough. Then I define two classes, readerThread and writerThread, each of which extends threading.Thread. readerThread simply loops and, if there is any output from the serial port, it prints it out. writerThread is the inverse &#8211; it loops, and waits for input from stdin each time through. It takes that input, when it gets it, and writes it to the serial port. I start both threads and I&#8217;m good to go. </p>
<p>Let&#8217;s see how we can tie this into Flash.</p>
<h2>AIR and NativeProcess</h2>
<p>This is actually a lot more painless than you might expect, once you understand what&#8217;s going on. AIR 2 has exposed the NativeProcess API, meaning that we basically have access to a command line interface directly through our AIR application. Rather than stepping through every detail, I&#8217;ll just post my code below, with comments. Right now it&#8217;s all one file:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:WindowedApplication</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">					   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">					   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span></span>
<span style="color: #000000;">					   closing=<span style="color: #ff0000;">&quot;killProc()&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
&nbsp;
<span style="color: #000000;">			// create our native process</span>
<span style="color: #000000;">			private var np:NativeProcess = new NativeProcess<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #000000;">			// create our native process startup info, which will hold things like the path to python and any arguments.</span>
<span style="color: #000000;">			private var npi:NativeProcessStartupInfo = new NativeProcessStartupInfo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #000000;">			/**</span>
<span style="color: #000000;">			 * 	This method gets called when the user clicks the <span style="color: #ff0000;">&quot;init&quot;</span> button. It basically makes sure that your python </span>
<span style="color: #000000;">			 *  path is correct, then assembles the NativeProcess call, assigns listeners and starts the process.</span>
<span style="color: #000000;">			 */</span>
<span style="color: #000000;">			private function setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
&nbsp;
<span style="color: #000000;">				// the file we<span style="color: #ff0000;">'re actually going to be executing is python itself - the rest, my script included, gets passed in as arguments.</span>
<span style="color: #000000;">				var exec:File = File.applicationDirectory.resolvePath(pythonLocation.text);</span>
&nbsp;
<span style="color: #000000;">				// check to see if the python path resolved correctly.</span>
<span style="color: #000000;">				if (exec.exists) {</span>
<span style="color: #000000;">					initButton.enabled = false;</span>
<span style="color: #000000;">					killButton.enabled = true;</span>
<span style="color: #000000;">					npi.executable = exec; // assign &quot;exec&quot; to be the executable in our startup info.</span>
<span style="color: #000000;">					var args:Vector.&lt;String&gt;</span></span> = new Vector.<span style="color: #000000;">&lt;String<span style="color: #7400FF;">&gt;</span></span>; // create a vector to hold arguments - don't assign til the end.
					args[0] = &quot;-i&quot;; // python needs this to handle I/O correctly, details to follow.
					args[1] = File.applicationDirectory.resolvePath(&quot;ThreadedSerialInterface.py&quot;).nativePath; // this is the path to our python script, included with the AIR app.
					args[2] = serialPort.text; // this is the serial port, &quot;COM3&quot; etc on pc or &quot;/dev/tty.usbserial-XXXXXX&quot; on mac, etc.
					args[3] = baudRate.text; // this is our baud rate.
&nbsp;
					npi.arguments = args; // assign the arguments to the startup info object.
&nbsp;
&nbsp;
					// add listeners for stdout, stderr and process exit.
					np.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, stdoutHandler);
					np.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, sterrHandler);
					np.addEventListener(NativeProcessExitEvent.EXIT, exitHandler);
&nbsp;
					// start the NativeProcess
					np.start(npi);
				}
			}
&nbsp;
			/**
			 * 	this method passes a string to our native process, which passes it to the microcontroller.
			 */
			private function writeToSerial():void {
				np.standardInput.writeMultiByte(toSerial.text + &quot;\n&quot;, File.systemCharset);
				toSerial.text = &quot;&quot;;
			}
&nbsp;
			/**
			 * 	This method handles output from the NativeProcess. I have some basic parsing logic in here to separate output by thread.
			 */
			private function stdoutHandler(e:ProgressEvent):void {
				var output:String = np.standardOutput.readMultiByte(np.standardOutput.bytesAvailable, File.systemCharset);
				if (output.indexOf(&quot;[R]&quot;) &gt; -1) {
					logOutputFromReaderThread(output.slice(3));
				}
&nbsp;
				if (output.indexOf(&quot;[W]&quot;) &gt; -1) {
					logOutputFromWriterThread(output.slice(3));
				}
&nbsp;
&nbsp;
				trace(&quot;[Output from Python] &quot; + output);
&nbsp;
			}
&nbsp;
			/**
			 * 	utility function to log Reader thread output.
			 */
			private function logOutputFromReaderThread(s:String):void {
				var text:String = s += readerOut.text;
				readerOut.text = text;
			}
&nbsp;
&nbsp;
			/**
			 * 	utility function to log Writer thread output.
			 */
			private function logOutputFromWriterThread(s:String):void {
				var text:String = s += writerOut.text;
				writerOut.text = text;
			}
&nbsp;
			/**
			 * 	This handles STDERR output, right now it's just tracing.
			 */
			private function sterrHandler(e:ProgressEvent):void {
				var output:String = np.standardError.readMultiByte(np.standardError.bytesAvailable, File.systemCharset);
				trace(&quot;[Error!] &quot; + output);
			}
&nbsp;
			/**
			 * 	This fires when the native process is terminated. 
			 */
			private function exitHandler(e:NativeProcessExitEvent):void {
				trace(&quot;Native Process has terminated!&quot;);	
				initButton.enabled = true;
				killButton.enabled = false;
			}
&nbsp;
			/**
			 * 	This forces the NativeProcess to close. You must call this when you quit your program, 
			 *  or else your processes will live on.
			 * 
			 *  Notice that the Application is using this to handle the Closing event - so when you close the app,
			 *  your process is killed.
			 */
			private function killProc():void {
				trace(&quot;Killing native process&quot;);
				np.exit(true);	
			}
&nbsp;
		]]&gt;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- MXML for layout, self-explanatory I hope --&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> x=<span style="color: #ff0000;">&quot;105&quot;</span> y=<span style="color: #ff0000;">&quot;16&quot;</span> width=<span style="color: #ff0000;">&quot;174&quot;</span> id=<span style="color: #ff0000;">&quot;pythonLocation&quot;</span> text=<span style="color: #ff0000;">&quot;C:\\Python26\\python.exe&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;16&quot;</span> text=<span style="color: #ff0000;">&quot;Python Location&quot;</span> height=<span style="color: #ff0000;">&quot;22&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> x=<span style="color: #ff0000;">&quot;105&quot;</span> y=<span style="color: #ff0000;">&quot;50&quot;</span> width=<span style="color: #ff0000;">&quot;174&quot;</span> id=<span style="color: #ff0000;">&quot;serialPort&quot;</span> text=<span style="color: #ff0000;">&quot;COM3&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;50&quot;</span> text=<span style="color: #ff0000;">&quot;Serial Port&quot;</span> height=<span style="color: #ff0000;">&quot;22&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> x=<span style="color: #ff0000;">&quot;105&quot;</span> y=<span style="color: #ff0000;">&quot;80&quot;</span> width=<span style="color: #ff0000;">&quot;174&quot;</span> id=<span style="color: #ff0000;">&quot;baudRate&quot;</span> text=<span style="color: #ff0000;">&quot;9600&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;80&quot;</span> text=<span style="color: #ff0000;">&quot;Baud Rate&quot;</span> height=<span style="color: #ff0000;">&quot;22&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;initButton&quot;</span> x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;110&quot;</span> label=<span style="color: #ff0000;">&quot;Init&quot;</span> width=<span style="color: #ff0000;">&quot;269&quot;</span> click=<span style="color: #ff0000;">&quot;setup()&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;killButton&quot;</span> x=<span style="color: #ff0000;">&quot;9&quot;</span> y=<span style="color: #ff0000;">&quot;143&quot;</span> label=<span style="color: #ff0000;">&quot;Kill Process&quot;</span> width=<span style="color: #ff0000;">&quot;269&quot;</span> click=<span style="color: #ff0000;">&quot;killProc()&quot;</span> enabled=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HRule</span> x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;172&quot;</span> width=<span style="color: #ff0000;">&quot;268&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> x=<span style="color: #ff0000;">&quot;11&quot;</span> y=<span style="color: #ff0000;">&quot;189&quot;</span> text=<span style="color: #ff0000;">&quot;Write to Serial:&quot;</span> height=<span style="color: #ff0000;">&quot;20&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> x=<span style="color: #ff0000;">&quot;98&quot;</span> y=<span style="color: #ff0000;">&quot;187&quot;</span> width=<span style="color: #ff0000;">&quot;174&quot;</span> id=<span style="color: #ff0000;">&quot;toSerial&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;217&quot;</span> label=<span style="color: #ff0000;">&quot;Send&quot;</span> width=<span style="color: #ff0000;">&quot;262&quot;</span> enabled=<span style="color: #ff0000;">&quot;{toSerial.text.length}&quot;</span> click=<span style="color: #ff0000;">&quot;writeToSerial()&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HRule</span> x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;251&quot;</span> width=<span style="color: #ff0000;">&quot;268&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextArea</span> x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;292&quot;</span> width=<span style="color: #ff0000;">&quot;435&quot;</span> height=<span style="color: #ff0000;">&quot;299&quot;</span> id=<span style="color: #ff0000;">&quot;readerOut&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextArea</span> x=<span style="color: #ff0000;">&quot;453&quot;</span> y=<span style="color: #ff0000;">&quot;292&quot;</span> width=<span style="color: #ff0000;">&quot;421&quot;</span> height=<span style="color: #ff0000;">&quot;299&quot;</span> id=<span style="color: #ff0000;">&quot;writerOut&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;272&quot;</span> text=<span style="color: #ff0000;">&quot;Output from Reader Thread:&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> x=<span style="color: #ff0000;">&quot;453&quot;</span> y=<span style="color: #ff0000;">&quot;272&quot;</span> text=<span style="color: #ff0000;">&quot;Output from Writer Thread:&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:WindowedApplication</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<h2>Results</h2>
<p>So, this ALMOST works. That is to say, it does work but it&#8217;s not quite ideal. I&#8217;m having some issues with input and output into python, and I think they&#8217;re caused by the fact that I don&#8217;t have an actual terminal window. When python is waiting for raw_input(), it outputs a prompt (&#8220;>>>&#8221;). When I print serial anything out, it&#8217;s expecting a console to be able to print to. Because we&#8217;re running this as a process from inside of AIR, there is no actual terminal for interface &#8211; which brings us to the &#8220;-i&#8221; argument I&#8217;m passing in above.</p>
<p>Now, I&#8217;m not a python developer &#8211; I&#8217;ve made that clear, right? &#8211; but from what I can tell, &#8220;-i&#8221; is telling Python to act as through there&#8217;s a terminal even though there isn&#8217;t. It&#8217;s saying &#8220;Trust me, someone is listening even if you can&#8217;t see them.&#8221; Without that argument, the script waits until it exits to output anything. Obviously that&#8217;s no good for our purposes because we want this thing to be constantly running, listening for output. So, the &#8220;-i&#8221; argument helps us out a lot &#8211; but there&#8217;s one final facet of this puzzle that&#8217;s throwing me for a loop.</p>
<p>When I run this application, it works great &#8211; except that only <em>every other</em> command I try to write to the serial port goes through. Boot it up, run it and see. Hit the init button, wait for the &#8220;Initialized, waiting for input.&#8221; response from the Reader thread, type a number into your &#8220;Write to Serial&#8221; box and hit submit. The Writer thread should respond with &#8220;You input 1&#8243;, and if your arduino unit is doing anything in response to serial input it should happen. Now type another number and hit submit &#8211; nothing happens. Type a third and hit submit, everything is fine.</p>
<p>I was confused until I ran it in debugger mode, and realized that I&#8217;m getting output from STDERR &#8211; specifically, every other time I submit serial input it returns &#8220;>>>&#8221;, a prompt, via the Error stream. I have no idea why.</p>
<p><strong><span style="color:#ff0000">See comment thread for more information &#8211; this problem was solved! Specifically, I replaced the &#8220;-i&#8221; command line option with a &#8220;-u&#8221;.</span></strong></p>
<h2>Conclusion</h2>
<p>This is obviously a work in progress, and I&#8217;m going to update this as I go. I&#8217;m writing this post today, perhaps a bit prematurely, because there&#8217;s been some noise on Twitter lately about other folks trying to do similar stuff and I thought I&#8217;d throw this out there in case it helps anyone. If you have any feedback, I&#8217;d love it in the comments below &#8211; especially any feedback on the python section. I&#8217;m not 100% understanding every part of it. </p>
<p>I think as Flash developers many of us tend to live in very small boxes (albeit boxes with lots of cool stuff inside). This project has helped me to realize just how little I understand about programming in general, and in that regard it&#8217;s been very helpful. I hope to continue learning as I go. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://mykola.bilokonsky.net/2010/11/adobe-air-nativeprocess-and-python-introduction/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Arduino GPS Unit</title>
		<link>http://mykola.bilokonsky.net/2010/10/arduino-gps-unit/</link>
		<comments>http://mykola.bilokonsky.net/2010/10/arduino-gps-unit/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 18:39:23 +0000</pubDate>
		<dc:creator>mykola</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[GPS Shield]]></category>
		<category><![CDATA[soldering]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://mykola.bilokonsky.net/?p=12</guid>
		<description><![CDATA[Learn how to build your own hand-held GPS unit. Intermediate level - you need an Arduino Main Board, the GPS Shield and a few other pieces of equipment.]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_13" class="wp-caption alignleft" style="width: 234px"><a href="http://mykola.bilokonsky.net/wp-content/uploads/2010/10/gps.jpg"><img src="http://mykola.bilokonsky.net/wp-content/uploads/2010/10/gps.jpg" alt="Arduino GPS Unit" title="gps" width="224" height="300" class="size-full wp-image-13" /></a><p class="wp-caption-text">This is the final product of this tutorial.</p></div><br />
My local Microcenter has started carrying a relatively extensive collection of Arduino hardware. I somehow find myself trekking up there periodically and driving home with yet another back of circuit boards, jumper cables and hobbyist electronic tools. </p>
<p>I&#8217;ve been playing around a lot with using Adobe AIR&#8217;s new NativeProcess API to replace the current standard for Arduino-Into-Flash workflow (serproxy or tinkerproxy to turn serial input into a socket connection, then listening on localhost), but I&#8217;m not quite ready to present that yet. So instead, let me give you a quick writeup of my weekend project &#8211; a portable battery-powered GPS unit, complete with LCD screen for output. </p>
<p>This puppy gives me a four decimal places of Lat/Lon data consistently, which is pretty cool! The fifth decimal place seems somewhat reliable, but not quite &#8211; and the last one is all over the place, moving around even while the unit itself is sitting still. That&#8217;s some pretty decent where-in-the-world-are-you resolution for a hand-made weekend project!</p>
<p>It&#8217;s probably an intermediate-level project &#8211; you&#8217;ll need a soldering iron, for one, and you&#8217;ll need to be comfortable working with loose wires dangling from a breadboard, plugging things in like a mad scientist until it all just magically works. Sound like fun? Read on!<br />
<span id="more-12"></span></p>
<h2>The Parts</h2>
<p>First, here&#8217;s a list of the parts I used.</p>
<ol>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=666">Arduino Duemilanove</a> main board &#8211; the heart of the device, this allows me to upload code and run it as long as I have power to the chip. Note that this board has just recently been replaced by the brand-new Arduino Uno board. Either should work just fine.</li>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9898">Sparkfun GPS Shield with GPS Chip</a> &#8211; this allows me to receive GPS data and send it directly into the Arduino mainboard via a built-in Serial interface.</li>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=255">16&#215;2 LCD Screen</a> &#8211; this is a digital display that allows me to output various data from the Arduino into a human readable format even when I&#8217;m not plugged into a computer. Note that most 16&#215;2 LCD&#8217;s share common pin configurations, so don&#8217;t lose sleep over which one you use &#8211; but the models that have all 16 pin holes in a straight line are a bit easier to breadboard.</li>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9806">10k Potentiometer</a> &#8211; this is used to adjust contrast on the LCD Screen. Note that any 10k pot will work &#8211; you probably have a few laying around from misc. part sets.</li>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9518">9v Battery Case</a> &#8211; finally, this allows me to power the device even when I&#8217;m not plugged into a USB port. Note that the one I used is a little different from the one I&#8217;ve linked here, but it shouldn&#8217;t really matter.</li>
<li>Equipment: you&#8217;ll need a soldering iron, some solder and a breadboard &#8211; one of the larger ones (30 pins deep or so), not one of the tiny ones that comes with some starter kits. You&#8217;ll also need a 9v Battery.</ol>
<h2>Pre-Assembly</h2>
<p>The first thing you have to do is assemble your components &#8211; there are really two steps here. First, you&#8217;ll need to solder together your GPS Shield. If you have any experience soldering Arduino shields this&#8217;ll be cake &#8211; you only need to worry about the headers. Take a look at Sparkfun&#8217;s <a href="http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=184">GPS Shield Assembly Guide</a> if you have any questions. Once all your soldering is done, take the actual GPS unit and plug it into the little slot near the front of the shield to actually connect it.</p>
<p>The next thing you should do is set up your LCD screen. Rather than typing out all of the steps, I&#8217;ll link you directly to the tutorial I followed to set this up &#8211; so follow the steps here: <a href="http://www.ladyada.net/learn/lcd/charlcd.html">LCD Tutorial</a>. Disregard the code stuff, you&#8217;re only worried about the hardware!</p>
<p>When you&#8217;re done, you should have breadboard with a bunch of cables sticking out and a functional LCD screen that lights up when you power the breadboard.</p>
<p>Finally, if your 9v battery case needs any soldering done, go ahead and take care of that. Note that you may have to unscrew the tip that will eventually plug into the Arduino Board to expose the soldering spots. </p>
<h2>Putting the Hardware Together</h2>
<p>OK, the rest of the hardware stuff is super easy!</p>
<ol>
<li>Push your freshly soldered GPS Shield directly into your Arduino mainboard. Just make sure that all of your pins are connecting (sometimes, especially if you weren&#8217;t careful with your soldering angles, your headers can stick out at odd angles &#8211; if that happens and you can&#8217;t gently bend it back, heat up the soldering gun, loosen up the solder and adjust it) and you&#8217;re set.</li>
<li>Connect your LCD Screen &#8211; run +5v and ground from the shield to the breadboard, then attach your LCD wires. Pin 14 on the LCD should connect to Digital Input 12, pin 4 should connect to Digital Input 7. The other wires should just be plugged into the board between those two, in the same order that they come out of the breadboard. (14 -> 12, 13->11, 12->10, 11->9, 6->8)</li>
<li>That&#8217;s it, until we&#8217;re ready to test!</li>
</ol>
<h2>The Code</h2>
<p>First of all, to be clear I didn&#8217;t come up with any of this code &#8211; I followed a tutorial which pointed me at some code which more or less worked out of the box. Then there&#8217;s one minor change I had to make to the code to get the GPS working, and I added just a bit of code below to get the output to the LCD screen working. Most of this is borrowed directly from the link below, though.</p>
<p>Before we open the Arduino IDE, let&#8217;s go ahead and install those libraries &#8211; they&#8217;re called NewSoftSerial and TinyGPS, and both are available from <a href="http://arduiniana.org/">Arduiniana.org</a>. Download them and add them to your Arduino Libraries. Then fire up Arduino, and paste in <a href="http://www.sparkfun.com/tutorial/GPSQuickStart/gps_parsing_v12ii.pde">this code</a>. </p>
<p>Find the lines that say:</p>
<p><code><br />
#define RXPIN 3<br />
#define TXPIN 2<br />
</code></p>
<p>and simply swap them. RXPIN should be 2, TXPIN should be 3 &#8211; at least, that&#8217;s what my board seemed to require. I had to read through a bunch of comment threads to figure out why my GPS chip was getting a solid lock, but failing to communicate with my device. Hit the play button in the upper left of your Arduino IDE &#8211; this will compile the code, confirming to you that you don&#8217;t have any problems. If you DO get a problem, double-check that you&#8217;ve correctly installed the two libraries from arduiniana.</p>
<p>The final step in the code is to add support for the LCD Display. </p>
<p>First, add the following line to the very top of your code:</p>
<p><code>#include &lt;LiquidCrystal.h&gt;</code></p>
<p>That&#8217;ll get you access to the pre-built LCD libraries, which will make your life a lot easier. Next, find the line of code that says &#8220;#define GPSBAUD 4800&#8243; &#8211; after that line, add the following:</p>
<p><code>LiquidCrystal lcd(7, 8, 9, 10, 11, 12);</code></p>
<p>This instantiates our LCD object in code, so now when we want to output text to the LCD screen it&#8217;s as simple as writing <code>lcd.print("TESTING");</code> and it&#8217;ll work.</p>
<p>Now, go into your setup function and find the place where it&#8217;s printing &#8220;Please wait&#8221; etc to the serial port. Leave that there, but add the following lines after the serial outputs:</p>
<p><code><br />
lcd.begin(16, 2);<br />
lcd.print("Searching");<br />
</code></p>
<p>This way we&#8217;ll know that the arduino is working even if for whatever reason the GPS unit isn&#8217;t able to establish a satellite lock. Finally, let&#8217;s tell the Arduino to output our actual coordinates. Find the function called getgps(), and find the line of code that says <code>Serial.println(longitude,5);</code> &#8211; hit enter, and input the following code immediately following that line:</p>
<p><code><br />
  int latStart;<br />
  int lonStart;</p>
<p>  if (longitude > 0) {<br />
   lonStart = 5;<br />
  } else {<br />
   lonStart = 4;<br />
  }</p>
<p>  if (latitude > 0) {<br />
   latStart = 5;<br />
  } else {<br />
    latStart = 4;<br />
  }</p>
<p>  lcd.setCursor(0, 0);<br />
  lcd.print("LAT:");<br />
  lcd.setCursor(latStart, 0);<br />
  lcd.print(latitude, 5);</p>
<p>  lcd.setCursor(0, 1);<br />
  lcd.print("LON:");<br />
  lcd.setCursor(lonStart, 0);<br />
  lcd.print(longitude, 5);<br />
</code></p>
<p>You&#8217;ll notice that we&#8217;re offsetting the position for lat and lon output depending on whether or not they&#8217;re negative &#8211; this way, we have room to put the minus sign in one or the other rows without offsetting the other digits. The &#8220;5&#8243; that we&#8217;re passing into the print() command tells Arduino to output five decimal places for each number &#8211; important, unless you&#8217;re only interested in a very general idea of where you are.</p>
<p>That should do it for the code. Before we upload it, there&#8217;s one more thing to pay attention to. Look at your GPS shield &#8211; look closer. There&#8217;s a very tiny little black switch next to where the GPS serial cord plugs in, near the front-right of the shield. Make sure it&#8217;s set to &#8220;on&#8221; &#8211; I spent about 45 minutes trying to figure out why my GPS wasn&#8217;t working!</p>
<p>Plug your Arduino board in, upload your code and cross your fingers.</p>
<h2>Using your Arduino GPS Unit</h2>
<p>If everything goes smoothly, your LCD screen should briefly say &#8220;SEARCHING&#8221; and then begin outputting your coordinate data. You&#8217;ll notice that on the one corner of the GPS chip is a small red LED &#8211; if this LED never comes on, it means that your chip is not powered on &#8211; test your connections. If this light is a steady red light &#8211; no blinking &#8211; it means that it&#8217;s searching for a satellite signal. If you&#8217;re inside, try moving near a window until it starts blinking.</p>
<p>You want it to blink, this means that it has a satellite lock and is outputting data.</p>
<p>If your unit is blinking but not writing to the LCD screen it means there&#8217;s some sort of problem in the wiring. Open your Arduino IDE&#8217;s serial monitor and you should see GPS data coming down. If you&#8217;re getting the data to your serial monitor but not to your LCD, test all of your connections. You might try testing the LCD on its own following the steps in the tutorial I linked above.</p>
<p>If you can&#8217;t get a lock after all of this, I&#8217;m not sure what else to tell you. You could try un-reversing the RXPIN and TXPIN that we changed &#8211; I swapped them because I was not able to get a lock with the current configuration, and swapping seemed to fix it. Other than that, I guess look around &#8211; feel free to leave a comment, but I can&#8217;t guarantee that I can help you.</p>
<p>If everything works, congratulations! I&#8217;m pretty happy with my setup, and will hopefully soon be using this to allow me to control a robot using a google maps interface. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://mykola.bilokonsky.net/2010/10/arduino-gps-unit/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

