<?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>Gotbadger &#187; Programing</title>
	<atom:link href="http://www.gotbadger.org.uk/category/programing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gotbadger.org.uk</link>
	<description>The adventures of Philip Hayton</description>
	<lastBuildDate>Sat, 31 Jul 2010 14:22:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Arduino controlled EPSON TM-T88P Printer Part1</title>
		<link>http://www.gotbadger.org.uk/2010/06/20/arduino-controlled-epson-tm-t88p-printer-part1/</link>
		<comments>http://www.gotbadger.org.uk/2010/06/20/arduino-controlled-epson-tm-t88p-printer-part1/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 16:27:10 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programing]]></category>

		<guid isPermaLink="false">http://www.gotbadger.org.uk/?p=160</guid>
		<description><![CDATA[The EPSON TM-T88P is a parallel controled printer. It came to be in my possession after going along to a kind of computer jumble sale 5quid got me this: Centronics Handsake It turns out there are a number of ways to communicate with printers and the Epson supports a number of these methods. I decided [...]]]></description>
			<content:encoded><![CDATA[<p>The EPSON TM-T88P is a parallel controled printer. It came to be in my possession after going along to a kind of computer jumble sale 5quid got me this:</p>
<div class="wp-caption aligncenter" style="width: 160px"><a href="http://twitpic.com/19sj14"><img title="Epson printer at #bcne3" src="http://twitpic.com/show/thumb/19sj14.jpg" alt="" width="150" height="150" /></a><p class="wp-caption-text">Epson printer at #bcne3</p></div>
<h2>Centronics Handsake</h2>
<p>It turns out there are a number of ways to communicate with printers and the Epson supports a number of these methods. I decided to go with the Centronics standard AKA Compatibility Mode since its about as basic as you can get. Heres a diagram from the excellent <a href="http://www.beyondlogic.org">http://www.beyondlogic.org</a></p>
<div id="attachment_167" class="wp-caption aligncenter" style="width: 387px"><a href="http://www.beyondlogic.org/spp/parallel.htm#3"><img class="size-full wp-image-167" title="Centronics Handshake" src="http://www.gotbadger.org.uk/wp-content/uploads/2010/06/parallelport_img_0.jpg" alt="" width="377" height="253" /></a><p class="wp-caption-text">Centronics Handshake Diagram from beyondlogic.org</p></div>
<p>Think of the handshake as; you wait for the printer to be free (busy low) enter the number you want to send (set the 8 bits of your byte on the data lines) then pull the send lever old cash register style  (strobe low wait stobe high). Its not a partuclay dificult concept but I found the diagram hard to understand becuase for some reason I thought it had to be more complicated than it actualy was.</p>
<h2>Wiring Up</h2>
<p>Nothing too complex here the table below show the Socket to Arduino linkup:</p>
<table>
<tbody>
<tr>
<th colspan="2">Socket</th>
<th colspan="2">Arduino</th>
</tr>
<tr>
<th>Pin</th>
<th>Name</th>
<th>Pin</th>
<th>pinMode</th>
</tr>
<tr>
<td>1</td>
<td>Strobe</td>
<td>13</td>
<td>OUTPUT</td>
</tr>
<tr>
<td>2</td>
<td>D0</td>
<td>2</td>
<td>OUTPUT</td>
</tr>
<tr>
<td>3</td>
<td>D1</td>
<td>3</td>
<td>OUTPUT</td>
</tr>
<tr>
<td>4</td>
<td>D2</td>
<td>4</td>
<td>OUTPUT</td>
</tr>
<tr>
<td>5</td>
<td>D3</td>
<td>5</td>
<td>OUTPUT</td>
</tr>
<tr>
<td>6</td>
<td>D4</td>
<td>6</td>
<td>OUTPUT</td>
</tr>
<tr>
<td>7</td>
<td>D5</td>
<td>7</td>
<td>OUTPUT</td>
</tr>
<tr>
<td>8</td>
<td>D6</td>
<td>8</td>
<td>OUTPUT</td>
</tr>
<tr>
<td>9</td>
<td>D7</td>
<td>9</td>
<td>OUTPUT</td>
</tr>
<tr>
<td>10</td>
<td>ACK</td>
<td>10</td>
<td>INPUT</td>
</tr>
<tr>
<td>11</td>
<td>BUSY</td>
<td>11</td>
<td>INPUT</td>
</tr>
<tr>
<td>25</td>
<td>GND</td>
<td>GND</td>
<td>n/a</td>
</tr>
</tbody>
</table>
<p>You only need to wire up one of the ground lines since they will all be connected to ground in the printer anyway (lazy method) <img src='http://www.gotbadger.org.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Programming</h2>
<p>Its worth pointing out at this stage that you might want to make up some kind of parallel port debuger so you can get an idea of whats actualy happening at a low level and that your program is producing the expected output.</p>
<p>First lets setup the pins as in the table above we will also setup a serial connection so we can do debugging.</p>
<pre class="brush: c;">int strobe = 12;
int busy = 11;
int ack = 10;

void setup()   {
  pinMode(strobe, OUTPUT);
  //setup stobe high
  digitalWrite(strobe, HIGH);
  //setup handshake listeners
  pinMode(busy, INPUT);
  pinMode(ack, INPUT);
  for(int i=2;i&lt;10;i++){
     pinMode(i, OUTPUT);
     //setup inital condition
     digitalWrite(i, LOW);
  }
  Serial.begin(115200);
  Serial.println("READY:");
}
</pre>
<p>To start with we can actual simplify the handsake further by ignoring the ACK since BUSY should always go low when we are OK to send more data. With this in mind we end up with 3 main steps:</p>
<ol>
<li>Wait for not busy</li>
<li>Set Data</li>
<li>Strobe</li>
</ol>
<p>For the wait not busy function i decided to go with a simple poll, every 100 iterations it prints a &#8216;.&#8217; so we can see in the terminal if its got stuck.</p>
<pre class="brush: c;">void pollWait(int port){
  int i = 0;
  while(digitalRead(port) == 1){
    i++;
    if(i&gt;100){
      i=0;
     Serial.print(".");
    }
  }
}
</pre>
<p>Strobe function is nice and simple. Suposidly you can have any value greater than 0.5 microseconds for the strobe and it will work. To keep it simple i just went with 1ms.</p>
<pre class="brush: c;">void doStrobe(){
    digitalWrite(strobe, LOW);
    delay(1);
    digitalWrite(strobe, HIGH);
}
</pre>
<p>Setting the datalines we use i+2 as the first bit is written to pin 2 etc.</p>
<pre class="brush: c;">void setLines(byte out){
  //loop over data lines
  for(int i=0;i&lt;8;i++){
    //check and set
   if(bitRead(out, i) == 1){
     //write to pint we start at 2 so +2
     digitalWrite(i+2, HIGH);
   }else{
     //bit is 0 so set low
     digitalWrite(i+2, LOW);
   }

  }
}</pre>
<p>Now we use all these functions to send a byte to the printer</p>
<pre class="brush: c;">void dataHandShake(byte a){
    pollWait(busy);
    setLines(a);
    doStrobe();
}
</pre>
<p>Finaly we can make a small program to print somthing. Its worth making sure things only happen once&#8230; you dont want your printer spewing paper while you try and turn it off!</p>
<p>Add the following global:</p>
<pre class="brush: c;">    boolean go = true;
</pre>
<p>Then quick and dirty hello world:</p>
<pre class="brush: c;">void loop()
{
 //so we dont end up with a constant stream
 if(go){
     dataHandShake('H');
     dataHandShake('e');
     dataHandShake('l');
     dataHandShake('l');
     dataHandShake('o');
     dataHandShake(' ');
     dataHandShake('W');
     dataHandShake('o');
     dataHandShake('r');
     dataHandShake('l');
     dataHandShake('d');
     //send Line feed so it prints the line
     dataHandShake(0x0A);
     go = false;
     Serial.println("DONE");
   }
}
</pre>
<p>We now end up with somthing that looks like this:<br />
<div id="attachment_197" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.gotbadger.org.uk/wp-content/uploads/2010/06/2010-06-20-16.53.29.jpg"><img src="http://www.gotbadger.org.uk/wp-content/uploads/2010/06/2010-06-20-16.53.29-300x225.jpg" alt="" title="Physical Output" width="300" height="225" class="size-medium wp-image-197" /></a><p class="wp-caption-text">Hello World!</p></div></p>
<p>Thats all for now in a future post (hopefully!) I will be looking at more advanced printing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gotbadger.org.uk/2010/06/20/arduino-controlled-epson-tm-t88p-printer-part1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flicked; Flicker Plugin For Media Portal</title>
		<link>http://www.gotbadger.org.uk/2009/02/11/flicked-flicker-plugin-for-media-portal/</link>
		<comments>http://www.gotbadger.org.uk/2009/02/11/flicked-flicker-plugin-for-media-portal/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 13:17:14 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Media Portal]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programing]]></category>

		<guid isPermaLink="false">http://gotbadger.co.uk/?p=48</guid>
		<description><![CDATA[Meant to post infos about this a few weeks ago.  Its a plugin for media portal that lets you view all your photos, groups and contacts just as you would on your flicker homepage. This plugin also uses the flickr api so any photos you have marked private etc will be viewable though this plugin. [...]]]></description>
			<content:encoded><![CDATA[<p>Meant to post infos about this a few weeks ago.  Its a plugin for media portal that lets you view all your photos, groups and contacts just as you would on your flicker homepage. This plugin also uses the flickr api so any photos you have marked private etc will be viewable though this plugin.</p>
<p>The plugin reached its first milestone and has been released here;<a href="http://forum.team-mediaportal.com/plugins-47/flicked-flickr-plugin-mediaportal-53103/"> http://forum.team-mediaportal.com/plugins-47/flicked-flickr-plugin-mediaportal-53103/</a></p>
<p>Currently im awaiting the release of media portal 1.0.1 before moving on with development due to the plugin/skin revamp.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gotbadger.org.uk/2009/02/11/flicked-flicker-plugin-for-media-portal/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TF2 servers and WordPress</title>
		<link>http://www.gotbadger.org.uk/2007/11/11/tf2-servers-and-wordpress/</link>
		<comments>http://www.gotbadger.org.uk/2007/11/11/tf2-servers-and-wordpress/#comments</comments>
		<pubDate>Sun, 11 Nov 2007 18:02:42 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Programing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[TF2]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://gotbadger.co.uk/2007/11/11/tf2-servers-and-wordpress/</guid>
		<description><![CDATA[Ive been playing a lot of Team Fortress 2 with the 9m guys recently and we have decided to enter into some competitive play. All this means we needed a website so in true quick and dirty fashion I knocked up a WP site and modified an existing theme. Now one thing I thought that [...]]]></description>
			<content:encoded><![CDATA[<p>Ive been playing a lot of Team Fortress 2 with the <a href="http://9men.org.uk">9m guys</a> recently and we have decided to enter into some competitive play. All this means we needed a website so in true quick and dirty fashion I knocked up a WP site and modified an existing theme.</p>
<p>Now one thing I thought that would be pretty cool would be a server monitor plug-in, there was nothing currently out there so using my non existent knowledge of widgets I tried my luck&#8230; and failed terribly I just couldn&#8217;t get the server to query correctly at all. I guessed someone must have done something similar to this in PHP the answer was <a href="http://gameq.sourceforge.net/" title="game q a handy libary for querying game server">GameQ</a>. Its a nice little library that wraps everything up nicely and gives us back a lot of really easy arrays using this and my basic understanding of plugins I managed to knock up the server monitor you see on the <a href="http://9men.org.uk">9m website</a></p>
<p>I have plans at some point to improve and hopefully release the widget under GPL when I have a better understanding of how to deal with the configuration side of things, until then its all hard coded configuration. If anyone&#8217;s interested at all in the source code drop me a line.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gotbadger.org.uk/2007/11/11/tf2-servers-and-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adventures With Analytics</title>
		<link>http://www.gotbadger.org.uk/2007/10/07/adventures-with-analytics/</link>
		<comments>http://www.gotbadger.org.uk/2007/10/07/adventures-with-analytics/#comments</comments>
		<pubDate>Sun, 07 Oct 2007 09:52:26 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Programing]]></category>
		<category><![CDATA[Site]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[stats]]></category>

		<guid isPermaLink="false">http://gotbadger.co.uk/2007/10/07/adventures-with-analytics/</guid>
		<description><![CDATA[Now if your the kind of person I am you will love stats. I don&#8217;t even think its a geek thing, some people just don&#8217;t seem to be able to resist the lure of the how many and when, from programing to football to government reports you cant escape them so why should my site [...]]]></description>
			<content:encoded><![CDATA[<p>Now if your the kind of person I am you will love stats. I don&#8217;t even think its a geek thing, some people just don&#8217;t seem to be able to resist the lure of the how many and when, from programing to football to government reports you cant escape them so why should my site be any different?</p>
<p>Pretty much everyone has heard of <a href="http://www.google.co.uk/analytics/">google analytics</a> by now but I wounder how many people <em>really</em> know what it can do and have seen it in action and how many people actually use it to its full potential? Untill a couple of days ago I knew neither what it could do or used it to its full potential now I&#8217;m doing both and the ammount of detailed statistics it can show is amazing maybe a little scary. Most people will just use the bit of code it gives you when you first get an analytics account this will give you some info but not everything to get the full benifit you need to do stuff with onclicks to monitor outbound links downloads etc. Now thats a lot of work you may think (unles you do some horibly slow client side dom traversal)  well it is if you&#8217;ve already got an existing site but then I got thinking &#8211; &#8220;wordpress? somone must have done it&#8221; and they had.</p>
<p>Enter <a href="http://www.joostdevalk.nl/" title="SEO loving guy from the Netherlands">Joost de Valk</a> a SEO loving guy from the Netherlands. I had a look at a few plugins but his <a href="http://www.joostdevalk.nl/wordpress/google-analytics/" title="wordpress google analytics">was the best</a> you can get an awfull lot of data on outgoing links and downloads using this and it has the ablity to do some other stuff aswell he was also kind enough to give some help and decent default settings to get you going straight away.</p>
<p>All this got me thinking about the data that could possibly be collected on a e-commerce site and which no doubt is collected by the major players and the value that data must have to them. Now with using analytics I can see the potential it has in the smaller market and how a smaller nieche store might really benifit from it and the potential extra value it might add to any such site&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gotbadger.org.uk/2007/10/07/adventures-with-analytics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Free Ruby on Rails Ebook</title>
		<link>http://www.gotbadger.org.uk/2007/10/02/free-ruby-on-rails-ebook/</link>
		<comments>http://www.gotbadger.org.uk/2007/10/02/free-ruby-on-rails-ebook/#comments</comments>
		<pubDate>Tue, 02 Oct 2007 08:40:41 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Programing]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://gotbadger.co.uk/?p=5</guid>
		<description><![CDATA[The people at sitepoint are giving away one of their books, check it out at http://rails.sitepoint.com its free for the next 60 days so get it while you can&#8230;]]></description>
			<content:encoded><![CDATA[<p>The people at sitepoint are giving away one of their books, check it out at <a href="http://rails.sitepoint.com/" target="_blank">http://rails.sitepoint.com</a> its free for the next 60 days so get it while you can&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gotbadger.org.uk/2007/10/02/free-ruby-on-rails-ebook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Change Of Heart</title>
		<link>http://www.gotbadger.org.uk/2007/10/01/a-change-of-heart/</link>
		<comments>http://www.gotbadger.org.uk/2007/10/01/a-change-of-heart/#comments</comments>
		<pubDate>Mon, 01 Oct 2007 18:45:11 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Programing]]></category>
		<category><![CDATA[Site]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://gotbadger.co.uk/?p=4</guid>
		<description><![CDATA[It was in some respects a long time coming like a lot of people out there I have made the move to word-press and for once actually managed to create a semi-decent (I think) looking theme. I liked Mephisto but I couldn&#8217;t do &#8216;things&#8217; with it. It kind of leads me into what I have [...]]]></description>
			<content:encoded><![CDATA[<p>It was in some respects a long time coming like a lot of people out there I have made the move to word-press and for once actually managed to create a semi-decent (I think) looking theme. I liked Mephisto but I couldn&#8217;t do &#8216;things&#8217; with it. It kind of leads me into what I have been having quite some thought about latley and that is PHP.</p>
<p>I ve had somewhat of a resurgence in my love for PHP, Ive been toying with RoR and done some C# stuff recently at work and I came to miss the pure dirtiness of PHP. The reason I originally had started to hate PHP can probably be pinned on two things; doing maintenance on existing projects and as a result writing increasingly hacky and horrible code. The change of heart came from realising finally that I could write beautiful OO PHP5 that was incredibly rewarding to write if I wanted to. The epiphany was mostly down to the fact that programing in a language like C# made me give up a lot of my bad programing habits. Its quite easy to write bad C# apps but it quickly becomes quite self evident how horrendous it is, while doing something equally bad in PHP like mixing up function with formatting isn&#8217;t so obvious until much later when problems start cropping up. By bringing these good habits from C# and RoR to PHP5 I can write much more reliable and readable code thats also fairly agile. This article by <a href="http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html">Derek Sivers</a> kinda sums things up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gotbadger.org.uk/2007/10/01/a-change-of-heart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
