<?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>AlferSoft Blog</title>
	<atom:link href="http://www.alfersoft.com.ar/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alfersoft.com.ar/blog</link>
	<description>Explaining this blog in a few words since 1999</description>
	<lastBuildDate>Wed, 01 Feb 2012 22:36:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Scoreboard (Part 3: Final &#8211; Communicating with Android and more)</title>
		<link>http://www.alfersoft.com.ar/blog/2012/02/01/scoreboard-part-3-final-communicating-with-android-and-more/</link>
		<comments>http://www.alfersoft.com.ar/blog/2012/02/01/scoreboard-part-3-final-communicating-with-android-and-more/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 22:23:12 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[assembler]]></category>
		<category><![CDATA[attiny]]></category>
		<category><![CDATA[attiny45]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[bluetooth]]></category>
		<category><![CDATA[scoreboard]]></category>
		<category><![CDATA[VGA]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=414</guid>
		<description><![CDATA[The Scoreboard project is now finished and working! The idea of this project is pretty simple: control a ping-pong electronic scoreboard from an Android bluetooth-enabled device. To do this, I used an ATtiny45 which main function is to display the current scores in a VGA monitor while reading from a bluetooth module UART interface waiting [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2715.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2715-300x200.jpg" alt="Scoreboard - Final" title="Scoreboard - Final" width="300" height="200" class="alignleft size-medium wp-image-416" /></a>The Scoreboard project is now finished and working!<br/><br />
The idea of this project is pretty simple: control a ping-pong electronic scoreboard from an Android bluetooth-enabled device.<br />
To do this, I used an ATtiny45 which main function is to display the current scores in a VGA monitor while reading from a bluetooth module UART interface waiting for &#8220;commands&#8221; that will tell it what to display. The Android device sends the commands via bluetooth, running an application specially designed for this project.<br/><br />
As usual, the whole project is open source, including schematics, AVR firmware and the Android application.<br />
<span id="more-414"></span><br />
<strong>Schematic and Board</strong><br/><br />
Schematic and board were made with Eagle CAD software.<br />
Note: In this schematic I&#8217;ve used an ATtiny13, because I could not find the ATtiny45 in my Eagle library. As it was said before, in the project I ended using an ATtiny45. I guess the memory of ATtiny13 is enough to run the scoreboard firmware but can&#8217;t say for sure.<br />
<div id="attachment_419" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/scoreboard_schematic.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/scoreboard_schematic-300x300.png" alt="Scoreboard Schematic" title="Scoreboard Schematic" width="300" height="300" class="size-medium wp-image-419" /></a><p class="wp-caption-text">Scoreboard Schematic</p></div><br />
<div id="attachment_420" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/scoreboard_pcb.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/scoreboard_pcb-300x191.png" alt="Scoreboard PCB" title="Scoreboard PCB" width="300" height="191" class="size-medium wp-image-420" /></a><p class="wp-caption-text">Scoreboard PCB</p></div><br />
<strong>List of materials</strong><br/></p>
<table style="background-color: white; border: 1px solid #C3C3C3; border-collapse: collapse; width: 100%;">
<tbody>
<tr>
<th>Qty</th>
<th>Component</th>
<th>Sch. Code</th>
<th>Datasheet</th>
<th>Price (avg. US$)</th>
</tr>
<tr>
<td>1</td>
<td>3.3v Regulator</td>
<td>IC1</td>
<td><a href='http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/02/tlv1117-33.pdf'>tlv1117-33</a></td>
<td>0.79</td>
</tr>
<tr>
<td>1</td>
<td>Atmel ATtiny45 microcontroller</td>
<td>IC2</td>
<td></td>
<td>2.31</td>
</tr>
<tr>
<td>1</td>
<td>Bluetooth module</td>
<td>P$1</td>
<td><a href='http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/02/bluetoothddatasheet.pdf'>bluetooth</a></td>
<td>6.60 (on <a href="http://www.dealextreme.com/p/wireless-bluetooth-rs232-ttl-transceiver-module-80711" title="Bluetooth module on DealExtreme">DealExtreme</a>)</td>
</tr>
<tr>
<td>2</td>
<td>104 Ceramic capacitor</td>
<td>C1, C4</td>
<td></td>
<td>0.05 (each)</td>
</tr>
<tr>
<td>2</td>
<td>10uf Electrolytic capacitor</td>
<td>C2, C3</td>
<td></td>
<td>0.05 (each)</td>
</tr>
<tr>
<td>2</td>
<td>22pF Ceramic capacitor</td>
<td>C5, C6</td>
<td></td>
<td>0.05 (each)</td>
</tr>
<tr>
<td>1</td>
<td>20Mhz Crystal oscillator</td>
<td>Q1</td>
<td></td>
<td>0.65</td>
</tr>
<tr>
<td>1</td>
<td>Led</td>
<td>LED1</td>
<td></td>
<td>0.15</td>
</tr>
<tr>
<td>1</td>
<td>470R Resistor</td>
<td>R1</td>
<td></td>
<td>0.01</td>
</tr>
<tr>
<td>1</td>
<td>VGA DB-15 connector</td>
<td></td>
<td></td>
<td>2.28</td>
</tr>
<tr>
<td><del datetime="2012-01-31T21:31:08+00:00">1</del></td>
<td><del datetime="2012-01-31T21:31:08+00:00">10K Resistor</del></td>
<td><del datetime="2012-01-31T21:31:08+00:00">R2</del></td>
<td></td>
<td></td>
</tr>
<tr>
<td>1</td>
<td>Plain PCB / Printout / Iron chloride</td>
<td></td>
<td></td>
<td>3.00</td>
</tr>
</tbody>
</table>
<p><strong>Circuit</strong><br/><br />
Circuit is pretty straight as you can see. An external C/C power supply is needed to power the circuit. There is a voltage regulator so the supply in this case can be up to 15V (I didn&#8217;t measure consumption yet). The regulator has its respective capacitors in the input and output, used as filters. The bluetooth module and the microcontroller are connected through a single wire between module&#8217;s UART TXD and the PB5 pin of the ATtiny fused as an input (read more on <a href="http://www.alfersoft.com.ar/blog/2012/01/23/scoreboard-part-2-reading-uart-from-the-bluetooth-module/" title="Scoreboard (Part 2: Reading UART from the Bluetooth Module)">Part 2</a> of this series).<br />
A blue led with a resistor is attached to PIN24 of the bluetooth module, it will blink while the module is waiting for a connection and keep on when a connection is established, that&#8217;s using the default module firmware linvor1.5 that comes pre-programmed from DealExtreme, if you buy a different module or use a different firmware, you will need to review all the pin connections. According to the bluetooth module datasheet (at least the one that is supposed to be the correct one) you should put a 10K resistor from the reset pin to the ground, BUT actually I had to remove it to get the module working, otherwise it won&#8217;t even turn on. So <strong>DO NOT PUT R2.</strong></p>
<p>The meaning of the pads in the PCB is the following:</p>
<ul>
<li>PAD1: Input supply V+</li>
<li>PAD2: V- (ground)</li>
<li>PAD3: HSYNC to the VGA connector DB-15 pin 13</li>
<li>PAD4: VSYNC to the VGA connector DB-15 pin 14</li>
<li>PAD5: RGB to the VGA connector DB-15 pin 1 to 3</li>
<li>PAD6: Ground to the VGA connector DB-15 pin 5 to 10</li>
</ul>
<p><div id="attachment_426" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2721.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2721-300x200.jpg" alt="Scoreboard on the breadboard" title="Scoreboard on the breadboard" width="300" height="200" class="size-medium wp-image-426" /></a><p class="wp-caption-text">Scoreboard on the breadboard</p></div><br />
<div id="attachment_427" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2725.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2725-300x200.jpg" alt="Scoreboard on PCB (top view)" title="Scoreboard on PCB (top view)" width="300" height="200" class="size-medium wp-image-427" /></a><p class="wp-caption-text">Scoreboard on PCB (top view)</p></div><br />
<div id="attachment_432" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/02/IMG_2728.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/02/IMG_2728-300x200.jpg" alt="Scoreboard on PCB (bottom view)" title="Scoreboard on PCB (bottom view)" width="300" height="200" class="size-medium wp-image-432" /></a><p class="wp-caption-text">Scoreboard on PCB (bottom view)</p></div><br />
<strong>Android Application</strong><br/><br />
Thanks to CarlosBar!!! that made the program for me. He used the Android chat example as a base, changed the UUID to be able to connect using the SPP serial bluetooth (after all is what the DX bluetooth module is, an SPP serial port). Then he designed a nice GUI to control the scores, with an internal stack to support an Undo functionality in case you score on the wrong team.<br />
Also, you can control the scores with the Volume Up/Down keys for convenience.<br />
We have created a public repository on <a href="https://bitbucket.org/fvicente/scoreboard" title="BitBucket repository for Scoreboard Android Application" target="_blank">https://bitbucket.org/fvicente/scoreboard</a> where you can checkout the source code.<br />
Also it is available on the Android Market (search for &#8220;Scoreboard SPP&#8221;), I recommend to check out other CarlosBar project like the excellent <a href="http://code.google.com/p/ttsaid/" title="TTSAid" target="_blank">TTSAid</a>.<br/><br />
<div id="attachment_424" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2716.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2716-300x200.jpg" alt="Scoreboard Android Application" title="Scoreboard Android Application" width="300" height="200" class="size-medium wp-image-424" /></a><p class="wp-caption-text">Scoreboard Android Application</p></div><br/><br />
<strong>Related Posts</strong><br/><br />
You can find more details on the ATtiny firmware, the UART communication and the VGA output, on previous posts:<br />
<a href="http://www.alfersoft.com.ar/blog/2011/08/30/scoreboard-part-1-vga-signal-from-an-attiny45/" title="Scoreboard (Part 1: VGA signal from an ATtiny45)">Scoreboard (Part 1: VGA signal from an ATtiny45)</a><br />
<a href="http://www.alfersoft.com.ar/blog/2012/01/23/scoreboard-part-2-reading-uart-from-the-bluetooth-module/" title="Scoreboard (Part 2: Reading UART from the Bluetooth Module)">Scoreboard (Part 2: Reading UART from the Bluetooth Module)</a><br/><br />
<strong>Download</strong><br/><br />
<a href='http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/02/scoreboard_final.zip'>Scoreboard Final Source Code</a><br />
Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2012/02/01/scoreboard-part-3-final-communicating-with-android-and-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scoreboard (Part 2: Reading UART from the Bluetooth Module)</title>
		<link>http://www.alfersoft.com.ar/blog/2012/01/23/scoreboard-part-2-reading-uart-from-the-bluetooth-module/</link>
		<comments>http://www.alfersoft.com.ar/blog/2012/01/23/scoreboard-part-2-reading-uart-from-the-bluetooth-module/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 20:41:03 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[attiny]]></category>
		<category><![CDATA[attiny45]]></category>
		<category><![CDATA[bluetooth]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[scoreboard]]></category>
		<category><![CDATA[uart]]></category>
		<category><![CDATA[VGA]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=394</guid>
		<description><![CDATA[In this post, you will find how the Bluetooth module interacts with the ATtiny45 in the VGA Scoreboard project. The Bluetooth module will wait for a connection from a device (e.g. an Android phone) and will act as an SPP (Serial Port Profile) re-passing everything received from the device to the UART interface. In our [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/sku_80711_1_small.jpg" alt="Bluetooth Module" title="Bluetooth Module" width="140" height="140" class="alignleft size-full wp-image-397" />In this post, you will find how the <a href="http://www.dealextreme.com/p/wireless-bluetooth-rs232-ttl-transceiver-module-80711" title="Cheap Bluetooth Module" target="_blank">Bluetooth module</a> interacts with the ATtiny45 in the <a href="http://www.alfersoft.com.ar/blog/2011/08/30/scoreboard-part-1-vga-signal-from-an-attiny45/" title="Scoreboard (Part 1: VGA signal from an ATtiny45)" target="_blank">VGA Scoreboard</a> project.<br/><br />
The Bluetooth module will wait for a connection from a device (e.g. an Android phone) and will act as an SPP (Serial Port Profile) re-passing everything received from the device to the UART interface. In our case the ATtiny will read the data but won&#8217;t &#8220;speak back&#8221; to the module, so it&#8217;s really a one way communication from that point of view.<br/><br />
<span id="more-394"></span><br />
Electrically speaking, we just need one wire to connect the TXD pin of the bluetooth module (PIN 1) to the PB5 (PIN 1) of the ATtiny, which will be configured as an input.<br/><br />
Now the tricky part is on the microcontroller&#8217;s firmware side, since we need to read the input without disrupting the VGA timing. Our ATtiny is running at 20Mhz which gives 0.05μs per cycle, in the program the main loop is based on the VGA horizontal timings so we can read the input every 635 cycles (31.75μs). On the other side the BT module is configured at 2400 bauds which means that every bit will last for 416.66μs. So, doing a quick math, 416.66 / 31.75 = 13.12, meaning each bit will be read about 13 times. We will assume the read #7 as the valid one and we wont do any kind of checks.<br/><br />
The UART will be sending a &#8220;high&#8221; signal when is idle, as soon as we get a &#8220;low&#8221; we know that the &#8220;start bit&#8221; is arriving, so we set a global flag and start reading the 8 bits and putting them into a register (r19). You can read more about UART on <a href="http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter" title="Wikipedia UART" target="_blank">this Wikipedia article</a>. We use another register (r25) as a counter, to know when to read and stop reading.<br />
This is how the code looks like:</p>
<pre>
	;
	; UART read input
	; This code is executed every 635 cycles in the Scoreboard code
	;
	in r18, _SFR_IO_ADDR(PINB)		; 1 clock

	cpi r25, 0
	breq waitlow
	inc r25
	mov r16, r25
	andi r16, 0x0F
	cpi r16, 7
	brne chkfornext5togo
	lsr r19
	sbrc r18, INPUT
	ori r19, 0x80
	nop
	rjmp chkfornext
chkfornext5togo:
	nop
	nop
	nop
	nop
	nop
chkfornext:
	cpi r16, 14
	brne chkend3togo
	subi r25, 0xEF	; add 17
	andi r25, 0xF1
	rjmp chkend
chkend3togo:
	nop
	nop
	nop
chkend:
	nop
	rjmp hsyncoff

waitlow:
	; waiting for low
	sbrs r18, INPUT
	inc r25
	nop
	delay3x 4
	nop
	nop
	rjmp hsyncoff

hsyncoff:
	...... HSYNC code ......
        ...... if r25 == 0x91 then the UART was read and stored in r19......
	...... process and reset both registers ....
</pre>
<p>Since we read one byte at the time, it seems pretty convenient for our project to define a set of &#8220;commands&#8221; (of one byte long), to set the characters that must be displayed (four commands to set each one of characters), and additionally another command to display little square on the corners of the screen which will indicate who is currently serving.<br />
Here is our list of commands:</p>
<pre>
0 0 0 1 D D D D		(character 1) [0-D] -> 0 1 2 3 4 5 6 7 8 9 (SPACE) B O G
0 0 1 0 D D D D		(character 2)
0 0 1 1 D D D D		(character 3)
0 1 0 0 D D D D		(character 4)
0 1 0 1 0 0 0 1		(serve A top)
0 1 0 1 0 0 1 0		(serve B bottom)
0 1 0 1 0 1 0 0		(serve A top)
0 1 0 1 1 0 0 0		(serve b bottom)
</pre>
<p>All we need now is a device to connect to the bluetooth module and send the commands.<br />
Don&#8217;t miss the final part of this project, that I will publish soon including source codes and a controller developed for Android platforms.<br/><br />
<strong>Configuring the Bluetooth Module with Arduino</strong><br/><br />
The bluetooth module comes with a firmware called &#8220;linvor1.5&#8243; by default (at least the one on DX). To program it, you need to send a series of AT commands via the TX/RX pins, Arduino seems to be ideal for this task. Connect two cables between the TX/RX of the Arduino and the RX/TX of the Bluetooth module (they need to be crossed, RX with TX and TX with RX). Then put the following code on the Arduino:</p>
<pre>
int incomingByte = 0;	// for incoming serial data

void setup() {
  Serial.begin(9600);
  Serial.print("AT");
}

void loop() {
	// send data only when you receive data:
	if (Serial.available() > 0) {
		// read the incoming byte:
		incomingByte = Serial.read();

		// say what you got:
		Serial.write(incomingByte);
	}

}
</pre>
<p>Upload it to the Arduino and click on the Monitor, you will get the following response:<br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/2012-01-28-04.24.13-pm.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/2012-01-28-04.24.13-pm-300x193.png" alt="" title="ATOK" width="300" height="193" class="aligncenter size-medium wp-image-441" /></a><br />
Now we are going to change the default name to &#8220;scoreboard&#8221;, to do so, replace the <code>Serial.print("AT")</code> with <code>Serial.print("AT+NAMEscoreboard")</code> and repeat the procedure.<br />
Finally, we need to set the baud rate to 2400, using the following command: <code>Serial.print("AT+BAUD2")</code><br />
<br/><br />
Comments and questions are welcome!</p>
<p><strong>Related Posts</strong><br />
<a href="http://www.alfersoft.com.ar/blog/2011/08/30/scoreboard-part-1-vga-signal-from-an-attiny45/" title="Scoreboard (Part 1: VGA signal from an ATtiny45)">Scoreboard (Part 1: VGA signal from an ATtiny45)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2012/01/23/scoreboard-part-2-reading-uart-from-the-bluetooth-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protoboard adapter for cheap Bluetooth module</title>
		<link>http://www.alfersoft.com.ar/blog/2012/01/22/protoboard-adapter-for-cheap-bluetooth-module/</link>
		<comments>http://www.alfersoft.com.ar/blog/2012/01/22/protoboard-adapter-for-cheap-bluetooth-module/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 18:52:46 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[adapter]]></category>
		<category><![CDATA[bluetooth]]></category>
		<category><![CDATA[breadboard]]></category>
		<category><![CDATA[deal extreme]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[protoboard]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=380</guid>
		<description><![CDATA[I finally received some stuff from DealExtreme.com including a cheap Bluetooth Module which I will use to finish my remote scoreboard project. But first, I made this small PCB to adapt the module to a breadboard for testing and programming. I found on the Internet someone that already did this, but I wanted to use [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2621.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2621-300x200.jpg" alt="Protoboard adapter for Bluetooth module" title="Protoboard adapter for Bluetooth module" width="300" height="200" class="alignleft size-medium wp-image-381" /></a>I finally received some stuff from DealExtreme.com including a <a href="http://www.dealextreme.com/p/wireless-bluetooth-rs232-ttl-transceiver-module-80711" title="Bluetooth Module" target="_blank">cheap Bluetooth Module</a> which I will use to finish my remote scoreboard project.<br/><br />
But first, I made this small PCB to adapt the module to a breadboard for testing and programming. I found on the Internet <a href="http://elasticsheep.com/2011/09/bluetooth-module-breakout-boards-are-back-in-stock/" title="Bluetooth module adapter" target="_blank">someone that already did this</a>, but I wanted to use the SPI programming interface too, then I needed to lay pins 14 to 21 let&#8217;s say vertically, to be able to plug it on the protoboard.<br/><br />
<span id="more-380"></span><br />
The module is really small 2.7 cm x 1.3 cm x 0.1 cm, take a look to this picture in relation to a R$1 coin (Brazilian Real).<br/><br />
<div id="attachment_382" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2593.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2593-300x200.jpg" alt="Stuff from dealextreme.com" title="Stuff from dealextreme.com" width="300" height="200" class="size-medium wp-image-382" /></a><p class="wp-caption-text">Stuff from dealextreme.com</p></div><br />
Tip: Soldering the BT module to the adapter is easy, if you use <a href="http://en.wikipedia.org/wiki/Soldering#Flux" title="Soldering Flux (Wikipedia)" target="_blank">flux</a>.<br/><br />
<div id="attachment_383" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2634.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2634-300x200.jpg" alt="Soldering BT module to the adapter" title="Soldering BT module to the adapter" width="300" height="200" class="size-medium wp-image-383" /></a><p class="wp-caption-text">Soldering BT module to the adapter</p></div><br />
The PCB design was made in Eagle CAD, I made a library that represents the Bluetooth adapter.<br />
I have two versions of the adapter:</p>
<ul>
<li>Version 1 (the one in the pictures) with a higher separation between the pins.</li>
<li>Version 2 improved to use less space for smaller breadboards (I didn&#8217;t produce this one).</li>
</ul>
<p><div id="attachment_387" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/BT-adapter.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/BT-adapter-300x221.png" alt="BT Module Adapter PDF" title="BT Module Adapter PDF" width="300" height="221" class="size-medium wp-image-387" /></a><p class="wp-caption-text">BT Module Adapter PDF</p></div><br/><br />
With this adapter, I was able to test and update the firmware of the bluetooth module. By the way, if you are looking for information about how to upgrade the firmware, check out this excellent <a href="http://byron76.blogspot.com/" title="Byron76 blog" target="_blank">blog</a> from Byron76.<br />
To test, send commands and configure the module, you need to communicate with it via 3.3v serial interface (I used my Arduino Duemilanove), but if you just want to test the Bluetooth communication, you can simply interconnect TXD and RXD pins (pin # 1 and 2) and any character you send will be echoed. This fantastic page Elasticsheep.com gives <a href="http://elasticsheep.com/2011/05/serial-bluetooth-module-masterslave-connection/" title="Elasticsheep.com testing Bluetooth module" target="_blank">detailed instructions</a> on how to test the module.<br/><br />
<a href='http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/btadap.zip'>Download schematics, Eagle CAD library and PDF</a> and feel free modify and use it however you want.<br />
Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2012/01/22/protoboard-adapter-for-cheap-bluetooth-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Revenge of the Tiny Pong VGA, now controlled with a single button</title>
		<link>http://www.alfersoft.com.ar/blog/2012/01/22/revenge-of-the-tiny-pong-vga-now-controlled-with-a-single-button/</link>
		<comments>http://www.alfersoft.com.ar/blog/2012/01/22/revenge-of-the-tiny-pong-vga-now-controlled-with-a-single-button/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 04:09:16 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[assembler]]></category>
		<category><![CDATA[attiny]]></category>
		<category><![CDATA[attiny45]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[pong]]></category>
		<category><![CDATA[tiny]]></category>
		<category><![CDATA[VGA]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=345</guid>
		<description><![CDATA[As it was suggested by Hackaday&#8217;s guys, I&#8217;ve added a simple push button in the only available pin of my ATtiny45 in order to control the Tiny Pong VGA. The switch toggles the paddle direction up and down, every time you release it. I&#8217;ve made some little changes in the code, so check it out, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/push_button_dn.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/push_button_dn-150x150.png" alt="Tiny Pong VGA push button" title="Tiny Pong VGA push button" width="150" height="150" class="alignleft size-thumbnail wp-image-363" /></a>As it was suggested by <a href="http://hackaday.com/2011/10/07/8-pin-micro-plays-pong-on-you-widescreen/" title="Hackaday Tiny Pong VGA" target="_blank">Hackaday&#8217;s guys</a>, I&#8217;ve added a simple push button in the only available pin of my ATtiny45 in order to control the Tiny Pong VGA. The switch toggles the paddle direction up and down, every time you release it.<br/><br />
I&#8217;ve made some little changes in the code, so check it out, you might find something interesting or useful. As always, source code, schematics, etc. freely available for download.<br/><br />
<span id="more-345"></span><br />
<strong>Hardware</strong><br/><br />
Compared to <a href="http://www.alfersoft.com.ar/blog/2011/09/19/tiny-pong-more-fun-with-attiny45-and-vga/" title="Tiny Pong: More fun with ATtiny45 and VGA" target="_blank">Tiny Pong 1.0</a>, I just added a push button on PB5 with a 10K ohms resistor as pull-down.<br />
Here is a picture of the circuit on the breadboard.<br />
<div id="attachment_364" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2702.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/IMG_2702-300x200.jpg" alt="Tiny Pong VGA on the protoboard" title="Tiny Pong VGA on the protoboard" width="300" height="200" class="size-medium wp-image-364" /></a><p class="wp-caption-text">Tiny Pong VGA on the protoboard</p></div><br />
And a prototype I made with <a href="http://fritzing.org/" title="Fritzing" target="_blank">Fritzing</a><br/><br />
<div id="attachment_365" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/Tiny-Pong-VGA-Fritzing.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/Tiny-Pong-VGA-Fritzing-300x121.png" alt="Tiny Pong VGA - Fritzing" title="Tiny Pong VGA - Fritzing" width="300" height="121" class="size-medium wp-image-365" /></a><p class="wp-caption-text">Tiny Pong VGA - Fritzing</p></div><br />
<div id="attachment_369" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/vga_pinout.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/vga_pinout-300x300.jpg" alt="VGA pinout" title="VGA pinout" width="300" height="300" class="size-medium wp-image-369" /></a><p class="wp-caption-text">VGA pinout</p></div><br />
<strong>ATtiny firmware</strong><br/><br />
To use PB5 as an I/O port we need to reprogram the ATtiny fuses with some specific flags. Once you do this, you won&#8217;t be able to reprogram it anymore using a regular ISP programmer. If you need to flash another firmware, you will need to reset the fuses using a High Voltage programmer; <a href="http://www.rickety.us/2010/03/arduino-avr-high-voltage-serial-programmer/" title="AVR High Voltage programmer" target="_blank">this one</a> worked fine for me.<br />
AVR GNU toolchain is used for this project, so the code is written in GNU assembler.<br />
In order to build the firmware, I use the following script:</p>
<pre>
#!/bin/sh
avr-gcc -mmcu=attiny45 -mmcu=attiny45 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT pong.o -MF pong.o.d  -x assembler-with-cpp -Wa,-gdwarf2 -c pong.S tables.S
avr-gcc -mmcu=attiny45 -Wl,-Map=pong.map pong.o tables.o -o pong.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature pong.elf pong.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex pong.elf pong.eep || exit 0
avr-size -C --mcu=attiny45 pong.elf
rm *.o
rm *.o.d
rm pong.eep
rm pong.elf
rm pong.map
</pre>
<p>And to upload it to the chip (note that I&#8217;m using the Arduino with mega-isp) I use the following script</p>
<pre>
#!/bin/sh
[ -e "/dev/tty.usbserial-A8008VmU" ] &#038;&#038; PORT=/dev/tty.usbserial-A8008VmU || PORT=/dev/ttyUSB0
avrdude -F -P $PORT -p attiny45 -c avrisp -b 19200 -U flash:w:pong.hex
# fuses
# WARNING: fuses with PB5 as I/O port
#avrdude -F -P $PORT -p attiny45 -c avrisp -b 19200 -U flash:w:pong.hex -Ulfuse:w:0xce:m -Uhfuse:w:0x5f:m -Uefuse:w:0xff:m
</pre>
<p>Uncomment the last line to program the fuses.<br/><br />
<strong>Code</strong><br/><br />
The source code is almost the same as the first version, but I fixed a few bugs. First, the Bresenham&#8217;s algorithm was wrongly implemented, and since I needed it only to calculate the next position of the ball when the angle is 22.5 or 67.5, I realized that was easier to simply increment the X (or Y) coordinate when the ball is at an even position.<br />
Regarding the button reading, it is done during the vertical blanking zone, 60 times per second which gives a pretty good responsiveness &#8211; see the <code>chkinput</code> label in the code for more details.<br />
<br/><br />
<iframe width="560" height="315" src="http://www.youtube.com/embed/VMZvNSRKmWE" frameborder="0" allowfullscreen></iframe><br />
<br/><br />
Download the <a href='http://www.alfersoft.com.ar/blog/wp-content/uploads/2012/01/tinypong_2.0.zip'>Tiny Pong 2.0</a> source code<br />
Enjoy!<br />
<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2012/01/22/revenge-of-the-tiny-pong-vga-now-controlled-with-a-single-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Lightbox: Adjust big images to the window size</title>
		<link>http://www.alfersoft.com.ar/blog/2011/12/09/jquery-lightbox-adjust-big-images-to-the-window-size/</link>
		<comments>http://www.alfersoft.com.ar/blog/2011/12/09/jquery-lightbox-adjust-big-images-to-the-window-size/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 12:21:27 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[customization]]></category>
		<category><![CDATA[image size]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[lightbox]]></category>
		<category><![CDATA[limit size]]></category>
		<category><![CDATA[photo size]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=350</guid>
		<description><![CDATA[jQuery lightBox is a great plugin inspired in the well-known Lightbox JS by Lokesh Dhakar. After starting using it I realized that things became messy with big images, so I made a small modification to limit the image size to the current browser window size. Also I added an option to hide the image information. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/12/jquery-lightbox-alfersoft-mod.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/12/jquery-lightbox-alfersoft-mod-300x257.png" alt="" title="jQuery lightBox AlferSoft Mod" width="200" class="alignleft size-medium wp-image-358" /></a><a href="http://leandrovieira.com/projects/jquery/lightbox/" title="jQuery lightBox plugin" target="_blank">jQuery lightBox</a> is a great plugin inspired in the well-known <a href="http://www.huddletogether.com/projects/lightbox2/" title="LightBox JS" target="_blank">Lightbox JS</a> by Lokesh Dhakar.<br/><br />
After starting using it I realized that things became messy with big images, so I made a small modification to limit the image size to the current browser window size.<br/><br />
Also I added an option to hide the image information. The images used to navigate between images and close the preview are in English, so I modified the images to be more neutral (just icons)<br />
<span id="more-350"></span><br />
<strong>Code</strong><br />
Two new options were added:</p>
<pre class="brush: jscript; title: ; notranslate">
fitToWindow: true,		// option to fit preview to window size if the
                                // image is too big
showInfo:    true		// option to show or hide image info
</pre>
<p>To fit the preview to the window size, I&#8217;ve replaced the call to _resize_container_image_box() with _adjust_image_size().<br/><br />
Here is the definition of the new function:</p>
<pre class="brush: jscript; title: ; notranslate">
function _adjust_image_size(objImagePreloader) {
    // get image size
    var imgWidth = objImagePreloader.width;
    var imgHeight = objImagePreloader.height;

    var arrayPageSize = ___getPageSize();
    // calculate proportions
    var imageProportion = imgWidth / imgHeight;
    var winProportion = arrayPageSize[2] / arrayPageSize[3];
    if (imageProportion &gt; winProportion) {
        // calculate max width base on page width
        var maxWidth = arrayPageSize[2] - (settings.containerBorderSize * 2) - (arrayPageSize[2] / 10);
        var maxHeight = Math.round(maxWidth / imageProportion);
    } else {
        // calculate max height base on page height
        var maxHeight = arrayPageSize[3] - (settings.containerBorderSize * 2) - (arrayPageSize[3] / 10) - 40;
        var maxWidth = Math.round(maxHeight * imageProportion);
    }
    if (imgWidth &gt; maxWidth || imgHeight &gt; maxHeight) {
        imgWidth = maxWidth;
        imgHeight = maxHeight;
    }
    $('#lightbox-image').attr('width', imgWidth);
    $('#lightbox-image').attr('height', imgHeight);
    _resize_container_image_box(imgWidth, imgHeight);
};
</pre>
<p>Finally, to optionally hide or show the image info, just canged the following line:</p>
<pre class="brush: jscript; title: ; notranslate">
if ( settings.imageArray.length &gt; 1 ) {
</pre>
<p>to:</p>
<pre class="brush: jscript; title: ; notranslate">
if ( settings.showInfo &amp;&amp; (settings.imageArray.length &gt; 1) ) {
</pre>
<p><a href='http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/12/jquery-lightbox-0.5-alfersoft-mod.zip'>Download modified code here &#8211; jQuery lightBox 0.5 AlferSoft Mod</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2011/12/09/jquery-lightbox-adjust-big-images-to-the-window-size/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Brute force attack a BIOS with Arduino</title>
		<link>http://www.alfersoft.com.ar/blog/2011/11/14/brute-force-attack-a-bios-with-arduino/</link>
		<comments>http://www.alfersoft.com.ar/blog/2011/11/14/brute-force-attack-a-bios-with-arduino/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 00:55:27 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[attack]]></category>
		<category><![CDATA[bios]]></category>
		<category><![CDATA[brute]]></category>
		<category><![CDATA[Duemilanove]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[password]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=320</guid>
		<description><![CDATA[The goal of this experiment is to convert the Arduino board into an USB keyboard plus a VGA sniffer to crack the password of a standard BIOS using the brute force attack method. There are no advantages in using this method, in fact this can be very slow and you may never find the password [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/IMG_1964.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/IMG_1964-300x200.jpg" alt="BIOS hack" title="BIOS hack" width="300" height="200" class="alignleft size-medium wp-image-322" /></a>The goal of this experiment is to convert the Arduino board into an USB keyboard plus a VGA sniffer to crack the password of a standard BIOS using the <a href="http://en.wikipedia.org/wiki/Brute-force_attack" title="Brute force attack">brute force attack</a> method. There are no advantages in using this method, in fact this can be very slow and you may never find the password at all, but as always we do it for fun. It&#8217;s just a proof of concept, there are many ways of resetting a BIOS specially if you have access to the hardware, and you need it anyway because we&#8217;re talking about BIOS and there is no &#8220;remote access&#8221; as far as I know.<br/><br />
<span id="more-320"></span><br />
In theory, you can use it with other programs also not only a BIOS setup, but there must be some special conditions, for example the software must be one of those that doesn&#8217;t block after a few failed password entry attempts.<br/><br />
Also one of the main limitations is that we cannot read the whole VGA frame and process it, instead we read one single pixel from (more or less) the middle of the screen, and according to its color we go through the different steps, for example: a red pixel in the middle of the screen may indicate that the password is wrong in a regular BIOS setup, while a blue pixel can indicate that it is ready to receive the next password.<br/></p>
<h5>USB Keyboard Emulator</h5>
<p>For the USB keyboard part, I&#8217;ve used the <a href="http://code.google.com/p/vusb-for-arduino/" title="V-USB for Arduino" target="_blank">V-USB for Arduino</a> code, which in turns uses <a href="http://www.obdev.at/products/vusb/download.html" title="V-USB" target="_blank">V-USB library</a>. You will need to install the V-USB for Arduino to make the &#8220;pde&#8221; work.</p>
<h5>Circuit</h5>
<p>The Arduino shield for this project is pretty simple, I&#8217;ve attached a regular LCD module to have an output to avoid a second computer just to see the progress or result.<br />
A couple of Zener diodes to make the USB keyboard interface (it&#8217;s one of the four options suggested in the V-USB Readme, here is a <a href="http://www.practicalarduino.com/projects/virtual-usb-keyboard" title="Virtual USB Keyboard Arduino" target="_blank">link to another project</a> that uses this method also).<br />
There is a button which is used to pause/continue the attack. If you keep the button pressed for more than 2 seconds, the attack will be reset.<br />
<br/><br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/schematic.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/schematic-300x159.png" alt="BIOS hack schematic" title="BIOS hack schematic" width="300" height="159" class="aligncenter size-medium wp-image-326" /></a><br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/board.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/board-300x213.png" alt="BIOS hack board" title="BIOS hack board" width="300" height="213" class="aligncenter size-medium wp-image-327" /></a><br />
<br/></p>
<h5>Sniff the VGA</h5>
<p>To know the color of the pixel in the middle of the screen, we need to read the analog Red signal, and also the vertical and horizontal synch pulses to know when to read the Red. The first attempt was using Arduino&#8217;s <code>attachInterrupt</code> to capture the HSYNC and VSYNC but the overhead made the USB keyboard to stop working.<br/><br />
The ISR() and SIGNAL() macros seems to work better in this case, so the VSYNC pulse will reset a global variable called <code>h_line</code> while the HSYNC will increment it to know in which line is the VGA frame being drawn.<br/><br />
Our <code>waitWrongPassword</code> function does the analysis of the pixel. It waits for a few seconds to appear the red pixel, and keeps looking at the line counter so when it is in the #238 (almost the vertical middle in an 640&#215;480 resolution) it will delay a little bit to get the horizontal middle timing, and read the analog input.<br/><br />
Then, after reading the red analog input the result is compared to see if the &#8216;wrong password&#8217; dialog is popped, I&#8217;m talking about the <code>if (valueR > 140)</code>. You will probably <strong>need</strong> to change this value, according to your VGA card levels.</p>
<h5>Code</h5>
<p>You need to define the character set that you want to use for the attack. To do this, modify the <code>charset</code> array adding the USB key codes you want to use. We only have <code>KEY_A, KEY_B, KEY_C</code> by default in the example code. Also, you need to modify a second array called <code>charset_log</code> which must have the same size, but instead of the key code it reflects the printable byte, for logging purposes.<br />
The other thing you need to change is the maximum length of the password, by default set to 4. Look for the <code>MAX_LEN</code> define.<br />
The state is periodically saved in the EEPROM so in case of power failure, you can continue from the last (or near the last) tested password.<br />
<br/><br />
Download the <a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/BIOSHack.zip" title="BIOS Hack Source Code and Circuit">code here</a>, and feel free to modify it if you need.<br />
<br/><br />
Here some pictures of the shield<br />
<div id="attachment_334" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/IMG_1950.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/IMG_1950-300x200.jpg" alt="" title="BIOS Hack case" width="300" height="200" class="size-medium wp-image-334" /></a><p class="wp-caption-text">An iPod box for the case</p></div><br />
<div id="attachment_335" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/IMG_1957.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/IMG_1957-300x200.jpg" alt="" title="BIOS Hack circuit board" width="300" height="200" class="size-medium wp-image-335" /></a><p class="wp-caption-text">Tone transfer method to make the board. A little bit burnt due to the excessive ironing.</p></div><br />
<div class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/IMG_1961.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/IMG_1961-300x200.jpg" alt="" title="BIOS Hack front view" width="300" height="200" class="aligncenter size-medium wp-image-337" /></a><p class="wp-caption-text">Front</p></div><br />
<div id="attachment_339" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/IMG_1962.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/IMG_1962-300x200.jpg" alt="" title="BIOS Hack back view" width="300" height="200" class="size-medium wp-image-339" /></a><p class="wp-caption-text">Back</p></div><br />
Bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2011/11/14/brute-force-attack-a-bios-with-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating GAE Blobstore to an HRD application</title>
		<link>http://www.alfersoft.com.ar/blog/2011/11/14/migrating-gae-blobstore-to-an-hrd-application/</link>
		<comments>http://www.alfersoft.com.ar/blog/2011/11/14/migrating-gae-blobstore-to-an-hrd-application/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 03:09:40 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Programming FAQ]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[blobinfo]]></category>
		<category><![CDATA[blobstore]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[GAE]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[high replication database]]></category>
		<category><![CDATA[HRD]]></category>
		<category><![CDATA[migrate]]></category>
		<category><![CDATA[migration]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=296</guid>
		<description><![CDATA[If you are planning to migrate your Google App Engine application to the &#8220;new&#8221; High Replication Database scheme, then you probably know that the Google migration process won&#8217;t handle Blobstore files. Here you will find some python scripts that will help you to move the Blobstore files from the old application to the new one, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/google-app-engine_logo_0111.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/11/google-app-engine_logo_0111.png" alt="Google App Engine" title="google app engine" width="150" height="150" class="alignleft size-full wp-image-301" /></a>If you are planning to migrate your Google App Engine application to the &#8220;new&#8221; High Replication Database scheme, then you probably know that the Google migration process won&#8217;t handle Blobstore files.</p>
<p>Here you will find some python scripts that will help you to move the Blobstore files from the old application to the new one, and correct all the references in the new database. As always, use at your own risk, don&#8217;t try to do anything without reading and understanding the scripts, otherwise you may loose your data permanently.</p>
<p><span id="more-296"></span></p>
<p>Some considerations:</p>
<ul>
<li>We did used these scripts in our very own application, so I can say it works. However, I had to edit the original scripts to make them more &#8220;generic&#8221;, remove my database references and names, etc.</li>
<li>I will try to describe the steps of the migration, but please don&#8217;t try to do anything before reading the whole article first.</li>
<li>This is not by any means intended to be a fully automatic migration, in fact, the steps needs to be manually executed one by one.</li>
<li><b>The scripts won&#8217;t migrate big files.</b> We have migrated files up to 40Mb without problems, but if you have files bigger than that, it will probably fail. For example we tried a 300Mb file unsuccessfully, the reason is that the file needs to be downloaded from the old app to the new, and there is a 1 minute timeout for the app requests, so if the download takes more than that it will fail.</li>
</ul>
<h5>How does the script works</h5>
<p>You will need to put the script in your applications, both the new (HRD) and the old one. It basically exposes four URLs and you will need to access two of them from the HRD application.<br />
By doing this you will download all the blob files from the old application to the new one, the script will create a model that keeps a map between the old and new references.<br />
The final step is to migrate the old references to the new one in the HRD databases.</p>
<h5>Prerequisites</h5>
<ul>
<li>All the references to blob files in your models must be of type <code>blobstore.BlobReferenceProperty</code>, if not you will need to adjust them first.</li>
<li>Migrate the databases from the old app to the new HRD app using the <a href="http://code.google.com/appengine/docs/adminconsole/applicationsettings.html#Migrate_from_Master/Slave_to_High_Replication_Datastore" title="Google App Engine migrate datastore">standard Google migration method</a>.</li>
</ul>
<h5>Steps</h5>
<ul>
<li>Add the URLs to your application</li>
</ul>
<pre>
<pre class="brush: python; title: ; notranslate">
def main():
    application = webapp.WSGIApplication(
          [
           # ... Your app URLs here ...
           # TODO - REMOVE THIS AFTER MIGRATION
           ('/mig/__getblob/(.+)', GetBlob),
           ('/mig/__getblobkeys/?', GetBlobKeys),
           ('/mig/__migrateblobs/?', MigrateBlobs),
           ('/mig/__migratereferences/?', MigrateBlobReferences),
          ], debug=True)
    run_wsgi_app(application)

if __name__ == '__main__':
  main()
</pre>
</pre>
<ul>
<li>Then add the migration code</li>
</ul>
<pre>
<pre class="brush: python; title: ; notranslate">
####
# TEMPORARY BLOBSTORE MIGRATION CODE
####

MODELS = (
    # add your (model, blobinfo_field_name) tuples here
    (&quot;myModel1&quot;, &quot;blobinfofield&quot;),
    (&quot;myModel2&quot;, &quot;BlobInfo&quot;),
)

class mig_BlobMig(db.Model):
    fname = db.StringProperty()
    blobinfo = blobstore.BlobReferenceProperty()
    origkey = db.StringProperty()

class MigrateBlobReferences(blobstore_handlers.BlobstoreDownloadHandler):
    '''Migrate blob info references'''
    def get(self):
        import models
        tb = dict([(str(blob.origkey), blob.blobinfo) for blob in mig_BlobMig.all()])
        for modelname, field in MODELS:
            to_put = []
            skipped = 0
            for obj in db.GqlQuery('SELECT * FROM %s'%modelname):
                oldkey = getattr(obj, field)
                if oldkey:
                    oldkey = str(oldkey.key())
                if oldkey in tb:
                    setattr(obj, field, tb[oldkey])
                    to_put.append(obj)
                else:
                    skipped += 1
            db.put(to_put)
            self.response.out.write(&quot;[%s] - Migrated %d references!&lt;br/&gt;Skipped: %d&lt;br/&gt;\n&quot;%(modelname, len(to_put), skipped))

class MigrateBlobs(blobstore_handlers.BlobstoreDownloadHandler):
    '''Migrate blobs from myoldapp to mynewapp'''
    def get(self):
        import time
        from google.appengine.api import files, urlfetch
        start_time = time.time()
        timed_out = False
        migrated_keys = set([str(blob.origkey) for blob in mig_BlobMig.all()])
        all_blobs = eval(urlfetch.fetch(&quot;https://myoldapp.appspot.com/mig/__getblobkeys&quot;, deadline=15.0).content)
        all_keys = set(all_blobs.keys())
        missing_keys = list(all_keys-migrated_keys)
        if not missing_keys:
            self.response.out.write(&quot;Nothing to migrate!&quot;)
            return
        # Download 20 blobs per round
        download_keys = missing_keys[:20]
        MAXSIZE = (10*1024*1024) # 10MB
        for origkey in download_keys:
            blob = all_blobs[origkey]
            url = &quot;https://myoldapp.appspot.com/mig/__getblob/%s&quot;%urllib.quote_plus(origkey)
            blob_path = files.blobstore.create(mime_type=blob[&quot;content_type&quot;], _blobinfo_uploaded_filename=blob[&quot;filename&quot;])
            fsize = int(blob[&quot;size&quot;])
            with files.open(blob_path, 'a') as f:
                for first_byte in range(0, fsize, MAXSIZE):
                    last_byte = (first_byte+MAXSIZE-1)
                    if last_byte&gt;=fsize: last_byte=(fsize-1)
                    bytes_range = &quot;bytes=%d-%d&quot;%(first_byte,last_byte)
                    logging.info(&quot;Downloading [%s] range [%s] key=[%s]&quot;%(blob[&quot;filename&quot;], bytes_range, origkey))
                    res = urlfetch.fetch(url, deadline=35.0, headers={&quot;Range&quot;: bytes_range})
                    f.write(res.content)
                    del res.content
                    del res
                    if (time.time()-start_time &gt; 40.0):
                        timed_out = True
                        break
            if timed_out:
                self.response.out.write(&quot;Stopped due to time limit!&lt;br/&gt;&quot;)
                break
            files.finalize(blob_path)
            blob_key = files.blobstore.get_blob_key(blob_path)
            blob_info = blobstore.BlobInfo.get(blob_key)
            mig_BlobMig(fname=blob[&quot;filename&quot;], blobinfo=blob_info, origkey=origkey).put()
            logging.info(&quot;Successfully downloaded [%s]!!!&quot;%(blob[&quot;filename&quot;]))
            self.response.out.write(&quot;Migrated %s&lt;br/&gt;&quot;%blob[&quot;filename&quot;])
        self.response.out.write(&quot;&lt;br/&gt;SUCCESS!&quot;)

class GetBlobKeys(blobstore_handlers.BlobstoreDownloadHandler):
    '''Retrieve all Blob Keys, as a JSON string'''
    def get(self):
        from simplejson.encoder import JSONEncoder
        blobs = {}
        for blob_info in blobstore.BlobInfo.all():
            blobs[str(blob_info.key())] = {
             &quot;filename&quot;:str(blob_info.filename),
             &quot;content_type&quot;:str(blob_info.content_type),
             &quot;size&quot;:int(blob_info.size),
             &quot;key&quot;:str(blob_info.key()),
            }
        self.response.headers[&quot;Content-type&quot;] = &quot;application/json&quot;
        self.response.out.write(JSONEncoder().encode(blobs))

class GetBlob(blobstore_handlers.BlobstoreDownloadHandler):
    '''Download a blob given its key'''
    def get(self, blobkey):
        blobkey = str(urllib.unquote(blobkey))
        blob_info = blobstore.BlobInfo.get(blobkey)
        if not blob_info:
            self.error(404)
            return
        self.response.headers[&quot;Content-type&quot;] = str(blob_info.content_type)
        self.send_blob(blob_info, save_as=True)

####
# END OF TEMPORARY BLOBSTORE MIGRATION CODE
####
</pre>
</pre>
<ul>
<li>Modify the <code>MODELS</code> variable adding the models and blob info fields that you need to update</li>
<li>Replace <code>myoldapp</code> URLs with the actual URL of your old application</li>
<li>Synchronize the code on both apps</li>
<li>Open a browser and point it to <code>http://mynewapp.appspot.com/mig/__migrateblobs</code>. Of course, <code>mynewapp</code> must be replaced with your actual HRD application name. This will download the blobs from the old app to the new one. Because there is a timeout limitation you will need to call it many times. <b>WARNING: You must make only one request at time, never call it from two browsers / tabs at the same time or you will mess the migration database!!!</b>. So this step must be carefully executed, one request at time and wait for it to finish before calling the next one. Repeat this until you see the message <code>Nothing to migrate!</code>. This step can be very slow depending on how many files you have in the blobstore and the size of them, it might take a long time to get all the files downloaded. Be patient!</li>
<li>Once all the files are copied to the new app, point the browser to <code>http://mynewapp.appspot.com/mig/__migratereferences</code>. Should be quick, and it needs to be executed only one time. However doesn&#8217;t harm to call it more than once.</li>
<li>The last step, remove the migration code and URLs and synchronize the code again. You can also remove the <code>mig_BlobMig</code> database.</li>
</ul>
<p>Good migration.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2011/11/14/migrating-gae-blobstore-to-an-hrd-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tiny Pong: More fun with ATtiny45 and VGA</title>
		<link>http://www.alfersoft.com.ar/blog/2011/09/19/tiny-pong-more-fun-with-attiny45-and-vga/</link>
		<comments>http://www.alfersoft.com.ar/blog/2011/09/19/tiny-pong-more-fun-with-attiny45-and-vga/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 02:54:13 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[assembler]]></category>
		<category><![CDATA[atmel]]></category>
		<category><![CDATA[attiny]]></category>
		<category><![CDATA[attiny45]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[pong]]></category>
		<category><![CDATA[VGA]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=284</guid>
		<description><![CDATA[I&#8217;m still waiting for my cheap Bluetooth module from China which will serve as an input interface for my scoreboard project. In the meantime, I&#8217;ll show you how to convert your ATtiny microcontroller into a Pong game (with no input so far). So, I&#8217;ve used the scoreboard source as a base and changed a little [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m still waiting for my cheap <a href="http://www.dealextreme.com/p/wireless-bluetooth-rs232-ttl-transceiver-module-80711" title="Bluetooth Module">Bluetooth module from China</a> which will serve as an input interface for my <a href="http://www.alfersoft.com.ar/blog/2011/08/30/scoreboard-part-1-vga-signal-from-an-attiny45/" title="Scoreboard (Part 1: VGA signal from an ATtiny45)">scoreboard project</a>. In the meantime, I&#8217;ll show you how to convert your ATtiny microcontroller into a Pong game (with no input so far).</p>
<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/09/IMG_2019.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/09/IMG_2019-300x200.jpg" alt="" title="Tiny Pong" width="300" height="200" class="alignnone size-medium wp-image-285" /></a><br />
<span id="more-284"></span><br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/09/IMG_2018.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/09/IMG_2018-300x200.jpg" alt="" title="Tiny Pong in the  protoboard" width="300" height="200" class="alignnone size-medium wp-image-288" /></a><br />
So, I&#8217;ve used the scoreboard source as a base and changed a little bit the pinout.</p>
<pre>

                       ATtiny45
                  +-----------------+
                  |                 |
           IN ----| 1 (PB5) (VCC) 8 |---- +5V
    22pf          |                 |
  +--||----+------| 2 (PB3) (PB2) 7 |---- HSYNC
  |       [ ] XTAL|                 |
  +--||----+------| 3 (PB4) (PB1) 6 |---- VSYNC
  | 22pf          |                 |
  +---------------| 4 (GND) (PB0) 5 |---- RGB
  |               |                 |
 GND              +-----------------+
</pre>
<p>Now the RGB is connected to PB0, and there is a good reason for this. I&#8217;m still using the same technique of storing what I want to render in registers but instead of 4, this time I&#8217;m using 15 so I can achieve an horizontal resolution of 120 by 96 to make the pixels somehow squared. Now, to be able to walk trough the 120 bits and turn the RGB pin on/off accordingly (and evenly) I needed to crop the code, removing the loops (so you will see a lot of similar code in the part that renders the line) and the conditional skip now replaced by an &#8220;add with carry&#8221; after the shift into a temporary register that will be used with &#8220;out&#8221; which is less expensive than &#8220;sbi&#8221; and &#8220;cbi&#8221;.</p>
<p>So, in terms of code optimization, this:</p>
<pre>
	; r1 bit 0
	cbr r16, 1
	lsl r1
	adc r16, r22
	out PORT, r16
	... repeated 120 time (8 times per bit and 15 times per register)
</pre>
<p>Is better than:</p>
<pre>
	ldi r16, 0x08
line44:
	rol r8
	brcc rgboff44
	nop
	; RGB on
	sbi PORT, RGB		; sbi = 2 clocks
	rjmp cont44
rgboff44:
	; RGB off
	cbi PORT, RGB		; cbi = 2 clocks
	nop
	nop
cont44:
	dec r16
	nop
	nop
	nop
	nop
	nop
	brne line44
</pre>
<p>There are also other parts of the code that might be of interest. For example, I&#8217;ve use <a href="http://en.wikipedia.org/wiki/Linear_feedback_shift_register" title="Linear feedback shift register">LFSR</a> to add some pseudo-random variables to the ball direction and the paddle &#8220;computer&#8221; movements. Also, I&#8217;ve used the <a href="http://en.wikipedia.org/wiki/Bresenham's_line_algorithm" title="Bresenham's line algorithm">Bresenham&#8217;s line algorithm</a> to determine the ball position.<br />
The missing part, is still the input. I&#8217;m not sure how this will work with only one pin available, but I guess I&#8217;ll work out something with the Bluetooth module and one of the synch signals (if even possible).<br />
I&#8217;ve tried to add some intro screen or &#8220;splash&#8221;, but the program memory is so small that I&#8217;ve quickly exceeded the 4096 available bytes.</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/8KlHqu1tnMg" frameborder="0" allowfullscreen></iframe></p>
<p>Download the <a href='http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/09/tinypong_1.0.zip'>Tiny Pong 1.0 source code</a> and enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2011/09/19/tiny-pong-more-fun-with-attiny45-and-vga/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Playing around with Arduino</title>
		<link>http://www.alfersoft.com.ar/blog/2011/08/31/playing-around-with-arduino/</link>
		<comments>http://www.alfersoft.com.ar/blog/2011/08/31/playing-around-with-arduino/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 04:10:03 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Duemilanove]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=277</guid>
		<description><![CDATA[Some quick thoughts about the Arduino Duemilanove board. First Impressions I&#8217;ve got one of these boards like a month ago, and I can tell you so far that I like many things about it. First of all the simplicity of plugging the USB cable and get things working almost instantly. I don&#8217;t think is necessary [...]]]></description>
			<content:encoded><![CDATA[<p>Some quick thoughts about the <a href="http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove" title="Arduino Duemilanove Board" target="_blank">Arduino Duemilanove</a> board.</p>
<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/Duemilanove.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/Duemilanove-300x300.jpg" alt="Duemilanove" title="Duemilanove" width="300" height="300" class="alignnone size-medium wp-image-278" /></a></p>
<p><span id="more-277"></span></p>
<p><strong>First Impressions</strong></p>
<p>I&#8217;ve got one of these boards like a month ago, and I can tell you so far that I like many things about it. First of all the simplicity of plugging the USB cable and get things working almost instantly. I don&#8217;t think is necessary to explain anything in this blog since the Internet is plenty of Arduino tutorials, examples, projects, documents, forums, etc. If you just got one of this boards, your starting point should be here: <a href="http://arduino.cc/en/Guide/HomePage" title="Arduino Home Page" target="_blank">http://arduino.cc/en/Guide/HomePage</a><br />
So, first thing you will do is download the Arduino software, install it and try to upload one of the sample programs already included like the blinking led, using the provided IDE.</p>
<p><strong>Easy</strong></p>
<p>If you are impatient like me, you will probably read the first page and then jump to the board and try to connect components, like a led or maybe a 16&#215;2 LCD display, etc. and you will quickly discover that it IS really easy to use: the core Arduino API already have functions to handle LCD displays, interruptions are trivial with &#8220;attachInterrupt&#8221;, then with the &#8220;shiftOut&#8221; function you can extend your ports by attaching one or more 74HC595, and many other features.</p>
<p><strong>First Depressions</strong></p>
<p>On the other hand, I don&#8217;t like the IDE, maybe because I&#8217;m adult?. If you are used to any other IDE, like eclipse, or notepad.exe (he he), you may not like the IDE too. I mean, if you select a text and press Ctrl+F, what do you expect to appear in the search box? well, according to this IDE, nothing or the text from the last search. Not to talk about the annoying (Java?) bug that doesn&#8217;t allows you to use dead keys with some specific combinations of JDK and OS.<br />
Then you have the Sketches concept. Sketches, are files with .pde extension which happens to be actually C++ files. Before building this file, the IDE instruments it to add a core include &#8220;WProgram.h&#8221; and prototypes all your functions. Then the IDE will link with the core files which already includes a very simple main() that calls the init(), setup() and loop() functions, as you can see in the core Arduino source code main.cpp:</p>
<pre>
#include <WProgram.h>

int main(void)
{
	init();

	setup();

	for (;;)
		loop();

	return 0;
}
</pre>
<p><strong>A more advanced test</strong></p>
<p>I&#8217;ve been able to convert the Arduino into an USB keyboard with a few external components following the example from <a href="http://www.practicalarduino.com/projects/virtual-usb-keyboard" title="Arduino Virtual USB Keyboard" target="_blank">www.practicalarduino.com</a> which uses the <a href="http://code.google.com/p/vusb-for-arduino/" title="V-USB for Arduino" target="_blank">Arduino V-USB library</a> which in turns uses the <a href="http://www.obdev.at/products/vusb/index.html" title="V-USB AVR" target="_blank">Virtual USB Port for AVR microcontrollers</a>. This will be the base for one of my upcoming project involving brute-force attack BIOS hacking <img src='http://www.alfersoft.com.ar/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><strong>Shields</strong></p>
<p>Finally, I would like to recommend this shield if you need an ISP programmer: <a href="http://drug123.org.ua/mega-isp-shield/" title="Mega-ISP Shield" target="_blank">The Mega-ISP Shield</a>.<br />
I made it, it works and is great! really. With this shield you can convert your Arduino into an ISP programmer by loading the <a href="http://code.google.com/p/mega-isp/" title="mega-isp" target="_blank">mega-isp</a> &#8220;sketch&#8221;.</p>
<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/IMG_1986.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/IMG_1986-300x200.jpg" alt="Mega-ISP Shield" title="Mega-ISP Shield" width="300" height="200" class="alignnone size-medium wp-image-279" /></a></p>
<p>As a side note, you will notice that you won&#8217;t be able to create a shield using the regular perforated boards, because of the pin alignment. Unless you only need pins 1 to 7 Xor 8 to 13 from the D port.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2011/08/31/playing-around-with-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scoreboard (Part 1: VGA signal from an ATtiny45)</title>
		<link>http://www.alfersoft.com.ar/blog/2011/08/30/scoreboard-part-1-vga-signal-from-an-attiny45/</link>
		<comments>http://www.alfersoft.com.ar/blog/2011/08/30/scoreboard-part-1-vga-signal-from-an-attiny45/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 03:09:52 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[assembler]]></category>
		<category><![CDATA[atmel]]></category>
		<category><![CDATA[attiny]]></category>
		<category><![CDATA[attiny45]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[VGA]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=262</guid>
		<description><![CDATA[This project aims to display a scoreboard in a regular VGA monitor, remotely controlled with an Android device (cellphone, tablet) via Bluetooth. One of the challenges was trying to use cheap components (except for the monitor) and Atmel&#8217;s ATtiny45 sounds great for this purpose. It can run at 20MHz with an external oscillator, the downside [...]]]></description>
			<content:encoded><![CDATA[<p>This project aims to display a scoreboard in a regular VGA monitor, remotely controlled with an Android device (cellphone, tablet) via Bluetooth.</p>
<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/IMG_1989.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/IMG_1989-300x200.jpg" alt="Scoreboard on TV" title="Scoreboard on TV" width="300" height="200" class="alignnone size-medium wp-image-263" /></a></p>
<p><span id="more-262"></span></p>
<p>One of the challenges was trying to use cheap components (except for the monitor) and <a href="http://www.atmel.com/dyn/products/product_card.asp?part_id=3618" title="ATtiny45" target="_blank">Atmel&#8217;s ATtiny45</a> sounds great for this purpose. It can run at 20MHz with an external oscillator, the downside is that the number of I/O pins available is very limited. The external oscillator will take PB2 and PB3, thus using an external clock (a crystal with some circuitry that generates TTL) I could save PB2!, unfortunately I don&#8217;t have one, and is not easy to find here.</p>
<p>There are still 4 pins available, PB0 and PB1 will be used for the VGA HSYNC and VSYNC respectively, PB2 to generate the RGB (only one color!). PB5 to get the input information that I want to display, hopefully this will come from a bluetooth module specially tuned for this, or from another ATtiny45 in the worst case.</p>
<p><strong>VGA signal generation</strong></p>
<p>I knew that 20MHz would be enough to generate an acceptable VGA output because of <a href="http://www.linusakesson.net/scene/craft/" title="Craft" target="_blank">Linus Akesson&#8217;s Craft</a> project. In this case he uses an ATmega88 with more I/O ports. Like you can read in his page, this is all about VGA timing. Sending the horizontal and vertical sync pulses at the right time is essential, so the obvious language for having control of every cycle used was assembler (using the gnu compiler in this case).</p>
<p>You can read more about VGA timings <a href="http://en.wikipedia.org/wiki/Video_Graphics_Array" title="VGA Wikipedia" target="_blank">in the Wikipedia</a> and <a href="http://courses.engr.illinois.edu/ece412/MP_files/mp3/vga_timing.pdf" title="VGA timing" target="_blank">here</a>. Basically I send a HSYNC pulse during the so called &#8220;horizontal blanking&#8221; period just before painting each of the 480 lines. After the 480, I need to send another 45 lines to make the vertical blanking period (no RGB is sent). During the blanking period I also need to send the VSYNC pulse, to signalize that the frame painting is about to start (talking in &#8216;lines&#8217; the VSYNC pulse will be between line 10 and 12 of the vertical blanking).</p>
<p>The horizontal blanking can be divided in three parts: the front porch 0.94µs, the sync pulse 3.77µs and the back porch 1.89µs. I take advantage of these cycles to determine which information should be &#8216;painted&#8217; according to the line number. Since I&#8217;m trying to paint 4 numbers to display the score, I&#8217;ve defined that each character is 8&#215;10 so it can be represented in only 10 bytes. So I store the line that I need to paint for each character in 4 different registers. Also I need to repeat the line vertically to give some proportional height to the characters this is done by mapping line number to font lines in a fixed table. That will result in very ugly and big characters, but that&#8217;s OK for the scope of this project <img src='http://www.alfersoft.com.ar/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p><strong>Schematic</strong></p>
<p>No Eagle for now, but here is an ASCII schematic of the circuit.</p>
<pre>
                      ATtiny45
                  +-----------------+
                  |                 |
           IN ----| 1 (PB5) (VCC) 8 |---- +5V
    22pf          |                 |
  +--||----+------| 2 (PB3) (PB2) 7 |---- RGB
  |       [ ] XTAL|                 |
  +--||----+------| 3 (PB4) (PB1) 6 |---- VSYNC
  | 22pf          |                 |
  +---------------| 4 (GND) (PB0) 5 |---- HSYNC
  |               |                 |
 GND              +-----------------+
</pre>
<p>Note: I&#8217;ve used an external 12v power source with a 5v voltage regulator 78L05. In my case it was very important to put two filter capacitors in the input and output of the regulator, without them the noise generated by the power supply won&#8217;t let the monitor synchronize properly.</p>
<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/IMG_1997.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/IMG_1997-300x200.jpg" alt="ATtiny45 in the protoboard" title="ATtiny45 in the protoboard" width="300" height="200" class="alignnone size-medium wp-image-265" /></a></p>
<p><strong>Some code</strong></p>
<p>Let&#8217;s see some interesting parts.</p>
<p>Character definition. Like I said the characters have a fixed size of 8&#215;10, in the code they look like this:</p>
<pre>
number0:
	.byte 0b00000000
	.byte 0b00111000
	.byte 0b01000100
	.byte 0b01000100
	.byte 0b01000100
	.byte 0b01000100
	.byte 0b01000100
	.byte 0b00111000
	.byte 0b00000000
	.byte 0b00000000
</pre>
<p>The mapping between screen lines and font lines looks like this:</p>
<pre>
maplines1:
	; map lines (from 50 to 205)
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
	.byte 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
	.byte 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
	...
</pre>
<p>So lines 50 to 88 will map to the first character line (I keep 50 lines of margin at the top and 50 at the bottom, so I actually use 380 lines, divided by ten will result in 38 VGA lines for each font line).</p>
<p>Finally, to get the font line data given the font line number (in r17), I&#8217;ll use the lpm instruction like this:</p>
<pre>
linefor0:
	ldi ZL, lo8(number0)
	ldi ZH, hi8(number0)
	add ZL, r17
	adc ZH, r22
	lpm
	ret
</pre>
<p>The code doesn&#8217;t look complicated at all. The complicated part maybe was making sure to get the right timings, that will be measuring the cycles used between each part of the code. I found that AVR Studio is a great tool for debugging, however cycle measuring between two instructions in the code is something that can take some time, I could&#8217;t found conditional breakpoints, and clicking 480 times the &#8220;continue&#8221; button to test the limits can be a little bit annoying. So, I&#8217;ve made a little tool in Python / PySide to help me with this measuring. It&#8217;s like an assembler emulator with only a few instructions implemented and of course cycle calculation.</p>
<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/2011-08-29-11.18.22-pm.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/2011-08-29-11.18.22-pm-300x168.png" alt="Basic AVR Debugger" title="Basic AVR Debugger" width="300" height="168" class="alignnone size-medium wp-image-266" /></a></p>
<p>Everything, including the AVR debugger is available for download here. You can do whatever you want with it at your own risk, and in case you feel more comfortable with a license: BSD</p>
<p><a href='http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/scoreboard_part1.zip'>Scoreboard source Part 1</a></p>
<p>Things to do for the next parts:<br />
- Once my <a href="http://www.dealextreme.com/p/wireless-bluetooth-rs232-ttl-transceiver-module-80711" title="DealExtreme Bluetooth Module" target="_blank">cheap Bluetooth module</a> arrives from China, I&#8217;ll try to hack it. If I can&#8217;t modify its firmware at all, I&#8217;ll probably end up with a second ATtiny doing the communication between my VGA ATtiny board and the module.<br />
- Make the Android program to communicate with the Bluetooth module (I guess its plenty of examples in the Internet)<br />
- Last thing, would be trying to improve the characters on screen. I don&#8217;t have too much memory in the ATtiny, and certainly not much processing capacity between each pixel, but I guess I can try to emulate some squared pixels, maybe like this:</p>
<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/2011-08-29-11.43.21-pm.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/08/2011-08-29-11.43.21-pm.png" alt="Scoreboard - nice to have" title="Scoreboard - nice to have" width="280" height="91" class="alignnone size-full wp-image-268" /></a></p>
<p>I could event try to get the yellowish color by putting some diodes in the correct RGB wires, but that&#8217;s for next chapter.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2011/08/30/scoreboard-part-1-vga-signal-from-an-attiny45/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

