<?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>www.OhmPie.com</title>
	<atom:link href="http://www.ohmpie.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ohmpie.com</link>
	<description>Linux, Programming, Electronics, Freedom</description>
	<lastBuildDate>Fri, 09 Dec 2011 02:08:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
	
	
	<!-- google ad injected by adsense-optimizer http://www.adsenseoptimizer.de -->
	<div  style="padding:7px; float: right; padding-right: 0; margin: 3px;"><!-- Ad number: 1 --><script type="text/javascript"><!--
    	 
    	google_ad_client = "pub-7721485558976096"; google_alternate_color = "FFFFFF";
		google_ad_width = 468; google_ad_height = 60;
		google_ad_format = "468x60_as"; google_ad_type = "text_image";
		google_ad_channel =""; google_color_border = "336699";
		google_color_link = "0000FF"; google_color_bg = "FFFFFF";
		google_color_text = "000000"; google_color_url = "008000";
		google_ui_features = "rc:6"; //--></script>
		<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div>	<item>
		<title>Element 14 XL_Star Review</title>
		<link>http://www.ohmpie.com/element-14-xl_star-review/</link>
		<comments>http://www.ohmpie.com/element-14-xl_star-review/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 07:09:03 +0000</pubDate>
		<dc:creator>esalazar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ohmpie.com/?p=164</guid>
		<description><![CDATA[Last week I received an Element 14 XL_Star board from Farnell/Newark. My condition for receiving this board was that I do a review. I must admit that I have been on a quest for the perfect controller board for a &#8230; <a href="http://www.ohmpie.com/element-14-xl_star-review/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Last week I received an<a href="http://www.element14.com/community/community/new_technology/development_boards/xl_star"> Element 14 XL_Star</a> board from<a href="http://www.newark.com/element14/star-xl-s08/xl-star-mc9s08mm128-mcu-board/dp/27T2966?Ntt=XL_STAR"> Farnell/Newark.</a> My condition for receiving this board was that I do a review. I must admit that I have been on a quest for the perfect controller board for a very long time. In my journey I have gone though pic microcontrollers, Parallax Basic Stamps, Arduinos and Arduino clones, TI MSP430s, mbed rapid prototyping and last the LeafLabs maple controller.<br />
<span id="more-164"></span><br />
<a title="parts in box.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/6087662401/"><img src="http://farm7.static.flickr.com/6186/6087662401_f978acc747.jpg" alt="parts in box.JPG" width="500" height="375" /></a></p>
<p>At the heart of the XL_Star is the Freescale MC9S08MM128CLK a very <a href="http://www.newark.com/freescale-semiconductor/mc9s08mm128clk/8bit-128k-flash/dp/74R8739?Ntt=MC9S08MM128CLK">inexpensive</a> 8-bit microcontroller with some impressive specs including a clock speed up to 48Mhz, USB, 128KB flash, 12Kb ram, 4 differential 16bit ADC ports. 8 single ended ADC ports, single 12bit DAC, and 47 GPIO. Also on the board includes a second freescale processor primarily used for programming and debugging the Freescale MC9S08JM60CLD. Last as a bonus feature, this board includes a three axis 14bit accelerometer the <a href="http://www.newark.com/jsp/search/productdetail.jsp?sku=84R7351&amp;COM=element14_shoppingcart">MMA845QT</a>.</p>
<p><a title="XL_STAR.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/6087662639/"><img src="http://farm7.static.flickr.com/6191/6087662639_da07f1baf5.jpg" alt="XL_STAR.JPG" width="500" height="375" /></a></p>
<p><strong>Software install </strong></p>
<p><strong> </strong>I was really hopping that this environment would have Linux support, however that was not the case so I started up an Windows 7 machine in Virtual Box. The CD has a wizard to help guide you though installing all the software and drivers necessary.</p>
<p><a title="install wizard.jpg by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/6087662779/"><img src="http://farm7.static.flickr.com/6065/6087662779_4a5552de43.jpg" alt="install wizard.jpg" width="500" height="447" /></a></p>
<p>This process took a long time, roughly 30min. CodeWarror is a very large package that kept constantly asking for verification to install system drivers. Then on top of that you have to install a couple patches along with updated drivers.</p>
<p>After the install is complete you can start the application and select the Sample XL_STAR project to open the default program</p>
<p><a title="codeWarrior.jpg by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/6088208758/"><img src="http://farm7.static.flickr.com/6181/6088208758_3dfbe0abcd.jpg" alt="codeWarrior.jpg" width="500" height="334" /></a></p>
<p><strong>Programming and Debugging</strong></p>
<p>At this point I plugged in the USB to the bottom debugging port and selected &#8220;Debug&#8221; (F5) from the project menu. Another window opened that showed the source along with the assembly dump, registers and memory.</p>
<p><a title="debugger.jpg by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/6087662965/"><img src="http://farm7.static.flickr.com/6183/6087662965_cfd16ef257.jpg" alt="debugger.jpg" width="500" height="365" /></a></p>
<p>I must say that this real time debugger is a very cool feature. You start the program by either stepping though the line of code or hitting the start button. You get interactive feedback while the program is running. I ran the default program that shows the data from the accelerometer.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="345" 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/WWmp2XFmTUM?version=3&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="345" src="http://www.youtube.com/v/WWmp2XFmTUM?version=3&amp;hl=en_US" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>I also tried to modify the code to write my own custom program. This program will uses the led circle method to display a growing circle in a infinite loop.</p>
<pre>while(1) {
    for(i=0;i&lt;6;i++) {
        leds_circle(i);
        millisecond_delay(100);
    }
}</pre>
<p><object width="560" height="345"><param name="movie" value="http://www.youtube.com/v/uj3fqKqOL_k?version=3&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/uj3fqKqOL_k?version=3&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" width="560" height="345" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<strong>Conclusion</strong></p>
<p>I must say that this is a very sophisticated board for it&#8217;s price.  I have very mixed feelings about the software. I would really like a Linux option. It may be a future possibility since <a href="http://www.freescale.com/webapp/sps/site/overview.jsp?code=LINUX_CW_TOOLS">Freescale does offer tools for linux</a>. Their web page indicates that any download are for evaluation only unless your purchase. The active debugging was a very neat feature that I have not had in the past. I am going to have to spend a lot of time learning more about this board so far I get the impression that it is very complex and the tools are not as user friendly as the microcontrollers I am normally used to running. I hope to incorporate this board in some future projects</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/element-14-xl_star-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Experiments With Audio Vacuum Tubes</title>
		<link>http://www.ohmpie.com/experiments-with-audio-vacuum-tubes/</link>
		<comments>http://www.ohmpie.com/experiments-with-audio-vacuum-tubes/#comments</comments>
		<pubDate>Sat, 14 May 2011 01:50:51 +0000</pubDate>
		<dc:creator>esalazar</dc:creator>
				<category><![CDATA[Eletronics]]></category>

		<guid isPermaLink="false">http://www.ohmpie.com/?p=140</guid>
		<description><![CDATA[Previously I tested a El84 using series of 9 volt batteries to generate the high B+ voltages. While it was very simple by nature, it still fell short of the desired voltages that are required to make a useful audio amplifier. Normally &#8230; <a href="http://www.ohmpie.com/experiments-with-audio-vacuum-tubes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Previously I tested a El84 using series of 9 volt batteries to generate the high B+ voltages. While it was very simple by nature, it still fell short of the desired voltages that are required to make a useful audio amplifier. Normally the solution to this problem is to use a step up transformer and rectify the mains current.  These transformers are not cheap, very heavy, and costly to ship, but above all I did not have one at the time. Another option is direct rectification of the mains AC. This technique has been used in radios of the past and is extremely dangerous! Without a fuse this circuit will draw as much current as you house will deliver.  Also the ground of the circuit will be directly coupled to the neutral of your home. If you use a non polarized plug or there is a mis-wiring of your outlets, the ground of your circuit would complete a direct 120v path with the &#8220;ground&#8221; of another circuit. So for initial testing I decided to go with a boost converter.<br />
<span id="more-140"></span><br />
<strong>The Boost conveterter</strong></p>
<p>The operating principal of a boost converter is very simple, am inductor is charged and then released though a diode to charge a capacitor. This principal is used in switch mode power supply units. Most switching regulators are designed to work at lower voltages, say bump up a 5V supply to a 12V supply. I have a few MC34063A switching regulators I bought a while back for the exactly purpose of running 12V out of a couple AA batteries.</p>
<p><a href="http://www.ohmpie.com/wp-content/uploads/2011/05/inverter.gif"><img class="alignnone size-medium wp-image-145" title="inverter" src="http://www.ohmpie.com/wp-content/uploads/2011/05/inverter-300x286.gif" alt="" width="300" height="286" /></a></p>
<p>This devices is only rated to 40V. So I had to add some supplementary components in order to ramp the voltage over 100V. To do this I did the switching using a IRF740 MOSFET. At first I tried driving the opamp directly from the regulator. In simulation this would work however I discovered that real MOSFETs have a fair amount of capacitance at high frequencies that will create a lot of resistance. So I had to create a MOSFET driver. For this I chose a 2n222 / 2n907 NPN/PNP pair. When working with high voltages it is important that all the components are rated appropriately. This is espcially important for the capacitor and diode following the MOSFET.  The capacitor I chose was surplus disposable flash capacitor rated at 330V with a capacitance of 270uF. The diode is a simple rectifying diode, I may have had better performance with a Schottky diode however all the ones I have were not rated for voltages this high.</p>
<p><a title="180v_Boost_Converter.png by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5557308389/"><img src="http://farm6.static.flickr.com/5186/5557308389_70f6068738.jpg" alt="180v_Boost_Converter.png" width="500" height="384" /></a></p>
<p><a title="P1020503.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5557849910/"><img src="http://farm6.static.flickr.com/5026/5557849910_110be84db5.jpg" alt="P1020503.JPG" width="500" height="375" /></a></p>
<p><strong>Designing an Audio Amplifier</strong></p>
<p>For designing the audio amplifier I went back to the circuit simulator. Falstad&#8217;s  simulator has a triode and the it&#8217;s model parameters can be edited by exporting and re-importing the circuit file. I asked <a href="http://www.falstad.com/" target="_blank">Paul</a> how to change the characteristic of the tube and he replied with the model that he used to simulate the triode that is as follows: ((Vgk+Vpk/mu)^1.5)/kg1 where Vgk = gate-cathode voltage and Vpk = plate-cathode.  In order for me to simulate commercially available triodes I needed to find kg1 and mu values that would get me close. For this I wrote a python program using matplotlib to allow me to play with different values and visualize the results.  Below are a couple screen shots.</p>
<p>An 12ax7 Preamp Troide, The y axes is milliamperes and the x is volts<br />
<a title="tube_plot_12ax7.png by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5714890400/"><img src="http://farm4.static.flickr.com/3597/5714890400_9787b82b02_o.png" alt="tube_plot_12ax7.png" width="650" height="524" /></a></p>
<p>A El84 Poweramp Pentode running in Triode mode<br />
<a title="tube_plot_el84.png by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5714328563/"><img src="http://farm4.static.flickr.com/3495/5714328563_5c152715ea_o.png" alt="tube_plot_el84.png" width="650" height="524" /></a></p>
<p>The source code for this project can be found on my Github account under <a href="https://github.com/senormeow/Tube-Plot" target="_blank">Tube Plot</a>. This code was developed on Ubuntu using python 2.6.5 and <a href="http://matplotlib.sourceforge.net/" target="_blank">matplotlib</a>.</p>
<p>After finding values that were close to the original data sheets (at least for the voltages I intended to run) I then did some simulations.</p>
<p>The Preamp<br />
<a title="tube_preamp.png by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5714328831/"><img src="http://farm3.static.flickr.com/2226/5714328831_44ae15efa5.jpg" alt="tube_preamp.png" width="500" height="354" /></a></p>
<p>The Poweramp<br />
<a title="tube_poweramp.png by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5714328973/"><img src="http://farm4.static.flickr.com/3271/5714328973_a60b287a9d.jpg" alt="tube_poweramp.png" width="500" height="354" /></a></p>
<p><strong>Putting it all together</strong></p>
<p>Now that I ran some simulations I deiced to try building it all out. First I tried using the switching power supply and only the power amp state using a function generator as the preamp.</p>
<p><a title="P1020509 by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5618542750/"><img src="http://farm6.static.flickr.com/5268/5618542750_863e6638ed.jpg" alt="P1020509" width="500" height="375" /></a></p>
<p>While this did work, it was very stressful on the boost converter. A lot of current had to be drawn. I spent about a day or two playing with different inductors and switching frequencies to get optimal efficiency. In this time I blew a couple mosfets and diodes. Eventually a ham buddy of mine gave me a step up transformer to play with so I deiced to make a traditional power supply.<br />
<a title="P1020515 by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5617958365/"><img src="http://farm6.static.flickr.com/5103/5617958365_a83b9d20c0.jpg" alt="P1020515" width="500" height="375" /></a></p>
<p>I used a broken PSU as the case so I could recycle the power connectors and power switch. I also added a fuse along with the rectification circuit. This PSU reads arround 200v unloaded and 180v loaded, about the same as my switching supply.</p>
<p>So I could actually play music from my iPod, I built out the 12ax7 preamp. Both tubes heaters are using a 6V battery in this test. So far everything seems to work well.  In the video blelow I used an old Bose speaker and played some music.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="349" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/HgMLEBTwTtU?fs=1&amp;hl=en_US&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="349" src="http://www.youtube.com/v/HgMLEBTwTtU?fs=1&amp;hl=en_US&amp;rel=0" allowfullscreen="true"></embed></object></p>
<p>The song being played is &#8220;Against all Odds by&#8221; Brian Botkiller. The little pocket oscilloscope from  <a href="http://www.gabotronics.com/" target="_blank">Gabotronics</a> is displaying the voltage ripple of the power supply.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/experiments-with-audio-vacuum-tubes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Home made 555 timer from NPN and PNP transistors</title>
		<link>http://www.ohmpie.com/hm555/</link>
		<comments>http://www.ohmpie.com/hm555/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 01:11:11 +0000</pubDate>
		<dc:creator>esalazar</dc:creator>
				<category><![CDATA[Eletronics]]></category>

		<guid isPermaLink="false">http://www.ohmpie.com/?p=113</guid>
		<description><![CDATA[Before the 555 contest was announced I was reading the free online book 50 555 Circuits from talking electronics. I was very amazed with how much could be done with the 555 timer. So I decided the best way to understand the 555 would &#8230; <a href="http://www.ohmpie.com/hm555/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Before the 555 contest was announced I was reading the free online book <a href="http://talkingelectronics.com/projects/50%20-%20555%20Circuits/50%20-%20555%20Circuits.html">50 555 Circuits</a> from talking electronics. I was very amazed with how much could be done with the 555 timer. So I decided the best way to understand the 555 would be to try and build one. First I looked at some generic block diagrams and also the schematic diagram published in the National Semiconductor datasheet. After I understood the theory, I tested it out in my favorite <a href="http://www.falstad.com/circuit/" target="_blank">circuit simulator by Paul Falstad</a>. This program should be up to the task of simulating at a very high level.<br />
<span id="more-113"></span></p>
<p><a title="555_circut by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5469822514/"><img src="http://farm6.static.flickr.com/5174/5469822514_750bcde960.jpg" alt="555_circut" width="500" height="360" /></a></p>
<p>So far so good, Next I needed to build an SR latch out of transistors. A SR or Set Reset latch consists of two NOR gates. When S is set high Q will stay high until S is set low and R is set high. This circuit is useful in itself for button de-bouncing. I did a simulation building out the latch only using NPN transistors.</p>
<p><a title="SR_Latch by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5469229053/"><img src="http://farm6.static.flickr.com/5019/5469229053_71580a263c.jpg" alt="SR_Latch" width="500" height="287" /></a></p>
<p>After tweaking the resistor values  I went ahead started building out the circuit. For reliability and ease I decided to use the Manhattan Style of construction, a variant of of <a href="http://www.qrp.pops.net/ugly.asp">Ugly Construction</a>. This style is very popular in the QRP Ham Radio community. It consists of using little copper pads on top of a sheet of copper clad. It has many advantages including prototyping speed, high reliability, low noise, high frequency opearation, and last it allows you to mix and match through hole and surface mount parts. The disadvantages is well, it&#8217;s ugly looking.<br />
<a title="P1020380.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5467607810/"><img src="http://farm6.static.flickr.com/5012/5467607810_d7b7ba2ac6.jpg" alt="P1020380.JPG" width="500" height="375" /></a></p>
<p><a title="P1020382.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5467010703/"><img src="http://farm6.static.flickr.com/5016/5467010703_30534c5a1e.jpg" alt="P1020382.JPG" width="500" height="375" /></a></p>
<p>Using a cheap Harbor Freight punch I cut out all the the circular pads in two different diameters. I then clean the corrosion off the pads using sand paper, This helps with soldering and gluing.</p>
<p><a title="P1020411.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5467011835/"><img src="http://farm6.static.flickr.com/5297/5467011835_b61029ca66.jpg" alt="P1020411.JPG" width="500" height="375" /></a></p>
<p>Pads are glued to the board with a generic super glue and then fluxed and tinned with solder. I can then cut and bend the parts leads in order to solder them to the board. All NPN transistors are 2n3904 and PNP are 2n2907.</p>
<p><a title="P1020414.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5467609976/"><img src="http://farm6.static.flickr.com/5173/5467609976_6a2d1baa33.jpg" alt="P1020414.JPG" width="500" height="375" /></a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="390" 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/DB2JFmWvbRs?fs=1&amp;hl=en_US&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="390" src="http://www.youtube.com/v/DB2JFmWvbRs?fs=1&amp;hl=en_US&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>The circuit tested just fine, Now for something a bit more challenging, designing the voltage comparators.  I looked at some transistor op-amps schematics along with the LM555 data sheet schematic. The first op amp appeared to use Darlington pair NPN transistors.  I simplified things a bit by directly using resistors instead of current mirrors. I played with a few variants of the circuit and decided on the one below.</p>
<p><a title="Voltage-comparator-NPN by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5469229073/"><img src="http://farm6.static.flickr.com/5093/5469229073_18eb0205bb.jpg" alt="Voltage-comparator-NPN" width="500" height="360" /></a></p>
<p>Since I was not too confident about how it would work I tested it on a breadboard first. My major concerns were if it was going to be able to drive the SR latch and if the imperfect current gain (Beta) would throw off the comparator.<br />
<a title="P1020442.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5467610550/"><img src="http://farm6.static.flickr.com/5136/5467610550_af9c6ab673.jpg" alt="P1020442.JPG" width="500" height="375" /></a></p>
<p>When the negative side was connected to the reference and the positive was to the variable power it worked great. However the opposite was not true. Looking back at the data sheet it appears the LM555 uses PNP transistors for the second voltage comparator. I was hopping I could just build two of these and move on. So I had to go back to the simulator and play with some other designs.</p>
<p><a title="Voltage-comparator-PNP by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5469822554/"><img src="http://farm6.static.flickr.com/5212/5469822554_0f56ceb30f.jpg" alt="Voltage-comparator-PNP" width="500" height="360" /></a></p>
<p>The Transistor on the right is not part of the voltage comparator but there to simulate this interfacing with the next stage. When I interfaced with the SR latch I bypassed the 10k resistor connected to the base.</p>
<p><a title="P1020461.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5467613310/"><img src="http://farm6.static.flickr.com/5099/5467613310_d4bee7da8c.jpg" alt="P1020461.JPG" width="500" height="375" /></a></p>
<p>Here I am testing both comparators connecting to the SR latch. The reference voltages is coming from three 22k resistors on the breadboard.  The top refrence should be (Vcc *.66) and the bottom is (Vcc *.33). Vcc is a 9v battery and the input was a variable power supply.</p>
<p><a title="P1020462.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5467016163/"><img src="http://farm6.static.flickr.com/5179/5467016163_7fb6eba637.jpg" alt="P1020462.JPG" width="500" height="375" /></a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="390" 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/6vMUfUW1WrY?fs=1&amp;hl=en_US&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="390" src="http://www.youtube.com/v/6vMUfUW1WrY?fs=1&amp;hl=en_US&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Besides having a huge mess of wires everywhere it seems to work out just fine. The switching is not perfect on 3 and 6 volts but this is probably because the battery is not perfectly 9v and the resistors are not perfect.</p>
<p><a title="P1020465.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5467016869/"><img src="http://farm6.static.flickr.com/5059/5467016869_bcb7775847.jpg" alt="P1020465.JPG" width="500" height="375" /></a></p>
<p>Here is the final board with all the modules cleaned up and soldered together with the the series 5k resistors on the board. It should have been obvious before but this was the first time I realized why this device is called the 555, it has to be because of the three 5k series resistors that govern how the device behaves. The transistor to drain the timing capacitor is on the bread board. It was not possible to drive it directly from the latch so I had to use another transistor as a voltage follower. In the video clip it is wired as an astable oscillator with R1 and R1 at 1K and C1 = 470uF and it looks to be working satisfactory.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="390" 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/814aS3KFOIY?fs=1&amp;hl=en_US&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="390" src="http://www.youtube.com/v/814aS3KFOIY?fs=1&amp;hl=en_US&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Here it is running much faster, R1 and R2 are still 1k but C1 is now .015uF. That should equal 34.44khz with a duty cycle of %66. From the scope I roughly measured 31.2k and visually it look to be about %66. So I would say this is functionality correctly.</p>
<p><a title="P1020474.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5474823423/"><img src="http://farm6.static.flickr.com/5257/5474823423_5896a4f86f.jpg" alt="P1020474.JPG" width="500" height="375" /></a></p>
<p>So after three weeks and using 15 BJTs plus some sacrifices to error I have a huge 555 timer. This particular design does not have the output buffer stage but than can be added easily and not need for this testing. In the unlikely even&#8217;t 555s no longer exist I am prepaid. More importantly this project has really help me understand analog circuity, an art I feel that is an art that is dying fast in the digital world.  I hope this information proves to be useful or at least inspire. Maybe I will tackle an LM741 next. You can see the full photo set on my <a href="http://www.flickr.com/photos/esalazar/">Flickr page</a>.</p>
<p><strong>References</strong></p>
<ul>
<li><a href="http://www.oup.com/us/pdf/microcircuits/students/bjt/2N2907-fair.pdf">Fairchild 2n2907</a></li>
<li><a href="http://www.fairchildsemi.com/ds/2N/2N3904.pdf">Fairchild 2n3904</a></li>
<li><a href="http://www.falstad.com/">Paul Falstad</a></li>
<li><a href="http://www.national.com/profile/snip.cgi/openDS=LM555">National Semiconductor LM555 Datasheet</a></li>
<li><a href="http://www.talkingelectronics.com/te_interactive_index.html">Talking Electronics</a></li>
<li><a href="http://www.electronics.dit.ie/staff/mtully/555%20folder/555%20timer.htm">The 555 Timer at Electronics.dit.ie</a></li>
</ul>
<p><strong><br />
</strong></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/hm555/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	
	
	<!-- google ad injected by adsense-optimizer http://www.adsenseoptimizer.de -->
	<div  style="padding:7px; float: left; padding-left: 0px; margin: 3px;"><!-- Ad number: 2 --><script type="text/javascript"><!--
    	 
    	google_ad_client = "pub-7721485558976096"; google_alternate_color = "FFFFFF";
		google_ad_width = 468; google_ad_height = 60;
		google_ad_format = "468x60_as"; google_ad_type = "text_image";
		google_ad_channel =""; google_color_border = "E3FA11";
		google_color_link = "FFFFFF"; google_color_bg = "A2AB2B";
		google_color_text = "000000"; google_color_url = "FFFFFF";
		google_ui_features = "rc:0"; //--></script>
		<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div>	<item>
		<title>Testing an El84 Vacuum Tube with 9v Batteries</title>
		<link>http://www.ohmpie.com/el84-tube/</link>
		<comments>http://www.ohmpie.com/el84-tube/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 21:49:13 +0000</pubDate>
		<dc:creator>esalazar</dc:creator>
				<category><![CDATA[Eletronics]]></category>

		<guid isPermaLink="false">http://www.ohmpie.com/?p=81</guid>
		<description><![CDATA[I  have always been interested in vacuum tube amplifiers, however the high voltages from the mains has always kept me from experimenting with them. About a year ago I played with an low power tube the 1t4 in a regenerative receiver.  The B+ was set to 45V powered &#8230; <a href="http://www.ohmpie.com/el84-tube/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>I  have always been interested in vacuum tube amplifiers, however the high voltages from the mains has always kept me from experimenting with them. About a year ago I played with an low power tube the 1t4 in a regenerative receiver.  The B+ was set to 45V powered from an array of 9v batteries.  I decided to revisit an old guitar amplifier project I started in high school using an EL84 power pentode.<br />
<span id="more-81"></span><br />
The first part was to figure out a way to mount the tube so I could experiment with it. I found an small metal box that worked well for mounting the tube socket. I then took some wires from a broken ATX power supply and soldered them to the tube socket.</p>
<p><a title="P1020321.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5365026073/"><img src="http://farm6.static.flickr.com/5166/5365026073_d5972735f5.jpg" alt="P1020321.JPG" width="500" height="375" /></a></p>
<p><a title="P1020324.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5365642236/"><img src="http://farm6.static.flickr.com/5008/5365642236_0a8d0e674d.jpg" alt="P1020324.JPG" width="500" height="375" /></a></p>
<p><a title="P1020327.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5365643474/"><img src="http://farm6.static.flickr.com/5122/5365643474_5cbd8a2f48.jpg" alt="P1020327.JPG" width="500" height="375" /></a></p>
<p><a title="P1020328.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5365030195/"><img src="http://farm6.static.flickr.com/5290/5365030195_13cc656f34.jpg" alt="P1020328.JPG" width="500" height="375" /></a></p>
<p><a title="P1020329.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5365644854/"><img src="http://farm6.static.flickr.com/5204/5365644854_553ebc7be2.jpg" alt="P1020329.JPG" width="500" height="375" /></a></p>
<p>After I had everything assembled I brought it to the test bench and wired up the test circuit below. I measured the current at the anode versus the voltage at the gate. I kept adding 9v batters to the B+ supply and noted the results.</p>
<p><a title="el84-test by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5396599140/"><img src="http://farm6.static.flickr.com/5175/5396599140_2fca071c8a.jpg" alt="el84-test" width="500" height="278" /></a></p>
<p><a title="P1020337.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5365032651/"><img src="http://farm6.static.flickr.com/5088/5365032651_7dc7a3e6b3.jpg" alt="P1020337.JPG" width="500" height="375" /></a></p>
<p>Below are the results I noted along with a graph. I also included the triode configuration graph from the original datasheet.</p>
<p><a title="P1020340.JPG by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5365033233/"><img src="http://farm6.static.flickr.com/5210/5365033233_3e9c63e494.jpg" alt="P1020340.JPG" width="500" height="375" /></a></p>
<p><a title="El84 by esalazar1981, on Flickr" href="http://www.flickr.com/photos/esalazar/5365668096/"><img src="http://farm6.static.flickr.com/5049/5365668096_263b7b6d89.jpg" alt="El84" width="500" height="450" /></a></p>
<p><a href="http://www.flickr.com/photos/esalazar/5367503402/" title="el84-philips1969-triod by esalazar1981, on Flickr"><img src="http://farm6.static.flickr.com/5208/5367503402_87e96de4a5.jpg" width="349" height="500" alt="el84-philips1969-triod" /></a></p>
<p>So far the data looks consistent with the original datasheet for the tube in triode mode. The tube can sink a lot more current when VG2 is around 350V running in the full pentode configuration. Even with all 12 9V batteries I might be able to drive about 1watt of audio to a speaker. I was also surprised that the heater alone took around .7 amps at 6.3V. This is definitely not the most efficient way to drive a speaker I hope to get an proper impedance matching transformer so I can hear how it performers soon.  </p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/el84-tube/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Laser Modem with an Arduino Microcontroller</title>
		<link>http://www.ohmpie.com/lasermodem/</link>
		<comments>http://www.ohmpie.com/lasermodem/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 01:03:12 +0000</pubDate>
		<dc:creator>esalazar</dc:creator>
				<category><![CDATA[Eletronics]]></category>

		<guid isPermaLink="false">http://dev.ohmpie.com/?p=56</guid>
		<description><![CDATA[This started when I ordered an IR led and phototransistor pair from Spark Fun along with some spare ATMega168 microcontrollers. I first experimented using the IR led to transmit 2400 baud serial to the phototransistor. I programmed my Arduino Diecimila &#8230; <a href="http://www.ohmpie.com/lasermodem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>This started when I ordered an <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=241">IR led and phototransistor</a> pair from Spark Fun along with some spare ATMega168 microcontrollers. I first experimented using the IR led to transmit 2400 baud serial to the phototransistor. I programmed my <a href="http://www.arduino.cc/en/Main/ArduinoBoardDiecimila">Arduino Diecimila</a> with the sample serial program altering the baud rate and allowing it to run in a continuous loop.<br />
<span id="more-56"></span></p>
<blockquote><p><strong>diff ~/arduino-0011/examples/Communication/ASCIITable/ASCIITable.pde laserModem.pde</strong></p>
<p><span style="font-family: monospace;"><br />
<span style="color: #a52a2a;"><strong>6c6</strong></span><br />
<span style="color: #6a5acd;">&lt;   Serial.begin(9600); </span><br />
<span style="color: #6a5acd;">&#8212;</span><br />
<span style="color: #008b8b;">&gt;   Serial.begin(2400); </span><br />
<span style="color: #a52a2a;"><strong>38,40c38,39</strong></span><br />
<span style="color: #6a5acd;">&lt;     while(true) { </span><br />
<span style="color: #6a5acd;">&lt;       continue; </span><br />
<span style="color: #6a5acd;">&lt;     } </span><br />
<span style="color: #6a5acd;">&#8212;</span><br />
<span style="color: #008b8b;">&gt;     number = 0;</span><br />
<span style="color: #008b8b;">&gt; </span><br />
<span style="color: #a52a2a;"><strong>45c44</strong></span><br />
<span style="color: #6a5acd;">&lt;   delay(100); // allow some time for the Serial data to be sent </span><br />
<span style="color: #6a5acd;">&#8212;</span><br />
<span style="color: #008b8b;">&gt;   delay(10); // allow some time for the Serial data to be sent </span><br />
</span></p></blockquote>
<p>After programing the Arduino, I took out the ATMega168 and wried it into a breadboard along with a 16mhz crystal and 5 volt regulator.  For the receiver I used the phototransistor wired into two logic gates of a inverting Hex Schmitt trigger. I used the Schmitt trigger to act as a buffer and ensure only proper logic level enter the USB to serial converter on the Diecimila board. While the first test was successful, I was was not able to place the led more than an inch away from the phototransistor. To allow for more range I used an <a href="http://www.analog.com/en/other/militaryaerospace/ad620/products/product.html">AD620AN instrumentation amplifier</a> IC. For control I wired the gain pins of the amplifier into a small 10k potentiometer. After adjusting the gain I was able to get about a foot of range with reliable data transfer. Any further and there was too much noise in the signal.</p>
<p><a href="http://www.evansalazar.com/ohmpie/laserModem/parts.jpg"><img src="http://www.evansalazar.com/ohmpie/laserModem/parts_small.jpg" alt="" /></a></p>
<p>At this moment I wondered if I could use a laser to extend my range. I happened to have a small laser that I pulled from a cheap laser level. I pulled out the laser and wired it where the IR led was minus the resistor. I then pointed the laser at the phototransistor and noticed it instantly reacted. In fact I had to turn the gain on the amplifier way down to use the signal. To test my range I wired my ATMega168 to a 9v battery and mounted the laster in a small vise a few feet away. After adjusting the gain I was able to transmit data easily. Attached is a video along with the final schematic I used.</p>
<p><a href="http://www.evansalazar.com/ohmpie/laserModem/laserModem.png"><img src="http://www.evansalazar.com/ohmpie/laserModem/laserModem_small.jpg" alt="" /></a></p>
<p><a href="http://www.ohmpie.com/laserModemVideo"><br />
</a></p>
<h3><a href="http://www.ohmpie.com/laserModemVideo">View the Laser Modem Video Here</a></h3>
<p><a href="http://www.ohmpie.com/laserModemVideo"> </a></p>
<p><a href="http://www.ohmpie.com/laserModemVideo"></a></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/lasermodem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fractal Mountain Generation with Qt and OpenGL</title>
		<link>http://www.ohmpie.com/mountains/</link>
		<comments>http://www.ohmpie.com/mountains/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 04:29:08 +0000</pubDate>
		<dc:creator>esalazar</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dev.ohmpie.com/?p=53</guid>
		<description><![CDATA[The purpose of this project is to create 3d mountain terrain using a recursive midpoint displacement formula. For this project I decided a GUI would be useful, that way manipulations could be seen in real time. This would require a &#8230; <a href="http://www.ohmpie.com/mountains/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>The purpose of this project is to create 3d mountain terrain using a recursive midpoint displacement formula. For this project I decided a GUI would be useful, that way manipulations could be seen in real time.<span id="more-53"></span> This would require a 3d rendering package. My choices were DirectX, OpenGL and Java3d. Since I prefer to do my development in Linux, DirectX was ruled out. I have not been very impressed with the performance of Java3d so that left me with OpenGL. After deciding on my rendering package I needed to choose a language and a GUI framework. <a id="hgn8" title="GLUI" href="http://en.wikipedia.org/wiki/OpenGL_User_Interface_Library">GLUI</a> is an excellent framework for leaning OpenGL, but lacks control over the layout of the interface. So I decided on <a id="w7f9" title="QT" href="http://en.wikipedia.org/wiki/Qt_%28toolkit%29">QT</a> by Trolltech which was just recently acquired by Nokia.</p>
<p><strong>Midpoint Displacement Formula</strong></p>
<p>The midpoint Displacement Formula is simply to take two points, find the midpoint and then add or subtract a random number. This formula can then be repeated for each segment creating a fractal. This same concept can be converted to 3d in what is known as the <a id="ouag" title="Diamond-Square algorithm" href="http://en.wikipedia.org/wiki/Diamond-square_algorithm">Diamond-Square algorithm</a>. Instead of  two points we take a plane defined by four points, calculate the midpoint and add a random number. We can start with one large plane and perform the algorithm. Then divide the plane into four sub-planes and repeat. A <a id="dwp8" title="recursive function" href="http://en.wikipedia.org/wiki/Recursion">recursive function</a> works well for this task. For the mountains to look real, it is best to shorten the range of random numbers as the algorithm progresses. Below is the midpoint Function I wrote for this program in C++.<br />
<span style="color: #0000ff;">/*</span><span style="color: #0000ff;">***************************************</span><br />
<span style="color: #0000ff;"> *This is the recursive algorithm of the </span><br />
<span style="color: #0000ff;"> * midpoint formula </span><br />
<span style="color: #0000ff;"> ***************************************</span><span style="color: #0000ff;">*/</span><br />
<span style="color: #2e8b57;"><strong>int</strong></span> GenFractal::midpoint(<span style="color: #2e8b57;"><strong>int</strong></span> i,<span style="color: #2e8b57;"><strong>int</strong></span> start,<span style="color: #2e8b57;"><strong>int</strong></span> topx, <span style="color: #2e8b57;"><strong>int</strong></span> topy) {<br />
<span style="color: #0000ff;">//Base case</span><br />
<span style="color: #a52a2a;"><strong>if</strong></span>(i&lt;<span style="color: #ff00ff;">1</span>) {<br />
<span style="color: #a52a2a;"><strong>return</strong></span> <span style="color: #ff00ff;">0</span>;<br />
}</p>
<p><span style="color: #0000ff;">//find lenght for this section</span><br />
<span style="color: #2e8b57;"><strong>int</strong></span> len = (<span style="color: #2e8b57;"><strong>int</strong></span>)pow(<span style="color: #ff00ff;">2</span>,i);</p>
<p><span style="color: #0000ff;">//Calculate midpoints</span></p>
<p><span style="color: #0000ff;">//Top middle</span><br />
<span style="color: #2e8b57;"><strong>int</strong></span> x1 = topx + len/<span style="color: #ff00ff;">2</span>;<br />
<span style="color: #2e8b57;"><strong>int</strong></span> y1 = topy;</p>
<p><span style="color: #0000ff;">//Right middle</span><br />
<span style="color: #2e8b57;"><strong>int</strong></span> x2 = topx + len;<br />
<span style="color: #2e8b57;"><strong>int</strong></span> y2 = topy + len/<span style="color: #ff00ff;">2</span>;</p>
<p><span style="color: #0000ff;">//Bottom middle</span><br />
<span style="color: #2e8b57;"><strong>int</strong></span> x3 = x1;<br />
<span style="color: #2e8b57;"><strong>int</strong></span> y3 = y1 + len;</p>
<p><span style="color: #0000ff;">//Left Middle</span><br />
<span style="color: #2e8b57;"><strong>int</strong></span> x4 = x2 &#8211; len;<br />
<span style="color: #2e8b57;"><strong>int</strong></span> y4 = y2;</p>
<p><span style="color: #0000ff;">//Midpoint</span><br />
<span style="color: #2e8b57;"><strong>int</strong></span> xmid = x1;<br />
<span style="color: #2e8b57;"><strong>int</strong></span> ymid = y2;</p>
<p><span style="color: #0000ff;">//Calculate the values of the midpoints</span></p>
<p><span style="color: #0000ff;">//Top middle</span><br />
data[x1][y1] = data[topx][topy] +<br />
(data[topx+len][topy] &#8211; data[topx][topy])/<span style="color: #ff00ff;">2</span>;</p>
<p><span style="color: #0000ff;">//Right middle</span><br />
data[x2][y2] = data[topx+len][topy] +<br />
(data[topx+len][topy+len] &#8211; data[topx+len][topy])/<span style="color: #ff00ff;">2</span>;</p>
<p><span style="color: #0000ff;">//Bottom middle </span><br />
data[x3][y3] = data[topx][topy+len] +<br />
(data[topx+len][topy+len] &#8211; data[topx][topy+len])/<span style="color: #ff00ff;">2</span>;</p>
<p><span style="color: #0000ff;">//Left middle</span><br />
data[x4][y4] = data[topx][topy] +<br />
(data[topx][topy+len] &#8211; data[topx][topy])/<span style="color: #ff00ff;">2</span>;</p>
<p><span style="color: #0000ff;">//Midpoint</span><br />
data[xmid][ymid] = data[x1][y1] + (data[x3][y3] &#8211; data[x1][y1])/<span style="color: #ff00ff;">2</span>;</p>
<p><span style="color: #0000ff;">//Decrease the varence of randomness as iterations go foward</span><br />
<span style="color: #2e8b57;"><strong>float</strong></span> min = hmin * (((<span style="color: #2e8b57;"><strong>float</strong></span>)start &#8211; ((<span style="color: #2e8b57;"><strong>float</strong></span>)start &#8211; (<span style="color: #2e8b57;"><strong>float</strong></span>)i)) / (<span style="color: #2e8b57;"><strong>float</strong></span>)start);<br />
<span style="color: #2e8b57;"><strong>float</strong></span> max = hmax * (((<span style="color: #2e8b57;"><strong>float</strong></span>)start &#8211; ((<span style="color: #2e8b57;"><strong>float</strong></span>)start &#8211; (<span style="color: #2e8b57;"><strong>float</strong></span>)i)) / (<span style="color: #2e8b57;"><strong>float</strong></span>)start);<br />
<span style="color: #0000ff;">//Add random value to midpoint from hmin to hmax</span></p>
<p>data[xmid][ymid] +=  (<span style="color: #2e8b57;"><strong>int</strong></span>)(min + ((<span style="color: #2e8b57;"><strong>float</strong></span>)rand() / (<span style="color: #2e8b57;"><strong>float</strong></span>) <span style="color: #ff00ff;">RAND_MAX</span>) * (max &#8211; min));</p>
<p><span style="color: #0000ff;">//As mountians get larger add less varence of random data</span></p>
<p><span style="color: #0000ff;">//Decrease I</span><br />
i&#8211;;</p>
<p><span style="color: #0000ff;">//Recursive steps</span></p>
<p><span style="color: #0000ff;">//Upper left quadrant</span><br />
midpoint(i,start,topx,topy);</p>
<p><span style="color: #0000ff;">//Upper right quadrant</span><br />
midpoint(i,start,x1,y1);</p>
<p><span style="color: #0000ff;">//Lower left quadrant</span><br />
midpoint(i,start,x4, y4);</p>
<p><span style="color: #0000ff;">//Lower right quadrant</span><br />
midpoint(i,start,xmid,ymid);</p>
<p><span style="color: #a52a2a;"><strong>return</strong></span> <span style="color: #ff00ff;">0</span>;</p>
<p><strong>Building the Framework</strong><br />
For this project I decided on using QT4 with OpenGL. Since I am running Ubuntu, I used apt-get to install the QT4 development packages.</p>
<blockquote><p>sudo apt-get install libqt4-dev qt4-dev-tools qt4-designer qt4-doc</p></blockquote>
<p>For my development environment I chose the <a id="tgu3" title="Eclipse IDE for C/C++ Developers" href="http://www.eclipse.org/downloads/">Eclipse IDE for C/C++ Developers</a> with the <a id="qeli" title="QT Eclipse Integration Plugin" href="http://trolltech.com/developer/downloads/qt/eclipse-integration-download">QT Eclipse Integration Plugin</a>. This allows for rapid development of QT applications. I decided to use <a id="yc4_" title="CVS" href="http://en.wikipedia.org/wiki/Concurrent_Versions_System">CVS</a> for version control since it is easy to setup and is integrated into eclipse.</p>
<p><a href="http://www.evansalazar.com/ohmpie/mountains/eclipse.jpg"><img src="http://www.evansalazar.com/ohmpie/mountains/eclipse-small.jpg" alt="" /></a></p>
<p><strong>Building the Interface</strong><br />
I built the interface using the Qt4 designer. Below you can see a screen shot of my application&#8217;s layout.</p>
<p><a href="http://www.evansalazar.com/ohmpie/mountains/qtdesigner.jpg"><img src="http://www.evansalazar.com/ohmpie/mountains/qtdesigner-small.jpg" border="0" alt="" /></a><br />
<br style="font-weight: bold;" /></p>
<p><strong>Rendering</strong><br />
For OpenGL rendering I had to create a <a id="s20z" title="QGLWidget" href="http://doc.trolltech.com/4.2/qglwidget.html">QGLWidget</a> Class. Once the class is created you can then paint to this widget using regular OpenGL functions. My OpenGL skills are not nearly as good as I would like. I have a copy of the <a id="as5_" title="Red" href="http://www.opengl.org/documentation/red_book/">Red</a> and <a id="zo.:" title="Blue Book" href="http://www.opengl.org/documentation/blue_book/">Blue Book</a> which is enough information to get a rendering window, setup lighting and draw some polygons. For this project I converted the elevation map to triangles with the normals facing up and packed them into a GLfloat array. The polygons can be rendered with the following commands.</p>
<blockquote><p><span style="color: #0000ff;"> //Create array for triangles</span><br />
GLfloat * vert = fractal.getTriangles();<br />
<span style="color: #2e8b57;"><strong>int</strong></span> length = fractal.getNumTriangles();<br />
glEnableClientState(GL_VERTEX_ARRAY);<br />
glVertexPointer(<span style="color: #ff00ff;">3</span>,GL_FLOAT,<span style="color: #ff00ff;">0</span>,vert);</p>
<p>GLuint list = glGenLists(<span style="color: #ff00ff;">1</span>);<br />
glNewList(list, GL_COMPILE);</p>
<p><span style="color: #0000ff;">//Set Color</span><br />
<span style="color: #2e8b57;"><strong>float</strong></span> colorBlue[] = { <span style="color: #ff00ff;">1.0f</span>, <span style="color: #ff00ff;">0.5f</span>, <span style="color: #ff00ff;">0.0f</span>, <span style="color: #ff00ff;">0.0f</span> };<br />
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colorBlue);</p>
<p><span style="color: #0000ff;">//Draw the triangles from array</span><br />
glDrawArrays(GL_TRIANGLES,<span style="color: #ff00ff;">0</span>,length);</p>
<p>glEndList();</p></blockquote>
<p>This same data can then be used for my RAW triangles export by simply converting it to ASCII.<br />
<br style="font-weight: bold;" /><br />
<strong>Windows XP / Vista Port</strong><br />
After I had a satisfactory application I decided to try porting it to windows. This is so windows users can try this program without having to compile it. I simply download <a id="ipn5" title="QT for Windows" href="http://trolltech.com/developer/downloads/qt/windows">QT for Windows</a> with the <a id="homu" title="MinGW" href="http://www.mingw.org/">MinGW</a> GNU compiler and ran &#8216;qmake&#8217; and &#8216;make&#8217;. Thats was about all that was needed.</p>
<p><a href="http://www.evansalazar.com/ohmpie/mountains/mountains-vista.jpg"><img src="http://www.evansalazar.com/ohmpie/mountains/mountains-vista-small.jpg" border="0" alt="" /></a></p>
<p><a href="http://www.evansalazar.com/ohmpie/mountains/3dobjectconverter.jpg"><img src="http://www.evansalazar.com/ohmpie/mountains/3dobjectconverter-small.jpg" border="0" alt="" /></a></p>
<p><strong>Conclusion</strong></p>
<p>This turned out to be a very involved programming project for me. There is a saying that no software is ever finished. This project has really solidified that for me. There are still may improvements and features I would like to add. I am still not 100% satisfied with the terrain generation. I feel that I could use some improvements of my algorithm.</p>
<p><a href="http://www.evansalazar.com/ohmpie/mountains/mountains.jpg"><img src="http://www.evansalazar.com/ohmpie/mountains/mountains-small.jpg" border="0" alt="" /></a></p>
<p><strong>Download</strong><br />
Source Code Tarball: <a href="http://www.evansalazar.com/ohmpie/mountains/Mountains.Feb-4-2008.tar.gz">Mountains.Feb-4-2008.tar.gz</a></p>
<p>Source Code Zip: <a href="http://www.evansalazar.com/ohmpie/mountains/Mountains.Feb-4-2008.zip">Mountains.Feb-4-2008.zip</a></p>
<p>Win32 Binary: <a href="http://www.evansalazar.com/ohmpie/mountains/Mountains-win32.zip">Mountains-win32.zip</a></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/mountains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a packet sniffer to track games/applications phoning home, and how to block them via the routing table or the hosts file</title>
		<link>http://www.ohmpie.com/stopphoninghome/</link>
		<comments>http://www.ohmpie.com/stopphoninghome/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 06:11:13 +0000</pubDate>
		<dc:creator>tdavis</dc:creator>
				<category><![CDATA[Freedom]]></category>

		<guid isPermaLink="false">http://dev.ohmpie.com/?p=48</guid>
		<description><![CDATA[The other day I was trying to play an old game I bought some time ago on my LAN. I was just trying to enjoy a little cooperative bot killing fun with my buddy, but for some reason, the game &#8230; <a href="http://www.ohmpie.com/stopphoninghome/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>The other day I was trying to play an old game I bought some time ago on my LAN.  I was just trying to enjoy a little cooperative bot killing fun with my buddy, but for some reason, the game kept telling me my &#8216;master key&#8217; or something along those lines didn&#8217;t check out.  Needless to say I wasn&#8217;t happy with it&#8230; I bought this game&#8230; and maybe I wasn&#8217;t supposed to play it on two machines at once&#8230; but at the very least I certainly didn&#8217;t want it phoning home for a simple LAN game, a game mode where no master server or internet should be required.<br />
<span id="more-48"></span><br />
So I decided to see what my &#8216;game&#8217; was up to.  A quick download of <A HREF="http://www.wireshark.org">Wireshark</A> (formerly Ethereal) and an even quicker packet sniff and sure enough I could see where my &#8216;game&#8217; was initiating connections and across what port.  </p>
<p>After booting up wireshark, simply click on the &#8220;Capture&#8221; menu and select &#8220;Interfaces&#8230;&#8221; and from there it will show you a list of available ones to capture from.  Select your active connection (the one with an IP thats NOT your localhost (127.0.0.1)), and click start.  You should see something similar to this screenshot as Wireshark attempts to capture all the packets entering and leaving your machine.  </p>
<p><a><img src="http://lh4.google.com/tylerclaytondavis/R4RF7EhbwxI/AAAAAAAACb8/-tVk5h4PCfk/s800/wireshark3.JPG" /></a></p>
<p>If you&#8217;ve closed all your other connections (browsers, streaming music, etc.) you should now try to recreate the traffic you wish to sniff.  In my case this involves launching the game I want to play and trying to connect to a LAN game, with which I am promptly kicked back for failing to &#8216;check out&#8217; with the master server correctly.  Now exit the game and pull up Wireshark to see what it caught. </p>
<p><a><img src="http://lh4.google.com/tylerclaytondavis/R4Q-pEhbwuI/AAAAAAAACbg/QVC5j23nSVc/s800/wireshark1.JPG" /></a></p>
<p>In the interest of not angering anyone, I&#8217;ve obscured the specific IP and domain name that my machine is connecting to.  But for these purposes, it shouldn&#8217;t matter.  Notice there are numerous outbound and inbound packets originating from the IP 216.27.xx.xxx, and in the right hand column you can [almost] see that an actual domain name has also been found.  </p>
<p>This is where the windows &#8216;hosts&#8217; file comes into action.  The hosts file is a pretty simple file to deal with, usually located at c:/windows/system32/drivers/etc/hosts on xp machines (On most linux distributions a similar file is located at /etc/hosts).  Here is where you can redirect certain domains to other IPs for a variety of reasons.  In our case we want to redirect the server xxxxx.server1.xxxxx.com to the localhost, to prevent the game from phoning home.  </p>
<p><a><img src="http://lh4.google.com/tylerclaytondavis/R4RJNEhbwzI/AAAAAAAACcQ/p6tKSmOPObc/s800/hosts.JPG" /></a></p>
<p>In the screenshot above you&#8217;ll notice I&#8217;ve added a line to my hosts file to redirect the offending domain.  Now all outbound connections to xxxxx.server1.xxxxx.com will be redirected to the localhost, preventing any real connection from occurring between the two.  But what if there&#8217;s no domain name listed?   Then the hosts file will be fairly worthless to you, but there are a couple of possible alternatives.</p>
<p>First, try doing an &#8216;nslookup&#8217; on the IP that looks suspect, and see if you get a domain name to return, in most cases you probably won&#8217;t.  The next possible solution is to do a google search for the statistics, analytics or authentication server your program is trying to connect to.  In many cases google will know the answer already for you.  But if both of these methods fail, its time edit the routing table on your machine.</p>
<p>Bring up a [lame] windows command line, if you don&#8217;t know how simply click the &#8216;start&#8217; menu, select &#8216;run&#8230;&#8217; and type in &#8216;cmd.&#8217;  From here you can view and alter the routing table.  </p>
<p><a><img src="http://lh5.google.com/tylerclaytondavis/R4RutUhbw0I/AAAAAAAACcw/ejVCnFE5Ntg/s800/route1.JPG" /></a></p>
<p>Type &#8216;route print&#8217; at the command line and it should print out the routing table for you to like the screenshot above.  If at any point you wish to learn more about route just type in &#8216;route&#8217; by itself and it will print out detailed help.  What we want to do now is create a route for the offensive IP to be sent to the localhost.  In some cases this can be done by simply pointing the offending IP to 127.0.0.1, however in my case I had to point it to the actual local IP address of my machine (192.168.2.5) since there was already a route in place to direct traffic heading to 192.168.2.5 to the localhost at 127.0.0.1.</p>
<blockquote>
<p>
C:\Documents and Settings\Administrator>route print</p>
<p>IPv4 Route Table<br />
===========================================================================<br />
Interface List<br />
0&#215;1 &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230; MS TCP Loopback interface<br />
0&#215;2 &#8230;00 01 29 d2 2c 2b &#8230;&#8230; NVIDIA nForce Networking Controller &#8211; Packet Sch<br />
eduler Miniport<br />
0&#215;3 &#8230;00 01 29 d2 2c 2a &#8230;&#8230; Marvell Yukon 88E8001/8003/8010 PCI Gigabit Ethe<br />
rnet Controller &#8211; Packet Scheduler Miniport<br />
===========================================================================<br />
===========================================================================<br />
Active Routes:<br />
Network Destination        Netmask          Gateway       Interface  Metric<br />
          0.0.0.0          0.0.0.0      192.168.2.1      192.168.2.5     20<br />
        127.0.0.0        255.0.0.0        127.0.0.1        127.0.0.1      1<br />
      192.168.2.0    255.255.255.0      192.168.2.5      192.168.2.5     20<br />
      192.168.2.5  255.255.255.255        127.0.0.1        127.0.0.1     20<br />
    192.168.2.255  255.255.255.255      192.168.2.5      192.168.2.5     20<br />
        224.0.0.0        240.0.0.0      192.168.2.5      192.168.2.5     20<br />
  255.255.255.255  255.255.255.255      192.168.2.5      192.168.2.5      1<br />
  255.255.255.255  255.255.255.255      192.168.2.5                2      1<br />
Default Gateway:       192.168.2.1<br />
===========================================================================<br />
Persistent Routes:</p>
<p>C:\Documents and Settings\Administrator></p>
</blockquote>
<p>Use the &#8216;add&#8217; parameter to add a new route to your table like this (change destination and source IP accordingly)</p>
<blockquote>
<p>C:\Documents and Settings\Administrator>route add 216.27.xx.xxx 192.168.2.5<br />
C:\Documents and Settings\Administrator></p>
</blockquote>
<p><a><img src="http://lh4.google.com/tylerclaytondavis/R4Q-pEhbwtI/AAAAAAAACbY/I-_cNhYAMmE/s800/route2.JPG" /></a></p>
<p>You can also use the route command to change the route for entire subnets, but for my purposes its unnecessary, all I needed to do is redirect a specific IP.  </p>
<p>Now launch a new session of Wireshark and begin capturing.  Open up the offending game or application and test that it works (no longer phones home for any reason).  In my case I can see that a bunch of traffic formerly headed to that rouge IP is now heading to 192.168.2.5, which then heads to 127.0.0.1, and effectively gets nowhere.  </p>
<p><a><img src="http://lh4.google.com/tylerclaytondavis/R4RHZEhbwyI/AAAAAAAACcI/-FMwJF7u0bk/s800/wireshark2.JPG" /></a></p>
<p>Congratulations!  You&#8217;ve now stopped your game or application from &#8216;checking home.&#8217;  It should be noted that on many high end firewalls/routers, its possible to do similar things from within the router itself, but I&#8217;ve found that with most consumer level firewalls this still isn&#8217;t an option.  For instance, on my cheap Belkin I can restrict specific port ranges by internal IP, which would actually work fine for this particular problem, but is a less than perfect solution since it would block ALL traffic outbound on that specific port (a less than optimal solution if the application is using a standard port).  </p>
<p>In this day and age you can really never be too careful about privacy, more and more seemingly everyday games and applications religiously phone home your personal information about everything from your private browsing habits to your choice of music.  In my case, I&#8217;d like to keep them from finding that type of information out.  </p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/stopphoninghome/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	
	
	<!-- google ad injected by adsense-optimizer http://www.adsenseoptimizer.de -->
	<div  style="padding:7px; display: block; margin-left: auto; margin-right: auto; text-align: center;"><!-- Ad number: 3 --><script type="text/javascript"><!--
    	 
    	google_ad_client = "pub-7721485558976096"; google_alternate_color = "FFFFFF";
		google_ad_width = 468; google_ad_height = 60;
		google_ad_format = "468x60_as"; google_ad_type = "text_image";
		google_ad_channel =""; google_color_border = "336699";
		google_color_link = "0000FF"; google_color_bg = "FFFFFF";
		google_color_text = "000000"; google_color_url = "008000";
		google_ui_features = "rc:6"; //--></script>
		<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div>	<item>
		<title>Encoding an image to sound</title>
		<link>http://www.ohmpie.com/imageencode/</link>
		<comments>http://www.ohmpie.com/imageencode/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 03:36:05 +0000</pubDate>
		<dc:creator>esalazar</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dev.ohmpie.com/?p=44</guid>
		<description><![CDATA[The purpose of this project is to encode an image to a sound that can be viewed with a spectrogram. For some time I have known that musical artists have encoded pictures into their music. Most notable of these is &#8230; <a href="http://www.ohmpie.com/imageencode/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>The purpose of this project is to encode an image to a sound that can be viewed with a <a href="http://en.wikipedia.org/wiki/Spectrogram">spectrogram</a>. For some time I have known that musical artists have encoded pictures into their music. Most notable of these is artists is Aphex Twin. Luckily I had a copy of Windolicker and a great visualization program <a href="http://www.sonicvisualiser.org/">Sonic Visualiser</a>. After looking at the images I decided it would be cool to try and encode my own images. I saw a few programs available, but decided it would be a better challenge to write my own program from scratch using Perl.<br />
<span id="more-44"></span></p>
<p><strong>Spectrograms </strong></p>
<p>A spectrogram is a graph representing the intensity or a frequency with relation to time. Normally the frequencies are along the Y axis, with the time on the X axis. The intensity of the frequency is represented by the brightness of the color. The frequency and color can use either a linear scale or a logarithmic scale. Below is an spectrogram of a few piano chords. The audio file used can be found on Wikipedia <a href="http://upload.wikimedia.org/wikipedia/en/d/d7/Cmaj_min_inversions.ogg">here</a>.</p>
<p><a href="http://www.evansalazar.com/ohmpie/imageEncode/Cmaj_min.jpg"><img src="http://www.evansalazar.com/ohmpie/imageEncode/Cmaj_min_small.jpg" border="0" alt="" width="500" height="355" /></a></p>
<p><strong>Image encoding</strong></p>
<p>The idea I had to encode the image was to simply create a sine wave at a corresponding frequency to represent  the Y axis, a corresponding time to represent the X axis and a corresponding amplitude to represent the pixel color intensity.</p>
<p><strong>Creating Sound</strong></p>
<p>The first step to encoding an image was to learn how audio formats work. At first I tried writing a script that plays a frequency to the &#8216;/dev/dsp&#8217; (Which is the sound card on Linux). When writing straight to  /dev/dsp you are limited by a sample rate of 8000hz and a sample size of 8bits. Below simple Perl script that plays a concert A 440hz. To execute run &#8216;./sin.pl &gt; /dev/dsp&#8217;.</p>
<blockquote><p><span style="font-family: monospace;"><br />
<span style="color: #a020f0;">#!/usr/bin/perl</span><br />
<span style="color: #a52a2a;"><strong>use </strong></span>Math::Trig;<br />
<span style="color: #a52a2a;"><strong>use strict</strong></span>;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>POSIX;</span></p>
<p><span style="font-family: monospace;"><span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$sample</span> = <span style="color: #ff00ff;">8000</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$frequency</span> = <span style="color: #ff00ff;">440</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$cycles</span> = <span style="color: #ff00ff;">6</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$period</span> = POSIX::floor(<span style="color: #008b8b;">$sample</span> / <span style="color: #008b8b;">$frequency</span> * <span style="color: #008b8b;">$cycles</span>);</span></p>
<p><span style="font-family: monospace;"><span style="color: #a52a2a;"><strong>while</strong></span> (<span style="color: #ff00ff;">1</span>) {<br />
<span style="color: #a52a2a;"><strong>for</strong></span>(<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$i</span>=<span style="color: #ff00ff;">1</span>;<span style="color: #008b8b;">$i</span>&lt;=<span style="color: #008b8b;">$period</span>;<span style="color: #008b8b;">$i</span>++)<br />
{<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$x</span> = <span style="color: #ff00ff;">128</span> + <span style="color: #a52a2a;"><strong>sin</strong></span>(<span style="color: #008b8b;">$cycles</span> * <span style="color: #ff00ff;">2</span> * pi * <span style="color: #008b8b;">$i</span> / <span style="color: #008b8b;">$period</span>) * <span style="color: #ff00ff;">128</span>;<br />
<span style="color: #008b8b;">$x</span> = POSIX::floor(<span style="color: #008b8b;">$x</span>);<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$char</span> = <span style="color: #a52a2a;"><strong>pack</strong></span>(<span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">C</span><span style="color: #ff00ff;">&#8220;</span>,<span style="color: #008b8b;">$x</span>);<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #008b8b;">$char</span> color=&#8221;#ff00ff&#8221;&gt;&#8221;</span>;<br />
}<br />
}</p></blockquote>
<p>The DSP defaults do not offer much fidelity I needed at least the fidelity of an audio CD, which is 16bits at  44.1khz. I did some of searching on CPAN to find a library that allowed me write wave files.  Most of the audio libraries had a too much overhead for what I wanted to do. Instead <a href="http://ccrma.stanford.edu/courses/422/projects/WaveFormat/">I looked up the file format for a &#8216;.wav&#8217;</a> and coded my own library. This library is limited to only producing a 16bit 44.1khz mono wave.</p>
<blockquote><p><span style="font-family: monospace;"><br />
<span style="color: #a020f0;">#!/usr/bin/perl</span><br />
<span style="color: #0000ff;">#Author Evan Salazar</span><br />
<span style="color: #0000ff;">#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span><br />
<span style="color: #0000ff;">#</span><br />
<span style="color: #0000ff;">#Generate a .wav file for 16 bit mono PCM</span><br />
<span style="color: #0000ff;">#</span><br />
<span style="color: #0000ff;">#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span><br />
<span style="color: #a52a2a;"><strong>use strict</strong></span>;<br />
<span style="color: #a52a2a;"><strong>package</strong></span><span style="color: #2e8b57;"><strong> SimpleWave;</strong></span></span></p>
<p><span style="font-family: monospace;"><span style="color: #a52a2a;"><strong>sub</strong></span><span style="color: #008b8b;"> </span><span style="color: #008b8b;">genWave</span><span style="color: #008b8b;"> </span>{</span></p>
<p><span style="color: #0000ff;">#Get the reference to the data array</span></p>
<p><span style="color: #a52a2a;"><strong>my</strong></span> (<span style="color: #008b8b;">$audioData</span>) = <span style="color: #008b8b;">@_</span>;</p>
<p><span style="color: #0000ff;">#This is the default sample rate</span><br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$samplerate</span> = <span style="color: #ff00ff;">44100</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$bits</span> = <span style="color: #ff00ff;">16</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$samples</span> = <span style="color: #008b8b;">$#</span>{<span style="color: #008b8b;">$audioData</span>} + <span style="color: #ff00ff;">1</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$channels</span> = <span style="color: #ff00ff;">1</span>;</p>
<p><span style="color: #0000ff;">#Do Calculations for data wave headers</span><br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$byterate</span> = <span style="color: #008b8b;">$samplerate</span> * <span style="color: #008b8b;">$channels</span> * <span style="color: #008b8b;">$bits</span> / <span style="color: #ff00ff;">8</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$blockalign</span> = <span style="color: #008b8b;">$channels</span> * <span style="color: #008b8b;">$bits</span> / <span style="color: #ff00ff;">8</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$filesize</span> = <span style="color: #008b8b;">$samples</span> * (<span style="color: #008b8b;">$bits</span>/<span style="color: #ff00ff;">8</span>) * <span style="color: #008b8b;">$channels</span> + <span style="color: #ff00ff;">36</span>;</p>
<p><span style="color: #0000ff;">#RIFF Chunk;</span><br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$riff</span> = <span style="color: #a52a2a;"><strong>pack</strong></span>(<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">a4Va4</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">RIFF</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #008b8b;">$filesize</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">WAVE</span><span style="color: #ff00ff;">&#8216;</span>);</p>
<p><span style="color: #0000ff;">#Format Chunk</span><br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$format</span> = <span style="color: #a52a2a;"><strong>pack</strong></span>(<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">a4VvvVVvv</span><span style="color: #ff00ff;">&#8216;</span>,<br />
<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">fmt </span><span style="color: #ff00ff;">&#8216;</span>,<br />
<span style="color: #ff00ff;">16</span>,<span style="color: #ff00ff;">1</span>,<br />
<span style="color: #008b8b;">$channels</span>,<br />
<span style="color: #008b8b;">$samplerate</span>,<br />
<span style="color: #008b8b;">$byterate</span>,<br />
<span style="color: #008b8b;">$blockalign</span>,<br />
<span style="color: #008b8b;">$bits</span>);</p>
<p><span style="color: #0000ff;">#Data Chunk</span><br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$dataChunk</span> = <span style="color: #a52a2a;"><strong>pack</strong></span>(<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">a4V</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">data</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #008b8b;">$blockalign</span> * <span style="color: #008b8b;">$samples</span>);</p>
<p><span style="font-family: monospace;"><span style="color: #0000ff;">#Read audoData array</span><br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$data</span>;<br />
<span style="color: #a52a2a;"><strong>for</strong></span>(<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$i</span>=<span style="color: #ff00ff;">0</span>;<span style="color: #008b8b;">$i</span>&lt;<span style="color: #008b8b;">$samples</span>;<span style="color: #008b8b;">$i</span>++) {</span></p>
<p><span style="color: #008b8b;">$data</span> .= <span style="color: #a52a2a;"><strong>pack</strong></span>(<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">v</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #008b8b;">$audioData</span>-&gt;[<span style="color: #008b8b;">$i</span>]);<br />
}</p>
<p><span style="color: #0000ff;">#Return a byte string of the wave</span><br />
<span style="color: #a52a2a;"><strong>return</strong></span> <span style="color: #008b8b;">$riff</span> . <span style="color: #008b8b;">$format</span> . <span style="color: #008b8b;">$dataChunk</span>. <span style="color: #008b8b;">$data</span>;<br />
}<br />
<span style="color: #ff00ff;">1</span>;</p></blockquote>
<p><strong>Reading a Bitmap</strong></p>
<p>Luckily I found a simple bitmap reader on CPAN called <a href="http://search.cpan.org/~daveola/Image-BMP-1.15/lib/Image/BMP.pm">Image::BMP</a>. This is a nice lightweight library that dose not depend on any external libraries or compiled code. Using this library I was able to easily load and read the bitmap data.</p>
<p><strong>Encoding the Image</strong></p>
<p>The first pass of my program disregarded the color data and only produced a frequency for the Y axis if the color intensity was less that half the sum of all colors. Below is an example. Note: I converted the WAV to an MP3 to conserve bandwidth, at 320kbps not much data is lost.</p>
<p><a href="http://www.evansalazar.com/ohmpie/imageEncode/audioOhmpie.jpg"><img src="http://www.evansalazar.com/ohmpie/imageEncode/audioOhmpie_small.jpg" border="0" alt="" /></a></p>
<p><a href="http://www.evansalazar.com/ohmpie/imageEncode/ohmpie.mp3">Audio File: ohmpie.mp3</a></p>
<p>I was really shocked to fist see the image! The only tweaking I needed to do was to use a linear scale for the frequency. Also if I selected too high an amplitude for the sin wave, clipping occurred in areas with too much black. For image above I used an amplitude of about 1000 on a scale of 0 to 32768.</p>
<p>The next step was to add amplitude scaling to match the color intensity. For this I summed all the color channels for a given pixel and scaled it to represent the max amplitude &#8216;(R + G + B) / 768 * max_amplitude&#8217;. Below is a picture of me after using the scaling.</p>
<p><a href="http://www.evansalazar.com/ohmpie/imageEncode/evan_spec.jpg"><img src="http://www.evansalazar.com/ohmpie/imageEncode/evan_spec_small.jpg" border="0" alt="" /></a><br />
<a href="http://www.evansalazar.com/ohmpie/imageEncode/evan.mp3">Audio File: evan.mp3</a></p>
<p>By selecting a color scheme that goes from black to white and using a linear scale for the volume I get a very good black and white image. To prevent clipping on very dark images I added an inverse option that will invert the color producing a negative image.</p>
<p><a href="http://www.evansalazar.com/ohmpie/imageEncode/evanInv_spec1.jpg"><img src="http://www.evansalazar.com/ohmpie/imageEncode/evanInv_spec1_small.jpg" border="0" alt="" /></a></p>
<p><a href="http://www.evansalazar.com/ohmpie/imageEncode/evanInv.mp3">Audo File: evanInv.mp3</a></p>
<p>You can reverse the color scheme to go from white to black to produce the regular image</p>
<p><a href="http://www.evansalazar.com/ohmpie/imageEncode/evanInv_spec2.jpg"><img src="http://www.evansalazar.com/ohmpie/imageEncode/evanInv_spec2_small.jpg" border="0" alt="" /></a></p>
<p><strong>Full Program</strong></p>
<p>Below you can view and/or download the full code to this program. Currently performance is not optimized. So don&#8217;t write me telling me its slow. I currently have a few idea to speed it up. Also for best results use a small image around 100px tall.</p>
<p><a href="http://www.evansalazar.com/ohmpie/imageEncode/imageEncode-0.7.tar.gz">Download: imageEncode-0.7.tar.gz</a></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/imageencode/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
<enclosure url="http://upload.wikimedia.org/wikipedia/en/d/d7/Cmaj_min_inversions.ogg" length="0" type="audio/ogg" />
<enclosure url="http://www.evansalazar.com/ohmpie/imageEncode/ohmpie.mp3" length="386611" type="audio/mpeg" />
<enclosure url="http://www.evansalazar.com/ohmpie/imageEncode/evan.mp3" length="336456" type="audio/mpeg" />
<enclosure url="http://www.evansalazar.com/ohmpie/imageEncode/evanInv.mp3" length="336456" type="audio/mpeg" />
		</item>
		<item>
		<title>Class Serialization in Perl</title>
		<link>http://www.ohmpie.com/serialization/</link>
		<comments>http://www.ohmpie.com/serialization/#comments</comments>
		<pubDate>Fri, 28 Dec 2007 01:15:02 +0000</pubDate>
		<dc:creator>esalazar</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dev.ohmpie.com/?p=41</guid>
		<description><![CDATA[Serialization in Perl is the process of saving a class with multiple data types to a scalar (string of bytes). This can be used to save objects to a file or to transmit objects across the Internet. For this article &#8230; <a href="http://www.ohmpie.com/serialization/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p><a href="http://en.wikipedia.org/wiki/Serialization">Serialization</a> in Perl is the process of saving a class with multiple data types to a scalar (string of bytes). This can be used to save objects to a file or to transmit objects across the Internet. For this article I am going to describe the basics of creating a class in Perl and serialize it using the following packages: Data::Dumper, FreezeThaw, PHP::Serialization, and XML::Dumper.<br />
<span id="more-41"></span></p>
<p><strong>Data types in Perl</strong></p>
<p>Before we serialize anything we first need to learn a bit about the data types in Perl. There are only three data types in Perl, these are scalars, arrays and hash tables. Below is an example of each.</p>
<blockquote><p><span style="color: #008b8b;">$myScalar</span> = <span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">This is a Scalar</span><span style="color: #ff00ff;">&#8216;</span>;<br />
<span style="color: #008b8b;">@myArray</span> = (<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">Element zero</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">Element one</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">Element Two</span><span style="color: #ff00ff;">&#8216;</span>);<br />
<span style="color: #008b8b;">%myHash</span> = ( <span style="color: #ff00ff;">keyOne </span>=&gt; <span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">Data1</span><span style="color: #ff00ff;">&#8216;</span>, <span style="color: #ff00ff;">keyTwo </span>=&gt; <span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">Data2</span><span style="color: #ff00ff;">&#8216;</span>);</p>
<p><span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Scalar Data: </span><span style="color: #ff00ff;">&#8220;</span> . <span style="color: #008b8b;">$myScalar</span> . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Array element at index 1: </span><span style="color: #ff00ff;">&#8220;</span> . <span style="color: #008b8b;">@myArray</span>[<span style="color: #ff00ff;">1</span>] . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Hash at KeyOne: </span><span style="color: #ff00ff;">&#8220;</span> . <span style="color: #008b8b;">$myHash</span>{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">keyOne</span><span style="color: #ff00ff;">&#8216;</span>} . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;</p></blockquote>
<p>Output:</p>
<blockquote>
<pre>Scalar Data: This is a Scalar
Array element at index 1: Element one
Hash at KeyOne: Data1</pre>
</blockquote>
<p>Like in C and C++, you can also have references to the data in each data type. The reference is not the data its self, but a location where the data can be found. By using special syntax the data can be retrieved from the reference itself.</p>
<blockquote><p><span style="color: #008b8b;">$scalarReference</span> = <span style="color: #008b8b;">\$myScalar</span>;<br />
<span style="color: #008b8b;">$arrayReference</span> = <span style="color: #008b8b;">\@myArray</span>;<br />
<span style="color: #008b8b;">$hashReference</span> = <span style="color: #008b8b;">\%myHash</span>;</p>
<p><span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Scalar Reference: </span><span style="color: #008b8b;">$scalarReference</span><span style="color: #ff00ff;"> </span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Array Reference: </span><span style="color: #008b8b;">$arrayReference</span><span style="color: #ff00ff;"> </span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Hash Reference: </span><span style="color: #008b8b;">$hashReference</span><span style="color: #ff00ff;"> </span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;</p>
<p><span style="color: #0000ff;">#Different ways to print the referenced data</span></p>
<p><span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Scalar Data: </span><span style="color: #ff00ff;">&#8220;</span> . ${<span style="color: #008b8b;">$scalarReference</span>} . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>; <span style="color: #0000ff;">#Or</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Scalar Data: </span><span style="color: #ff00ff;">&#8220;</span> . <span style="color: #008b8b;">$$scalarReference</span> . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;</p>
<p><span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Array element at index 1: </span><span style="color: #ff00ff;">&#8220;</span> . @{<span style="color: #008b8b;">$arrayReference</span>}[<span style="color: #ff00ff;">1</span>] . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>; <span style="color: #0000ff;">#Or</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Array element at index 1: </span><span style="color: #ff00ff;">&#8220;</span> . <span style="color: #008b8b;">@$arrayReference</span>[<span style="color: #ff00ff;">1</span>] . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;   <span style="color: #0000ff;">#Or</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Array element at index 1: </span><span style="color: #ff00ff;">&#8220;</span> . <span style="color: #008b8b;">$arrayReference</span>-&gt;[<span style="color: #ff00ff;">1</span>] . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;</p>
<p><span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Hash at KeyOne: </span><span style="color: #ff00ff;">&#8220;</span> . ${<span style="color: #008b8b;">$hashReference</span>}{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">keyOne</span><span style="color: #ff00ff;">&#8216;</span>} . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;  <span style="color: #0000ff;">#Or</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Hash at KeyOne: </span><span style="color: #ff00ff;">&#8220;</span> . <span style="color: #008b8b;">$hashReference</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">keyOne</span><span style="color: #ff00ff;">&#8216;</span>} . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;</p></blockquote>
<p>Output:</p>
<blockquote>
<pre>Scalar Reference: SCALAR(0x8153600)
Array Reference:  ARRAY(0x8153630)
Hash Reference:   HASH(0x8153690)
Scalar Data: This is a Scalar
Scalar Data: This is a Scalar
Array element at index 1: Element one
Array element at index 1: Element one
Array element at index 1: Element one
Hash at KeyOne: Data1
Hash at KeyOne: Data1</pre>
</blockquote>
<p><strong>Classes in Perl</strong></p>
<p>Perl was not originally designed to be an object oriented language, although it is possible to use it as one by using the following techniques. A class in Perl is basically just a module that returns a reference to a hash containing the data that is accessible to the class. This referenced is then “blessed” which means that it is bounded to the module. Perl uses some syntactical sugar to make this processes easy. Below is a test class in Perl that uses each of the data types. This class was created to test the serialization of each package.</p>
<blockquote><p><span style="color: #a020f0;">#!/usr/bin/perl</span><br />
<span style="color: #0000ff;">#####################################################</span><br />
<span style="color: #0000ff;">#Author:Evan Salazar</span><br />
<span style="color: #0000ff;">#This is a just a simple perl class that uses</span><br />
<span style="color: #0000ff;">#different data types to be used in serialization</span><br />
<span style="color: #0000ff;">#####################################################</span><br />
<span style="color: #a52a2a;"><strong>package</strong></span><span style="color: #2e8b57;"><strong> TestClass;</strong></span><br />
<span style="color: #a52a2a;"><strong>use strict</strong></span>; <span style="color: #0000ff;">#Normally use to keep data clean</span></p>
<p><span style="color: #0000ff;">#The Constructor </span><br />
<span style="color: #a52a2a;"><strong>sub</strong></span><span style="color: #008b8b;"> </span><span style="color: #008b8b;">new</span><span style="color: #008b8b;"> </span>{<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Creating the Class </span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;</p>
<p><span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$obj</span> = {<br />
<span style="color: #ff00ff;">name </span>=&gt; {<span style="color: #ff00ff;">firstName </span>=&gt; <span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">none</span><span style="color: #ff00ff;">&#8216;</span>, <span style="color: #ff00ff;">lastName </span>=&gt; <span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">none</span><span style="color: #ff00ff;">&#8216;</span>}, <span style="color: #0000ff;">#Test Hash </span><br />
<span style="color: #ff00ff;">email </span>=&gt; <span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">none@none.com</span><span style="color: #ff00ff;">&#8216;</span>, <span style="color: #0000ff;">#Test Scalar </span><br />
<span style="color: #ff00ff;">skills </span>=&gt; <span style="color: #a52a2a;"><strong>undef</strong></span>,         <span style="color: #0000ff;">#Test array</span><br />
<span style="color: #ff00ff;">gpgKey </span>=&gt; <span style="color: #ff00ff;">&#8221;</span> };                  <span style="color: #0000ff;">#Binary Data</span><br />
<span style="color: #a52a2a;"><strong>bless</strong></span>(<span style="color: #008b8b;">$obj</span>);</p>
<p><span style="color: #a52a2a;"><strong>return</strong></span> <span style="color: #008b8b;">$obj</span>;</p>
<p>}</p>
<p><span style="color: #0000ff;">#Set the Contact Name</span><br />
<span style="color: #a52a2a;"><strong>sub</strong></span><span style="color: #008b8b;"> </span><span style="color: #008b8b;">setName</span><span style="color: #008b8b;"> </span>{<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$self</span> = <span style="color: #a52a2a;"><strong>shift</strong></span>;<br />
<span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">name</span><span style="color: #ff00ff;">&#8216;</span>}-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">firstName</span><span style="color: #ff00ff;">&#8216;</span>} = <span style="color: #008b8b;">$_</span>[<span style="color: #ff00ff;">0</span>];<br />
<span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">name</span><span style="color: #ff00ff;">&#8216;</span>}-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">lastName</span><span style="color: #ff00ff;">&#8216;</span>} = <span style="color: #008b8b;">$_</span>[<span style="color: #ff00ff;">1</span>];<br />
}</p>
<p><span style="color: #0000ff;">#Set the E-Mail</span><br />
<span style="color: #a52a2a;"><strong>sub</strong></span><span style="color: #008b8b;"> </span><span style="color: #008b8b;">setEmail</span><span style="color: #008b8b;"> </span>{<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$self</span> = <span style="color: #a52a2a;"><strong>shift</strong></span>;<br />
<span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">email</span><span style="color: #ff00ff;">&#8216;</span>} = <span style="color: #008b8b;">$_</span>[<span style="color: #ff00ff;">0</span>];<br />
}</p>
<p><span style="color: #0000ff;">#Set the Skills</span><br />
<span style="color: #a52a2a;"><strong>sub</strong></span><span style="color: #008b8b;"> </span><span style="color: #008b8b;">setSkills</span><span style="color: #008b8b;"> </span>{<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$self</span> = <span style="color: #a52a2a;"><strong>shift</strong></span>;<br />
<span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">skills</span><span style="color: #ff00ff;">&#8216;</span>} = <span style="color: #008b8b;">\@_</span>;<br />
}</p>
<p><span style="color: #0000ff;">#Set the GPG Key</span><br />
<span style="color: #a52a2a;"><strong>sub</strong></span><span style="color: #008b8b;"> </span><span style="color: #008b8b;">setGpgKey</span><span style="color: #008b8b;"> </span>{<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$self</span> = <span style="color: #a52a2a;"><strong>shift</strong></span>;<br />
<span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">gpgKey</span><span style="color: #ff00ff;">&#8216;</span>} = <span style="color: #008b8b;">$_</span>[<span style="color: #ff00ff;">0</span>];<br />
}</p>
<p><span style="color: #0000ff;">#Print all of the class Data</span><br />
<span style="color: #a52a2a;"><strong>sub</strong></span><span style="color: #008b8b;"> </span><span style="color: #008b8b;">printAll</span><span style="color: #008b8b;"> </span>{</p>
<p><span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$self</span> = <span style="color: #a52a2a;"><strong>shift</strong></span>;</p>
<p><span style="color: #0000ff;">#Print Full Name</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Name: </span><span style="color: #ff00ff;">&#8220;</span> .<br />
<span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">name</span><span style="color: #ff00ff;">&#8216;</span>}-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">firstName</span><span style="color: #ff00ff;">&#8216;</span>} .<br />
<span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;"> </span><span style="color: #ff00ff;">&#8220;</span> .<br />
<span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">name</span><span style="color: #ff00ff;">&#8216;</span>}-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">firstName</span><span style="color: #ff00ff;">&#8216;</span>} . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #0000ff;">#Print E-Mail</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">E-Mail: </span><span style="color: #ff00ff;">&#8220;</span> . <span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">email</span><span style="color: #ff00ff;">&#8216;</span>} . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;</p>
<p><span style="color: #0000ff;">#Print Skills</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Skills: </span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>for</strong></span>(<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$i</span>=<span style="color: #ff00ff;">0</span>;<span style="color: #008b8b;">$i</span>&lt;=<span style="color: #008b8b;">$#</span>{<span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">skills</span><span style="color: #ff00ff;">&#8216;</span>}};<span style="color: #008b8b;">$i</span>++) {<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">skills</span><span style="color: #ff00ff;">&#8216;</span>}[<span style="color: #008b8b;">$i</span>] . <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;"> </span><span style="color: #ff00ff;">&#8220;</span>;<br />
}<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">GPG Key: </span><span style="color: #ff00ff;">&#8220;</span> . <span style="color: #a52a2a;"><strong>unpack</strong></span>(<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">H*</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #008b8b;">$self</span>-&gt;{<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">gpgKey</span><span style="color: #ff00ff;">&#8216;</span>}) . <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span></p>
<p>}</p>
<p><span style="color: #ff00ff;">1</span>;</p></blockquote>
<p><strong>Perl Serialization Methods</strong></p>
<p>There is no built in serialization in Perl, therefor serialization has to be done with an external package. After searching <a href="http://www.cpan.org/">CPAN</a> I found the following packages.</p>
<ul>
<li><a href="http://search.cpan.org/~ilyam/Data-Dumper-2.121/Dumper.pm">Data::Dumper</a> &#8211; Serialize data into Perl code that can then be unserialized  using the eval() procedure.</li>
<li><a href="http://search.cpan.org/~ilyaz/FreezeThaw-0.43/FreezeThaw.pm">FreezeThaw</a> &#8211; Converts objects to a string for data storage and retrieval.</li>
<li><a href="http://search.cpan.org/~jbrown/PHP-Serialization-0.27/lib/PHP/Serialization.pm">PHP::Serialization</a> &#8211; Serialize using a method that is compatible with the serialize() method in PHP.</li>
<li><a href="http://search.cpan.org/~mikewong/XML-Dumper-0.81/Dumper.pm">XML::Dumper</a> &#8211; Serialize to XML. Does not work with binary data.</li>
</ul>
<p>These packages can be installed by downloading the source code and compiling or by using the following &#8216;cpan&#8217; commands.</p>
<blockquote>
<pre>sudo cpan install Data::Dumper
sudo cpan install FreezeThaw
sudo cpan install PHP::Serialization
sudo cpan install XML::Dumper</pre>
</blockquote>
<p><strong>Serializing  TestClass</strong></p>
<p>Below is a program that will serialize TestClass initialized with some sample data. The data will be serialized using all 4 classes.</p>
<blockquote><p><span style="color: #a020f0;">#!/usr/bin/perl</span><br />
<span style="color: #0000ff;">#####################################################</span><br />
<span style="color: #0000ff;">#Author: Evan Salazar</span><br />
<span style="color: #0000ff;">#Serialize The data in TestClass</span><br />
<span style="color: #0000ff;">#####################################################</span><br />
<span style="color: #a52a2a;"><strong>use strict</strong></span>;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>Storable;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>PHP::Serialization;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>FreezeThaw;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>TestClass;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>XML::Dumper;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>Data::Dumper;</p>
<p><span style="color: #0000ff;">#Create the New Test Class</span><br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$myclass</span> = TestClass::<span style="color: #a52a2a;"><strong>new</strong></span>();</p>
<p><span style="color: #0000ff;">#Fill the Test Class with data</span><br />
<span style="color: #008b8b;">$myclass</span>-&gt;setName(<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">Evan</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">Salazar</span><span style="color: #ff00ff;">&#8216;</span>);<br />
<span style="color: #008b8b;">$myclass</span>-&gt;setEmail(<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">esalazar1981@gmail.com</span><span style="color: #ff00ff;">&#8216;</span>);<br />
<span style="color: #008b8b;">$myclass</span>-&gt;setSkills(<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">Perl</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">PHP</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">Java</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">C</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">C++</span><span style="color: #ff00ff;">&#8216;</span>);<br />
<span style="color: #0000ff;">#&#8212;&#8211;Comment out to use XML::Dumper&#8212;&#8212;&#8212;&#8212;&#8211;# </span><br />
<span style="color: #008b8b;">$myclass</span>-&gt;setGpgKey(<span style="color: #a52a2a;"><strong>pack</strong></span>(<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">H*</span><span style="color: #ff00ff;">&#8216;</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">11061398fe828dcd83a4b9a79594c399</span><span style="color: #ff00ff;">&#8216;</span>)); <span style="color: #0000ff;">#Not really my key but 128bits of random data</span></p>
<p><span style="color: #0000ff;">#Open File for wrting Serialized Data</span><br />
<span style="color: #a52a2a;"><strong>open</strong></span>(<span style="color: #008b8b;">PHPSER</span>,    <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">&gt;phpser</span><span style="color: #ff00ff;">&#8220;</span>);<br />
<span style="color: #a52a2a;"><strong>open</strong></span>(<span style="color: #008b8b;">FREEZETHAW</span>, <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">&gt;freezeThaw</span><span style="color: #ff00ff;">&#8220;</span>);<br />
<span style="color: #a52a2a;"><strong>open</strong></span>(<span style="color: #008b8b;">XMLDUMPER</span>, <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">&gt;xmldumper.xml</span><span style="color: #ff00ff;">&#8220;</span>);<br />
<span style="color: #a52a2a;"><strong>open</strong></span>(<span style="color: #008b8b;">DATADUMPER</span>, <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">&gt;dataDumper.pl</span><span style="color: #ff00ff;">&#8220;</span>);</p>
<p><span style="color: #0000ff;">#Serialize Using Data::Dumper</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Data::Dumper</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #008b8b;">DATADUMPER</span> Data::Dumper::Dumper(<span style="color: #008b8b;">$myclass</span>);</p>
<p><span style="color: #0000ff;">#Serialize Using FreezeThaw</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">FreezeThaw</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #008b8b;">FREEZETHAW</span> FreezeThaw::freeze(<span style="color: #008b8b;">$myclass</span>);</p>
<p><span style="color: #0000ff;">#Serialize Using PHP::Serialization</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">PHP::Serializatoin</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #008b8b;">PHPSER</span> PHP::Serialization::serialize(<span style="color: #008b8b;">$myclass</span>);</p>
<p><span style="color: #0000ff;">#Serialize Using XML::Dumper</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">XML::Dumper</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$dump</span> = <span style="color: #a52a2a;"><strong>new</strong></span> XML::Dumper;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #008b8b;">XMLDUMPER</span> <span style="color: #008b8b;">$dump</span>-&gt;pl2xml(<span style="color: #008b8b;">$myclass</span>);</p></blockquote>
<p>This is the output from each method:</p>
<p>dataDumper.pl</p>
<blockquote><p>&lt;br /&gt; $VAR1 = bless( {&lt;br /&gt;                  &#8216;email&#8217; =&gt; &#8216;esalazar1981@gmail.com&#8217;,&lt;br /&gt;                  &#8216;skills&#8217; =&gt; [&lt;br /&gt;                                'Perl',&lt;br /&gt;                                'PHP',&lt;br /&gt;                                'Java',&lt;br /&gt;                                'C',&lt;br /&gt;                                'C++'&lt;br /&gt;                              ],&lt;br /&gt;                  &#8216;name&#8217; =&gt; {&lt;br /&gt;                              &#8216;firstName&#8217; =&gt; &#8216;Evan&#8217;,&lt;br /&gt;                              &#8216;lastName&#8217; =&gt; &#8216;Salazar&#8217;&lt;br /&gt;                            },&lt;br /&gt;                  &#8216;gpgKey&#8217; =&gt; &#8216;���������Ù&#8217;&lt;br /&gt;                }, &#8216;TestClass&#8217; );&lt;br /&gt;</p></blockquote>
<p>FreezeThaw</p>
<blockquote><p>&lt;br /&gt; FrT;@1|&gt;&gt;0|$9|TestClass%8|$5|email$6|gpgKey$4|name$6|skills$22|esalazar1981@gmail.com$16|���������Ù%4|$9|firstName$8|lastName$4|Evan$7|Salazar@5|$4|Perl$3|PHP$4|Java$1|C$3|C++&lt;br /&gt;</p></blockquote>
<p>phpser</p>
<blockquote><p>&lt;br /&gt; O:9:&#8221;TestClass&#8221;:4:{s:5:&#8221;email&#8221;;s:22:&#8221;esalazar1981@gmail.com&#8221;;s:6:&#8221;skills&#8221;;a:5:{i:0;s:4:&#8221;Perl&#8221;;i:1;s:3:&#8221;PHP&#8221;;i:2;s:4:&#8221;Java&#8221;;i:3;s:1:&#8221;C&#8221;;i:4;s:3:&#8221;C++&#8221;;}s:4:&#8221;name&#8221;;a:2:{s:9:&#8221;firstName&#8221;;s:4:&#8221;Evan&#8221;;s:8:&#8221;lastName&#8221;;s:7:&#8221;Salazar&#8221;;}s:6:&#8221;gpgKey&#8221;;s:16:&#8221;���������Ù&#8221;;}&lt;br /&gt;</p></blockquote>
<p>xmldumper.xml</p>
<blockquote><p>&lt;/p&gt; &lt;perldata&gt;  &lt;hashref blessed_package=&#8221;TestClass&#8221; memory_address=&#8221;0x8314de4&#8243;&gt;&lt;br /&gt;   &lt;item key=&#8221;email&#8221;&gt;esalazar1981@gmail.com&lt;/item&gt;&lt;br /&gt;   &lt;item key=&#8221;gpgKey&#8221;&gt;���������Ù&lt;/item&gt;&lt;br /&gt;   &lt;item key=&#8221;name&#8221;&gt;&lt;br /&gt;    &lt;hashref memory_address=&#8221;0x8152c28&#8243;&gt;&lt;br /&gt;     &lt;item key=&#8221;firstName&#8221;&gt;Evan&lt;/item&gt;&lt;br /&gt;     &lt;item key=&#8221;lastName&#8221;&gt;Salazar&lt;/item&gt;&lt;br /&gt;    &lt;/hashref&gt;&lt;br /&gt;   &lt;/item&gt;&lt;br /&gt;   &lt;item key=&#8221;skills&#8221;&gt;&lt;br /&gt;    &lt;arrayref memory_address=&#8221;0x823bcf0&#8243;&gt;&lt;br /&gt;     &lt;item key=&#8221;0&#8243;&gt;Perl&lt;/item&gt;&lt;br /&gt;     &lt;item key=&#8221;1&#8243;&gt;PHP&lt;/item&gt;&lt;br /&gt;     &lt;item key=&#8221;2&#8243;&gt;Java&lt;/item&gt;&lt;br /&gt;     &lt;item key=&#8221;3&#8243;&gt;C&lt;/item&gt;&lt;br /&gt;     &lt;item key=&#8221;4&#8243;&gt;C++&lt;/item&gt;&lt;br /&gt;    &lt;/arrayref&gt;&lt;br /&gt;   &lt;/item&gt;&lt;br /&gt;  &lt;/hashref&gt; &lt;/perldata&gt;</p></blockquote>
<p><strong>Unserializing the Data</strong></p>
<p>Below is the program that will unseralize the data from the previous program. Note that any binary data will not be unseralized using  XML::Dumper. If you need to serialize binary data with this package, consider first encoding it using UUencode or base64 encode.</p>
<blockquote><p><span style="color: #a020f0;">#!/usr/bin/perl</span><br />
<span style="color: #0000ff;">#####################################################</span><br />
<span style="color: #0000ff;">#Author: Evan Salazar</span><br />
<span style="color: #0000ff;">#Unserialize the data in TestClass</span><br />
<span style="color: #0000ff;">#####################################################</span><br />
<span style="color: #a52a2a;"><strong>use strict</strong></span>;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>Storable;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>PHP::Serialization;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>FreezeThaw;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>TestClass;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>XML::Dumper;<br />
<span style="color: #a52a2a;"><strong>use </strong></span>Data::Dumper;</p>
<p><span style="color: #0000ff;">#Set Slurp mode for reading</span><br />
<span style="color: #a52a2a;"><strong>local</strong></span>(<span style="color: #008b8b;">$/</span>) = <span style="color: #a52a2a;"><strong>undef</strong></span>;</p>
<p><span style="color: #0000ff;">#Open File for reading  Serialized Data</span><br />
<span style="color: #a52a2a;"><strong>open</strong></span>(<span style="color: #008b8b;">PHPSER</span>,    <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">phpser</span><span style="color: #ff00ff;">&#8220;</span>);<br />
<span style="color: #a52a2a;"><strong>open</strong></span>(<span style="color: #008b8b;">FREEZETHAW</span>, <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">freezeThaw</span><span style="color: #ff00ff;">&#8220;</span>);<br />
<span style="color: #a52a2a;"><strong>open</strong></span>(<span style="color: #008b8b;">XMLDUMPER</span>, <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">xmldumper.xml</span><span style="color: #ff00ff;">&#8220;</span>);<br />
<span style="color: #a52a2a;"><strong>open</strong></span>(<span style="color: #008b8b;">DATADUMPER</span>, <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">dataDumper.pl</span><span style="color: #ff00ff;">&#8220;</span>);</p>
<p><span style="color: #0000ff;">#Unserialize Using Data::Dumper</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">Data::Dumper</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$dataDumper</span> = <span style="color: #008b8b;">&lt;DATADUMPER&gt;</span>;<br />
<span style="color: #0000ff;">#print $dataDumper</span><br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$VAR1</span>;<br />
<span style="color: #a52a2a;"><strong>eval</strong></span>(<span style="color: #008b8b;">$dataDumper</span>); <span style="color: #0000ff;">#Data is stored into variable $VAR1</span><br />
<span style="color: #008b8b;">$VAR1</span>-&gt;printAll;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;</p>
<p><span style="color: #0000ff;">#Unserialize Using FreezeThaw</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">FreezeThaw</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$freezeThaw</span> = <span style="color: #008b8b;">&lt;FREEZETHAW&gt;</span>;<br />
<span style="color: #0000ff;">#print $freezeThaw;</span><br />
<span style="color: #a52a2a;"><strong>my</strong></span> (<span style="color: #008b8b;">$classFreeze</span>) = FreezeThaw::thaw(<span style="color: #008b8b;">$freezeThaw</span>);<br />
<span style="color: #008b8b;">$classFreeze</span>-&gt;printAll;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;</p>
<p><span style="color: #0000ff;">#Unserialize Using PHP::Serialization</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">PHP::Serializatoin</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$phpser</span> = <span style="color: #008b8b;">&lt;PHPSER&gt;</span>;<br />
<span style="color: #0000ff;">#print $phpser;</span><br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$classPHP</span> = PHP::Serialization::unserialize(<span style="color: #008b8b;">$phpser</span>);<br />
<span style="color: #a52a2a;"><strong>bless</strong></span>(<span style="color: #008b8b;">$classPHP</span>,<span style="color: #ff00ff;">&#8216;</span><span style="color: #ff00ff;">TestClass</span><span style="color: #ff00ff;">&#8216;</span>);<br />
<span style="color: #008b8b;">$classPHP</span>-&gt;printAll;<br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;</p>
<p><span style="color: #0000ff;">#Unserialize Using XML::Dumper</span><br />
<span style="color: #a52a2a;"><strong>print</strong></span> <span style="color: #ff00ff;">&#8220;</span><span style="color: #ff00ff;">XML::Dumper</span><span style="color: #6a5acd;">\n</span><span style="color: #ff00ff;">&#8220;</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$xmlDumper</span> = <span style="color: #008b8b;">&lt;XMLDUMPER&gt;</span>;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$dump</span> = <span style="color: #a52a2a;"><strong>new</strong></span> XML::Dumper;<br />
<span style="color: #a52a2a;"><strong>my</strong></span> <span style="color: #008b8b;">$xmlClass</span> = <span style="color: #008b8b;">$dump</span>-&gt;xml2pl(<span style="color: #008b8b;">$xmlDumper</span>);<br />
<span style="color: #008b8b;">$xmlClass</span>-&gt;printAll;</p></blockquote>
<p>Program Output</p>
<blockquote>
<pre>Data::Dumper
Name: Evan Evan
E-Mail: esalazar1981@gmail.com
Skills: Perl PHP Java C C++
GPG Key: 11061398fe828dcd83a4b9a79594c399

FreezeThaw
Name: Evan Evan
E-Mail: esalazar1981@gmail.com
Skills: Perl PHP Java C C++
GPG Key: 11061398fe828dcd83a4b9a79594c399

PHP::Serializatoin
Name: Evan Evan
E-Mail: esalazar1981@gmail.com
Skills: Perl PHP Java C C++
GPG Key: 11061398fe828dcd83a4b9a79594c399

XML::Dumper

not well-formed (invalid token) at line 4, column 21, byte 148 at /usr/lib/perl5/XML/Parser.pm line 187</pre>
</blockquote>
<p>If you remove the binary data you will get</p>
<blockquote>
<pre>Data::Dumper
Name: Evan Evan
E-Mail: esalazar1981@gmail.com
Skills: Perl PHP Java C C++
GPG Key:

FreezeThaw
Name: Evan Evan
E-Mail: esalazar1981@gmail.com
Skills: Perl PHP Java C C++
GPG Key:

PHP::Serializatoin
Name: Evan Evan
E-Mail: esalazar1981@gmail.com
Skills: Perl PHP Java C C++
GPG Key:

XML::Dumper
Name: Evan Evan
E-Mail: esalazar1981@gmail.com
Skills: Perl PHP Java C C++
GPG Key:</pre>
</blockquote>
<p><strong>Conclusion</strong></p>
<p>All of these methods worked well for the given class, although binary to ASCII encoding is necessary for XML serialization. I personally prefer XML serialization because the data can be used with a wide variety of languages. Also XML serialization is human readable.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/serialization/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Data encryption in Linux using Truecrypt</title>
		<link>http://www.ohmpie.com/truecrypt/</link>
		<comments>http://www.ohmpie.com/truecrypt/#comments</comments>
		<pubDate>Sun, 16 Dec 2007 02:58:42 +0000</pubDate>
		<dc:creator>esalazar</dc:creator>
				<category><![CDATA[Freedom]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dev.ohmpie.com/?p=38</guid>
		<description><![CDATA[Personal data security is often overlooked by many computer users today. As people use their computers more, they never stop to think about how much personal data is accessible on their hard drive. I have been looking for a safe &#8230; <a href="http://www.ohmpie.com/truecrypt/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Personal data security is often overlooked by many computer users today. As people use their computers more, they never stop to think about how much personal data is accessible on their hard drive. I have been looking for a safe and convenient way to deploy cryptology in Linux. So far Truecrypt has been the best choice. It is very convenient and cross platform. This story will show how to use it on Ubuntu Linux along with some basic data safety principals.<br />
<span id="more-38"></span><br />
<strong>A quick word about data in Linux</strong><br />
One of the first things that fascinated me about Linux is devices are treated as files. For example if you have an IDE hard drive, it is located at /dev/hda or a SCSI hard drive is located at /dev/sda. This is true about all devices in Linux including serial ports /dev/ttyS0 and sound cards /dev/dsp.</p>
<p>You could output the data from these devices as they where any other file, for example you could redirect the data from your hard drive to the standard output using</p>
<blockquote><p>cat /dev/sda</p></blockquote>
<p>On most computers this will generate garbage to the screen. It is better to pipe this data to a utility called &#8216;hexdump&#8217; to see the data in hexadecimal format. Note the -C command will also display the ASCII output</p>
<blockquote><p>cat /dev/sda | hexdump -C</p></blockquote>
<p>Using this command will output all of your data to the screen. It is probably not usefully to try to read all the data at once. It is better to use the &#8216;dd&#8217; utility so you can control how much data you read and write. The parameter &#8216;if=&#8217; is the device your copying from, &#8216;bs=&#8217; is the block size and &#8216;count=&#8217; is the number of blocks to copy.</p>
<blockquote><p>dd if=/dev/sda bs=512 count=1 | hexdump -C</p></blockquote>
<p>In this example you can clearly see my boot record. Notice that the copy stops at line 200 where 200 is hexadecimal for 512.<br />
<img src="http://www.evansalazar.com/ohmpie/truecrypt/hexdump.png" alt="" /></p>
<p><strong>Random data</strong><br />
Two important devices on any Linux system are /dev/random and /dev/urandom. These are both pseudo random number generators. The difference between /dev/random and /dev/urandom is that the second is known as a non-blocking random number generator. To see this we have the following example. Try typing the following into your console.</p>
<blockquote><p>cat /dev/random | hexdump -C</p></blockquote>
<p>You will notice that not much data is coming out. If you move your mouse or start opening programs, you will see more output. This is because /dev/random listens to hardware for a good source of true random data. If you try the same example with /dev/urandom you will instantly see lots of data being outputted. This is because urandom will not wait for fresh random data and generate pseudo random filler when needed. This makes it much faster.<br />
<img src="http://www.evansalazar.com/ohmpie/truecrypt/random.png" alt="" /></p>
<p><strong>Preparing a hard dive for security</strong><br />
Having random data is very important to format ones hard drive.  A normal format and even operating re-install will not destroy old data. For example the following pictures are from an old hard drive I  installed a fresh copy of Slackware Linux on.<br />
<img src="http://www.evansalazar.com/ohmpie/truecrypt/fdisk.png" alt="" /><br />
<img src="http://www.evansalazar.com/ohmpie/truecrypt/ls.png" alt="" /><br />
I never did any personal work on this installation. It was was only used once in a hardware experiment. If I pipe the raw data do a program called &#8216;strings&#8217; which only shows ASCII data then grep my name, I see old e-mails and  other personal data from when this hard drive was in my computer running windows XP.</p>
<blockquote><p>esalazar@manchester:~$ cat /dev/sdb | strings | grep evan | less</p></blockquote>
<p><img src="http://www.evansalazar.com/ohmpie/truecrypt/strings.png" alt="" /><br />
For most people this could be very frightening. But yet most people sell or give their old computers away doing nothing but a simple format and re-installation. It is very important to copy random data to the entire hard drive before using. This will ensure that any previous data will be completely erased. It is important to use random data because copying zeros will not be sufficient. In a forensic analysis some bytes will be more “zero” than others leaving all the data available. Some would suggest that the following procedure be carried out 7 times on a drive for maximum security.</p>
<blockquote><p>dd if=/dev/urandom of=/dev/sdb</p></blockquote>
<p>On my computer this ran at about 4.3MB (Megabytes) a second. For larger drives you may want to create a simple script to run this 7 times while you sleep. If this is a new drive, one pass should be sufficient.</p>
<p><strong>Installing Truecrypt</strong><br />
Although Truecrypt is open source, there is not yet an available package for Ubuntu in the regular repositories. Therefor true crypt has to be installed manually from the source code (Actually a .deb package was recently released for 7.10). As of this writing the current version is 4.3a and can be downloaded from <a href="http://www.truecrypt.org/downloads.php">http://www.truecrypt.org/downloads.php</a>.</p>
<p>Once the source code is downloaded un-tar it in your home folder</p>
<blockquote><p>tar xvzf truecrypt-4.3a-source-code.tar.gz</p></blockquote>
<p>If you do not have the kernel source code and compiler packages you can download them with the following command.</p>
<blockquote><p>sudo apt-get install build-essential build-common<br />
sudo apt-get install linux-source-2.6.22</p></blockquote>
<p>Where 2.6.20 is your current version, you can use &#8216;uname -a&#8217; to see your kernel version<br />
Once you finish downloading the packages go to the Linux source folder and un-tar the kernel.</p>
<blockquote><p>cd /usr/src/linux<br />
sudo tar xvjf linux-source-2.6.22.tar.bz2</p></blockquote>
<p>Now go to the Trucrypt build folder and type the following to build and install Truecrypt</p>
<blockquote><p>cd ~/truecrypt-4.3a-source-code/Linux<br />
sudo ./build.sh<br />
sudo ./install.sh</p></blockquote>
<p>At this point the install of Truecrypt should be complete. You can verify by running &#8216;truecrypt –help&#8217;.</p>
<p><strong>Drive Encryption</strong><br />
Now that Truecrypt is installed and we have a properly formated hard drive we can now encrypt it. I will first start by running in interactive mode with the quick flag. The quick flag disables the copying of random data to the drive. This is not needed in this case because the drive I am using already has random data.</p>
<blockquote><p>esalazar@manchester:~$ sudo truecrypt &#8211;quick -c<br />
Volume type:<br />
1) Normal<br />
2) Hidden<br />
Select [1]:</p></blockquote>
<p>The first prompt will ask what volume type we are using. For this I am going to create a Normal type. The next prompt ask for the path to the volume. In my case I am going to use /dev/sdb</p>
<blockquote><p>Enter file or device path for new volume: /dev/sdb<br />
WARNING: Data on device will be lost. Continue? [y/N]: y</p></blockquote>
<p>For the file type I am going to select none. This is because I plan on using ext3 instead of FAT.</p>
<blockquote><p>Filesystem:<br />
1) FAT<br />
2) None<br />
Select [1]: 2</p></blockquote>
<p>Next is the Hash algorithm. I normally go with <a href="http://en.wikipedia.org/wiki/RIPEMD">RIPEMD-160</a> From my research this looks like the most secure.</p>
<p>Now for the encryption algorithm. Truecrypt gives you the option to chain several algorithms for maximum security. In this example I am going to choose Serpent-Twofish-AES</p>
<blockquote><p>Encryption algorithm:<br />
1) AES<br />
2) Blowfish<br />
3) CAST5<br />
4) Serpent<br />
5) Triple DES<br />
6) Twofish<br />
7) AES-Twofish<br />
 <img src='http://www.ohmpie.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> AES-Twofish-Serpent<br />
9) Serpent-AES<br />
10) Serpent-Twofish-AES<br />
11) Twofish-Serpent<br />
Select [1]: 10</p></blockquote>
<p>Now for the password. You can use a password, key file or both for your security. If you are only using a password make sure to pick a very strong one. More than likely the easiest way to crack your volume will be through a dictionary attack.</p>
<blockquote><p>Enter password for new volume &#8216;/dev/sdb&#8217;:<br />
Re-enter password:</p>
<p>Enter keyfile path [none]:</p></blockquote>
<p>Last Truecrypt will need random data to build its internal key. If you are running Truecrypt as root or sudo you can enter random data by moving the mouse.</p>
<blockquote><p>Please move the mouse randomly until the required amount of data is captured&#8230;<br />
Mouse data captured: 100%</p>
<p>Now the drive is complete</p>
<p>Done: 38172.75 MB  Speed: 38170.54 MB/s  Left: 0:00:00<br />
Volume created.</p></blockquote>
<p><strong>Filesystem creation</strong><br />
Now that the drive is setup for encryption, we need to put a file system on it. For this example I am going to use ext3. First step is to map the device</p>
<blockquote><p>esalazar@manchester:~$ truecrypt -i<br />
Enter esalazar&#8217;s or root&#8217;s system password:<br />
Enter volume path: /dev/sdb<br />
Enter mount directory [none]:<br />
Protect hidden volume? [y/N]:<br />
Enter keyfile path [none]:<br />
Enter password for &#8216;/dev/sdb&#8217;:</p></blockquote>
<p>Now the hard drive is mapped to &#8216;/dev/mapper/truecrypt0&#8242; you can verify this by typing &#8216;truecrypt -l&#8217;. This means that any plantext or un-encrypted data that is sent to  /dev/mapper/truecrypt0 will be encrypted and written to /dev/sdb. At this point I can create a the ext3 filesystem on /dev/mapper/truecrypt0</p>
<blockquote><p>esalazar@manchester:~$ sudo mkfs.ext3 /dev/mapper/truecrypt0<br />
mke2fs 1.40.2 (12-Jul-2007)<br />
Filesystem label=<br />
OS type: Linux<br />
Block size=4096 (log=2)<br />
Fragment size=4096 (log=2)<br />
4889248 inodes, 9772224 blocks<br />
488611 blocks (5.00%) reserved for the super user<br />
First data block=0<br />
Maximum filesystem blocks=0<br />
299 block groups<br />
32768 blocks per group, 32768 fragments per group<br />
16352 inodes per group<br />
Superblock backups stored on blocks:<br />
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,<br />
4096000, 7962624</p>
<p>Writing inode tables: done<br />
Creating journal (32768 blocks): done<br />
Writing superblocks and filesystem accounting information: done</p>
<p>This filesystem will be automatically checked every 25 mounts or<br />
180 days, whichever comes first.  Use tune2fs -c or -i to override.</p></blockquote>
<p>Now that a filesystem is on the drive I can mount it like any other drive.</p>
<blockquote><p>esalazar@manchester:~$ cd /media<br />
esalazar@manchester:/media$ sudo mkdir mydrive<br />
esalazar@manchester:/media$ sudo mount /dev/mapper/truecrypt0 mydrive/</p></blockquote>
<p>Now that the drive is mounted I will create home folder for myself that I  have access to.</p>
<blockquote><p>esalazar@manchester:~$ cd /media/mydrive/<br />
esalazar@manchester:/media/mydrive$ sudo mkdir esalazar<br />
esalazar@manchester:/media/mydrive$ sudo chown esalazar:esalazar esalazar/</p></blockquote>
<p>Now I can access my drive like any other drive.<br />
<img src="http://www.evansalazar.com/ohmpie/truecrypt/folder.png" alt="" /></p>
<p><strong>Un-Mounting / Un-Mapping</strong><br />
Remember that the drive is still vulnerable while mapped. Therefor it is very important to un-map and un-mount when not in use.</p>
<blockquote><p>esalazar@manchester:~$ sudo umount /dev/mapper/truecrypt0<br />
esalazar@manchester:~$ truecrypt -d</p></blockquote>
<p>Remember you can verify the drive is un-mapped with &#8216;truecrypt -l&#8217;.</p>
<blockquote><p>esalazar@manchester:~$ truecrypt -l<br />
No volumes mapped</p></blockquote>
<p><strong>Headers backup</strong><br />
Since hard drives are prone to failure it is important to backup the Truecrypt header. The header is the key that the entire hard drive is encrypted with along with some meta-data.  This key is then encrypted using your password hash as its key. So if one bit gets corrupted in your header none of your data will ever be able to be restored (Not very easily at least). It is also important to remember that the backup of your header will also have to be kept secure because if it is cracked, it can be used to decrypt your data. Use your best judgment on how you want to save your header.</p>
<blockquote><p>esalazar@manchester:~$ truecrypt &#8211;backup-headers mybackup /dev/sdb</p></blockquote>
<p><strong>Conclusion</strong><br />
Unfortunately I have barely scratched the surface of cryptology. The cryptology Wiki has some excellent  information for those who wish to know more. Much of my interest in cryptology came from Neal Stephenson&#8217;s book <a href="http://www.amazon.com/Cryptonomicon-Neal-Stephenson/dp/0060512806/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1197770656&amp;sr=1-1">Cryptonomicon. </a> It is a great book with many technical details along with an epic plot. Fell free to send me any suggestions or comments.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/truecrypt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Stamp tokenizing and flashing from the Linux CLI</title>
		<link>http://www.ohmpie.com/bs2linuxtokenizer/</link>
		<comments>http://www.ohmpie.com/bs2linuxtokenizer/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 00:21:40 +0000</pubDate>
		<dc:creator>tdavis</dc:creator>
				<category><![CDATA[Eletronics]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://dev.ohmpie.com/?p=34</guid>
		<description><![CDATA[For those of you who aren&#8217;t familiar with the Basic Stamp, its a small microcontroller available from Parallax. It runs at a whopping 20Mhz and has a full 2K of storage on board for instructions. Although it may not sound &#8230; <a href="http://www.ohmpie.com/bs2linuxtokenizer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>For those of you who aren&#8217;t familiar with the Basic Stamp, its a small microcontroller available from <a href="http://www.parallax.com/">Parallax</a>. It runs at a whopping 20Mhz and has a full 2K of storage on board for instructions.  Although it may not sound like much, its more than enough to program the stamp to do some interesting things.   The Basic Stamp is programmed in PBASIC, parallax&#8217;s version of <a href="http://en.wikipedia.org/wiki/BASIC">BASIC</a> the stamp interprets.<br />
<span id="more-34"></span><br />
Rather than waste your time explaining the coolness of the Basic Stamp, (if you&#8217;ve found this page you&#8217;re probably already interested) I want to focus on how it can be utilized under linux.  Currently, Parallax has a very nice PBASIC IDE but its available for windows only.  It can however be run under <a href="http://www.winehq.org/">Wine</a>, and with the proper font settings it doesn&#8217;t look too horrible and is quite functional.  But what is the fun in that?</p>
<p>If you&#8217;re more of a &#8216;vim&#8217; guy like me, there&#8217;s a better alternative.  A quick visit over to <a href="http://bstamp.sourceforge.net/">sourceforge</a> and you&#8217;ll find a set of command line tools available for download that make it easy to tokenize code and send it to the stamp without needing to reboot into windows.</p>
<p>After downloading the tarball, unpack it and move into the directory.  All you need to do now is build it, and it shouldn&#8217;t require much more than a simple &#8216;make&#8217;.</p>
<p><strong>unpack&#8230;</strong></p>
<blockquote><p>tdavis@tdavis-64:~$ tar xvzf bstamp-2006.05.31.tar.gz<br />
bstamp/<br />
bstamp/bstamp_run.cpp<br />
bstamp/tokenizer.h<br />
bstamp/PBASIC_Tokenizer_Software_Distribution_License.txt<br />
bstamp/pbasic_examples/<br />
bstamp/pbasic_examples/hello.bs2<br />
bstamp/pbasic_examples/Makefile<br />
bstamp/pbasic_examples/touch.bs2<br />
bstamp/Makefile<br />
bstamp/PBASIC_Tokenizer_Software_Distribution_License.pdf<br />
bstamp/TODO.txt<br />
bstamp/GPL.txt<br />
bstamp/README.txt<br />
bstamp/CHANGES.txt<br />
bstamp/COPYING.txt<br />
bstamp/bstamp_tokenize.cpp<br />
bstamp/tokenizer.so<br />
bstamp/error_handling.cpp<br />
tdavis@tdavis-64:~$</p></blockquote>
<p><strong>move into the directory where you unpacked the tarball&#8230;</strong></p>
<blockquote><p>tdavis@tdavis-64:~$ cd bstamp/<br />
tdavis@tdavis-64:~/bstamp$</p></blockquote>
<p><strong>and build it&#8230;</strong></p>
<blockquote><p>tdavis@tdavis-64:~/bstamp$ make<br />
tdavis@tdavis-64:~/bstamp$ make install</p></blockquote>
<p>The last step is to make a symbolic link to whatever serial port your stamp is hooked up to.  In my case it was /dev/ttyUSB0 because I&#8217;m using a serial to usb converter, but for a regular serial connection its likely to be /dev/ttyS0 or /dev/ttyS1.  The symlink needs to point the serial device to a new location, /dev/bstamp.  If at any point you encounter any problems, don&#8217;t forget to check out the README.txt that comes with the program.</p>
<blockquote><p>tdavis@tdavis-64:~/bstamp$ sudo ln -s /dev/ttyUSB0 /dev/bstamp</p></blockquote>
<p>Now you just need some code to tokenize, as an example here&#8217;s  a simple program I wrote that does nothing more than monitor the light levels off a photo resistor and produce output accordingly. (It beeps and blinks!)  Its certainly not the most beautiful code, but it does the trick.</p>
<p><tt>'for Basic Stamp 2<br />
'basic light meter that shows on 7 segment display<br />
'and controls LEDs related to the amount<br />
'of light detected; can also produce<br />
'audio output through a piezo electric<br />
'speaker based on the amount of light detected<br />
'@ Tyler Davis 2007<br />
' {$STAMP BS2}<br />
' {$PBASIC 2.5}<br />
DEBUG "program running!"<br />
index VAR Nib<br />
time  VAR Word<br />
dark  CON 25<br />
OUTH = %00000000<br />
DIRH = %11111111<br />
'FREQOUT 2, 2000, 4500  'test spk on p2</tt></p>
<p><tt>DO<br />
GOSUB Get_RC  'grab light level info<br />
GOSUB Delay   'delay between refreshes<br />
GOSUB Update_Display<br />
GOSUB sound   'play sound that changes as light<br />
'measurments do<br />
LOOP</tt></p>
<p><tt>Get_RC:<br />
HIGH 0    '0 pin<br />
PAUSE 3<br />
RCTIME 0, 1, time<br />
DEBUG HOME, "time = ", DEC5 time<br />
IF (time &gt; 200) THEN HIGH 6         'for green and<br />
IF (time &lt; 200) THEN LOW 6          'red lights<br />
IF (time &lt; 200) THEN HIGH 4<br />
IF (time &gt; 200) THEN LOW 4<br />
IF (time &lt; 35) THEN HIGH 5<br />
IF (time &gt; 35) THEN LOW 5<br />
IF (time &gt; 400) THEN HIGH 3<br />
IF (time &lt; 400) THEN LOW 3<br />
RETURN<br />
Delay:<br />
PAUSE time<br />
RETURN</p>
<p>Update_Display: 'to adjust 7 segment display<br />
IF index = 6 THEN index = 0<br />
LOOKUP index, [ %01000000,<br />
%10000000,<br />
%00000100,<br />
%00000010,<br />
%00000001,<br />
%00100000  ], OUT<br />
index = index + 1<br />
RETURN</p>
<p></tt></p>
<p><tt></tt></p>
<p><tt>sound: 'to create audible sounds related to<br />
'detected illumination levels<br />
FREQOUT 1, 50, time + 4000<br />
RETURN<br />
</tt></p>
<p>Now I&#8217;m gonna assume you&#8217;re using your own code since my code is kind of worthless without a corresponding schematic, but I guess it could be figured out.  Since I don&#8217;t feel like drawing up one I&#8217;ll just post a picture and if someone wants to try and figure it out they&#8217;re welcome to.  (Sorry but they&#8217;re terrible pictures, I&#8217;ll try and get better ones up as soon as I get a chance).</p>
<p><a><img src="http://lh5.google.com/tylerclaytondavis/R1jb6879r5I/AAAAAAAACZY/JUckdp4N_mo/s800/stamp1.jpg" alt="" /></a><br />
<a><img src="http://lh6.google.com/tylerclaytondavis/R1jb7M79r6I/AAAAAAAACZg/q0nzpKzCONc/s800/IMAG0046.jpg" alt="" /></a><br />
Otherwise the process of tokenizing the code and writing it to the stamp is quite straightforward.</p>
<blockquote><p>tdavis@tdavis-64:~/bstamp$ ./bstamp_tokenize lightmeter.bs2 lightmeter.tokenized<br />
: Success<br />
PBASIC Tokenizer Library version 1.23</p>
<p>tdavis@tdavis-64:~/bstamp$</p>
<p>tdavis@tdavis-64:~/bstamp$ cat lightmeter.tokenized | bstamp_run</p></blockquote>
<p>If you run into any problems, be sure to verify you&#8217;re working with the correct serial device.  Try a &#8216;dmesg | grep ttyS&#8217; and see what it brings up.  Or replace &#8216;ttyS&#8217; with &#8216;ttyU&#8217; if you have a USB connection.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/bs2linuxtokenizer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AC Motor / Generator Project</title>
		<link>http://www.ohmpie.com/acmotor/</link>
		<comments>http://www.ohmpie.com/acmotor/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 16:16:14 +0000</pubDate>
		<dc:creator>esalazar</dc:creator>
				<category><![CDATA[Eletronics]]></category>

		<guid isPermaLink="false">http://misato.senormeow.com/ohmpie/?p=21</guid>
		<description><![CDATA[This project started one night while I was lying in bed trying to visualize how an AC motor worked. I knew that it was different from a DC motor as in it did not require brushes and the speed was &#8230; <a href="http://www.ohmpie.com/acmotor/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>This project started one night while I was lying in bed trying to visualize how an AC motor worked. I knew that it was different from a DC motor as in it did not require brushes and the speed was controlled by frequency instead of voltage. After some research I came up with this project to better my understanding of AC motors.<br />
<span id="more-21"></span><br />
<strong>AC Theory:</strong><br />
AC Current is different from DC in that the polarity is constantly inverting in a given period. For example:  Lets say you have a standard battery hooked up to a volt meter. Normally you would connect the positive lead to the positive terminal of the battery as well as the negative lead to the negative terminal. If you wish to generate an AC current you would connect the leads normally for half a second and then invert them (where the positive terminal is connected to the negative lead and the negative terminal is connected to the positive lead) for another half second. If you constantly repeat this process you will have an AC current operating at one hertz (1hz). Where a hertz is 1 / Period. The period is the time the current is positive plus  the time it is negative in one cycle, so in our case 0.5s + 0.5s = 1s per period. In America AC voltage to your home is typically 110 Volts at 60hz in a smooth sine wave.<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/ac-wave.png" alt="" /></p>
<p><strong>Quick Magnet Theory:</strong><br />
A more in depth theory about magnets can be found <a href="http://en.wikipedia.org/wiki/Magnet">here</a>. For our practical purposes all we need to know is that a magnet has two poles, north and south. Poles attract each other when placed from north to south and repel when placed north to north or south to south.<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/Magnets.png" alt="" /></p>
<p><strong>Quick Electromagnet Theory:</strong><br />
An electromagnet is a magnet that is created with a coil. When current passes through the coil a magnetic flux is created. Conversely when a magnetic field passes through the coil a current is created. More information can be found <a href="http://hyperphysics.phy-astr.gsu.edu/hbase/magnetic/elemag.html">here</a>.<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/electromagnet.png" alt="" /><br />
<strong>AC Motor/Generator theory</strong><br />
Most of the information I used to design this motor came from this <a href="http://www.stanford.edu/~hydrobay/lookat/pmg.html#sect-6">page</a>.  I placed six magnets on the rotor with alternating poles and placed 6 coils in the housing with the polarities also alternating. When an AC current is run through the coils the polarity will switch the magnets poles from north to south at the given frequency. Therefor the rotor will turn so that the poles on the magnets will always line up.<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/motor-diagram.png" alt="" /><br />
<strong>Construction:</strong><br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/workbench.jpg" alt="" /><br />
After I had a good idea of how I was going to build this motor I needed to collect parts. I already had some bolts that I can use for coils along with copper magnet wire. So off to Hobby Lobby. There I found some ultra strong magnets along with construction Styrofoam.<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/parts.jpeg" alt="" /><br />
The base for the motor<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/base.jpeg" alt="" /><br />
Dividing the rotor into 6 sections<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/rotor.jpeg" alt="" /><br />
The completed measurements<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/rotor2.jpeg" alt="" /><br />
<strong>Coil winding:</strong><br />
At this stage I had to determine how strong of an electromagnet I needed for the magnets I bought. Since the magnets are rated at  “10” in strength, I had to create a electromagnet with enough magnetic flux to successfully repel the magnet.<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/magnets.jpeg" alt="" /><br />
Along with determining  the proper coil windings, I also had to label the polarity of each magnet. I used a +5V DC power supply to test the coil. After experimenting I decided to use 350 turns with 30 gauge wire.<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/coil.jpeg" alt="" /><br />
Once the polarity was determined for the magnets, I placed them in the rotor with hot glue.<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/rotor-magnets.jpg" alt="" />The base fully assembled<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/motor_nocoil.jpeg" alt="" /><br />
The base with coils.<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/motor_coil.jpeg" alt="" /><br />
After the unit was fully assembled it was time to test it out. First I tested to see if spinning the rotor would generate an AC current. I wired all of the coils in series and hooked them up to the oscilloscope. Spinning the rotor by hand produced a rough sine wave at a about 100mv. Now it is time to try powering the motor. To generate a AC current I used a HP 200A audio oscillator at around 50hz. This device cannot supply much current so I ran it at high voltage (70v) through a step down transformer (110V to 12.6-0-12.6). After playing with lining up the coils  I was able to successfully power the motor.<br />
<img src="http://www.evansalazar.com/ohmpie/acmotor/motor_running.jpeg" alt="" /><br />
<a href="http://www.ohmpie.com/acmotorvideo"><br />
</a></p>
<h3><a href="http://www.ohmpie.com/acmotorvideo">A Video of the Motor running can be found here</a></h3>
<p><a href="http://www.ohmpie.com/acmotorvideo"> </a></p>
<p><a href="http://www.ohmpie.com/acmotorvideo"></a></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.ohmpie.com/acmotor/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
