<?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>codetorment &#187; Hardware</title>
	<atom:link href="http://www.codetorment.com/category/hardware/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codetorment.com</link>
	<description>code, tech, random stuff</description>
	<lastBuildDate>Tue, 04 May 2010 21:04:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=7901</generator>
		<item>
		<title>FabLab @ University College of Ghent</title>
		<link>http://www.codetorment.com/2010/05/04/fablab-university-college-of-ghent/</link>
		<comments>http://www.codetorment.com/2010/05/04/fablab-university-college-of-ghent/#comments</comments>
		<pubDate>Tue, 04 May 2010 20:51:08 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Awesome]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[3D printing]]></category>
		<category><![CDATA[fablab]]></category>
		<category><![CDATA[hogent]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=1058</guid>
		<description><![CDATA[This monday I paid a visit to the new FabLab on our very own campus at the University College of Ghent. The FabLab offers a space where students can produce their own designs or just print stuff downloaded from thingiverse. The place is still in a build-up phase but have a look at all the good(ness/ies) [...]]]></description>
			<content:encoded><![CDATA[<p>This monday I paid a visit to the new FabLab on our very own campus at the <a title="HoGent" href="http://www.hogent.be/" target="_blank">University College of Ghent</a>.</p>
<p>The FabLab offers a space where students can produce their own designs or just print stuff downloaded from thingiverse. The place is still in a build-up phase but have a look at all the good(ness/ies) it has already.</p>
<div id="attachment_1059" class="wp-caption alignnone" style="width: 522px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9881_rsz.jpg"><img class="size-full wp-image-1059 " title="DSCN9881_rsz" src="http://www.codetorment.com/wp-content/uploads/DSCN9881_rsz.jpg" alt="DSCN9881 rsz FabLab @ University College of Ghent" width="512" height="384" /></a><p class="wp-caption-text">2 Bits from Bytes RepMan&#39;s</p></div>
<p>These can be purchased as a kit from <a title="BitsFromBytes.com" href="http://www.bitsfrombytes.com/" target="_blank">BitsFromBytes</a></p>
<div id="attachment_1060" class="wp-caption alignnone" style="width: 394px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9883_rsz.jpg"><img class="size-full wp-image-1060  " title="DSCN9883_rsz" src="http://www.codetorment.com/wp-content/uploads/DSCN9883_rsz.jpg" alt="DSCN9883 rsz FabLab @ University College of Ghent" width="384" height="512" /></a><p class="wp-caption-text">RepMan</p></div>
<div id="attachment_1061" class="wp-caption alignnone" style="width: 394px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9885_rsz.jpg"><img class="size-full wp-image-1061  " title="DSCN9885_rsz" src="http://www.codetorment.com/wp-content/uploads/DSCN9885_rsz.jpg" alt="DSCN9885 rsz FabLab @ University College of Ghent" width="384" height="512" /></a><p class="wp-caption-text">Funky Fan</p></div>
<div id="attachment_1062" class="wp-caption alignnone" style="width: 394px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9892_rsz.jpg"><img class="size-full wp-image-1062  " title="DSCN9892_rsz" src="http://www.codetorment.com/wp-content/uploads/DSCN9892_rsz.jpg" alt="DSCN9892 rsz FabLab @ University College of Ghent" width="384" height="512" /></a><p class="wp-caption-text">Mr. MakerBot aka Cupcake</p></div>
<p>Not entirely sure but my guess is the Cupcake was gutted from it&#8217;s electronics to be used to power the lasercut Mendel below.</p>
<p>The lasercut mendel is a thesis project by Frederic Decru aka the Lasercut-Mendel-Guy. He can be seen in <a title="video " href="http://coded.be/en/node/114" target="_blank">this video</a> and the model can be obtained from thingiverse by going <a title="lasercut mendel thingiverse" href="http://www.thingiverse.com/thing:2697" target="_blank">here</a></p>
<div id="attachment_1063" class="wp-caption alignnone" style="width: 394px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9886_rsz.jpg"><img class="size-full wp-image-1063  " title="DSCN9886_rsz" src="http://www.codetorment.com/wp-content/uploads/DSCN9886_rsz.jpg" alt="DSCN9886 rsz FabLab @ University College of Ghent" width="384" height="512" /></a><p class="wp-caption-text">Lasercut Mendel</p></div>
<div id="attachment_1064" class="wp-caption alignnone" style="width: 522px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9887_rsz.jpg"><img class="size-full wp-image-1064  " title="DSCN9887_rsz" src="http://www.codetorment.com/wp-content/uploads/DSCN9887_rsz.jpg" alt="DSCN9887 rsz FabLab @ University College of Ghent" width="512" height="384" /></a><p class="wp-caption-text">Lasercut Mendel looking all Acrylicalicaly&#39;ish</p></div>
<div id="attachment_1065" class="wp-caption alignnone" style="width: 394px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9889_rsz.jpg"><img class="size-full wp-image-1065  " title="DSCN9889_rsz" src="http://www.codetorment.com/wp-content/uploads/DSCN9889_rsz.jpg" alt="DSCN9889 rsz FabLab @ University College of Ghent" width="384" height="512" /></a><p class="wp-caption-text">Lasercut Mendel&#39;s good side</p></div>
<p>I hope to get me a lasercut mendel somewhere in the near future.</p>
<div id="attachment_1066" class="wp-caption alignnone" style="width: 522px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9895_rsz.jpg"><img class="size-full wp-image-1066  " title="DSCN9895_rsz" src="http://www.codetorment.com/wp-content/uploads/DSCN9895_rsz.jpg" alt="DSCN9895 rsz FabLab @ University College of Ghent" width="512" height="384" /></a><p class="wp-caption-text">Batist and a printed Mendel</p></div>
<p><a title="coded.be" href="http://coded.be/" target="_blank">Batist</a> started the FabLab and is seen constructing a printed version of the Mendel RepRap.</p>
<p>I hope to, someday soon, reserve a slot on one of the 3D printers in the FabLab and print the case I&#8217;m designing for my IGEPv2 board.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2010/05/04/fablab-university-college-of-ghent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IGEPv2 Platform</title>
		<link>http://www.codetorment.com/2010/04/24/igepv2-platform/</link>
		<comments>http://www.codetorment.com/2010/04/24/igepv2-platform/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 08:33:43 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[3D model]]></category>
		<category><![CDATA[IGEPv2]]></category>
		<category><![CDATA[omap]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=1013</guid>
		<description><![CDATA[A month ago I received my IGEPv2 platform from  ISEE It&#8217;s a beagleboard clone with the exception that this version comes packed with a RJ45 10/100Mb ethernet connection, bluetooth and  802.11b/g wifi. Oh and the price is about the same as a beagleboard (it&#8217;s actually cheaper then a BB when you opt for the non-wifi [...]]]></description>
			<content:encoded><![CDATA[<p>A month ago I received my IGEPv2 platform from  <a title="ISEE - IGEP website" href="http://www.igep-platform.com/" target="_blank">ISEE</a></p>
<p><a href="http://www.codetorment.com/wp-content/uploads/DSCN9856.jpg"><img class="alignnone size-large wp-image-1015" title="DSCN9856" src="http://www.codetorment.com/wp-content/uploads/DSCN9856-1024x768.jpg" alt="DSCN9856 1024x768 IGEPv2 Platform" width="574" height="430" /></a></p>
<p>It&#8217;s a <a title="beagleboard.org" href="http://beagleboard.org/" target="_blank">beagleboard</a> clone with the exception that this version comes packed with a RJ45 10/100Mb ethernet connection, bluetooth and  802.11b/g wifi. Oh and the price is about the same as a beagleboard (it&#8217;s actually cheaper then a BB when you opt for the non-wifi version).</p>
<p><span id="more-1013"></span></p>
<p>Here are some specs from the <a title="ISEE website" href="http://www.igep-platform.com/index.php?option=com_content&amp;view=article&amp;id=46&amp;Itemid=55" target="_blank">ISEE website</a>:</p>
<p><a href="http://www.codetorment.com/wp-content/uploads/igepv2_rc_photo2.jpg"><img class="alignnone size-full wp-image-1019" title="igepv2_rc_photo2" src="http://www.codetorment.com/wp-content/uploads/igepv2_rc_photo2.jpg" alt="igepv2 rc photo2 IGEPv2 Platform" width="544" height="394" /></a></p>
<ul>
<li>
<div>TI OMAP35x pin compatible family multicore processor</div>
</li>
<li>
<div>ARM CORTEX A8 core</div>
</li>
<li>DSP TMS320C64x+ core</li>
<li>POWERVR SGX 530 core (OpenGL® ES 2.0, OpenGL® ES 1.0 , OpenVG)</li>
<li>IVA2.2 (Video Hardware Accelerators)</li>
<li>DDR RAM plus NAND Flash Package on Package (PoP) memories (on OMAP chip)</li>
<li>Linux BSP available (Board Support Package)</li>
<li>Ethernet 10/100 Mb BaseT.</li>
<li>Wifi IEEE 802.11b/g + Bluetooth 2.0 (Integrated antenna).</li>
<li>Compatibility with a huge collection of USB peripherals including hubs, keyboards, mice, web cameras, and much more.</li>
<li>MicroSD connector.</li>
<li>DVI-D for connecting digital computer monitors.</li>
<li>Stereo audio in and out for a microphone and headphones or speakers.</li>
<li>Expansion connector with I/O, SPI, UART&#8230;</li>
<li>Expansion connector with access LCD lines.</li>
<li>Wall plug 5 Vdc or JST input.</li>
<li>RS-485 Transceiver.</li>
<li>2 ADC : 1 and 3 MSP/s.</li>
<li>Temperature Range: -40 to +80º C.</li>
<li>EMI and EMC precertificate. CE compliant.</li>
</ul>
<p>Did I mention it&#8217;s really small? As in &#8216;Djeez that sure is really small!&#8217;.</p>
<p><a href="http://www.codetorment.com/wp-content/uploads/DSCN98581.jpg"><img class="alignnone size-large wp-image-1017" title="DSCN9858" src="http://www.codetorment.com/wp-content/uploads/DSCN98581-1024x808.jpg" alt="DSCN98581 1024x808 IGEPv2 Platform" width="574" height="453" /></a></p>
<p>I&#8217;ve mounted the IGEPv2 board on a lego structure to make (dis)connecting cables a bit easier and to prevent static discharges of causing any mayhem. The mounting holes in the pcb are spaced equal to the offset in the lego beams so there was no need for drilling or hotglue.</p>
<p>Of course this is just fine for use on your desktop but rather useless when trying to protect your precious board from the (or atleast some) elements. So I wanted an affordable case. ISEE sells a <a title="ISEE IGEP HOUSING" href="http://igep-platform.com/shop/index.php?main_page=product_info&amp;products_id=36" target="_blank">housing</a> for 15EUR, but as I forgot to order one when ordering the board, the price of shipping about doubles that figure, crossing it from the list of options. Specialcomp has a <a title="Specialcomp" href="https://specialcomp.com/isee/order.htm" target="_blank">housing</a> for $29 making it even less of an option.</p>
<p><a href="http://borglabs.com/blog/build-your-own-igepv2-enclosure-part2" target="_blank">Borglabs</a> has a cool tutorial on how to hack a $5 soap box to make an enclosure. This is definitely the best value for money you&#8217;ll get.</p>
<p>I liked the specialcomp acrylic housing but disliked the pricetag. So I deciced to make my own. I fired up sketchup and looked for a model of the IGEP board in the store, none were found. So as any sensible human being would do, instead of just using a box with some holes as a mockup, I had to draw the thing myself.</p>
<p>Some renders of the 3D-model:</p>
<p><a href="http://www.codetorment.com/wp-content/uploads/igepv2_board_041.png"><img class="alignnone size-large wp-image-1029" title="igepv2_board_04" src="http://www.codetorment.com/wp-content/uploads/igepv2_board_041-1024x550.png" alt="igepv2 board 041 1024x550 IGEPv2 Platform" width="590" height="317" /></a></p>
<p><a href="http://www.codetorment.com/wp-content/uploads/igepv2_board_07.png"><img class="alignnone size-large wp-image-1030" title="igepv2_board_07" src="http://www.codetorment.com/wp-content/uploads/igepv2_board_07-1024x550.png" alt="igepv2 board 07 1024x550 IGEPv2 Platform" width="590" height="317" /></a></p>
<p><a href="http://www.codetorment.com/wp-content/uploads/igepv2_board_05.png"><img class="alignnone size-large wp-image-1031" title="igepv2_board_05" src="http://www.codetorment.com/wp-content/uploads/igepv2_board_05-1024x550.png" alt="igepv2 board 05 1024x550 IGEPv2 Platform" width="590" height="317" /></a></p>
<p><a href="http://www.codetorment.com/wp-content/uploads/igepv2_board_10.png"><img class="alignnone size-large wp-image-1032" title="igepv2_board_10" src="http://www.codetorment.com/wp-content/uploads/igepv2_board_10-1024x550.png" alt="igepv2 board 10 1024x550 IGEPv2 Platform" width="590" height="317" /></a></p>
<p>Most of the parts were just downloaded from the store and I don&#8217;t take any credit for them. I just wanted a 3D model where connector positions were accurate enough to design a case.</p>
<p>The model is on a 1/1 scale and the .kmz file can be downloaded here : <a href="http://www.codetorment.com/wp-content/uploads/igepv2_revB_board.zip">igepv2_revB_board</a></p>
<p>I&#8217;m getting some errors uploading the model to the sketchup store but I&#8217;ll post a link when it&#8217;s done.</p>
<p>Only thing left to do now is design a case. And when I have a few spare moments, I will.</p>
<p>So watch out for a future post with a 3D model of a case and probably some instructions on how to reproduce and assemble one yourself.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2010/04/24/igepv2-platform/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Arduino temperature data logger</title>
		<link>http://www.codetorment.com/2009/11/12/arduino-temperature-and-light-data-logging-and-chartplotting-webmonitor/</link>
		<comments>http://www.codetorment.com/2009/11/12/arduino-temperature-and-light-data-logging-and-chartplotting-webmonitor/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 16:27:09 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[ethernet]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=672</guid>
		<description><![CDATA[An arduino, a DB18S20 one-wire temperature sensor and an LDR (Light Dependent Resistor) are hooked up with some resistors and an ethernet shield to make a datalogger and webmonitor. Notes : for this setup the connections are made on the ethernet shield instead of directly on the arduino. Since Fritzing misses a library with external [...]]]></description>
			<content:encoded><![CDATA[<p>An arduino, a DB18S20 one-wire temperature sensor and an LDR (<em>Light Dependent Resistor</em>) are hooked up with some resistors and an ethernet shield to make a datalogger and webmonitor.</p>
<p><a href="http://www.codetorment.com/wp-content/uploads/DSCN9593-1.JPG"><img class="size-full wp-image-718 alignnone" title="DSCN9593-1" src="http://www.codetorment.com/wp-content/uploads/DSCN9593-1.JPG" alt=" Arduino temperature data logger" width="448" height="335" /></a></p>
<p><span id="more-672"></span>Notes :</p>
<ul>
<li>for this setup the connections are made on the ethernet shield instead of directly on the arduino. Since <a title="Fritzing" href="http://fritzing.org/" target="_blank">Fritzing</a> misses a library with external shield I used the arduino, the pinout stays the same either way.</li>
<li>check the <a title="DS18B20 datasheet" href="http://www.google.be/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;ved=0CAsQFjAA&amp;url=http%3A%2F%2Fdatasheets.maxim-ic.com%2Fen%2Fds%2FDS18B20.pdf&amp;rct=j&amp;q=ds18b20+datasheet&amp;ei=pSr8SqLvOtTX-Qaf5pSIAg&amp;usg=AFQjCNEA19aScsvJEYz5A_daB2kpye2SiA" target="_blank">DS18B20 datasheet </a>for the specifications on hooking up the sensor in parasite or powered mode</li>
</ul>
<p>Schematics :</p>
<p><a href="http://www.codetorment.com/wp-content/uploads/temp_light_monitor_tiny_bb.png"><img class="alignnone size-full wp-image-712" title="Arduino DS18B20 temperature sensor and LDR schematics" src="http://www.codetorment.com/wp-content/uploads/temp_light_monitor_tiny_bb.png" alt="Arduino DS18B20 temperature sensor and LDR schematics" width="526" height="246" /></a></p>
<p>The arduino reads the sensors every 10 seconds and passes the data to a php script on your website; which then stores the data in a text file. A second script generates a line chart of the collected data.</p>
<div id="attachment_729" class="wp-caption alignnone" style="width: 458px"><a href="http://www.codetorment.com/wp-content/uploads/tempgraph.php.png"><img class="size-full wp-image-729   " title="tempgraph.php" src="http://www.codetorment.com/wp-content/uploads/tempgraph.php.png" alt="22 hours of temperature data" width="448" height="233" /></a><p class="wp-caption-text">22 hours of temperature data</p></div>
<p>I started from <a title="Cyberspice's blog" href="http://www.cyberspice.org.uk/blog/2009/10/29/boarduino-vivarium-temperature-monitor/" target="_blank">Cyberspice&#8217;s</a> code and changed the arduino code to make use of the DB18S20 and the ethernet shield.</p>
<p>A variable was added to the upload php script in order to store the light intensity in addition to the temperature.</p>
<p>The graphing script was altered to also display the minimum temperature, the maximum temperature, the current temperature and the average temperature. A raster was added for a better interpretation of the plotted data and a green line is showing the average temperature  troughout the chart.</p>
<p>You need to alter your ip, domain and path as I explained in the post <a title="Arduino wireless motion detector" href="http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector-part-2/" target="_self">Arduino Wireless motion detector</a> so I won&#8217;t go into those details here.</p>
<p>The arduino sketch :</p>
<pre class="brush: cpp;">
#include &lt;OneWire.h&gt;
#include &lt;string.h&gt;
#include &lt;Ethernet.h&gt;

int count = 0;
OneWire ds(8);
int HighByte, LowByte, TReading, SignBit, Tc_100, Tf_100, Whole, Fract;
int Tcount = 1;
int W[6];
int F[6];
int photocellPin = 0;     // the cell and 10K pulldown are connected to a0
int light;     // the analog reading from the sensor divider

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
  192, 168, 1, 36};
byte server[] = { 77, 222, 78, 32};
// String buffer
char buffer[256];

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  // Serial.println(&quot;connecting...&quot;);

}

void loop()
{
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
    ds.reset_search();
    return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end

  delay(1000);            

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE);         // Read Scratchpad

  light = analogRead(photocellPin);
  Serial.print(&quot;light intensity = &quot;);
  Serial.print(light);
  Serial.print(&quot;\n&quot;);
  for ( i = 0; i &lt; 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }

  LowByte = data[0];
  HighByte = data[1];
  TReading = (HighByte &lt;&lt; 8) + LowByte;
  SignBit = TReading &amp; 0x8000;  // test most sig bit
  if (SignBit) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25

  Whole = Tc_100 / 100;  // separate off the whole and fractional portions
  Fract = Tc_100 % 100;

  if (SignBit) // If its negative
  {
    Serial.print(&quot;-&quot;);
  }
  Serial.print(Whole);
  Serial.print(&quot;.&quot;);
  if (Fract &lt; 10)
  {
    Serial.print(&quot;0&quot;);
  }
  Serial.print(Fract);
  Serial.print(&quot; C\n&quot;);

  if (client.connect()) {
    Serial.println(&quot;connected&quot;);
 sprintf(buffer, &quot;HEAD /path/to/script/newtemp.php?count=%d&amp;temp=%d.%d&amp;light=%d HTTP/1.1&quot;, Tcount, Whole, Fract, photocell);
 client.println(buffer);
 client.println(&quot;Host: yourdomain.com&quot;);
 client.println(&quot;Connection: close&quot;);
 client.println();
 client.stop();
 Tcount++;
 }
 else {
 Serial.println(&quot;connection failed&quot;);
 }
 delay(60000);  // wait 1 minute before sending new data
}
</pre>
<p>The upload script  &#8216;newtemp.php&#8217; :</p>
<pre class="brush: php;">
&lt;?php

if ($_SERVER['REQUEST_METHOD'] == 'HEAD') {

	$fields = explode(&quot;&amp;&quot;, $_SERVER['QUERY_STRING']);
	$values = array();

	foreach ($fields as $field) {
		$keyval = explode(&quot;=&quot;, $field);
		$values[$keyval[0]] = $keyval[1];
	}

	$file = fopen('./tempdata.txt','a+');
	if ($file) {
		fwrite($file, time() . ':' . $values['count'] . ':' . $values['temp'] . ':' . $values['light']);
		fwrite($file, &quot;\n&quot;);
		fclose($file);
	}
}

?&gt;
</pre>
<p>The graphing script &#8216;tempgraph.php&#8217; :</p>
<pre class="brush: php;">
&lt;?php

define('WIDTH', 1000);
define('HEIGHT', 520);
define('FONT', 1);
 define('FONT2',2);

// Get the temperature data
$data = array();
$file = fopen(&quot;./tempdata.txt&quot;,&quot;r&quot;);
if ($file) {
	while (!feof($file)) {
		$line = trim(fgets($file));
		if (strlen($line)) {
			$fields = explode(&quot;:&quot;, $line);
			$keyval = array();
			$keyval['time']        = $fields[0];
			$keyval['count']       = $fields[1];
			$keyval['temperature'] = $fields[2];
			$keyval['light'] 	   = $fields[3];
			$data[] = $keyval;
		}
	}

	fclose($file);
}

// Get the number of data points
$datapoints = count($data);

// Lines are chronological
$mintime = $data[0]['time'];
$maxtime = $data[$datapoints - 1]['time'];

// Temperatures need to be processed.
$mintemp = $data[0]['temperature'];
$maxtemp = $data[0]['temperature'];

foreach ($data as $datapoint) {
	$mintemp = $mintemp &lt; $datapoint['temperature'] ?
	           $mintemp : $datapoint['temperature'];
	$maxtemp = $maxtemp &gt; $datapoint['temperature'] ?
	           $maxtemp : $datapoint['temperature'];
	$avgtemp += $datapoint['temperature'];
	$curtemp = $datapoint['temperature'];
}
 $avgtemp = round(($avgtemp / $datapoints),2);

// Get the axis dimensions.  Round up and down to the nearest
// degree C and hour.
$lowtime  = intval($mintime / 3600) * 3600;
$hightime = (intval($maxtime / 3600) + 1) * 3600;
$difftime = $hightime - $lowtime;

$lowtemp  = intval($mintemp);
$hightemp = intval($maxtemp) + 1;
$difftemp = $hightemp - $lowtemp;

// Create the image
$image = imagecreate(WIDTH, HEIGHT);
if ($image) {
	$background = imagecolorallocate($image, 255, 255, 255);
	$black      = imagecolorallocate($image, 0, 0, 0);
	$red        = imagecolorallocate($image, 255, 0, 0);
	$blue       = imagecolorallocate($image, 0, 0, 255);
	$green		= imagecolorallocate($image, 0, 204, 5);
	$grey		= imagecolorallocate($image, 210,210,210);

	// Draw the axes
	imageline($image, 20, 20, 20, 485, $black);
	imageline($image, 15, 480, 980, 480, $black);
	imageline($image, 15, 20, 20, 20, $black);
	imageline($image, 980, 480, 980, 485, $black);

	// Draw top horizontal line
	imageline($image, 20, 20, 980, 20, $grey);

	// Draw right most vertical line
	imageline($image, 980, 20, 980, 479, $grey);

	for ($i = 3600; $i &lt; $difftime; $i += 3600) {
		$x = 20 + (($i * 960) / $difftime);
		// Draw ticks on horizontal axis
		imageline($image, $x, 480, $x, 483, $black);
		// Draw horizontal guides
		imageline($image, $x, 479, $x, 20, $grey);
	}
	$temp = intval($lowtemp);
	for ($i = 1; $i &lt; $difftemp; $i++) {
	    $y = 480 - (($i * 460) / $difftemp);
		// Draw ticks on vertical axis
		imageline($image, 17, $y, 20, $y, $black);

		// Draw vertical guides
		imageline($image, 21, $y, 980, $y, $grey);
		$temp = intval($temp) + 1;
		$ytemp = intval($y) - 5;
		//if($temp % 2 == 0){
			imagestring($image, FONT, 0, $ytemp, $temp . 'C', $black);
		//}
	}

	// Draw the labels
	imagestring($image, FONT, 8, 490, date(&quot;H:i&quot;, $lowtime), $black);
	imagestring($image, FONT, 970, 490, date(&quot;H:i&quot;, $hightime), $black);
	imagestring($image, FONT, 0, 475, $lowtemp . 'C', $black);
	imagestring($image, FONT, 0, 15, $hightemp . 'C', $black);

	// Draw min, max and avg
	imagestring($image, FONT2, 700, 430, &quot;Cur. temp : &quot; . $curtemp . &quot; °C&quot;,$black);
	imagestring($image, FONT2, 700, 450, &quot;Avg. temp : &quot; . $avgtemp . &quot; °C&quot;,$green);
	imagestring($image, FONT2, 850, 430, &quot;Min. temp : &quot; . $mintemp . &quot; °C&quot;,$blue);
	imagestring($image, FONT2, 850, 450, &quot;Max. temp : &quot; . $maxtemp . &quot; °C&quot;,$red);

	// Draw avg line

	$avgtemp = 480 - ((($avgtemp - $lowtemp) * 460) / $difftemp);
	imageline($image,20, $avgtemp, 980, $avgtemp, $green);

	// Draw the temperature points

	// Position of the first point
	$prevx = (($data[0]['time'] - $lowtime) * 960) / $difftime;
	$prevy = (($data[0]['temperature'] - $lowtemp) * 460) / $difftemp;

	// Draw line from previous point to current point
	for ($i = 1; $i &lt; $datapoints; $i++) {
		$x = (($data[$i]['time'] - $lowtime) * 960) / $difftime;
		$y = (($data[$i]['temperature'] - $lowtemp) * 460) / $difftemp;
		imageline($image, $prevx + 20, 480 - $prevy, $x + 20, 480 - $y, $red);
		$prevx = $x;
		$prevy = $y;
	}

	// Finally time and date stamp
	$generated = 'Generated: ' . date(&quot;r&quot;);
	imagestring($image,
	            FONT,
	            WIDTH - 15 - (imagefontwidth(FONT) * strlen($generated)),
	            HEIGHT - 15,
	            $generated,
	            $blue);

	// Output the image
	header('Content-Type: image/png');
	imagepng($image);

	// Destroy it
	imagedestroy($image);
}

?&gt;
</pre>
<p>I will soon post some improvements on the scripts :</p>
<ul>
<li>averaging 6 readings ( 1 minute ) to 1 datapoint to get rid of the noise</li>
<li>let the script fill one text file for each day, so you can look at a history over several days</li>
<li>split up data into different charts</li>
<li>last but not least, trying to add the S65 in the game : showing the current sensor readings or a graph</li>
</ul>
<p><a href="http://www.codetorment.com/wp-content/uploads/DSCN9596.JPG"><img class="alignnone size-full wp-image-786" title="DSCN9596" src="http://www.codetorment.com/wp-content/uploads/DSCN9596.JPG" alt=" Arduino temperature data logger" width="454" height="341" /></a></p>
<p>Please leave a comment or send me a link to show your arduino projects!</p>
<p><a title="Home" href="http://www.codetorment.com/" target="_self">Back to homepage</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/11/12/arduino-temperature-and-light-data-logging-and-chartplotting-webmonitor/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How the inductor works</title>
		<link>http://www.codetorment.com/2009/11/11/how-the-inductor-works/</link>
		<comments>http://www.codetorment.com/2009/11/11/how-the-inductor-works/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 08:57:35 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Awesome]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[capacitator]]></category>
		<category><![CDATA[diode]]></category>
		<category><![CDATA[electricity]]></category>
		<category><![CDATA[ic]]></category>
		<category><![CDATA[led]]></category>
		<category><![CDATA[resistor]]></category>
		<category><![CDATA[transistor]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=675</guid>
		<description><![CDATA[MAKE made another excellent video with Collin Cunningham. This time it&#8217;s on how inductors work. Learn more about wire coils and their capacity to store energy in electromagnetic fields. Be sure to check out the other videos &#8230; MAKE presents : the LED MAKE presents : the Resistor MAKE presents : the Capacitator MAKE presents [...]]]></description>
			<content:encoded><![CDATA[<p>MAKE made another excellent video with Collin Cunningham. This time it&#8217;s on how inductors work. Learn more about wire coils and their capacity to store energy in electromagnetic fields.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/STDlCdZnIsw&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="340" src="http://www.youtube.com/v/STDlCdZnIsw&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Be sure to check out the other videos &#8230;<br />
<span id="more-675"></span></p>
<p><a title="MAKE presents the LED" href="http://blog.makezine.com/archive/2008/11/make_presents_the_led.html" target="_blank">MAKE presents : the LED</a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="225" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=2284258&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="225" src="http://vimeo.com/moogaloop.swf?clip_id=2284258&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a title="MAKE presents the Resistor" href="http://blog.makezine.com/archive/2008/12/make_presents_the_resisto.html" target="_blank">MAKE presents : the Resistor</a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="225" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=2490503&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="225" src="http://vimeo.com/moogaloop.swf?clip_id=2490503&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a title="MAKE presents the Capacitator" href="http://blog.makezine.com/archive/2009/02/make_presents_the_capacitor.html" target="_blank">MAKE presents : the Capacitator</a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="225" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=3386456&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="225" src="http://vimeo.com/moogaloop.swf?clip_id=3386456&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a title="MAKE presents the Transistor" href="http://blog.makezine.com/archive/2009/03/make_presents_the_transistor.html" target="_blank">MAKE presents : the Transistor</a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="340" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/-td7YT-Pums&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="340" src="http://www.youtube.com/v/-td7YT-Pums&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a title="MAKE presents : the Diode" href="http://blog.makezine.com/archive/2009/04/make_presents_the_diode.html" target="_blank">MAKE presents : the Diode</a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="340" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/AqzYsuTRVRc&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="340" src="http://www.youtube.com/v/AqzYsuTRVRc&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a title="MAKE presents the Integrated Circuit" href="http://blog.makezine.com/archive/2009/07/make_presents_the_integrated_circui.html" target="_blank">MAKE presents : the Integrated Circuit (IC)</a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="340" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/uSRIc-sEgPw&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="340" src="http://www.youtube.com/v/uSRIc-sEgPw&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/11/11/how-the-inductor-works/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Awesome : Atmel AVR ATmega644 Homebrew device with iPhone aspirations</title>
		<link>http://www.codetorment.com/2009/11/04/awsome-atmel-avr-atmega644-homebrew-device-with-iphone-aspirations/</link>
		<comments>http://www.codetorment.com/2009/11/04/awsome-atmel-avr-atmega644-homebrew-device-with-iphone-aspirations/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 19:41:37 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Awesome]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[8-bit]]></category>
		<category><![CDATA[atmel]]></category>
		<category><![CDATA[avr]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=598</guid>
		<description><![CDATA[Rossum made a an awesome device with just an 8-bit Atmel AVR ATmega644 processor and a cheap touchscreen LCD. Hardware specifications from Rossums&#8217; site : 320&#215;240 LCD with 4 wire resistive touch screen &#8211; a ELT240320ATP variant from a dead Sylvania MP3 player &#8211; uses a ILI9325 controller. 12Mhz Atmega644 CPU with 64k Flash and [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/EF3-U9Lb12k&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/EF3-U9Lb12k&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a title="go" href="http://rossum.posterous.com/avr-homebrew-device-with-iphone-aspirations" target="_blank">Rossum</a> made a an awesome device with just an 8-bit Atmel AVR ATmega644 processor and a cheap touchscreen LCD.<span id="more-598"></span></p>
<p><span style="font-family: arial,sans-serif; border-collapse: collapse;"> </span></p>
<div><span style="font-family: arial,sans-serif; border-collapse: collapse;">Hardware specifications from </span><a href="http://rossum.posterous.com/avr-homebrew-device-with-iphone-aspirations" target="_blank"><span style="font-family: arial,sans-serif; border-collapse: collapse;">Rossums&#8217;</span></a><span style="font-family: arial,sans-serif; border-collapse: collapse;"><a href="http://rossum.posterous.com/avr-homebrew-device-with-iphone-aspirations" target="_blank"> site</a> :<a href="http://rossum.posterous.com/avr-homebrew-device-with-iphone-aspirations" target="_blank"><br />
</a></span></div>
<div><span style="font-family: arial,sans-serif; border-collapse: collapse;"></p>
<div>320&#215;240 LCD with 4 wire resistive touch screen &#8211; a ELT240320ATP variant from a dead Sylvania MP3 player &#8211; uses a ILI9325 controller.</div>
<div>12Mhz Atmega644 CPU with 64k Flash and 4k RAM &#8211; demo fits in 32k.</div>
<div>USB connector for PC communication and charging.</div>
<div>Lithium polymer battery with software controlled power.</div>
<div>Software controlled backlight.</div>
<div>SD Micro slot.</div>
<p>&nbsp;</p>
<div>I can&#8217;t wait to see where he takes his ATmega644 next!</div>
<p>&nbsp;</p>
<div><a title="home" href="http://www.codetorment.com/" target="_self">Back to homepage</a></div>
<p></span></div>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/11/04/awsome-atmel-avr-atmega644-homebrew-device-with-iphone-aspirations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino Goodness : Watterott S65-Shield 172&#215;136 pixels 16-bit color display</title>
		<link>http://www.codetorment.com/2009/11/03/arduino-goodness-watterott-s65-shield-16-bit-color-display-with-172x136-pixels/</link>
		<comments>http://www.codetorment.com/2009/11/03/arduino-goodness-watterott-s65-shield-16-bit-color-display-with-172x136-pixels/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 22:51:55 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[game of life]]></category>
		<category><![CDATA[s65]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[sdcard]]></category>
		<category><![CDATA[shield]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=554</guid>
		<description><![CDATA[Santa came early this year and brought me a S65-Shield revision 1.2 from watterott It consists of : - a Siemens S65 16-bit color screen with 172&#215;136 pixels - a rotary switch (left-right-press) - a micro-SD slot (bottom) You can visit the project page to check progress made to the libraries and hardware.The most recent [...]]]></description>
			<content:encoded><![CDATA[<p>Santa came early this year and brought me a S65-Shield revision 1.2 from <a title="Watterott.com" href="https://www.watterott.com/S65-Shield-fuer-Arduino-Duemilanove-Diecimila_1" target="_blank">watterott</a></p>
<div id="attachment_591" class="wp-caption alignnone" style="width: 458px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9584.JPG"><img class="size-full wp-image-591   " title="Arduino Goodness" src="http://www.codetorment.com/wp-content/uploads/DSCN9584.JPG" alt="Display text" width="448" height="336" /></a><p class="wp-caption-text">S65 displaying random text</p></div>
<p>It consists of :</p>
<p>- a Siemens S65 16-bit color screen with 172&#215;136 pixels</p>
<p>- a rotary switch (left-right-press)</p>
<p>- a micro-SD slot (bottom)<span id="more-554"></span></p>
<div id="attachment_558" class="wp-caption alignnone" style="width: 458px"><a href="http://www.codetorment.com/wp-content/uploads/sd65_bottom.JPG"><img class="size-full wp-image-558 " title="sd65_bottom" src="http://www.codetorment.com/wp-content/uploads/sd65_bottom.JPG" alt=" Arduino Goodness : Watterott S65 Shield 172x136 pixels 16 bit color display" width="448" height="337" /></a><p class="wp-caption-text">S65 bottom</p></div>
<p>You can visit the <a title="S65 Project Page" href="http://www.watterott.net/projects/s65-shield?" target="_blank">project page</a> to check progress made to the libraries and hardware.The most recent library is <a title="S65 v0.08 library download" href="http://www.watterott.net/arduino/s65-shield_v008.zip" target="_blank">v0.08</a> . It&#8217;s actually more like 3 libraries:  &#8216;S65Display&#8217;, &#8216;RotaryEncoder&#8217; and &#8216;SDCard&#8217;.</p>
<p>You can check the <a title="S65 Library Documentation" href="http://www.codetorment.com/wp-content/uploads/S65_Libraries_Docu.htm" target="_blank">documentation</a> that comes with the libraries to view this <span style="text-decoration: line-through;">baby</span> shields&#8217; possibilities. So far this shield seems to be a bargain (compaired to other display-shields out there) selling at only €35 that&#8217;s equal to $51.36600 or 4640.5276 Japanese  Yen or 149.793533 Polish Zloty or your virginity if you&#8217;re misfortuned enough to live in one of those countries, anyhow.</p>
<p>It has some pretty long headers which make it easy to mount on top of the tallest board you own.</p>
<div id="attachment_559" class="wp-caption alignnone" style="width: 458px"><a href="http://www.codetorment.com/wp-content/uploads/sd65_side.JPG"><img class="size-full wp-image-559  " title="sd65_side" src="http://www.codetorment.com/wp-content/uploads/sd65_side.JPG" alt="S65 mating with Duemilanove" width="448" height="335" /></a><p class="wp-caption-text">S65 mating with Duemilanove</p></div>
<p>I don&#8217;t have a microSD card at hand so I can&#8217;t test the SDCard library for now. Which sucks since you can load images stored on the microSD and display them on the screen. You can also use the images for buttons, icons, etc in your sketches&#8230; how cool is that?</p>
<p>Here&#8217;s an example of the awsome S65-Shield in action on an Arduino Duemilanove with 328 Atmel running a Game of Life sketch. I am not the author of this code, he gave me the code for testing and learning purposes. I just added the rotary delay. <span style="text-decoration: line-through;">Maybe he&#8217;ll give his consent later so I can post the code online.</span> Foo Joku gave his consent, the code is posted after the video.</p>
<p>The display and colors look much better in real life, this video was shot with an old digital camera in bad light conditions.</p>
<p><object style="width: 480px; height: 360px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="360" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=7421217&#038;server=vimeo.com&#038;show_title=1&#038;show_byline=1&#038;show_portrait=0&#038;color=&#038;fullscreen=1" /><embed style="width: 480px; height: 360px;" type="application/x-shockwave-flash" width="480" height="360" src="http://vimeo.com/moogaloop.swf?clip_id=7421217&#038;server=vimeo.com&#038;show_title=1&#038;show_byline=1&#038;show_portrait=0&#038;color=&#038;fullscreen=1"></embed></object></p>
<pre>GOL code:
<pre class="brush: cpp;">
#include &lt;S65Display.h&gt;
#include &lt;RotaryEncoder.h&gt;

#define GRID_X 28
#define GRID_Y 20

#define GRID_X_OFFSET 4
#define GRID_Y_OFFSET 6

#define COLOUR_SWITCH_INTERVAL 30

#define MAX_GENERATIONS 250

S65Display lcd;
RotaryEncoder encoder;

uint8_t grid[2][GRID_X][GRID_Y];
uint8_t current_grid = 0;

uint8_t generations = 0;
uint8_t r = 255,g = 0, b = 0;

// Encoder must be serviced regularly.
ISR(TIMER2_OVF_vect)
{
 TCNT2 -= 250; //1000 Hz
 encoder.service();
}

void setup()
{
 lcd.init(4);
 encoder.init();
 // More encoder stuff
 //init Timer2
 TCCR2B  = (1&lt;&lt;CS22); //clk=F_CPU/64
 TCNT2   = 0x00;
 TIMSK2 |= (1&lt;&lt;TOIE2); //enable overflow interupt

 sei();
 initGrid();
 lcd.clear(0);
 drawGrid();
}

void loop()
{
 //delay(50);
 checkEncoder();
 runGrid();
 drawGrid();
 generations++;
 if (generations &gt; MAX_GENERATIONS || cmpGrid()) {
 generations = 0;
 initGrid();
 }
 cycleColour();
 cycleColour();
 cycleColour();
}

int cmpGrid()
{
 int i, j;
 for (i=0; i &lt; GRID_Y; i++) {
 for (j=0; j &lt; GRID_X; j++) {
 if (grid[0][i][j] != grid[1][i][j]) { return 0; }
 }
 }
 return 1;
}

void initGrid()
{
 int i, j;
 int t;
 lcd.clear(0);
 current_grid = 0;
 for (i = 0; i &lt; GRID_X; i++) {
 for (j = 0; j &lt; GRID_Y; j++) {

 if ((uint8_t)random(255) % 3 == 0) {
 grid[0][i][j] = 1;
 } else {
 grid[0][i][j] = 0;
 }
 }
 }
}

void runGrid()
{
 uint8_t x, y;
 int count;
 char string[2] = {0,0};
 uint8_t value = 0;
 uint8_t new_grid;

 new_grid = 1 - current_grid;
 for (y = 0; y &lt; GRID_Y; y++) {
 for (x = 0; x &lt; GRID_X; x++) {
 count = count_neighbours(x, y);
 string[0] = count+48;
 if (count &lt; 2 || count &gt; 3) { value = 0; }
 else if (count == 3) { value = 3; }
 else { value = grid[current_grid][x][y]; }
 grid[new_grid][x][y] = value;
 }
 }
 current_grid = new_grid;
}

int count_neighbours(int x, int y)
{
 int i, j;
 int sx;
 int result = 0;

 x--;
 y--;
 for (i = 0; i &lt; 3; i++) {
 if (y &lt; 0 || y &gt; (GRID_Y - 1)) { continue; }
 for (j = 0; j &lt; 3; j++) {
 if (x &lt; 0 || x &gt; (GRID_X - 1)) { continue; }
 if (i==1 &amp;&amp; j == 1) { x++; continue; } // skip centre
 if (grid[current_grid][x][y]) { result++; }
 x++;
 }
 y++;
 x -= 3;
 }
 return result;
}

void drawGrid()
{
 uint8_t  x,  y;
 uint8_t cx, cy;
 uint8_t grid_next_colour = 0;
 cx = GRID_X_OFFSET;
 cy = GRID_Y_OFFSET;
 for (y = 0; y &lt; GRID_Y; y++) {
 cx = GRID_X_OFFSET;
 for (x = 0; x &lt; GRID_X; x++) {
 if (grid[1-current_grid][x][y] != grid[current_grid][x][y]) {
 if(grid[current_grid][x][y]) {
 lcd.drawRect(cx+1, cy+1, cx+5, cy+5, RGB(r,g,b));
 } else {
 lcd.drawRect(cx, cy, cx+6, cy+6, 0);
 }
 }
 cx += 6;
 }
 cy += 6;
 }
}

inline void cycleColour()
{
 if (!b &amp;&amp; r)  { r-=5; g+=5; }
 else if (g) { g-=5; b+=5; }
 else if (b) { b-=5; r+=5; }
}

void checkEncoder(void)
{
 int8_t press;
 press = encoder.sw();

 if ( !press ) { return; }

 if (SW_PRESSED == press || SW_PRESSEDLONG == press) {
 initGrid();
 lcd.clear(0);
 }
}
</pre>
<p> <a title="Home" href="http://www.codetorment.com/" target="_self">Back to homepage</a></pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/11/03/arduino-goodness-watterott-s65-shield-16-bit-color-display-with-172x136-pixels/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Arduino wireless motion detector : part 2</title>
		<link>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector-part-2/</link>
		<comments>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector-part-2/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 17:23:58 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[ethernet]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[rf-transmitter]]></category>
		<category><![CDATA[shield]]></category>
		<category><![CDATA[wireless]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=345</guid>
		<description><![CDATA[In this part we&#8217;ll connect to a webpage and fetch some data from a php script. When building a project it&#8217;s better to test and debug each part on its own instead of trying to debug a much larger system. So we&#8217;ll start by attaching an ethernet shield and get it to talk to a [...]]]></description>
			<content:encoded><![CDATA[<p>In this part we&#8217;ll connect to a webpage and fetch some data from a php script.</p>
<p>When building a project it&#8217;s better to test and debug each part on its own instead of trying to debug a much larger system. So we&#8217;ll start by attaching an ethernet shield and get it to talk to a webpage. Once that is up and running we&#8217;ll connect the second arduino and rf.</p>
<p><span style="color: #ffffff;">Note: For this part you&#8217;ll need a webhosting account with a company who provides access to PHP on it&#8217;s accounts. Or you&#8217;ll need to run a local webserver. Contact your webhost to verify if your account has PHP access enabled.</span></p>
<div id="attachment_350" class="wp-caption alignnone" style="width: 526px"><a href="http://www.codetorment.com/wp-content/uploads/DSCN9556.JPG"><img class="size-full wp-image-350   " title="DSCN9556" src="http://www.codetorment.com/wp-content/uploads/DSCN9556.JPG" alt="Arduino Ethernet Shield" width="516" height="425" /></a><p class="wp-caption-text">Arduino Ethernet Shield</p></div>
<p><span id="more-345"></span>First we&#8217;ll create a script named &#8216;time.php&#8217; which will print out the date and time when we visit www.yourdomain.com/time.php . Open the file and paste the following code:</p>
<pre class="brush: php;">
&lt;?php
// Prints something like: Sunday 25th of October 2009 07:12:46 PM
echo date('l jS \of F Y h:i:s A');
?&gt;
</pre>
<p>Now close, save and upload time.php to your domain. If you put the script in the www or public_html folder it will be accesible from www.yourdomain/time.php if you&#8217;ve placed it inside another folder make sure to use www.yourdomain.com/folder/time.php in the next part.</p>
<p>Before we continue, open a webbrowser and go to www.yourdomain/time.php or wherever you placed the script and make sure it shows the date and time.</p>
<p>When the script is working, start the arduino IDE , create a new sketch and copy paste the code below</p>
<pre class="brush: cpp;">
#include &lt;Ethernet.h&gt;

byte mac[] = {   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {   xxx, xxx, xxx, xxx};
byte server[] = { yyy, yyy, yyy, yyy};

Client client(server, 80);

void setup()
{
  pinMode(switchPin, INPUT);
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println(&quot;connecting...&quot;);

  if (client.connect()) {
    Serial.println(&quot;connected&quot;);
    client.print(&quot;GET http://www.yourdomain.com/folder/time.php HTTP/1.0\n&quot;);
    client.print(&quot;Host: www.yourdomain.com\n\n&quot;);
    client.println();
  }
  else {
    Serial.println(&quot;connection failed&quot;);
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println(&quot;disconnecting.&quot;);
    client.stop();
    for(;;)
      ;
  }
}
</pre>
<p>&nbsp;</p>
<pre class="brush: cpp;">byte ip[] = { xxx, xxx, xxx, xxx};
</pre>
<p>Make sure to change the xxx, xxx, xxx, xxx with your settings, where xxx, xxx, xxx, xxx should be an available ip in the range of your network. Check your router for the range of ip-adresses in your network.</p>
<p>in my case the above line would read :</p>
<pre class="brush: cpp;">
byte ip[] = { 192, 168, 1, 36};
</pre>
<p>Next is the ip address of the server you wish to connect to. If your webhost does not provide you with a unique ip dedicated to your domain you should try using google&#8217;s ip. To check if your domain is asigned a unique ip ( your domain is the only one hosted on that ip ) open a command prompt and ping your domain with &#8216;ping www.yourdomain.com&#8217;.  On the next line the ip adress associated with your domain should show up on windows in the form of &#8216;Ping statistics for domain xxx.xxx.xxx.xxx&#8217;. Now open a browser and type in xxx.xxx.xxx.xxx instead of www.yourdomain.com. If you are seeing your domain, you have a unique ip assigned to your domain. If not, ping www.google.com and use the ip adress returned for the yyy.yyy.yyy.yyy below.</p>
<pre class="brush: cpp;">
byte server[] = { yyy, yyy, yyy, yyy};
</pre>
<p><a href="http://www.codetorment.com/wp-content/uploads/cmd02.jpg"><img title="cmd02" src="http://www.codetorment.com/wp-content/uploads/cmd02.jpg" alt="cmd02 Arduino wireless motion detector : part 2" width="535" height="192" /></a></p>
<p>So the server ip becomes :</p>
<pre class="brush: cpp;">
byte server[] = { 74, 125, 67, 100};
</pre>
<p>These settings should get you up and running. The only thing left to do is change these lines to match your domain and the url of the time.php script :</p>
<pre class="brush: cpp;">
client.print(&quot;GET http://www.yourdomain.com/folder/time.php HTTP/1.0\n&quot;);
client.print(&quot;Host: www.yourdomain.com\n\n&quot;);
</pre>
<p>Now upload the code to the arduino and open the serial monitor.<br />
If all went well the monitor should show something similar:</p>
<div id="attachment_389" class="wp-caption alignnone" style="width: 409px"><a href="http://www.codetorment.com/wp-content/uploads/serial.JPG"><img class="size-full wp-image-389" title="serial" src="http://www.codetorment.com/wp-content/uploads/serial.JPG" alt="Serial Monitor" width="399" height="352" /></a><p class="wp-caption-text">Serial Monitor</p></div>
<p>As you can see second to last line displays the correct date and time.</p>
<p>Check <a title="Part 3" href="http://www.codetorment.com/2009/11/07/arduino-wireless-motion-detector-part-3/" target="_self">part 3</a> where I show you how to put it all together to create a weblogging wireless motion detector.</p>
<p><a title="Home" href="http://www.codetorment.com/" target="_self">Back to homepage</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Arduino wireless motion detector : part 1</title>
		<link>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector/</link>
		<comments>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 03:06:48 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[rf-transmitter]]></category>
		<category><![CDATA[shield]]></category>
		<category><![CDATA[wireless]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=316</guid>
		<description><![CDATA[This video shows a very basic setup of two arduinos talking wireless over RF. The two rf-boards used in this setup were discussed earlier in this post. The left arduino has a sensorshield with a PIR-sensor and a rf-transmitter connected to it. When the PIR-sensor detects changes in IR-radition in it&#8217;s field of view, it [...]]]></description>
			<content:encoded><![CDATA[<p>This video shows a very basic setup of two arduinos talking wireless over RF.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=7242154&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="300" src="http://vimeo.com/moogaloop.swf?clip_id=7242154&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>The two rf-boards used in this setup were discussed earlier in <a title="RF-transmitter-receiver" href="http://www.codetorment.com/2009/10/24/arduino-goodness-continued/" target="_blank">this</a> post.</p>
<p>The left arduino has a sensorshield with a PIR-sensor and a rf-transmitter connected to it. When the PIR-sensor detects changes in IR-radition in it&#8217;s field of view, it triggers the rf-transmitter and a red led.<span id="more-316"></span></p>
<p>The right arduino just has a rf-receiver and a green led connected to it. When the right arduino receives a radio signal the green led turns on.</p>
<p>Code for the transmitting arduino:</p>
<pre class="brush: cpp;">
int ledPin = 12;                 // pin
int pirPin = 4;                  // pin for PIR-sensor
int RFoutPin = 7;                // pin for RF transmitter
int value = 0;                   // used to store data from PIR-sensor

void setup() {
pinMode(RFoutPin, OUTPUT);       // declare RF-transmitter as output
  pinMode(ledPin, OUTPUT);       // declare led as output
pinMode(pirPin, INPUT);          // declare PIR-sensor as input
}

void loop() {
value = digitalRead(pirPin);     // read PIR-sensor
if (HIGH == value) {             // transmit HIGH signal
digitalWrite(RFoutPin, HIGH);
digitalWrite(ledPin, HIGH);
}
else {                           // transmit LOW signal
    digitalWrite(RFoutPin, LOW);
    digitalWrite(ledPin, LOW);
 }

}
</pre>
<p>Code for the receiving side:</p>
<pre class="brush: cpp;">
int ledPin = 11;                  // pin for the LED
int RFinPin = 7;                  // pin for the RF receiver
int val = 0;                      // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT);          // declare LED as output
pinMode(RFinPin, INPUT);          // declare RF receiver as input
}
void loop(){
 val = digitalRead(RFinPin);      // read input value
 if (val == HIGH) {               // check if the input is HIGH
    digitalWrite(ledPin, HIGH);   // turn LED ON
 } else {
  digitalWrite(ledPin, LOW);      // turn LED OFF
  }
}
</pre>
<p>Ok, maybe this example was a bit too easy.</p>
<p>Check <a title="Part 2" href="http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector-part-2/" target="_self">part 2</a> to learn how to connect arduino to a network and send/receive data to/from a webpage using the ethernet shield discussed <a href="http://www.codetorment.com/2009/10/24/arduino-goodness-ethernet-shield/">here</a>.</p>
<p><a title="Home" href="http://www.codetorment.com/" target="_self">Back to homepage</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/10/25/arduino-wireless-motion-detector/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Arduino Goodness : Continued</title>
		<link>http://www.codetorment.com/2009/10/24/arduino-goodness-continued/</link>
		<comments>http://www.codetorment.com/2009/10/24/arduino-goodness-continued/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 13:17:49 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[pir]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[rf-transmitter]]></category>
		<category><![CDATA[shield]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=270</guid>
		<description><![CDATA[In a recent shopping spre I bought some new arduino stuff to play with. This is the rest of the parts I received: The Arduino Sensor Shield is a handy extension for attaching sensors and servo&#8217;s using standard cables The shields provides you with: 6 analog connectors ( 5 on the left and one on [...]]]></description>
			<content:encoded><![CDATA[<p><strong>In a recent shopping spre I bought some new arduino stuff to play with.</strong></p>
<p>This is the rest of the parts I received:</p>
<div id="attachment_272" class="wp-caption alignnone" style="width: 469px"><a href="http://www.codetorment.com/wp-content/uploads/000_0273.JPG"><img class="size-large wp-image-272   " title="000_0273" src="http://www.codetorment.com/wp-content/uploads/000_0273-1024x770.jpg" alt="Arduino Sensor Shield" width="459" height="345" /></a><p class="wp-caption-text">Arduino Sensor Shield</p></div>
<p>The Arduino Sensor Shield is a handy extension for attaching sensors and servo&#8217;s using standard cables<span id="more-270"></span></p>
<p>The shields provides you with:</p>
<ul>
<li> 6 analog connectors ( 5 on the left and one on the bottom )</li>
<li>13 digital IO headers (4 x 4 3-pin headers )</li>
<li>6 analog IO headers ( 6 3-pin headers )</li>
<li>Communication port ( I2C or UART, connector on the right)</li>
</ul>
<div id="attachment_279" class="wp-caption alignnone" style="width: 469px"><a href="http://www.codetorment.com/wp-content/uploads/000_0278.JPG"><img class="size-large wp-image-279    " title="000_0278" src="http://www.codetorment.com/wp-content/uploads/000_0278-1024x762.jpg" alt="Sensor Shield with PIR-sensor" width="459" height="341" /></a><p class="wp-caption-text">Sensor Shield with PIR-sensor attached</p></div>
<p><!--more-->A PIR or Passive Infrared Sensor is a device that measures infrared light radiating from any objects in its field of view. These sensors are often used in backyard or driveway motion detectors.   Bassicaly they measure the amount of IR radiated by objects around it and detect sudden fluctuations  i.e. caused by a person walking into a sensors&#8217;  field of view.</p>
<p>I love the sensor shield for prototyping purposes, it will certainly lower the number of connections to your breadboard.</p>
<p>All these parts were bought on ebay, search for &#8216;arduino sensor shield&#8217; by clicking  <a title="Ebay Search 'Arduino+sensor+shield'" href="http://shop.ebay.com/?_from=R40&amp;_trksid=p3907.m38.l1313&amp;_nkw=arduino+sensor+shield&amp;_sacat=See-All-Categories" target="_blank">here</a></p>
<div id="attachment_297" class="wp-caption alignnone" style="width: 526px"><a href="http://www.codetorment.com/wp-content/uploads/000_0284.JPG"><img class="size-large wp-image-297   " title="000_0284" src="http://www.codetorment.com/wp-content/uploads/000_0284-1024x709.jpg" alt="RF receiver-transmitter pair" width="516" height="357" /></a><p class="wp-caption-text">RF receiver-transmitter pair</p></div>
<p>A RadioFrequency receiver-transmitter pair with 4-channels, 1 connector for each channel. The one on the left is the receiver, it also came with an antenna, like the one you see on the right, but it wasn&#8217;t soldered on.</p>
<p>The green transmitter and receiverboards have male headers and plug into the female headers mounted on the red extender boards. I have played around with them and can say that they work. I still need to check the maximum range these things will go. These were tested to be working at 4 meters appart with a wooden door and a drywall in between.</p>
<p>In a next post I&#8217;ll demonstrate an arduino motion-sensor-over-rf  to a webserver running php</p>
<p>pir-sensor  &gt;&gt;  arduino &gt;&gt;  rf-transmitter   . . .  _ _ _ . . .     rf-receiver  &gt;&gt;  arduino &gt;&gt;  ethernetshield &gt;&gt;  php</p>
<p><a title="Home" href="http://www.codetorment.com/" target="_self">Back to homepage</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/10/24/arduino-goodness-continued/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino Goodness : Ethernet Shield</title>
		<link>http://www.codetorment.com/2009/10/24/arduino-goodness-ethernet-shield/</link>
		<comments>http://www.codetorment.com/2009/10/24/arduino-goodness-ethernet-shield/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 10:11:02 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[ethernet]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[shield]]></category>

		<guid isPermaLink="false">http://www.codetorment.com/?p=114</guid>
		<description><![CDATA[In a recent shopping spre I bought some new arduino stuff to play with. This is the first of a few items I recentely bought from ebay: An arduino EthernetShield based on the WIZ5100 ethernet controller. Ever since I started thinkering with Arduino I wanted a way to connect it to a network.  So befor [...]]]></description>
			<content:encoded><![CDATA[<p><strong>In a recent shopping spre I bought some new arduino stuff to play with.</strong></p>
<p>This is the first of a few items I recentely bought from ebay: An arduino EthernetShield based on the WIZ5100 ethernet controller.</p>
<div id="attachment_117" class="wp-caption alignnone" style="width: 469px"><a href="http://www.codetorment.com/wp-content/uploads/000_0250.JPG"><img class="size-full wp-image-117   " title="Arduino Ethernet Shield" src="http://www.codetorment.com/wp-content/uploads/000_0250.JPG" alt=" Arduino Goodness : Ethernet Shield" width="459" height="394" /></a><p class="wp-caption-text">Arduino Ethernet Shield based on the WIZ5100 ethernet controller</p></div>
<address> </address>
<p>Ever since I started thinkering with Arduino I wanted a way to connect it to a network.  So befor I got this shield I started messing around <span id="more-114"></span>with a fonera router by connecting the rx-tx lines of the arduino to the tx-rx connections of a fonera 2100 router.  However  to be able to acces the fonera via serial you need to reflash it with a third-party image (open-wrt, dd-wrt,&#8230;) . The image needs to include the tty or stty command, which enables you to set the serial communication speed of the router to a baudspeed the arduino can handle.</p>
<div id="attachment_187" class="wp-caption alignnone" style="width: 522px"><a href="http://www.codetorment.com/wp-content/uploads/000_0129.JPG"><img class="size-full wp-image-187 " title="Arduino to Fonera Serial " src="http://www.codetorment.com/wp-content/uploads/000_0129.JPG" alt=" Arduino Goodness : Ethernet Shield" width="512" height="343" /></a><p class="wp-caption-text">Arduino to Fonera Serial Communication and Duvel beer</p></div>
<p>I&#8217;ll post a guide later containing information on how to connect to a fonera router and control it wireless. The major downside of this way of connecting to a network is the usage of the RX-TX lines on the arduino board. Making it harder to debug and thus making it harder to whip something up real quick.</p>
<p>To be completely honnest, she wasn&#8217;t my first&#8230; .  Some time ago in a moment of weakness I was in the believe I had struck upon a genuine bargain : a (very) cheap arduino ethernet shield. As I was later to realize, the price was about right. The problem with this shield is that is uses the Microchip&#8217;s ENC28J60 SPI based ethernet controller.</p>
<div id="attachment_193" class="wp-caption alignnone" style="width: 501px"><a href="http://www.codetorment.com/wp-content/uploads/000_0235.JPG"><img class="size-full wp-image-193  " title="Arduino Ethernet Shield V1.1" src="http://www.codetorment.com/wp-content/uploads/000_0235.JPG" alt="&quot;Arduino Ethernet Shield V1.1&quot; using ENC28J60 SPI controller." width="491" height="491" /></a><p class="wp-caption-text">&quot;Arduino Ethernet Shield V1.1&quot; using ENC28J60 SPI controller.</p></div>
<p>I don&#8217;t mean to bash the ENC28J60 based shield, but it shouldn&#8217;t be branded  &#8220;Arduino Ethernet Shield v1.1&#8243; as it uses a different chip and design as stated in the <a title="Arduino Ethernet Shield " href="http://www.arduino.cc/en/Main/ArduinoEthernetShield" target="_blank">reference design</a> on the arduino website.  Because of the different chip the library you need to include differs from the arduino ethernet library. Since the library is different the code you need to write is different and in this case it could use some more abastraction.</p>
<p><span style="color: #FFFFFF;">Note : I did not buy my shield from nuelectronics but from a seller on ebay. Both shields however use the ENC28j60 chip and both are branded Arduino Ethernet Shield V1.x so my guess is in one way or the other they originated from the same place/drawingboard.</span></p>
<p>To better explain what I&#8217;m talkin about I&#8217;ll show two example programs. The first example is for the ENC28j60 based shield, the second example is for the WIZ5100 based shield using the official ethernet library.</p>
<p>The first code example is included in the <a title="nuelectronics ethernetShield library" href="http://www.nuelectronics.com/download/projects/etherShield.zip" target="_blank">etherShield library</a> provided by  <a title="nuelectronics" href="http://www.nuelectronics.com/" target="_blank">nuelectronics</a></p>
<pre class="brush: cpp;">
#include &quot;etherShield.h&quot;

// please modify the following lines. mac and ip have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
static uint8_t myip[4] = {192,168,1,88};
static uint16_t my_port = 1200;     // client port

// client_ip - modify it when you have multiple client on the network
// for server to distinguish each ethershield client
static char client_ip[] = &quot;192.168.1.88&quot;;

// server settings - modify the service ip to your own server
static uint8_t dest_ip[4]={192,168,1,4};
static uint8_t dest_mac[6];

enum CLIENT_STATE
{
   IDLE, ARP_SENT, ARP_REPLY, SYNC_SENT
 };

static CLIENT_STATE client_state;

static uint8_t client_data_ready;

static uint8_t syn_ack_timeout = 0;

#define BUFFER_SIZE 500
static uint8_t buf[BUFFER_SIZE+1];

char sensorData[10];

EtherShield es=EtherShield();

// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf);
int8_t analyse_cmd(char *str);
// get current temperature
#define TEMP_PIN  3
void getCurrentTemp( char *temperature);
void client_process(void);

void setup(){

   /*initialize enc28j60*/
	 es.ES_enc28j60Init(mymac);
   es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
   delay(10);

	/* Magjack leds configuration, see enc28j60 datasheet, page 11 */
	// LEDA=greed LEDB=yellow
	//
	// 0x880 is PHLCON LEDB=on, LEDA=on
	// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
	es.ES_enc28j60PhyWrite(PHLCON,0x880);
	delay(500);
	//
	// 0x990 is PHLCON LEDB=off, LEDA=off
	// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
	es.ES_enc28j60PhyWrite(PHLCON,0x990);
	delay(500);
	//
	// 0x880 is PHLCON LEDB=on, LEDA=on
	// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
	es.ES_enc28j60PhyWrite(PHLCON,0x880);
	delay(500);
	//
	// 0x990 is PHLCON LEDB=off, LEDA=off
	// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
	es.ES_enc28j60PhyWrite(PHLCON,0x990);
	delay(500);
	//
  // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
  // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
  es.ES_enc28j60PhyWrite(PHLCON,0x476);
	delay(100);

  //init the ethernet/ip layer:
  es.ES_init_ip_arp_udp_tcp(mymac,myip,80);

  // intialize varible;
  syn_ack_timeout =0;
  client_data_ready = 0;
  client_state = IDLE;
  // initialize DS18B20 datapin
    digitalWrite(TEMP_PIN, LOW);
    pinMode(TEMP_PIN, INPUT);      // sets the digital pin as input (logic 1)

}

void loop(){

        if(client_data_ready==0){
          delay(60000UL);             // delay 60s
          getCurrentTemp(sensorData);
          client_data_ready = 1;
         }
	client_process();

}

uint16_t gen_client_request(uint8_t *buf )
{
	uint16_t plen;
	byte i;

	plen= es.ES_fill_tcp_data_p(buf,0, PSTR ( &quot;GET /ethershield_log/save.php?pwd=secret&amp;client=&quot; ) );
        for(i=0; client_ip[i]!='&#92;&#48;'; i++){
            buf[TCP_DATA_P+plen]=client_ip[i];
            plen++;
        }
        plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( &quot;&amp;status=temperature-&quot; ) );
        for(i=0; sensorData[i]!='&#92;&#48;'; i++){

                buf[TCP_DATA_P+plen]=sensorData[i];
                plen++;
        }	

	plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( &quot; HTTP/1.0\r\n&quot; ));
	plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( &quot;Host: 192.168.1.4\r\n&quot; ));
	plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( &quot;User-Agent: AVR ethernet\r\n&quot; ));
        plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( &quot;Accept: text/html\r\n&quot; ));
	plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( &quot;Keep-Alive: 300\r\n&quot; ));
	plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( &quot;Connection: keep-alive\r\n\r\n&quot; ));

	return plen;
}

//*****************************************************************************************
//
// Function : client_process
// Description : send temparature to web server, this option is disabled by default.
// YOU MUST install webserver and server script before enable this option,
// I recommented Apache webserver and PHP script.
// More detail about Apache and PHP installation please visit http://www.avrportal.com/
//
//*****************************************************************************************
void client_process ( void )
{
    uint16_t plen;
	uint8_t i;

    if (client_data_ready == 0)  return;     // nothing to send

	if(client_state == IDLE){   // initialize ARP
       es.ES_make_arp_request(buf, dest_ip);

	   client_state = ARP_SENT;
	   return;
	}

	if(client_state == ARP_SENT){

        plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

		// destination ip address was found on network
        if ( plen!=0 )
        {
            if ( es.ES_arp_packet_is_myreply_arp ( buf ) ){
                client_state = ARP_REPLY;
				syn_ack_timeout=0;
				return;
            }

		}
	        delay(10);
		syn_ack_timeout++;

		if(syn_ack_timeout== 100) {  //timeout, server ip not found
			client_state = IDLE;
			client_data_ready =0;
			syn_ack_timeout=0;
			return;
		}
    }

 // send SYN packet to initial connection
	if(client_state == ARP_REPLY){
		// save dest mac
		for(i=0; i&lt;6; i++){
			dest_mac[i] = buf[ETH_SRC_MAC+i];
		}

        es.ES_tcp_client_send_packet (
                       buf,
                       80,
                       1200,
                       TCP_FLAG_SYN_V,                 // flag
                       1,                                              // (bool)maximum segment size
                       1,                                              // (bool)clear sequence ack number
                       0,                                              // 0=use old seq, seqack : 1=new seq,seqack no data : new seq,seqack with data
                       0,                                              // tcp data length
		      dest_mac,
		      dest_ip
                       );

		client_state = SYNC_SENT;
	}
  // get new packet
  if(client_state == SYNC_SENT){
    plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

       // no new packet incoming
    if ( plen == 0 )
    {
        return;
    }

       // check ip packet send to avr or not?
       // accept ip packet only
    if ( es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){
		return;
    }

       // check SYNACK flag, after AVR send SYN server response by send SYNACK to AVR
    if ( buf [ TCP_FLAGS_P ] == ( TCP_FLAG_SYN_V | TCP_FLAG_ACK_V ) )
    {

               // send ACK to answer SYNACK

               es.ES_tcp_client_send_packet (
                       buf,
                       80,
                       1200,
                       TCP_FLAG_ACK_V,                 // flag
                       0,                                              // (bool)maximum segment size
                       0,                                              // (bool)clear sequence ack number
                       1,                                              // 0=use old seq, seqack : 1=new seq,seqack no data : new seq,seqack with data
                       0,                                              // tcp data length
						dest_mac,
						dest_ip
                       );
               // setup http request to server
               plen = gen_client_request( buf );
               // send http request packet
               // send packet with PSHACK
               es.ES_tcp_client_send_packet (
                                       buf,
                                       80,                                             // destination port
                                       1200,                                   // source port
                                       TCP_FLAG_ACK_V | TCP_FLAG_PUSH_V,                        // flag
                                       0,                                              // (bool)maximum segment size
                                       0,                                              // (bool)clear sequence ack number
                                       0,                                              // 0=use old seq, seqack : 1=new seq,seqack no data : &gt;1 new seq,seqack with data
                                       plen,                           // tcp data length
                                       dest_mac,
									   dest_ip
									   );
               return;
       }
       // after AVR send http request to server, server response by send data with PSHACK to AVR
       // AVR answer by send ACK and FINACK to server
       if ( buf [ TCP_FLAGS_P ] == (TCP_FLAG_ACK_V|TCP_FLAG_PUSH_V) )
       {
               plen = es.ES_tcp_get_dlength( (uint8_t*)&amp;buf );

               // send ACK to answer PSHACK from server
               es.ES_tcp_client_send_packet (
                                       buf,
                                       80,                                             // destination port
                                       1200,                                   // source port
                                       TCP_FLAG_ACK_V,                  // flag
                                       0,                                              // (bool)maximum segment size
                                       0,                                              // (bool)clear sequence ack number
                                       plen,                                           // 0=use old seq, seqack : 1=new seq,seqack no data : &gt;1 new seq,seqack with data
                                       0,                              // tcp data length
				      dest_mac,
				      dest_ip
               );;
               // send finack to disconnect from web server

               es.ES_tcp_client_send_packet (
                                       buf,
                                       80,                                             // destination port
                                       1200,                                   // source port
                                       TCP_FLAG_FIN_V|TCP_FLAG_ACK_V,                  // flag
                                       0,                                              // (bool)maximum segment size
                                       0,                                              // (bool)clear sequence ack number
                                       0,                                           // 0=use old seq, seqack : 1=new seq,seqack no data : &gt;1 new seq,seqack with data
                                       0,
										dest_mac,
										dest_ip
				);

               return;

       }
       // answer FINACK from web server by send ACK to web server
       if ( buf [ TCP_FLAGS_P ] == (TCP_FLAG_ACK_V|TCP_FLAG_FIN_V) )
       {
               // send ACK with seqack = 1
               es.ES_tcp_client_send_packet(

                                       buf,
                                       80,                                             // destination port
                                       1200,                                   // source port
                                       TCP_FLAG_ACK_V,                 // flag
                                       0,                                              // (bool)maximum segment size
                                       0,                                              // (bool)clear sequence ack number
                                       1,                                              // 0=use old seq, seqack : 1=new seq,seqack no data : &gt;1 new seq,seqack with data
                                       0,
									   dest_mac,
									   dest_ip
				);
			client_state = IDLE;		// return to IDLE state
			client_data_ready =0;		// client data sent
		}
  }
}

void OneWireReset(int Pin) // reset.  Should improve to act as a presence pulse
{
     digitalWrite(Pin, LOW);
     pinMode(Pin, OUTPUT); // bring low for 500 us
     delayMicroseconds(500);
     pinMode(Pin, INPUT);
     delayMicroseconds(500);
}

void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first).
{
   byte n;

   for(n=8; n!=0; n--)
   {
      if ((d &amp; 0x01) == 1)  // test least sig bit
      {
         digitalWrite(Pin, LOW);
         pinMode(Pin, OUTPUT);
         delayMicroseconds(5);
         pinMode(Pin, INPUT);
         delayMicroseconds(60);
      }
      else
      {
         digitalWrite(Pin, LOW);
         pinMode(Pin, OUTPUT);
         delayMicroseconds(60);
         pinMode(Pin, INPUT);
      }

      d=d&gt;&gt;1; // now the next bit is in the least sig bit position.
   }

}

byte OneWireInByte(int Pin) // read byte, least sig byte first
{
    byte d, n, b;

    for (n=0; n&lt;8; n++)
    {
        digitalWrite(Pin, LOW);
        pinMode(Pin, OUTPUT);
        delayMicroseconds(5);
        pinMode(Pin, INPUT);
        delayMicroseconds(5);
        b = digitalRead(Pin);
        delayMicroseconds(50);
        d = (d &gt;&gt; 1) | (b&lt;&lt;7); // shift d to right and insert b in most sig bit position
    }
    return(d);
}

void getCurrentTemp(char *temp)
{
  int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;

  OneWireReset(TEMP_PIN);
  OneWireOutByte(TEMP_PIN, 0xcc);
  OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec

  OneWireReset(TEMP_PIN);
  OneWireOutByte(TEMP_PIN, 0xcc);
  OneWireOutByte(TEMP_PIN, 0xbe);

  LowByte = OneWireInByte(TEMP_PIN);
  HighByte = OneWireInByte(TEMP_PIN);
  TReading = (HighByte &lt;&lt; 8) + LowByte;
  sign = TReading &amp; 0x8000;  // test most sig bit
  if (sign) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25

  whole = Tc_100 / 100;  // separate off the whole and fractional portions
  fract = Tc_100 % 100;

	if(sign) temp[0]='-';
	else 		 temp[0]='+';

	temp[1]= (whole-(whole/100)*100)/10 +'0' ;
	temp[2]= whole-(whole/10)*10 +'0';

	temp[3]='.';
	temp[4]=fract/10 +'0';
	temp[5]=fract-(fract/10)*10 +'0';

	temp[6] = '&#92;&#48;';
}
</pre>
<p>&nbsp;<br />
As you can see this example involves alot of lowlevel configuration specific lines which could be hidden away in the library for clarity&#8217;s sake.</p>
<p>The second code example is one from the standard <a title="standard ethernet library" href="http://arduino.cc/en/Reference/Ethernet" target="_blank">ethernet library</a> included with any recent installation of the arduino environment. This is code that runs straight on a WIZ5100 powered ethernet shield.<br />
&nbsp;</p>
<pre class="brush: cpp;">
/*
 * Web Server
 *
 * A simple web server that shows the value of the analog input pins.
 */

#include &lt;Ethernet.h&gt;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };

Server server(80);

void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop()
{
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (c == '\n' &amp;&amp; current_line_is_blank) {
          // send a standard http response header
          client.println(&quot;HTTP/1.1 200 OK&quot;);
          client.println(&quot;Content-Type: text/html&quot;);
          client.println();

          // output the value of each analog input pin
          for (int i = 0; i &lt; 6; i++) {
            client.print(&quot;analog input &quot;);
            client.print(i);
            client.print(&quot; is &quot;);
            client.print(analogRead(i));
            client.println(&quot;&lt;br /&gt;&quot;);
          }
          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        } else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}
</pre>
<p>&nbsp;<br />
Needless to say the latter is easier for the eye ( of mind ). Right now I use the WIZ5100 based shield for quick prototyping of new ideas and the ENC28j60 shield is used for more permanent setups, as the code isn&#8217;t stuff I want to rewrite on a daily basis.</p>
<p><a title="Arduino Goodness : Continued" href="http://www.codetorment.com/2009/10/24/arduino-goodness-continued/" target="_self">Next</a> up will be some more things I picked up :</p>
<ul>
<li>an rf-transmitter-receiver pair</li>
</ul>
<ul>
<li>a PIR-sensor</li>
</ul>
<ul>
<li>an Arduino sensor-shield</li>
</ul>
<p><a title="Home" href="http://www.codetorment.com/" target="_self">Back to homepage</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.codetorment.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.codetorment.com/2009/10/24/arduino-goodness-ethernet-shield/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
