<?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>StefanoCadenazzi</title>
	<atom:link href="http://stefanocadenazzi.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://stefanocadenazzi.com/blog</link>
	<description>since 1983.</description>
	<lastBuildDate>Fri, 02 Apr 2010 06:01:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Physical GMail Notifier v2</title>
		<link>http://stefanocadenazzi.com/blog/2010/02/physical-gmail-notifier-v2/</link>
		<comments>http://stefanocadenazzi.com/blog/2010/02/physical-gmail-notifier-v2/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 18:26:08 +0000</pubDate>
		<dc:creator>Stefano</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[VB6]]></category>

		<guid isPermaLink="false">http://stefanocadenazzi.com/?p=14</guid>
		<description><![CDATA[Based on original idea by Jamie Matthews What is it? When you&#8217;ve got new mail, in your GMail inbox, a led blinks. By modding the source you can make new alerts, like sound alerts, vibration alerts, there&#8217;s no limits. WOW! 3 blinks! I&#8217;ve got 3 new mails!! This project is composed by 2 parts: - [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanocadenazzi.com%2Fblog%2F2010%2F02%2Fphysical-gmail-notifier-v2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanocadenazzi.com%2Fblog%2F2010%2F02%2Fphysical-gmail-notifier-v2%2F&amp;source=CDNSFN&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Based on original idea by <a href="http://www.j4mie.org/2008/02/15/how-to-make-a-physical-gmail-notifier/" target="_blank">Jamie Matthews</a></p>
<h1>What is it?</h1>
<p>When you&#8217;ve got new mail, in your GMail inbox, a led blinks. By modding the source you can make new alerts, like sound alerts, vibration alerts, there&#8217;s no limits.</p>
<p><object id="showplayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="255" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="quality" value="best" /><param name="src" value="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&amp;file=http%3A//blip.tv/rss/flash/974869&amp;feedurl=http%3A//teto.blip.tv/rss/&amp;autostart=false&amp;brandname=Teto&amp;brandlink=http%3A//teto.blip.tv/" /><embed id="showplayer" type="application/x-shockwave-flash" width="400" height="255" src="http://blip.tv/scripts/flash/showplayer.swf?enablejs=true&amp;file=http%3A//blip.tv/rss/flash/974869&amp;feedurl=http%3A//teto.blip.tv/rss/&amp;autostart=false&amp;brandname=Teto&amp;brandlink=http%3A//teto.blip.tv/" quality="best"></embed></object></p>
<p><em><strong>WOW! 3 blinks! I&#8217;ve got 3 new mails!! </strong></em></p>
<p>This project is composed by 2 parts:</p>
<p>- Software side</p>
<p>- Hardware side</p>
<h1><strong>Software side</strong></h1>
<p>Written in VB6, this app only does 2 things. It checks if you have new mails, and it tells to the hardware part how many new mails there are.</p>
<h1><strong>Hardware side</strong></h1>
<p>Based on Arduino, the hardware read from the usb port how many new mails there are.</p>
<p>If there are 0 new mails, it does nothing.</p>
<p>If there are 1-9 new mails, it blinks X times, where X is the new mail count. Hey, it&#8217;s not a simple &#8220;blink blink&#8221;&#8230; Led fades on and off, it&#8217;s smooooth!</p>
<p>If there are 10+ mails, led turn on and keep on until you read (or delete!) mails.</p>
<p>Cool? No, not rly. Here&#8217;s the cool part:</p>
<p>1- Software and firmware are FREE and OPEN SOURCE</p>
<p>2- You can do this without any programming or electronic skill: just plug in cable, install drivers, and run app.</p>
<p>3- Rly cheap. Part list: an Arduino Diecimila (~15€), an usb cable (~5€), a LED (~0.1€), a GMail account (free!), a PC (hey you already have one, i&#8217;m sure), an internet connection (uh?). &#8212;-&gt; TOT: 20.10€. Oh, i forgot. If Arduino is TOO EXPENSIVE (&#8230;) you can build it by yourself; it&#8217;s opensource, too!</p>
<h1><strong>Let&#8217;s begin!</strong></h1>
<h2><strong>Software Side, written in Visual Basic </strong></h2>
<p>Files needed:</p>
<p>- MS Visual Basic 6 runtimes &#8211; http://support.microsoft.com/kb/290887</p>
<p>- MS Comm Control 6.0 (mscomm32.ocx)</p>
<p>- MS Internet Transfer Control 6.0 (msinet.ocx)</p>
<p>The main (and only) form looks like this:</p>
<p><img class="caption" title="PGN2 Main Form" src="images/stories/form.png" border="0" alt="PGN2 Main Form" align="bottom" /></p>
<p>There are a few buttons.. but don&#8217;t worry you don&#8217;t have to use them if you don&#8217;t want to play around with Arduino.<br />
On the top left you can see a text box and a button to send data to Arduino. Just in case you want to test how arduino reacts to some bytes.<br />
In the center there are the manual check mail button (guess what: it checks for new mail.) and the big debug textbox. Everything PGN2 does is logged here.</p>
<p>Sending data to serial is quite simple:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Public</span> <span style="color: #000080;">Sub</span> SendToArduino(Text <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>)
<span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span>
<span style="color: #000080;">With</span> Serial
 .DTREnable = <span style="color: #000080;">False</span> <span style="color: #008000;">'oh, some settings.
</span> .RTSEnable = <span style="color: #000080;">False</span> <span style="color: #008000;">'this, too.
</span> .PortOpen = <span style="color: #000080;">True</span> <span style="color: #008000;">'we open the port...
</span> .<span style="color: #000080;">Output</span> = Text <span style="color: #008000;">'we send the string...
</span> .PortOpen = <span style="color: #000080;">False</span> <span style="color: #008000;">'and we close the port! Remember: always close the door.
</span><span style="color: #000080;">End</span> <span style="color: #000080;">With</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p>I think it&#8217;s clear, isn&#8217;t it?<br />
Arduino accepts 1 char at time, so&#8230; what to do if there are 100 new mails??  I think it&#8217;s quite boring to see a led blinking 100 times. I prefer it works in this way:</p>
<p>no new mails: led off<br />
1-9 new mails: led blinks n times<br />
10+ new mails: led always on</p>
<p>but.. how to send &#8220;10&#8243; if Arduino only accepts 1 char?<br />
No problem. We don&#8217;t send &#8220;10&#8243;. We send &#8220;:&#8221;. If Arduino receive &#8220;:&#8221; it knows this means there are a lot of new mails.<br />
Now the big problem is how to check mail.. Hey Google offers a &#8220;feed&#8221; version of your inbox! Try to paste this address into your browser:</p>
<p>https://username:password@mail.google.com/mail/feed/atom</p>
<p>Please do not put the symbol &#8220;@&#8221; in your username. Use &#8220;+&#8221; instead. Example:</p>
<p>https://bill+gmail.com:linuxsucks@mail.google.com/mail/feed/atom</p>
<p>With visual basic we can parse this page with the Internet Transfer Control.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> CheckMail()
 <span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">GoTo</span> ERRR <span style="color: #008000;">'error handling. a must.
</span> Log (<span style="color: #800000;">&quot;Checking mail...&quot;</span>)
 <span style="color: #000080;">Dim</span> STRTemp <span style="color: #000080;">As</span> <span style="color: #000080;">String</span> <span style="color: #008000;">'in &quot;strtemp&quot; we put the whole web page
</span> STRTemp = INet.OpenURL(<span style="color: #800000;">&quot;https://&quot;</span> &amp;amp; Username &amp;amp; <span style="color: #800000;">&quot;:&quot;</span>  &amp;amp; _
 Password &amp;amp; <span style="color: #800000;">&quot;@mail.google.com/gmail/feed/atom&quot;</span>)
 STRTemp = Right(STRTemp, Len(STRTemp) - InStr(1, LCase(STRTemp), <span style="color: #800000;">&quot;fullcount&quot;</span>) - 9)
 <span style="color: #008000;">'ok with this step we delete all the crappy things to the left of our mail count
</span> STRTemp = Left(STRTemp, InStr(1, STRTemp, <span style="color: #800000;">&quot;&amp;lt;&quot;</span>) - 1)
 <span style="color: #008000;">'and with this step we remove the right part, too. So, we've got only the mail count!
</span> Log (<span style="color: #800000;">&quot;New Mail(s): &quot;</span> &amp;amp; Int(STRTemp))
 <span style="color: #000080;">If</span> Int(STRTemp) &amp;gt; 9 <span style="color: #000080;">Then</span> STRTemp = <span style="color: #800000;">&quot;:&quot;</span>
 <span style="color: #008000;">'if we have more than 9 mails, we tell arduino to keep the led on
</span> SendToArduino (STRTemp) <span style="color: #008000;">'send to arduino the mail count!
</span><span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
ERRR:
Log (<span style="color: #800000;">&quot;Error in CheckMail: &quot;</span> &amp;amp; Err.Description)
<span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<h2>Hardware side, Arduino language</h2>
<p>Ok, so now we have sent a byte to the serial port. Now, the hardware part.<br />
Arduino language is quite easy to understand. The whole code is here!</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> outPin <span style="color: #339933;">=</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Output connected to PWM pin 11</span>
<span style="color: #993333;">int</span> mail <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// mail count</span>
<span style="color: #993333;">int</span> val<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Value read from the serial port</span>
<span style="color: #993333;">int</span> pwm <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Led PWM control</span>
<span style="color: #993333;">int</span> myloop <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><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>
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: #339933;">;</span>
Serial.<span style="color: #202020;">flush</span><span style="color: #009900;">&#40;</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>
<span style="color: #666666; font-style: italic;">// Read from serial port</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: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
val <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>
Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>val <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">48</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>val <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">59</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> mail <span style="color: #339933;">=</span> val<span style="color: #339933;">-</span><span style="color: #0000dd;">48</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 48=0mails 49=1mail 50=2 ... 57=9 58=:</span>
<span style="color: #666666; font-style: italic;">// : is more than 9 mails, so we keep led always on</span>
<span style="color: #b1b100;">else</span> mail <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>mail <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> analogWrite<span style="color: #009900;">&#40;</span>outPin<span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>mail <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>mail <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>myloop <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> myloop <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> mail<span style="color: #339933;">;</span> myloop<span style="color: #339933;">+=</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
<span style="color: #666666; font-style: italic;">// loops N times (N = new mail count)</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>pwm <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">;</span> pwm <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">;</span> pwm<span style="color: #339933;">+=</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span>
<span style="color: #666666; font-style: italic;">// fade in (from min to max)</span>
<span style="color: #009900;">&#123;</span>
analogWrite<span style="color: #009900;">&#40;</span>outPin<span style="color: #339933;">,</span> pwm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// sets the value (range from 0 to 255)</span>
delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// waits for 20 milli seconds to see the dimming effect</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>pwm <span style="color: #339933;">=</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">;</span> pwm <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> pwm<span style="color: #339933;">-=</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span>
<span style="color: #666666; font-style: italic;">// fade out (from max to min)</span>
<span style="color: #009900;">&#123;</span>
analogWrite<span style="color: #009900;">&#40;</span>outPin<span style="color: #339933;">,</span> pwm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// waits 2 seconds before beginning next loop</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>mail <span style="color: #339933;">==</span> <span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span> analogWrite<span style="color: #009900;">&#40;</span>outPin<span style="color: #339933;">,</span><span style="color: #0000dd;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//or if there is A LOT of mail, it keeps led on</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Done. That&#8217;s all.<br />
All you need to do is to edit your PGN2.ini file with your settings (username, password, com port&#8230;)</p>
<p>Here&#8217;s a few links:</p>
<p>- <a href="http://code.google.com/p/pgn2/downloads/list">all files used in this project</a><br />
- <a href="http://arduino.cc">Arduino</a><br />
- <a href="http://code.google.com/p/pgn2/source/browse">Source codes</a></p>
<p><img class="alignleft" title="100% Free!" src="http://www.softpedia.com/base_img/softpedia_free_award_f.gif" alt="100% Free!" width="170" height="116" />And what I plan to do:</p>
<p>[ ] Better GUI -VB<br />
[ ] Encrypted password storage -VB<br />
[ ] Maybe, different blinking style (fade on, blink N times, fade off) -Arduino<br />
[ ] TrayIcon -VB<br />
[ ] Remove the 65 seconds limit (vb timer control limits interval to 65536 ms) -VB</p>
<p>Help is appreciated, and comments too!</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-shr">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Physical+GMail+Notifier+v2+-+http://&#x27A1;.ws/??&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://stefanocadenazzi.com/blog/2010/02/physical-gmail-notifier-v2/&amp;t=Physical+GMail+Notifier+v2" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://stefanocadenazzi.com/blog/2010/02/physical-gmail-notifier-v2/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://stefanocadenazzi.com/blog/2010/02/physical-gmail-notifier-v2/&amp;title=Physical+GMail+Notifier+v2" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://stefanocadenazzi.com/blog/2010/02/physical-gmail-notifier-v2/&amp;title=Physical+GMail+Notifier+v2" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://stefanocadenazzi.com/blog/2010/02/physical-gmail-notifier-v2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

