<?xml version="1.0"?>
<!--Copyright Brian Starkey 2011-->
<page title="LCD Shades" dir="projects/xmas_glasses" filename="xmas_glasses" type="windowpage" root="/xml_95" date="December 2010">

<window title="Christmas LCD Glasses">
	<menu>		
		<menu-item name="File">
			<!--<pdf-subitem name="Get PDF"/>-->
			<home-subitem name="Home" href="{/page/@root}"/>
			<menu-subitem name="XML" href="xmas_glasses.xml"/>
		</menu-item>
		<!--include common menu items (dynamically generated)-->
		<autogen type='category' category='all'/>
	</menu>
	<substance>
	<locations name="{/page/@title}">
		<folder name="Documentation">
			<!--<leaf class="pdfleaf" name="proj.pdf" href="proj.pdf" />-->
			<!-- img="/images/pdf_icon.gif" -->
			<leaf class="sectionleaf" name="Introduction" href="#Introduction"/>
			<leaf class="sectionleaf" name="Displays" href="#Displays"/>
			<leaf class="sectionleaf" name="Firmware" href="#Firmware"/>
			<leaf class="videoleaf" name="Video" href="#Video"/>
            <leaf class="sectionleaf" name="Hardware" href="#Hardware"/>
		</folder>
		<folder name="Code">
			<leaf class='codeleaf' name="snowman.c" href="code/snowman.c"/>
		</folder>
	</locations>
	<window-contents>
		<row>
			<image src="images/P1000487.JPG">Hot glue and wire</image>
			<image src="images/P1000492.JPG">Stylish and robust</image>
			<section-title name="Introduction"/>
			<section-content>
            I built some glasses with LCDs as lenses for a Christmas fancy dress party, exhibiting craftsmanship that is... errr... second to none o.0<br/>
            The project was hastily thrown together in the evenings of the week running up to the party, so if ever anything can be classed a 'quick and dirty' hack, this is it.<br/>
            The LCDs came from scrapped phones, and are 101*40 pixel graphic displays, which are controlled over a (poorly implemented) i2c bus. The glasses run off a couple of old camera LiPo batteries
            and an Attiny2313.
			</section-content>
		</row>
		<row>
			<image src="images/P1000474.JPG">Front of Display</image>
			<image src="images/P1000475.JPG">Rear of Display (Pin 1 on right)</image>
			<section-title name="Displays"/>
			<section-content>
            The display used is an 8-pin affair, a Seiko S-4548ACG (I have recently written a linux kernel driver for this display. Find out about that <link href="../../software/s4548/">here</link>). This display doesn't exist anywhere on the internet (except in some obscure <link href="http://ip.com/patent/US6334046">patent application</link>),
            however I was fortunate enough to obtain a datasheet and get it working.<br/>
            The display pinout is (pin1 is on the right when looking at the back of the display):
            <raw-html>
            <table rows="9" cols="4" class="single">
            <tr><th class="single">Pin</th><th class="single">Symbol</th><th class="single">Function</th><th class="single">Comment</th></tr>
            <tr><td class="single">1</td><td class="single">VLCD</td><td class="single">VLCD</td><td class="single">VDD-8V - VDD-5V</td></tr>
            <tr><td class="single">2</td><td class="single">VSS</td><td class="single">Logic Ground</td><td class="single">0V</td></tr>
            <tr><td class="single">3</td><td class="single">VDD</td><td class="single">VDD</td><td class="single">2.4V - 5.5V</td></tr>
            <tr><td class="single">4</td><td class="single">SCL</td><td class="single">I2C Clock</td><td class="single">~100kHz (though I managed more)</td></tr>
            <tr><td class="single">5</td><td class="single">SDA</td><td class="single">I2C Data</td><td class="single">Write address 0x74</td></tr>
            <tr><td class="single">6</td><td class="single">OSC1</td><td class="single">RC Oscillator input</td><td rowspan='2'>Connect 470k across OSC2/OSC1</td></tr>
            <tr><td class="single">7</td><td class="single">OSC2</td><td class="single">RC Oscillator output</td></tr>
            <tr><td class="single">8</td><td class="single">VDD</td><td class="single">VDD</td><td class="single">Tie 3 &amp; 8 together externally</td></tr>
            </table>
            </raw-html>
            <br/>
            The display's VRAM is split up into 5 pages (rows) of 101 bytes, so that each bit in each byte represents a pixel.<br/>
            The I2C transaction looks something like this:
            <raw-html>
            <table class="single">
            <tr>
            <td class="single" style="border-right: 1px solid black;">S</td>
            <td class="single">0</td>
            <td class="single">1</td>
            <td class="single">1</td>
            <td class="single">1</td>
            <td class="single">0</td>
            <td class="single">1</td>
            <td class="single">0</td>
            <td class="single">0</td>
            <td class="single" style="border-right: 1px solid black;">1</td><!-- ACK -->
            <td class="single">0</td>
            <td class="single">1</td>
            <td class="single">1</td>
            <td class="single">0</td>
            <td class="single">0</td>
            <td class="single">1</td>
            <td class="single">1</td>
            <td class="single">1</td>
            <td class="single" style="border-right: 1px solid black;">1</td><!-- ACK -->
            <td class="single">*</td>
            <td class="single">0</td>
            <td class="single">0</td>
            <td class="single">0</td>
            <td class="single">0</td>
            <td class="single">0</td>
            <td class="single">0</td>
            <td class="single">1</td>
            <td class="single" style="border-right: 1px solid black;">1</td><!-- ACK -->
            <td class="single">.</td>
            <td class="single">.</td>
            <td class="single" style="border-right: 1px solid black;">.</td>
            <td class="single">P</td>
            </tr>
            <tr>
            <td style="border: 0px; border-right: 1px solid black;">&#160;</td>
            <td class="single" colspan="8">I2C Address (0x74)</td>
            <td style="border: 0px; border-right: 1px solid black;">A</td>
            <td class="single" colspan="3">Page<br/>0b000 - 0b100</td>
            <td style="border: 0px">&#160;</td>
            <td style="border: 0px">&#160;</td>
            <td class="single" colspan="3">Cmd</td>
            <td style="border: 0px; border-right: 1px solid black;">A</td>
            <td style="border: 0px">&#160;</td>
            <td class="single" colspan="7">Col Address<br/> 0b0000000 - 0b1100100</td>
            <td style="border: 0px; border-right: 1px solid black;">A</td>
            <td style="border: 0px;">&#160; </td>
            <td style="border: 0px;">&#160;</td>
            <td style="border: 0px;">&#160;</td>
            <td style="border: 0px;">&#160;</td>
            </tr>
            </table>
            </raw-html>
            You may notice that all the 'ACK' (A) bits are written as 1, apparently there is an error in the silicon which means the LCD will not generate the correct ACK signal, so that cycle should be ignored
            (and ACK assumed). The "..." is the display data - here you write as many bytes as you want, which will go into the VRAM sequentially starting at the location specified by <i>Page</i> and <i>Col Address</i>.
            When the end of a page is reached (i.e you get to column 0x65), the next write will go to the first column of the next page and so on.<br/>
            The bits in the command field '<i>Cmd</i>' have the following meanings:
            <raw-html>
            <table class="single">
            <tr><td class="single">MSB</td><td class="single">All pixels ON(1)/OFF(0)</td></tr>
            <tr><td class="single">-</td><td class="single">Power Save ON(1)/OFF(0)</td></tr>
            <tr><td class="single">LSB</td><td class="single">Display ON(1)/OFF(0)</td></tr>
            </table>
            </raw-html>
            Power Save has the highest priority and select all pixels has second highest.<br/>
            </section-content>
		</row>
        <row>
			<section-title name="Firmware"/>
            <image src="images/DSC00259.JPG">"Aha! That should be a '1'!"</image>
            <image src="images/animated.gif">Let it snow!</image>
			<section-content>
            As much as I would have loved to implement a lovely, neat, general-purpose, hardware-accelerated I2C stack... I didn't.<br/>
            This being my first attempt at I2C on an AVR, I didn't have a ready-to-use I2C library (and though I did look online, I didn't like
            any of the implementations I saw). Given the tight time constraint, I wrote code to bit-bang the communications with the display.<br/>
            As the screens are write-only, I only bothered to implement writing, and was amazed when I managed to get the screen to do something 
            (after tracking down the odd erroneous bit on my oscilloscope).<br/>
            Once I could write to the screen, I had to decide what I was going to actually show on it. I broke out the GIMP and drew a little snowman, as well
            as 5 'pages' of snow (101*8 pixels), and used the ever helpful "C header file" output to save the monochrome bitmaps into something I could use. I had to do 
            some trivial modification to get the images into the 1 bit per pixel format I needed, and then got to work getting them onto the actual screen.<br/>
            By writing each 'page' of snow to each page of the screen, then incrementing the page number I started on, I could get a nice falling snow effect, and then I overlayed
            the snowman and sat back and admired my work.
            </section-content>
		</row>
        <row>
            <a id="Video"/>
            <video name="Video" src="http://www.youtube.com/embed/6J8z78ZGv1g"/>
            <section-content>
            So far so good... but it was still early, and encouraged by my success so far I wanted more. The first thing was to make the snowman move - simply shifting the starting
            column and bouncing back upon reaching the edge. "Too easy!" I said, and set about finding something else. <link href="http://www.linerider.org/play.php">Linerider</link> was a pretty popular game when
            I was at school, and I thought having the little dude on his sleigh dart across the glasses every now and again would be pretty cool. After grabbing an image off Google,
            making it monochrome and splitting it into pages like the others I added the image to the scene. The finished animation can be seen in the video. You will also notice the white light is fading in and out,
            I added an LED to each eye and used a couple of the Attiny's PWM pins to make them fade in and out to provide some illumination for the screen. Of course the problem with that was
            the LEDs completely whited out my vision whilst I was wearing the glasses, making it impossible to see anything unless the area was brightly lit.
            </section-content>
		</row>
        <row>
        <br/>
        <br/>
			<section-title name="Hardware"/>
            <image src="images/buffer.JPG">Power Supply</image>
            <image src="images/DSC00266.JPG">I should be a fashion designer</image>
			<section-content>
            The glasses were simply a piece of cardboard, cut to shape and reinforced with wire. I pulled the reflective backing off the displays and put them where the lenses should be, added a couple of LEDs and
            used copious (there really was a lot of it) amounts of hot glue to hold it all together. The power source was two 3.7 V Lithium camera batteries in series, giving me about 8 V when fully charged.
            This was split using an op-amp buffer to give me a virtual ground and the positive and negative supplies I needed to run the AVR and LCDs.<br/>
            A few wires and a rubber band later, and my creation was finished.<br/>
            </section-content>
		</row>
        
        <comments/>
        
	</window-contents>
	</substance>
</window>

</page>


