<?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>Starlino Electronics &#187; computer</title>
	<atom:link href="http://www.starlino.com/tag/computer/feed" rel="self" type="application/rss+xml" />
	<link>http://www.starlino.com</link>
	<description>Electronics and Robotics Projects, Tutorials, Reviews, Experiments</description>
	<lastBuildDate>Sat, 28 Jan 2012 01:38:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Accelerometer Controlled Usb Gamepad and Mouse using PIC18F2550 / PIC18F4550</title>
		<link>http://www.starlino.com/usb_gamepad.html</link>
		<comments>http://www.starlino.com/usb_gamepad.html#comments</comments>
		<pubDate>Sun, 21 Dec 2008 00:00:00 +0000</pubDate>
		<dc:creator>starlino</dc:creator>
				<category><![CDATA[Motion Sensing USB Devices]]></category>
		<category><![CDATA[accelerometer]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[gamepad]]></category>
		<category><![CDATA[motion]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://usb_gamepad</guid>
		<description><![CDATA[<p>Schematics and code for construction of an accelerometer controlled USB gamepad based on a Microchip PIC microcontroller.&#160;</p>]]></description>
			<content:encoded><![CDATA[<h2>Demo</h2>
<p><object height="340" width="560"><param name="movie" value="http://www.youtube.com/v/23SC7ZZ0P8E&amp;hl=en&amp;fs=1&amp;rel=0" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed allowfullscreen="true" allowscriptaccess="always" height="340" src="http://www.youtube.com/v/23SC7ZZ0P8E&amp;hl=en&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" width="560"></embed></object></p>
<p><object height="340" width="560"><param name="movie" value="http://www.youtube.com/v/szZv2YYQm0U&amp;hl=en&amp;fs=1&amp;rel=0" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed allowfullscreen="true" allowscriptaccess="always" height="340" src="http://www.youtube.com/v/szZv2YYQm0U&amp;hl=en&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" width="560"></embed></object></p>
<p><span id="more-5"></span></p>
<h2>Circuit</h2>
<p>This is the schematics for a PIC USB gamepad that I have built in a steering wheel shell. The code for the firmware was written in PicBasic Pro and it implements a HID USB device with 2 axes and 4 buttons (only 2 buttons connected in the prototype). The device is detected by Windows XP/Vista as a standard USB gamepad and can be used with many games and applications.</p>
<p>I am using a 2 Axes Buffered &plusmn;2g Accelerometer from <strong>DIMENSION ENGINEERING</strong>, it has a built in voltage regulator that allows powering the accelerometer dirrectly from the USB bus (5V):</p>
<p><a href="http://www.dimensionengineering.com/DE-ACCM2G.htm" target="_blank">http://www.dimensionengineering.com/DE-ACCM2G.htm</a></p>
<p>I highly recommend this accelerometer as well as other great Dimension Engineering products, check out their website: <a href="http://www.dimensionengineering.com/" target="_blank">www.dimensionengineering.com</a> !</p>
<p>&nbsp;</p>
<p><img alt="usb gamepad circuit" height="465" src="data/usb_gamepad/images/usb_gamepad_circuit.gif" width="674" /></p>
<p>Note: Optionally you can connect 2 more buttons to RB2 and RB3.</p>
<h2>Code</h2>
<p>Below is the PIC Basic code that works both on 18F4550 / 18F2550. (There are other requirements to build USB firmware including the HID header, see compiler documentation).</p>
<p>DOWNLOAD HEX FILE FOR PIC 18F2550 (You will need a PIC Programmer to transfer it to the chip, I&#39;m using PICKit2):</p>
<p><a href="data/usb_gamepad/18F2550_Gamepad.hex">18F2550_Gamepad.hex</a></p>
<p><strong>IMPORTANT NOTE:</strong> Please disconnect any Microchip Devices (including the PICKit2 programmer) before plugging this device since it&#39;s using same HID VENDOR /PRODUCT ID provided in Microchip sample files.<br />
	If you plug 2 devices with same VENDOR/PRODUCT ID you might get a hardware conflict and the devices might not work.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
	<span class="edit_monospace">Define&nbsp; OSC&nbsp;&nbsp;&nbsp;&nbsp; 48<br />
	&#39;CONFIGURATIONS ARE IN /PBP/18F2550.INC , YOU MIGHT WANT TO EDIT THEM</p>
<p>	&#39;ADC<br />
	DEFINE ADC_BITS 10 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&#39; Set number of bits in result<br />
	DEFINE ADC_CLOCK 6&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&#39; Set clock source&nbsp; Fosc/64&nbsp; =&gt; TAD =&gt; 1.34uS<br />
	DEFINE ADC_SAMPLEUS 50 &nbsp;&nbsp; &nbsp;&#39; Set sampling time in uS</p>
<p>
	TRISA.0 = 1<br />
	TRISA.1 = 1</p>
<p>	ADCON1 = %00001101 &#39; sets AN0,AN1 to analog mode </p>
<p>	ADCON2 = %10101110 &#39; <br />
	&nbsp;&nbsp; &nbsp;&#39;bit 0-2: ADCS ,OVERWRITTEN BY ADC_CLOCK,&nbsp; 110: Fosc/64&nbsp; =&gt; TAD =&gt; 1.34uS<br />
	&nbsp;&nbsp; &nbsp;&#39;bit 3-5: Aquisition time: 101: 12 TAD =&gt;&nbsp; 16uS<br />
	&nbsp;&nbsp; &nbsp;&#39;bit 6: not used<br />
	&nbsp;&nbsp; &nbsp;&#39;bit 7: Right justify for 10-bit <br />
	&nbsp;&nbsp; &nbsp;</p>
<p>	x&nbsp;&nbsp; &nbsp;VAR&nbsp;&nbsp; &nbsp;WORD <br />
	y&nbsp;&nbsp; &nbsp;VAR Word</p>
<p>	INTCON2.7=0&nbsp; &#39;RBPU =0 , TURN ON PORTB PULL-UPS</p>
<p>	bt1&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;VAR PORTB.0<br />
	&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;TRISB.0 = 1<br />
	bt2&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;VAR PORTB.1<br />
	&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;TRISB.1 = 1<br />
	bt3&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;VAR PORTB.2<br />
	&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;TRISB.2 = 1<br />
	bt4&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;VAR PORTB.3<br />
	&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;TRISB.3 = 1<br />
	&nbsp;&nbsp; &nbsp;</p>
<p>
	&#39;USB<br />
	buffer&nbsp;&nbsp; &nbsp;Var&nbsp;&nbsp; &nbsp;Byte[3]<br />
	USBInit</p>
<p>	main:<br />
	&nbsp;&nbsp; &nbsp;ADCIN 0,x&nbsp;&nbsp; &nbsp;&#39;read AN0<br />
	&nbsp;&nbsp; &nbsp;ADCIN 1,y&nbsp;&nbsp; &nbsp;&#39;read AN1<br />
	&nbsp;&nbsp; &nbsp;<br />
	&nbsp;&nbsp; &nbsp;&#39;x,y experimental measurments: ~512 @center / ~365 @ -90deg / -655 @ +90deg<br />
	&nbsp;&nbsp; &nbsp;<br />
	&nbsp;&nbsp; &nbsp;x = (x &gt;&gt; 2) &lt;&lt; 2&nbsp; &#39; clear last 2 bits<br />
	&nbsp;&nbsp; &nbsp;y = (y &gt;&gt; 2) &lt;&lt; 2&nbsp; &#39; clear last 2 bits<br />
	&nbsp;&nbsp; &nbsp;<br />
	&nbsp;&nbsp; &nbsp;<br />
	&nbsp;&nbsp; &nbsp;&#39;convert x,y from range [384..512..639] to [0..128..255] with edge clipping<br />
	&nbsp;&nbsp; &nbsp;x = ((x MAX 384) MIN 639 ) &#8211; 384<br />
	&nbsp;&nbsp; &nbsp;y = ((y MAX 384) MIN 639 ) &#8211; 384<br />
	&nbsp;&nbsp; &nbsp;<br />
	&nbsp;&nbsp; &nbsp;<br />
	&nbsp;&nbsp; &nbsp;buffer[0] = y&nbsp;&nbsp; &nbsp;&#39;gamepad&#39;s x-axis is accelerometer&#39;s y axis<br />
	&nbsp;&nbsp; &nbsp;buffer[1] = x&nbsp;&nbsp; &nbsp;&#39;gamepad&#39;s y-axis is accelerometer&#39;s x axis<br />
	&nbsp;&nbsp; &nbsp;buffer[2] = PORTB ^ %00001111 &amp;&nbsp;&nbsp; &nbsp;%00001111 &#39;separate and reverse first 4 bits</p>
<p>	&nbsp;&nbsp; &nbsp;USBService&nbsp;&nbsp; &nbsp;&#39; Must service USB regularly<br />
	&nbsp;&nbsp; &nbsp;USBOut 1, buffer, 3, main&nbsp; &#39; Send buffer to endpoint 1</p>
<p>	GOTO main&nbsp;&nbsp; &nbsp;&#39; Do it forever</span></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Here is how it is detected by Windows XP. Please note that if you don&#39;t change the USB HID Vendor ID and Product ID code this device might conflict with other microchip HID devices using same indentification, including the PICKIT II USB programmer (you can&#39;t have them plugged in both at the same time).</p>
<p><img alt="control_panel_game_controllers.jpg" height="627" src="data/usb_gamepad/images/control_panel_game_controllers.jpg" width="721" /></p>
<p>There&#39;s no need to calibrate the device on this Windows screen,&nbsp; since it will output values within 0..255 range for both axis and it will be centered close to&nbsp; 128,128 values (we took care of this in the program).</p>
<p>However you might want to adjust sensitivity in your game, based on your preference:</p>
<p><img alt="sensitivity.jpg" src="data/usb_gamepad/images/sensitivity.jpg" /></p>
<h2>Construction</h2>
<p>If using an existing USB cable , the wire coding is VDD red, VSS black , D+ green , D- white.</p>
<p><strong>Second prototype using PIC18F2550 chip.in a cheap Wii steering wheel shell. (Look for them on EBay they sell for about $1.45).</strong></p>
<p><img alt="game pad built from a wii steering wheel shell" height="480" src="data/usb_gamepad/images/IMG_0093.JPG" width="640" /></p>
<p><img alt="" height="480" src="data/usb_gamepad/images/IMG_0091.JPG" width="640" /></p>
<p><img alt="" height="480" src="data/usb_gamepad/images/IMG_0092.JPG" width="640" /></p>
<p>&nbsp;</p>
<p><strong>First prototype &quot;THE BRICK&quot; , using PIC18F4550 chip, accelerometer removed.</strong></p>
<p><img alt="" height="480" src="data/usb_gamepad/images/IMG_0094.JPG" width="640" /></p>
<p>&nbsp;</p>
<p><img alt="" height="480" src="data/usb_gamepad/images/IMG_0095.JPG" width="640" /></p>
<p>&nbsp;</p>
<h2>It can work as a motion MOUSE too !</h2>
<p><object height="344" width="425"><param name="movie" value="http://www.youtube.com/v/k13UPjzrauk&amp;hl=en&amp;fs=1&amp;rel=0" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed allowfullscreen="true" allowscriptaccess="always" height="344" src="http://www.youtube.com/v/k13UPjzrauk&amp;hl=en&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" width="425"></embed></object></p>
<p>&nbsp;</p>
<p>With a slightly different firmware and&nbsp; the same hardware you can build a USB Motion (Tilt/Pan) HID Mouse, source code is here:</p>
<p><a href="http://code.google.com/p/hidmouse/" target="_blank">http://code.google.com/p/hidmouse/</a></p>
<p>SVN Trunk:</p>
<p><a href="http://code.google.com/p/hidmouse/source/browse/#svn/trunk/%20hidmouse" target="_blank">http://code.google.com/p/hidmouse/source/browse/#svn/trunk/%20hidmouse</a></p>
<p>&nbsp;</p>
<p>Also for anyone interested in a quick build, with all parts and PCB -&nbsp; gamepad kits with pre-programmed PIC and accelerometer are available for&nbsp; 50 USD @&nbsp; <a href="http://gadgetgangster.com/231">http://gadgetgangster.com/231</a> .</p>
<p><span style="color: rgb(0, 128, 0);"><em><span class="edit_monospace"><br />
	</span></em></span></p>
<p>///starlino///</p>
]]></content:encoded>
			<wfw:commentRss>http://www.starlino.com/usb_gamepad.html/feed</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Use your TV Remote To Turn On Your Computer</title>
		<link>http://www.starlino.com/remote_pc_switch.html</link>
		<comments>http://www.starlino.com/remote_pc_switch.html#comments</comments>
		<pubDate>Sat, 20 Dec 2008 00:00:00 +0000</pubDate>
		<dc:creator>starlino</dc:creator>
				<category><![CDATA[Fun Projects]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[ir]]></category>
		<category><![CDATA[remote]]></category>

		<guid isPermaLink="false">http://remote_pc_switch</guid>
		<description><![CDATA[<p>Create a device that allows you to turn on and off your computer using your regular TV remote.</p>]]></description>
			<content:encoded><![CDATA[<h2>Demo</h2>
<p><object height="344" width="425"><param name="movie" value="http://www.youtube.com/v/ugZV_zwcE2A&amp;hl=en&amp;fs=1" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed allowfullscreen="true" allowscriptaccess="always" height="344" src="http://www.youtube.com/v/ugZV_zwcE2A&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" width="425"></embed></object></p>
<p><span id="more-1"></span></p>
<h2>Introduction</h2>
<p>I recently built a new Media PC for my living room. It runs on a Pentium M CPU (normally used in laptops) that draws very little power. Although many Media PCs already come with some sort of remote control (the case I used also came with a remote control) I find that using a wireless mouse is more convenient and can be used with all Windows application.</p>
<p>For my my Media PC remote control I wanted to use as few remote control devices as possible. I settled that to use a cheap wireless mouse and the TV remote control that I use anyway when watchign TV.</p>
<p><img alt="media pc setup" height="480" src="data/remote_pc_switch/images/IMG_0049.JPG" width="640" /><br />
	<em>My Media PC setup &#8211; the device described in this article is in the left bottom corner (the black box)</em>.</p>
<p>The keyboard shown on the pictured is wired and I don&#39;t use it for remote control. You can type on your computer using a wireless mouse. Windows has a little known application called On-Screen Keyboard. It can be started by going to Start &gt; Run and then typing <em>osk</em> in the Open: dialog. You can also create a shortcut on your quicklanch bar so you can easily start this application using your wireless mouse.</p>
<p>.<img alt="windows on screen keyboard" height="290" src="data/remote_pc_switch/images/osk.gif" width="716" /> <br />
	<em>Windows osk application allows you to type text using a mouse</em></p>
<p>My initial setup that used my Sony TV Remote and Wireless Mouse had one single remaining problem &#8211; there was no way to turn on the Media PC remotely. This was my motivation to build a simple low-cost device that would simulate the press on the computer power button when it received a predefined sequence of codes from the TV Remote Control.</p>
<h2>Circuit</h2>
<p>The circuit presented below uses a 38kHZ IR Detector to read the pulses sent from a Sony IR Remote Control. When a certain combination of keys was pressed on the remote it activates the relay which is connected to the PC power switch. <br />
	<img alt="circuit" height="595" src="data/remote_pc_switch/images/circuit.gif" width="734" /></p>
<h2>Parts</h2>
<p>To save you some time I will only mention that the 38kHZ IR Detectors can be purchased at the following retailers <a href="http://www.allelectronics.com/make-a-store/item/PCM-1/IR-RECEIVER-MODULE-FOR-REMOTE-CONTROL/1.html">AllElectronics</a> , <a href="http://www.parallax.com/Store/Components/Optoelectronics/tabid/152/CategoryID/30/List/0/SortField/0/Level/a/ProductID/177/Default.aspx">Parallax</a> , <a href="http://www.radioshack.com/product/index.jsp?productId=2049727&amp;cp=&amp;sr=1&amp;kw=ir&amp;origkw=ir&amp;parentPage=search">Radioshack</a> . Please note that although these detectors are similiar &#8211; they have diiferent pinouts, so consult the datasheet before using them! I only tested the detectors sold by AllElectronics and Parallax &#8211; they work the same, they even seem to have a similar range. The relay I used is a <a href="http://www.allelectronics.com/make-a-store/item/RLY-475/5-VDC-REED-RELAY/-/1.html">5VDC REED RELAY from AllElectronics</a> grab one if you&#39;ll be ordering the IR detectors from the same retailer. The other parts including the PIC microcontroller are realatively easy to find so I will not point to any specific stores.</p>
<h2>Code</h2>
<p>For this project I used a PIC18F1320 microcontroller there is no specific reason for this choice &#8211; I just had one available . If you are familiar with programming microcontrollers feel free to substitute this microcontroller with another one that you might have available. The program is simple so you should be able to adapt it even to a different programming environment. I&#39;ve done my first experiments on a Basic Stamp II and then migrated the code and circuit to PIC in order to reduce the cost of the project.</p>
<p>For this project I&#39;m using the Picbasic Compiler. My choice was based on the fact that Picabasic has the PULSIN command that proves to be very useful for detecting the IR pulses. In the code presented below the device is programmed to activate the relay for a period of 2 seconds only when two codes are received from the Sony TV Remote in exact sequence: 54 (SLEEP) and then 58 (DISPLAY). You don&#39;t have to press both keys at once. Just press one key, followed by the other one.</p>
<p>The keys have been chosen based on the fact that they should not have a bothersome effect for the TV viewer if received by TV. For example if I would have used one the number keys the TV would change channels while I try to turn on the PC. SLEEP and DISPLAY keys will only display some information if pressed just once, (pressing SLEEP more than once will actually activate the SLEEP mode, but I only need to press it once and that will just display the current sleep mode). Your TV set might act differently so choose your own combination !</p>
<p>Also I assumed that I would not normally press this sequence of keys accidentally. If you&#39;re paranoid that this might happen and your PC might turn off, or if you would like to have a stronger secret code and disconenct the front pannel computer switch as described in Suggested Modifications section, I suggest that you modify the program to use a longer sequence of keys. In Anex 1 you&#39;ll find other Sony Remote Codes that I determined experimentally on my Sony Remote.</p>
<p class="edit_monospace">&#39;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
	&#39;THESE ARE DEVICE SPECIFIC CONFIGURATIONS, IF YOU&#39;RE USING ANOTHER PIC YOU WILL HAVE TO CHANGE THEM<br />
	&#39;PLEASE NOTICE MCLRE IS OFF (THUS NO NEED TO USE A RESISTOR CONNECTED TO MCLR(VPP) PIN IN CIRCUIT ABOVE)</p>
<p class="edit_monospace">DEFINE OSC 4</p>
<p class="edit_monospace">&#39;If you get &quot;Overwriting previous address contents ..&quot;<br />
	&#39;Comment out these settings in PBP/18F1320.inc , or modify them dirrectly in that file, it gets included automatically in your program<br />
	@ __CONFIG _CONFIG1H, _INTIO2_OSC_1H <br />
	@ __CONFIG _CONFIG2H, _WDT_OFF_2H <br />
	@ __CONFIG _CONFIG4L, _LVP_OFF_4L<br />
	@ __CONFIG _CONFIG3H, _MCLRE_OFF_3H</p>
<p class="edit_monospace">
	OSCCON = $62 &#39;set clock to 4Mhz</p>
<p class="edit_monospace">&#39;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
	pinIR VAR PORTB.5<br />
	TRISB.5 = 1 &#39;INPUT PIN</p>
<p class="edit_monospace">pinLed VAR PORTB.1<br />
	TRISB.1 = 0 &#39;OUTPUT PIN</p>
<p class="edit_monospace">pinRelay VAR PORTB.3<br />
	TRISB.3 = 0 &#39;OUTPUT PIN</p>
<p class="edit_monospace">irPulse VAR Word<br />
	remoteCode VAR Byte<br />
	lastCode VAR Byte<br />
	&#39;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p class="edit_monospace">LOW pinRelay <strong style="color: red;">&#39;UPDATE BUG FIX: 1/14/2009</strong></p>
<p class="edit_monospace">HIGH pinLed</p>
<p class="edit_monospace">lastCode = 255</p>
<p class="edit_monospace">PAUSE 500</p>
<p class="edit_monospace">&#39;if 4MHz oscillator is used, the pulse width is returned in 10us increments<br />
	DEFINE PULSIN_ MAX 5000 &#39; wait 50 ms max<br />
	i VAR Word</p>
<p class="edit_monospace">start:<br />
	HIGH pinLed</p>
<p class="edit_monospace">remoteCode = 0<br />
	&#39;wait for &quot;start pulse&quot; ~ 2.4 ms<br />
	RCTIME pinIR, 0, irPulse<br />
	IF irPulse &lt; 200 THEN GOTO start &#39; &lt; 2 ms</p>
<p class="edit_monospace">&#39;now read bits , &quot;0&quot; ~ 0.6ms , &quot;1&quot; ~ 1.2 ms</p>
<p class="edit_monospace">&#39;WHILE(pinIR): WEND &#39;THESE STATEMENTS CAN BE USED INSTEAD OF PULSIN<br />
	&#39;RCTIME pinIR, 0, irPulse &#39;TESTED AND IT WORKED</p>
<p class="edit_monospace">&#39;you can also put the following in a loop, but you&#39;ll be wasting CPU cycles, timing is critical here</p>
<p class="edit_monospace">PULSIN pinIR, 0, irPulse<br />
	IF irPulse=0 THEN GOTO start<br />
	IF irPulse &gt; 100 THEN remoteCode.0 = 1 &#39;&gt; 1 ms</p>
<p class="edit_monospace">PULSIN pinIR, 0, irPulse<br />
	IF irPulse=0 THEN GOTO start<br />
	IF irPulse &gt; 100 THEN remoteCode.1 = 1</p>
<p class="edit_monospace">PULSIN pinIR, 0, irPulse<br />
	IF irPulse=0 THEN GOTO start<br />
	IF irPulse &gt; 100 THEN remoteCode.2 = 1</p>
<p class="edit_monospace">PULSIN pinIR, 0, irPulse<br />
	IF irPulse=0 THEN GOTO start<br />
	IF irPulse &gt; 100 THEN remoteCode.3 = 1</p>
<p class="style1"><span class="edit_monospace">PULSIN pinIR, 0, irPulse<br />
	IF irPulse=0 THEN GOTO start<br />
	IF irPulse &gt; 100 THEN remoteCode.4 = 1 </p>
<p>	PULSIN pinIR, 0, irPulse<br />
	IF irPulse=0 THEN GOTO start<br />
	IF irPulse &gt; 100 THEN remoteCode.5 = 1</span></p>
<p class="edit_monospace">PULSIN pinIR, 0, irPulse<br />
	IF irPulse=0 THEN GOTO start<br />
	IF irPulse &gt; 100 THEN remoteCode.6 = 1</p>
<p class="edit_monospace">LOW pinLed</p>
<p class="edit_monospace">&#39;combination to turn on the relay<br />
	IF lastCode=54 AND remoteCode=58 THEN &#39;SLEEP , DISPLAY<br />
	HIGH pinRelay<br />
	PAUSE 2000<br />
	LOW pinRelay<br />
	ENDIF</p>
<p class="edit_monospace">lastCode = remoteCode<br />
	PAUSE 50 &#39;keep led on</p>
<p class="edit_monospace">GOTO start</p>
<p class="edit_monospace">&#39;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Please note that this code will only work with Sony or compatible remote controls. If you happen to have a different remote control I suggest that you do some research about the protocol it uses and modify the programm accordingly. If you happen to have one of those universal remote controls try to programm your univrsal remote to send a sony code, because your TV is not Sony you might even use a single sony code (for instance POWER code 21) that will be ingnored by your non-Sony TV but will be captured by this device.</p>
<h2>Theory</h2>
<p>So how does it work ? The principle of opperation of this device is very simple: when you press a button on your remote , it sends a series of pulses that are detected by the IR detector. The IR detector is sensible only to frequences close to 38kHz so that other infra red emiters would not interfeer. The output signal of the IR detector is normally HIGH (1). Each code starts with a long pulse of 2.4ms, binary &quot;0&quot; is encoded as a pulse of 0.6ms, binary &quot;1&quot; is encoded as pulse of 1.2ms.</p>
<p><img alt="" height="175" src="data/remote_pc_switch/images/pulses.gif" width="603" /></p>
<p>Our code loops untill it detects a pulse that is longer than 2ms (that&#39;s got to be the 2.4ms starting pulse). For our microcontroller RCTIME command returns values in 10uS increments (you can read about this in the compiler manual) thus we compare against the value of 200 (2ms / 10us = 200). Note the first parameter of the RCTIME command is 0, this means that we are looking for the signal to go LOW(0) and we measure how long it stays low.</p>
<p><span class="style1">start:</span><br />
	&#8230;&#8230;.<br />
	<span class="style1">&#39;wait for &quot;start pulse&quot; ~ 2.4 ms<br />
	RCTIME pinIR, 0, irPulse</span><br />
	<span class="style1">IF irPulse &lt; 200 THEN GOTO start &#39; &lt; 2 ms</span></p>
<p>Once a start pulse has been detected , without waisting too much time, we read the next 7 pulses and get the first 7 bits of our code. Once we have our code we check the current code and the previous code and if it matches our combination we turn on the relay for 2 seconds. This would be equivalent to holding the switch button of the computer for 2 seconds. This is the part of the code that you would modify in order to change the key combination (check the codes for various keys in the Anex 1)</p>
<p><span class="style1">&#39;combination to turn on the relay<br />
	IF lastCode=54 AND remoteCode=58 THEN &#39;SLEEP , DISPLAY<br />
	HIGH pinRelay<br />
	PAUSE 2000<br />
	LOW pinRelay<br />
	ENDIF</span></p>
<p class="style1">lastCode = remoteCode<br />
	PAUSE 50 &#39;keep led on</p>
<p class="style1">GOTO start</p>
<p>Please note that the PAUSE 50 is added here in order to make the led blink when a key is being pressed. This proves to be usefull in order to give the user a visual feedback that the signal sent from remote is being received and decoded. After we store the current code in the lastCode variable we jump back to the start label and wait for another code.</p>
<h2>Construction</h2>
<p>I chose to place my device in an external enclosure. This might also be your choce if your PC is innacessible for the IR beams or you don&#39;t want to drill any openings in the frontpanel of you computer for the IR detector and the led. However you&#39;ll still need a small opening in your case to route the wire, you can usually find plenty of openings at the back of the case used for ventilation. Be careful not to route the wire close or through a fan opening!</p>
<p>This device can also be placed inside the case of your computer, this would be a more elegant solution for a Media PC. However you will need to create openings in the frontpanel for the IR Detector and optionally for the activity led. Your Media PC case might already have an opening for the IR detector. Mine actually has it, but I didn&#39;t use it. Remember Infra Red light will not pass through any solid materials, they need an unobstructed line of sight to the remote control IR emiter.</p>
<p>To power the device I used the PC ATX Powere supply. Even when your computer is turned off the power supply provides 5V on it&#39;s purple wire. To tap into the power supply wires I removed the insulation from the purple(5V) and one of the black(Ground) wires and then connected my wires that power the device. If you don&#39;t want to alter the cables on your power supply (as this might void your manfacturer warantee), I suggest that you use an ATX power supply extender and then you can tap into its wires. Another alternative is to use a different power supply altogether, like a 5V DC wall power adapter.</p>
<p><img alt="tap into power supply" height="480" src="data/remote_pc_switch/images/IMG_0052.JPG" width="640" /><br />
	<em>Taping into power supply wires. The purple wire gives you 5V even when your PC is off. The black wire is ground.</em></p>
<p>Here is the actual device that I&#39;ve built. I like to separate some subcircuits that I might &quot;borough&quot; later and use for other projects. Notice that the relay suncircuit is separated on its own little board. The device box is connected to the PC case with a regular 4 wire phone cable. Two wires (black and wite) are used to power the device from the ATX power supply as described above and the other two wires (green and yellow) are connected at one end to the relay and at the other end to the Power Switch header on your motherboard.</p>
<p><img alt="box" height="480" src="data/remote_pc_switch/images/IMG_0060.JPG" width="640" /><br />
	<em>IR Detector(top left), Green Led(top right) , PCB with PIC (middle), separted Relay Subcircuit</em> (bottom)</p>
<p>If you&#39;re having trouble finding the Power Switch header on your motherboard consult your motherboard manual. You&#39;re looking for 2 pins on your motherboard that are connected to the frontpannel power switch. These pins are usually located on the same header with other pins (like HDD LED, RESET SWITCH, SPEAKER, etc).</p>
<p><img alt="front panel connector" height="347" src="data/remote_pc_switch/images/front_panel_connector.gif" width="320" /><br />
	<em>Connection schematic using a sample motherboard frontpanel <br />
	connector, your connector might be different !</em></p>
<p>From the schematic above you can see that the relay terminals are connected in paralel with the frontpanel power swtich so you can use both to turn on and off the computer.</p>
<p>I created 2 Y spliiters using crimp pin terminals and a crip tool. Then I insulated the ends with shrink tubing. If you can&#39;t create these you may choose a more intrusive solution like taping into the wires that go to you frontpanel power switch just like we did for the power supply.</p>
<p><img alt="splitter" height="480" src="data/remote_pc_switch/images/IMG_0057.JPG" width="640" /><br />
	<em>Use these Y splitters to connect both the device and the frontpanel switch to the motherboard connector</em></p>
<p><img alt="" height="480" src="data/remote_pc_switch/images/IMG_0053.JPG" width="640" /><br />
	<em>One end of Y spliiters are conencted to motherboard frontpanel header. &quot;Power SW&quot; ramification <br />
	goes to frontpannel switch, the other ramifications (green and yellow wires) go to device relay switch.</em></p>
<h2>Suggested Modifications</h2>
<p>1. This device can be used as a secure way to turn on your computer. Just disconnect the frontpannel switch and the remote controll code will be the only way to turn on your PC. For added security place a lock on your PC enclosure, most enclosures have holes that allow to place a small lock on side covers. For this setup I would also suggest placing the device inside the PC case, otherwsie one could open the device box and short the switch wires.</p>
<p>2. If the permanetely lit led bothers you, you may reverse the action of the led (it will be normally off), just replace in the code above &#39;HIGH pinLed&#39; with &#39;LOW pinLed&#39; and vice-versa.</p>
<p>3. You can adapt this device to turn on other appliances not just your PC. Just make sure to use a relay that is rated for the currents you will be switching.</p>
<p>4. Although I didn&#39;t try it, I suspect that the relay subcircuit could be replaced by a single transistor since we&#39;re powering the device from the PC and we have a common ground. However the relay gives you a more universal solution that can also be used to switch other appliances with higher currents going through the switch (up to the maximum rated current of the relay).</p>
<h2>Anex 1 (Sony Remote Control Codes)</h2>
<p>TV/VIDEO 37<br />
	SLEEP 54<br />
	POWER 21</p>
<p>	FREEZE 92<br />
	PICTURE 100<br />
	WIDE 61</p>
<p>	GUIDE 14 <br />
	DISPLAY 58</p>
<p>	LEFT 52<br />
	RIGHT 51<br />
	UP 116<br />
	DOWN 117<br />
	CENTER 101</p>
<p>	RETURN 35<br />
	TOOLS 54<br />
	MENU 96 </p>
<p>	DIGITAL/ANALOG 13<br />
	JUMP 59</p>
<p>	1 0<br />
	&#8230;.<br />
	9 8<br />
	. 29<br />
	0 9<br />
	ENT 11</p>
<p>	MUTING 20<br />
	VOL UP 18<br />
	VOL DOWN 19<br />
	CH UP 16<br />
	CH DOWN 17</p>
]]></content:encoded>
			<wfw:commentRss>http://www.starlino.com/remote_pc_switch.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

