<?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>Patrick O'Doherty &#187; ys09</title>
	<atom:link href="http://patrickodoherty.com/tag/ys09/feed/" rel="self" type="application/rss+xml" />
	<link>http://patrickodoherty.com</link>
	<description>Ramblings on anything and everything</description>
	<lastBuildDate>Wed, 16 Jun 2010 15:46:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Young Scientist &#8217;09</title>
		<link>http://patrickodoherty.com/2009/01/young-scientist-09/</link>
		<comments>http://patrickodoherty.com/2009/01/young-scientist-09/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 22:38:18 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[misc]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[energy conservation]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[young scientist]]></category>
		<category><![CDATA[ys09]]></category>

		<guid isPermaLink="false">http://thelifeofpatrick.com/?p=21</guid>
		<description><![CDATA[After my experience in last years Young Scientist Exhibition I decided that I would definitely try and enter again this year. After a lot of thought I decided upon my project entitled &#8216;Energy Saving through Automation&#8217;. In a nutshell I created an automation system for controlling household appliances and domestic lighting to combat standby power [...]]]></description>
			<content:encoded><![CDATA[<p>After my experience in last years Young Scientist Exhibition I decided that I would definitely try and enter again this year. After a lot of thought I decided upon my project entitled &#8216;Energy Saving through Automation&#8217;. In a nutshell I created an automation system for controlling household appliances and domestic lighting to combat standby power wasting.</p>

<p>Fortunately my project won two prizes, being 1st in Intermediate Technology Individual and the Science Foundation of Ireland special award which is given for research/engineering in the field of energy conservation technology.</p>

<p>The electronics part of the project was created using the <a href="http://arduino.cc">Arduino</a> micro-controller platform. For those that don&#8217;t know what the Arduino is, its a prototyping electronics platform created for hobbyists, by hobbyists. The Arduino provided the perfect platform on which to start working with electronics. The board itself runs its own variant of C/C++ and the support forums and language reference are to say the least, second to none.</p>

<p><span id="more-21"></span>
The Arduino also provides easy communication through its serial interface. Implementing serial communication between my MacBook and the board proved to be a very simple affair, instead of being the difficult task I expected it to be. Things such as receiving strings through the serial interface provide the programmer with nice little challenges which I found did a lot for bringing me back to thinking in C.</p>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> <span style="color: #993333;">string</span><span style="color: #009900;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<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>
    Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Start the serial port with a baud rate of 9600</span>
<span style="color: #009900;">&#125;</span>
<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>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// If there is a character to be read</span>
        <span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Start a counter</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #993333;">string</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Append the character to create a string</span>
            i <span style="color: #339933;">+=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Increment the counter</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<p></p></p>

<p>Serial communication on the MacBook end also proved to be easier than I first thought. Using the
<a href="http://pyserial.sourceforge.net" title="pySerial">pySerial</a> module for Python made serial communication with the board a breeze.</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> read<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;">import</span> serial <span style="color: #808080; font-style: italic;"># Import the pySerial module</span>
    s = serial.<span style="color: black;">Serial</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/dev/tty.usbserial-A9005fkd&quot;</span>, <span style="color: #ff4500;">9600</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># Start the serial interface with a baud rate of 9600</span>
    message = s.<span style="color: #dc143c;">readline</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># Read a line from the serial interface</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> message <span style="color: #808080; font-style: italic;"># Return that line</span></pre></div></div>


<p>I decided to use <a href="http://python.org" title="Python">Python</a> to write the &#8220;handler&#8221; that controlled the Arduino for many reasons. The handler application controlled all communication between components allowing for things such as the web interface (see below) to control the Arduino remotely. The main reason I chose Python is that it has ease of use in abundance. Python comes with native support for the <a href="http://sqlite.org" title="SQLite">SQLite</a> database platform which I used to store information for a web interface in my project. Python also promotes good coding practices with things such as tab indentation (which every good programmer should use anyway) being required to nestle code under things such as if statements or while loops. This inherently breaks the code up into easily readable blocks making scripts a lot easier to read. </p>

<p>I decided that to keep things simple that I would write a web interface using Python as well for my project. There were many choices for web frameworks for Python but I eventually settled on the <a href="http://djangoproject.com">Django</a> framework as it was the one recommended to me by friends. Django made developing the web interface quite easy with things such as limiting access to views to authenticated users becoming a one-line addition to the code. I found this a very pleasant change from using PHP and the <a href="http://codeigniter.com" title="CodeIgniter">CodeIgniter</a> framework where such things would have to be written from scratch when starting a new project. It would make me seriously consider using Django for future development instead of PHP and CodeIgniter (although I do hear wonders about Ruby on Rails as well).</p>

<p>I hope to post more specifications on my project in the future but for reasons I can&#8217;t do it at the moment.</p>

<p>Enjoy, </p>

<p>Patrick</p>
]]></content:encoded>
			<wfw:commentRss>http://patrickodoherty.com/2009/01/young-scientist-09/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
