<?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 &#187; Electronic Projects</title>
	<atom:link href="http://www.alfersoft.com.ar/blog/category/elec/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>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>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>
		<item>
		<title>Make something useful out of your DPF (Digital Photo Frame)</title>
		<link>http://www.alfersoft.com.ar/blog/2011/04/04/make-something-useful-out-of-your-dpf-digital-photo-frame/</link>
		<comments>http://www.alfersoft.com.ar/blog/2011/04/04/make-something-useful-out-of-your-dpf-digital-photo-frame/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 16:52:05 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[circuit]]></category>
		<category><![CDATA[digital]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[dpf]]></category>
		<category><![CDATA[frame]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[serial]]></category>
		<category><![CDATA[switch]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=221</guid>
		<description><![CDATA[We had this great idea of using an old digital photo frame from smartparts to display some useful reports at work. In this case, useful will mean that the reports (pictures in the frame) needs to be automatically updated, with no human intervention. Take a look to this post, you may find something useful for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110401_171720.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110401_171720-150x150.jpg" alt="" title="IMG_20110401_171720" width="100" height="100" class="alignleft size-thumbnail wp-image-232" /></a>We had this great idea of using an old digital photo frame from <a href="http://smartpartsproducts.com/content/index.html">smartparts</a> to display some useful reports at work.<br />
In this case, useful will mean that the reports (pictures in the frame) needs to be automatically updated, with no human intervention.<br />
Take a look to this post, you may find something useful for your own DIY project!<br />
<span id="more-221"></span><br />
There are probably several ways to update the pictures dynamically, we have chosen the easiest one: connect it to an old Itona computer (we&#8217;ve plenty of these crappy machines 300Mhz processor, 512Mb of hard disk) running Ubuntu Linux and then make a script that will periodically (cron) gather the info we want to show from the Internet convert it to JPG images, and update the photo frame.</p>
<p><a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110404_105718.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110404_105718-225x300.jpg" alt="" title="IMG_20110404_105718" width="225" height="300" class="alignnone size-medium wp-image-225" /></a><br />
Too easy? Ok, a real ninja hacker solution would had been taking apart the photo frame, put a Linux on the nice ARC processor through the JTAG interface and then plug some Wi-Fi dongle and do Everything directly on the DPF itself. But that&#8217;s just dreaming, we don&#8217;t have experience nor time for that.</p>
<p>Now you may ask, why didn&#8217;t you plug a monitor on the machine and just display whatever you want directly on the monitor? and the first reason is, we don&#8217;t have spare LCD monitors for this purpose (in fact we have many CRT monitors that nobody uses, but that requires just too much space). The second reason is that we wanted to do something more exiting, like hacker things <img src='http://www.alfersoft.com.ar/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
<p>So we setup everything: we made the scripts to generate the images, installed Ubuntu Linux 10.4 on the Itona and actually we borrowed another 512mb (flash) hard disk form another Itona and put it in the secondary IDE to get a RAID configuration with 1GB of space, just enough for Ubuntu and our script. Then realized of a small problem, as soon as you plug the DPF on the USB port, it enters in &#8220;transfer mode&#8221; and stops displaying the images. No matter if you eject, unmount, safe remove, shut down the computer, etc. the photo frame wont show the pictures until you physically unplug the USB cable (cut off the +5V). Here is were our ingenious circuit enters in action. A <strong>USB interrupter controlled by the parallel port</strong> (I guess serial RS-232 would work fine also using one of the signal pins).<br />
After googling, I&#8217;ve found <a href="http://forum.allaboutcircuits.com/showthread.php?t=38544&#038;page=2">a circuit</a> that seemed usable for this purpose. Just a couple transistors and a few resistors is everything we need.<br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110331_185113.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110331_185113-300x225.jpg" alt="" title="IMG_20110331_185113" width="300" height="225" class="alignnone size-medium wp-image-226" /></a><br />
Crop the board and put it in a case&#8230;<br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110331_191457.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110331_191457-300x225.jpg" alt="" title="IMG_20110331_191457" width="300" height="225" class="alignnone size-medium wp-image-227" /></a><br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110331_191507.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110331_191507-300x225.jpg" alt="" title="IMG_20110331_191507" width="300" height="225" class="alignnone size-medium wp-image-228" /></a><br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110331_192915.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110331_192915-300x225.jpg" alt="" title="IMG_20110331_192915" width="300" height="225" class="alignnone size-medium wp-image-229" /></a><br />
Finally, the whole thing mounted:<br />
The Itona hidden behind the desk&#8230;<br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110404_103336.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110404_103336-225x300.jpg" alt="" title="IMG_20110404_103336" width="225" height="300" class="alignnone size-medium wp-image-230" /></a><br />
And the DPF showing the reports!! <img src='http://www.alfersoft.com.ar/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110401_171707.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110401_171707-300x225.jpg" alt="" title="IMG_20110401_171707" width="300" height="225" class="alignnone size-medium wp-image-231" /></a><br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110401_171720.jpg"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/IMG_20110401_171720-300x225.jpg" alt="" title="IMG_20110401_171720" width="300" height="225" class="alignnone size-medium wp-image-232" /></a></p>
<p>For the circuit you will need:</p>
<ul>
<li>1k resistor (2)</li>
<li>10k resistor (2)</li>
<li>PNP transistor</li>
<li>NPN transistor</li>
<li>USB connectors, 1 to plug into the computer, the other whatever is better for your DPF</li>
<li>DB-25 male connector (if you decided to do it via parallel too)</li>
</ul>
<p><strong>IMPORTANT: following image was borrowed from http://forum.allaboutcircuits.com/showthread.php?t=38544&#038;page=2</strong><br />
<a href="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/5V-Switch.png"><img src="http://www.alfersoft.com.ar/blog/wp-content/uploads/2011/04/5V-Switch-300x216.png" alt="" title="5V-Switch" width="300" height="216" class="alignnone size-medium wp-image-238" /></a><br />
I&#8217;ve connected the control-in to the PIN #2 of the DB-25, and the PIN #20 to the ground.<br />
To turn the parallel port signal on/off I&#8217;ve made the following program in C (para.c):</p>
<pre>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include
<linux/ppdev.h>

static int pfd;

int main(int argc, char* argv[])
{
	unsigned char data=0;

	if (argc != 3) {
		printf("Usage:\n\tpara [port] [val]\n\nport: parallel port e.g. /dev/parport0\nval:  1 to activate all data bits in parallel port, or\n      0 to disable all data bits in parallel port\n\n");
		return 1;
	}
	if (argv[2][0] == '1') {
		data=0xff;
	}
	pfd = open(argv[1], O_RDWR);
	if (pfd < 0) {
		perror("Failed to open port");
		exit(0);
	}
	if ((ioctl(pfd, PPEXCL) < 0) || (ioctl(pfd, PPCLAIM) < 0)) {
		perror("Failed to lock port");
		close(pfd);
		exit(0);
	}
	printf("Setting %s data bits to: %.2X\n", argv[1], data);
	ioctl(pfd, PPWDATA, &#038;data);
	close(pfd);
	return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2011/04/04/make-something-useful-out-of-your-dpf-digital-photo-frame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>USocket &#8211; USB controlled Socket with PIC18F4550</title>
		<link>http://www.alfersoft.com.ar/blog/2008/07/08/usocket-usb-controlled-socket-with-pic18f4550/</link>
		<comments>http://www.alfersoft.com.ar/blog/2008/07/08/usocket-usb-controlled-socket-with-pic18f4550/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 04:06:25 +0000</pubDate>
		<dc:creator>fvicente</dc:creator>
				<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[CDC]]></category>
		<category><![CDATA[circuit]]></category>
		<category><![CDATA[electronic]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[PIC16F4550]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">http://www.alfersoft.com.ar/blog/?p=9</guid>
		<description><![CDATA[Introduction The idea of this project is to control (switch off/on) two power sockets with a computer by using its USB port. I&#8217;ve chosen USB in first place because I wanted to experiment with the PIC18F4550 microchip&#8217;s microcontroller, and secondly because the power supplied by this port (500mA) is enough to activate a relay without [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>The idea of this project is to control (switch off/on) two power sockets with a computer by using its USB port. I&#8217;ve chosen USB in first place because I wanted to experiment with the PIC18F4550 microchip&#8217;s microcontroller, and secondly because the power supplied by this port (500mA) is enough to activate a relay without any additional power supply.</p>
<p><img src="http://www.alfersoft.com.ar/files/usocket/pictures/proto04.jpg" alt="Prototype" width="450" height="338" /></p>
<p><span id="more-9"></span></p>
<p>The firmware is based in <a title="SIXCA USBDAQ" href="http://www.sixca.com/eng/articles/usbdaq/">SIXCA USBDAQ</a> which is in turn based on <a title="Microchip's CDC sample" href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=2124&amp;param=en532204&amp;page=wwwFullSpeedUSB">microchip&#8217;s CDC sample</a>. USBDAQ is extremely easy to use. It implements a very simple set of ASCII commands to turn on/off the digital outputs, that I use to control the two relays. I just needed to adjust the bMaxPower in order to negotiate the 500mA with the host, and I also changed the vendor ID and the name of the device to USocket.</p>
<p>I&#8217;ve also made the schematic and board design of the circuit with <a title="CadSoft Eagle" href="http://www.cadsoftusa.com/">Eagle</a>, but I never used it since I made it on a strip board <img src='http://www.alfersoft.com.ar/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> , so if you plan to use it please double check everything before.</p>
<p>The whole project including PIC firmware and Eagle files is available for download. You are free to use or modify it as you like, but please verify Microchip&#8217;s CDC sample license if you plan to use it for commercial applications.</p>
<p><span class="BODYTEXT"><span class="BODYTEXT"><strong>Disclaimer:</strong> This project involves high voltage electricity. You should not attempt this project unless you are comfortable with basic concepts of AC and DC electricity, induction, and reading circuit schematics. You and your adult supervisor are responsible for your safety when doing this project!</span></span></p>
<p><strong>Advice:</strong> Despites the high voltage part of the circuit is virtually isolated from the controller circuit by relays, these devices always represents a risk of mechanical failure and they can possibly damage your equipment or even cause physical injuries, so we (the author or the webmasters) are not responsible of any lose or damage.</p>
<h2>The Circuit</h2>
<p style="text-align: center;"><a title="Schematic" href="http://www.alfersoft.com.ar/files/usocket/pictures/full.png" target="_blank"><img class="aligncenter" style="border: 1px solid black;" src="http://www.alfersoft.com.ar/files/usocket/pictures/full.png" alt="Figure 1 - Schematic" width="450" height="393" /></a></p>
<p style="text-align: center;">Figure 1 &#8211; Schematic</p>
<p>Pretty much the same as USBDAQ but two (identical) sub-circuits were added to control the relays. A Darlington-transistor is used to protect the hardware. Once again, the idea was obtained from the web (thanks to google) and <a title="Relay control" href="http://b-l-w.de/serialrelay_en.php">here is the link to the original article</a>.</p>
<p>The PCB is divided in 3 little boards, for commodity and socket case space issues. (I&#8217;ve used only 2 strip boards in the actual prototype).</p>
<p style="text-align: center;"><a title="Board" href="http://www.alfersoft.com.ar/files/usocket/pictures/full_board.png" target="_blank"><img class="aligncenter" style="border: 1px solid black;" src="http://www.alfersoft.com.ar/files/usocket/pictures/full_board.png" alt="Figure 2 - Board" width="450" height="271" /></a></p>
<p style="text-align: center;">Figure 2 &#8211; Board</p>
<p>List of materials:</p>
<ul>
<li>IC1 &#8211; PIC16F4550 Microchip&#8217;s micro-controller (<a title="PIC18F4550 by Microchip" href="http://www.alfersoft.com.ar/files/usocket/datasheets/pic18f4550-microchip.pdf">datasheet</a>)</li>
<li>Q2 &#8211; Crystal 20Mhz</li>
<li>R1 &#8211; Resistor 4.7K</li>
<li>R2 &#8211; Resistor 1M</li>
<li>R3, R5 &#8211; Resistors 150</li>
<li>R4, R6 &#8211; Resistors 100K</li>
<li>K1, K3 &#8211; 5v Relays. I&#8217;ve used FBR211 by Fujitsu (<a title="FBR211 Relay by Fujitsu" href="http://www.alfersoft.com.ar/files/usocket/datasheets/fbr211-relay-fujitsu.pdf">datasheet</a>)</li>
<li>D1, D2, D3. D4 &#8211; Diodes 1N4004</li>
<li>Q1, Q3 &#8211; BC517 Darlington-transistors (<a title="BC517 Darlington Transistor" href="http://www.alfersoft.com.ar/files/usocket/datasheets/bc517.pdf">datasheet</a>)</li>
<li>LED1, LED2 &#8211; Regular leds</li>
<li>C1, C2 &#8211; Capacitors 22pF</li>
<li>C3 &#8211; Capacitor 470pF</li>
<li>X1 &#8211; Mini-USB Connector Type B (<a title="USB connector type B" href="http://www.alfersoft.com.ar/files/usocket/datasheets/2411-02-lumberg-usb-connector-type-b.pdf">datasheet</a>)</li>
</ul>
<p></p>
<h2>PIC Firmware</h2>
<p>Here is what I needed to modify from the original <a title="SIXCA USBDAQ" href="http://www.sixca.com/eng/articles/usbdaq/" target="_blank">SIXCA USBDAQ</a>:</p>
<p>I set bMaxPower to 250, which means 500mA. The power provided by hosts and hubs is twice the value of bMaxPower field, but in reality they are likely to allocate either 100 or 500 milliamperes rather than the specified amount.</p>
<p>The file modified is the one that contains the USB descriptor: fw/cdc/autofiles/usbdsc.c</p>
<pre class="brush: cpp; title: ; notranslate">

/* Configuration 1 Descriptor */
CFG01=
{
/* Configuration Descriptor */
sizeof(USB_CFG_DSC),    // Size of this descriptor in bytes
DSC_CFG,                // CONFIGURATION descriptor type
sizeof(cfg01),          // Total length of data for this cfg
2,                      // Number of interfaces in this cfg
1,                      // Index value of this configuration
0,                      // Configuration string index
_DEFAULT,               // Attributes, see usbdefs_std_dsc.h
250,                    // Max power consumption (2X mA) 250 = 500mA

...
</pre>
<p>In the same file I modified the Vendor ID, Product ID and corresponding strings</p>
<pre class="brush: cpp; title: ; notranslate">

/* Device Descriptor */
rom USB_DEV_DSC device_dsc=
{
sizeof(USB_DEV_DSC),    // Size of this descriptor in bytes
DSC_DEV,                // DEVICE descriptor type
0x0200,                 // USB Spec Release Number in BCD format
CDC_DEVICE,             // Class Code
0x00,                   // Subclass code
0x00,                   // Protocol code
EP0_BUFF_SIZE,          // Max packet size for EP0, see usbcfg.h
0xAF01,                 // Vendor ID
0xAF0A,                 // Product ID: CDC RS-232 Emulation Demo
0x0000,                 // Device release number in BCD format
0x01,                   // Manufacturer string index
0x02,                   // Product string index
0x00,                   // Device serial number string index
0x01                    // Number of possible configurations
};

...

rom struct{byte bLength;byte bDscType;word string[16];}sd001={
sizeof(sd001),DSC_STR,
'a','l','f','e','r','s','o','f','t','.',
'c','o','m','.','a','r'};

rom struct{byte bLength;byte bDscType;word string[21];}sd002={
sizeof(sd002),DSC_STR,
'A','l','f','e','r','S','o','f','t',' ',
'U','S','o','c','k','e','t',' ','1','.','0'};
</pre>
<p>And the file driver/win2k_winxp/mchpcdc.inf  Windows, to match the new vendor, product ID and description</p>
<pre class="brush: cpp; title: ; notranslate">

[DeviceList]
%DESCRIPTION%=DriverInstall, USB\VID_AF01&amp;PID_AF0A

...

;------------------------------------------------------------------------------
;  String Definitions
;------------------------------------------------------------------------------

[Strings]
MCHP=&quot;alfersoft.com.ar&quot;
MFGNAME=&quot;alfersoft.com.ar&quot;
DESCRIPTION=&quot;Communications Port&quot;
SERVICE=&quot;AlferSoft USocket 1.0&quot;
</pre>
<h2>Programming the PIC</h2>
<p>I&#8217;ve used WinPic800 to program the PIC. Here is a screenshot of the parameters I used to program it.</p>
<p><img style="border: 1px solid black;" src="http://www.alfersoft.com.ar/files/usocket/pictures/usbparams.png" alt="Parameters to program the PIC" width="450" height="304" /></p>
<h2>Commands</h2>
<p>I didn&#8217;t modified any of the USBDAQ commands. They are all available but I only need to use these 4 commands:</p>
<ul>
<li>*A01 (activate relay 1)</li>
<li>*A00 (deactivate relay 1)</li>
<li>*A11 (activate relay 2)</li>
<li>*A10 (deactivate relay 2)</li>
</ul>
<p>All the commands are followed by an enter (chr(13) or &#8216;\n&#8217;).</p>
<h2>Installing (Windows)</h2>
<ol>
<li>Plug the device into the USB port, the following message will appear in the tray bar.</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket01_inst_win.png" alt="Installation Windows step 1" width="440" height="180" /></p>
<li>In the first page of the &#8220;Found New Hardware Wizard&#8221; select &#8220;No, not this time&#8221; and click Next button.</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket02_inst_win.png" alt="Installation Windows step 2" width="450" height="351" /></p>
<li>Select the &#8220;Install from a list or specific location (Advanced)&#8221; option and click Next button.</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket03_inst_win.png" alt="Installation Windows step 3" width="450" height="351" /></p>
<li>Mark the &#8220;Include this location in the search:&#8221; and browse for the directory where the .inf file is located (driver\win2k_winxp)</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket04_inst_win.png" alt="Installation Windows step 4" width="450" height="351" /></p>
<li>This message will appear:</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket05_inst_win.png" alt="Installation Windows step 5" width="450" height="351" /></p>
<li>And then this one:</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket06_inst_win.png" alt="Installation Windows step 6" width="450" height="351" /></p>
<li>When the installation is done press &#8220;Finish&#8221;</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket07_inst_win.png" alt="Installation Windows step 7" width="450" height="351" /></p>
<li>After that the hardware is ready to use.</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket08_inst_win.png" alt="Installation Windows step 8" width="440" height="180" /></p>
</ol>
<h2>Testing (Windows)</h2>
<ol>
<li>Go to the device manager and locate the new COM port added, in my example COM10 was added</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket09_test_win.png" alt="Installation Windows step 9" width="450" height="317" /></p>
<li>Open Hyperterminal and choose a name for the new conection</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket10_test_win.png" alt="Installation Windows step 10" width="332" height="299" /></p>
<li>Select the new COM port</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket11_test_win.png" alt="Installation Windows step 11" width="296" height="300" /></p>
<li>Set the Bit rate to 115200</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket12_test_win.png" alt="Installation Windows step 12" width="344" height="407" /></p>
<li>This step is optional to see what we are typing on the screen, choose ASCII Setup</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket13_test_win.png" alt="Installation Windows step 13" width="344" height="423" /></p>
<li>Then mark &#8220;Echo typed characters locally&#8221;</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket14_test_win.png" alt="Installation Windows step 14" width="263" height="316" /></p>
<li>Finally connect and type one of the commands</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket15_test_win.png" alt="Installation Windows step 15" width="450" height="302" /></p>
</ol>
<h2>Installing (Linux &#8211; Ubuntu)</h2>
<ol>
<li>Plug it. That&#8217;s it! a new device probably called /dev/ttyACM0 will be added by the OS.</li>
</ol>
<p></p>
<h2>Testing (Linux &#8211; Ubuntu)</h2>
<ol>
<li>Open gtkterm if you don&#8217;t have it installed type &#8220;sudo apt-get install gtkterm&#8221; from a terminal</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket01_linux.png" alt="Testing Linux step 1" width="450" height="294" /></p>
<li>Go to Configuration -&gt; Port, set the port to /dev/ttyACM0, the speed to 115200 and click OK</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket02_linux.png" alt="Testing Linux step 2" width="450" height="234" /></p>
<li>Select Configuration -&gt; Local echo</li>
<li>Type the command and press enter</li>
<p style="text-align: center;"><img class="aligncenter" src="http://www.alfersoft.com.ar/files/usocket/pictures/screenshots/usocket03_linux.png" alt="Testing Linux step 3" width="450" height="294" /></p>
<p style="text-align: center;">
</ol>
<h2>Problem</h2>
<p>After I mounted everything in the case a problem appeared, if I plug the USB cable to the computer and then the socket to the wall, the PIC hangs. But it works well the other way round (first plug to the wall and the to the computer). That is probably because the high voltage cables are too close to the PIC and unfortunatelly I&#8217;m not an expert in that matter and I don&#8217;t know how to fix it except by putting the circuit in a separated box. Experts needed! If you know another way to fix it please let me know!</p>
<h2>Pictures</h2>
<p><img src="http://www.alfersoft.com.ar/files/usocket/pictures/proto01.jpg" alt="Prototype" width="450" height="338" /></p>
<p><img src="http://www.alfersoft.com.ar/files/usocket/pictures/proto05.jpg" alt="Prototype" width="450" height="338" /></p>
<p><img src="http://www.alfersoft.com.ar/files/usocket/pictures/board02.jpg" alt="Board" width="450" height="338" /></p>
<p><img src="http://www.alfersoft.com.ar/files/usocket/pictures/board04.jpg" alt="Board" width="450" height="338" /></p>
<p><img src="http://www.alfersoft.com.ar/files/usocket/pictures/case01.jpg" alt="Case" width="450" height="338" /></p>
<p><img src="http://www.alfersoft.com.ar/files/usocket/pictures/case02.jpg" alt="Case" width="450" height="338" /></p>
<h2>Download</h2>
<p><a title="USocket Project" href="http://www.alfersoft.com.ar/files/usocket/usocket.zip">Link to download USocket project</a>, enjoy it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alfersoft.com.ar/blog/2008/07/08/usocket-usb-controlled-socket-with-pic18f4550/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

