<?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>Jkx@home</title>
	<atom:link href="http://www.larsen-b.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.larsen-b.com</link>
	<description>Titanium Exposé</description>
	<lastBuildDate>Sun, 22 Apr 2012 11:44:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language></language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Cheap DIY USB Tube DAC</title>
		<link>http://www.larsen-b.com/Article/414.html</link>
		<comments>http://www.larsen-b.com/Article/414.html#comments</comments>
		<pubDate>Fri, 20 Apr 2012 17:30:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[dac]]></category>
		<category><![CDATA[tube]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=414</guid>
		<description><![CDATA[Due to lot of homework, I haven&#8217;t found a lot of time to have fun electronic for some times. I decided to change this by building an cheap USB DAC with tube output.
There is a bunch of USB DAC on the market right now, but most of them aren&#8217;t really top quality. As I don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Due to lot of homework, I haven&#8217;t found a lot of time to have fun electronic for some times. I decided to change this by building an cheap USB DAC with tube output.</p>
<p>There is a bunch of USB DAC on the market right now, but most of them aren&#8217;t really top quality. As I don&#8217;t want to loose some time to build the USB part, I decided to buy a USB DAC Kit. After a little search on Ebay I found this one :</p>
<p><img class="alignnone" title="Ebay USB DAC" src="http://jkx.larsen-b.com/photos/blog/ebay_usb_dac.sized.jpg" alt="" width="640" height="541" /></p>
<p>This kit sports an CS8416+CS4398 combot plus an NE5532 output buffer, but as I want it to be a little audiophile, I will drop the NE5532 in favor of an simple tube preamp.</p>
<p>For the tube part, I think I will go for an 12AX7 or something similar. I really think 6SN7 are better, but this tube are overkill for an preamp I think.</p>
<p>Update, some links for the tube output :</p>
<ul>
<li><a href="http://www.shine7.com/audio/12ax7_pre.htm">http://www.shine7.com/audio/12ax7_pre.htm</a></li>
<li><a href="http://diyaudioprojects.com/Tubes/12AX7_Preamp/">http://diyaudioprojects.com/Tubes/12AX7_Preamp/</a></li>
</ul>
<p><strong>/Enjoy tube sound</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/414.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic FTP backup for servers</title>
		<link>http://www.larsen-b.com/Article/409.html</link>
		<comments>http://www.larsen-b.com/Article/409.html#comments</comments>
		<pubDate>Sat, 28 Jan 2012 17:07:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Utils]]></category>
		<category><![CDATA[duplicity]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=409</guid>
		<description><![CDATA[Today I need to find a way to do some backup on an FTP server. Of course there is a lot of way to do that, but I need something automatic that does some full (monthly) and incremental (daily) backup. I decided to use duplicity because it&#8217;s a really simple and effective software. The main [...]]]></description>
			<content:encoded><![CDATA[<p>Today I need to find a way to do some backup on an FTP server. Of course there is a lot of way to do that, but I need something automatic that does some full (monthly) and incremental (daily) backup. I decided to use <a href="http://duplicity.nongnu.org/">duplicity</a> because it&#8217;s a really simple and effective software. The main issue, is that duplicity command line is a bit hard to remember for me. So why not simply write a simple python script that does the job for me.</p>
<p>So here, we are :</p>
<pre><span style="color: #444444;">#!/usr/bin/python </span>
# Edit DATA and DEST
<span style="color: #2040a0;">DATA</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'/var/www'</span>
<span style="color: #2040a0;">DEST</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'ftp://username:password@ftp.server/backup'</span>

<strong>import</strong> <span style="color: #2040a0;">os</span>
<strong>import</strong> <span style="color: #2040a0;">sys</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">backup</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">b_type</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'incr'</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span>
    <span style="color: #2040a0;">dup_cmd</span> <span style="color: #4444ff;">=</span><span style="color: #008000;">'nice -n 19 duplicity %s  --volsize 512 --no-encryption --asynchronous-upload '</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">b_type</span>,<span style="color: #4444ff;">)</span>
    <span style="color: #2040a0;">temp</span> <span style="color: #4444ff;">=</span> <span style="color: #008000;">'%s %s %s'</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">dup_cmd</span>,<span style="color: #2040a0;">DATA</span>,<span style="color: #2040a0;">DEST</span><span style="color: #4444ff;">)</span>
    <span style="color: #2040a0;">os</span>.<span style="color: #2040a0;">system</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">temp</span><span style="color: #4444ff;">)</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">info</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span>
    <span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'duplicity collection-status  %s'</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">DEST</span><span style="color: #4444ff;">)</span>
    <span style="color: #2040a0;">os</span>.<span style="color: #2040a0;">system</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">)</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">list_files</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span>
    <span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'duplicity list-current-files  %s'</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">DEST</span><span style="color: #4444ff;">)</span>
    <span style="color: #2040a0;">os</span>.<span style="color: #2040a0;">system</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">)</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">clean</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span>
    <span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'duplicity remove-all-but-n-full 1 --force %s'</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">DEST</span><span style="color: #4444ff;">)</span>
    <span style="color: #2040a0;">os</span>.<span style="color: #2040a0;">system</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">)</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">usage</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span>
    <strong>print</strong> <span style="color: #008000;">"%s [-incr|-full|-list|-info|-clean]"</span> <span style="color: #4444ff;">%</span> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">]</span>

<strong>if</strong> <span style="color: #2040a0;">__name__</span><span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'__main__'</span><span style="color: #4444ff;">:</span>
    <strong>if</strong> <span style="color: #2040a0;">len</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">&gt;</span> <span style="color: #ff0000;">1</span><span style="color: #4444ff;">:</span>
        <strong>if</strong> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span> <span style="color: #008000;">'-incr'</span><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">backup</span><span style="color: #4444ff;">(</span><span style="color: #008000;">'inc'</span><span style="color: #4444ff;">)</span>
        <strong>elif</strong> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span> <span style="color: #008000;">'-full'</span><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">backup</span><span style="color: #4444ff;">(</span><span style="color: #008000;">'full'</span><span style="color: #4444ff;">)</span>
        <strong>elif</strong> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span> <span style="color: #008000;">'-info'</span><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">info</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
        <strong>elif</strong> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span> <span style="color: #008000;">'-list'</span><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">list_files</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
        <strong>elif</strong> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span> <span style="color: #008000;">'-clean'</span><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">clean</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
        <strong>else</strong><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">usage</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
    <strong>else</strong><span style="color: #4444ff;">:</span>
        <span style="color: #2040a0;">usage</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span></pre>
<p>Please note that I disabled the PGP encryption for this backup. Mainly because, I don&#8217;t want to deal w/ lost keys when I will need to restore the backup. But this can be done easily. I will post a complete guide if someone ask.</p>
<p>The next step call the script in cron.d for example with something like this : <em>30  3   *  *  * </em></p>
<p><strong>Feel happy no more stress with backup ;)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/409.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Connect NGW100 Linux (AVR32) to Arduino with I2C</title>
		<link>http://www.larsen-b.com/Article/398.html</link>
		<comments>http://www.larsen-b.com/Article/398.html#comments</comments>
		<pubDate>Sun, 08 Jan 2012 01:39:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[I2C]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[openwrt]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=398</guid>
		<description><![CDATA[For a Linux embedded training, I need to find something fun to plug on an AVR32 board. The board used for the training is a NGW100 board. I decided to try to use the I2C bus. I have several I2C stuff on the desk, but nothing really fun and I don&#8217;t want to solder a [...]]]></description>
			<content:encoded><![CDATA[<p>For a Linux embedded training, I need to find something fun to plug on an AVR32 board. The board used for the training is a <a href="http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4102">NGW100</a> board. I decided to try to use the <a href="http://en.wikipedia.org/wiki/I%C2%B2C">I2C</a> bus. I have several I2C stuff on the desk, but nothing really fun and I don&#8217;t want to solder a lot of stuff, and spend a lot of time on this. I decided to use a Arduino board as a I2C slave device and plug this to the NGW100 board.</p>
<p><strong>First step: S</strong>imply use the Arduino IDE and the <a href="http://arduino.cc/en/Reference/Wire">Wire lib</a>. I use an <a href="http://www.seeedstudio.com/blog/tag/seeeduino/">Seeeduino</a> because I need an Arduino that works at 3.3v level. Here the code :</p>
<pre><span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;Wire.h&gt;</span></strong></span>
<strong>void</strong> <span style="color: #2040a0;">setup</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">begin</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">4</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>                <span style="color: #444444;">// join i2c bus with address #4</span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">onReceive</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">receiveEvent</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">// register event</span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">onRequest</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">requestEvent</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">// register event</span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">begin</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">38400</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>           <span style="color: #444444;">// start serial for output</span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Boot Ok"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span>

<strong>void</strong> <span style="color: #2040a0;">loop</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{ </strong></span><span style="color: #2040a0;">delay</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">100</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span><span style="color: #4444ff;"> </span><span style="color: #4444ff;"><strong>}</strong></span>

<strong>void</strong> <span style="color: #2040a0;">receiveEvent</span><span style="color: #4444ff;">(</span><strong>int</strong> <span style="color: #2040a0;">howMany</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <strong>char</strong> <span style="color: #2040a0;">c</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">NULL</span><span style="color: #4444ff;">;</span>
  <strong>while</strong><span style="color: #4444ff;">(</span><span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">available</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">)</span> <span style="color: #444444;">// loop through all</span>
  <span style="color: #4444ff;"><strong>{</strong></span>
    <span style="color: #2040a0;">c</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">receive</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">// receive byte as a character</span>
    <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">print</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">c</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>         <span style="color: #444444;">// print the character</span>
  <span style="color: #4444ff;"><strong>}</strong></span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"==="</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span>

<strong>void</strong> <span style="color: #2040a0;">requestEvent</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"read"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">send</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Hello world from Arduino"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span></pre>
<p>To test the Arduino I used a <a href="http://dangerousprototypes.com/docs/Bus_Pirate">Bus Pirate</a>, this is quite simple and fun, here a little snipset of my initial test with the BP (note the string are different). The I2C slave is at the 0&#215;4 address (check the setup()).</p>
<pre>Searching I2C address space. Found devices at:
0x08(0x04 W) 0x09(0x04 R) 

Read content from the device, 'ABCD'
I2C&gt;[0x09 rrrrrr]
I2C START BIT
WRITE: 0x09 ACK
READ: 0x41
READ:  ACK 0x42
READ:  ACK 0x43
READ:  ACK 0x44
READ:  ACK 0xFF
READ:  ACK 0xFF
NACK
I2C STOP BIT
I2C&gt;

send content to the device 'ABC'
I2C&gt;[0x08 0x41 0x42 0x43]
I2C START BIT
WRITE: 0x08 ACK
WRITE: 0x41 ACK
WRITE: 0x42 ACK
WRITE: 0x43 ACK
I2C STOP BIT</pre>
<p><strong>Second step: </strong> Plug the Arduino to the NGW100. I used the wrapping technique. Simply connect SDA, SCL, and GND. (NGW100 pinouts : SDA=&gt;9, SCL=&gt;10, GND=&gt;2)</p>
<p><img style="border: 0px initial initial;" title="NGW100-AVR32 to Arduino" src="http://jkx.larsen-b.com/photos/blog/2012_01_05_13_57_32_001.sized.jpg" alt="" width="640" height="480" /></p>
<p>On Linux, load the I2C-GPIO kernel module. On <a href="http://openwrt.org">OpenWRT</a> (used on the NGW100), simply load the <strong>kmod</strong>-<strong>i2c-gpio</strong> package.</p>
<p><strong>Final step:</strong> If everything is Ok, we can now test the communication. I used a small piece of C code to deal with I2C on Linux.</p>
<pre><span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;string.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;stdio.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;stdlib.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;linux/i2c-dev.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;sys/ioctl.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;fcntl.h&gt;</span></strong></span>

<strong>void</strong> <span style="color: #2040a0;">i2c_run</span><span style="color: #4444ff;">(</span><strong>void</strong><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
    <strong>int</strong> <span style="color: #2040a0;">file</span><span style="color: #4444ff;">;</span>
    <strong>char</strong> <span style="color: #2040a0;">filename</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">40</span><span style="color: #4444ff;">]</span><span style="color: #4444ff;">;</span>
    <strong>int</strong> <span style="color: #2040a0;">addr</span> <span style="color: #4444ff;">=</span> <span style="color: #ff0000;">0x4</span><span style="color: #4444ff;">;</span>
    <strong>char</strong> <span style="color: #2040a0;">buf</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">32</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span> <span style="color: #4444ff;"><strong>{</strong></span><span style="color: #ff0000;">0</span><span style="color: #4444ff;"><strong>}</strong></span><span style="color: #4444ff;">;</span>
    <strong>int</strong> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">;</span>

    <span style="color: #2040a0;">sprintf</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">filename</span>,<span style="color: #008000;">"/dev/i2c-0"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">open</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">filename</span>,<span style="color: #2040a0;">O_RDWR</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">&lt;</span> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
        <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to open the bus."</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
        <span style="color: #2040a0;">exit</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>

    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">ioctl</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span>,<span style="color: #2040a0;">I2C_SLAVE</span>,<span style="color: #2040a0;">addr</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">&lt;</span> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
        <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to acquire bus access and/or talk to slave.<span style="color: #77dd77;">\n</span>"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
        <span style="color: #2040a0;">exit</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>

    <span style="color: #2040a0;">i</span> <span style="color: #4444ff;">=</span> <span style="color: #ff0000;">24</span><span style="color: #4444ff;">;</span>
    // <span style="color: #2040a0;">read</span> <span style="color: #2040a0;">I2C</span>
    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">read</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span>,<span style="color: #2040a0;">buf</span>,<span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">!</span><span style="color: #4444ff;">=</span> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
      <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to read from the i2c bus.<span style="color: #77dd77;">\n</span>"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span> <strong>else</strong> <span style="color: #4444ff;"><strong>{</strong></span>
      <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Read %d bytes from I2C: [%s]<span style="color: #77dd77;">\n</span>"</span>,<span style="color: #2040a0;">i</span>,<span style="color: #2040a0;">buf</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>

    <span style="color: #2040a0;">sprintf</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">buf</span>,<span style="color: #008000;">"IC2 from Linux to Arduino"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #2040a0;">i</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">strlen</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">buf</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">write</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span>,<span style="color: #2040a0;">buf</span>,<span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">!</span><span style="color: #4444ff;">=</span> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
        <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to write to the i2c bus.<span style="color: #77dd77;">\n</span>"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span> <strong>else</strong> <span style="color: #4444ff;"><strong>{</strong></span>
      <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Sent %d bytes to I2C: [%s]<span style="color: #77dd77;">\n</span>"</span>,<span style="color: #2040a0;">i</span>,<span style="color: #2040a0;">buf</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>
<span style="color: #4444ff;"><strong>}</strong></span>

<strong>int</strong> <span style="color: #2040a0;">main</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <span style="color: #2040a0;">i2c_run</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
  <strong>return</strong> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span></pre>
<p>As you can see this code is a bit rude, but works really well : Read the I2C bus, and send a sample string, a proof ? :)</p>
<p><img style="border: 0px initial initial;" title="openWRT I2C" src="http://jkx.larsen-b.com/photos/blog/openWRT_I2C_001.jpg" alt="" width="690" height="440" /></p>
<p>Of course, I used string values but in real life a small protocol shoud be used. Another important thing: I used a NGW100 but you can use the same idea on all Linux embedded board like the Fonera, or anything else.</p>
<p><strong>Update:</strong> Of course you can use the <a href="http://lm-sensors.org/wiki/I2CTools">i2c-tools</a> on Linux to detect your own device. To do that : Grab the i2c-tools source, and cross compile it for the AVR32. (You only have to change the CC path in the Makefile).</p>
<p><strong>/Enjoy small Linux</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/398.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calling GDB (Gnu debugger) within your code.</title>
		<link>http://www.larsen-b.com/Article/393.html</link>
		<comments>http://www.larsen-b.com/Article/393.html#comments</comments>
		<pubDate>Sat, 20 Aug 2011 12:19:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gdb]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=393</guid>
		<description><![CDATA[I spent a lot of time finding the right way to do this, so here is a quick note. For work, I need to debug a small piece of code I wrote. But the main software (closed source) load my library (via dlopen) and run it in a single thread.
That&#8217;s fine, but I&#8217;m unable to [...]]]></description>
			<content:encoded><![CDATA[<p>I spent a lot of time finding the right way to do this, so here is a quick note. For work, I need to debug a small piece of code I wrote. But the main software (closed source) load my library (via dlopen) and run it in a single thread.</p>
<p>That&#8217;s fine, but I&#8217;m unable to debug this part of the code because I&#8217;m unable to place a breakpoint. So I want to place a &#8220;break&#8221; in my code that&#8217;s return back to GDB. (exactly like you can launch the debugger within Python w/ a simple pdb.set_trace().</p>
<p>This is quite easy to do, and really useful but not really popular. The main trick is to call the interrupt number 3. This will rise a SIGTRAP signal in the Linux kernel that GDB can intercept .. so in your code simply add a macro :</p>
<pre>#define GDB()  asm("int $0x3")
int main()
{
 int a = 12;
 GDB();
 printf("A ==&gt; %u \n",a);
 return 0;   
}</pre>
<p><br/><br />
Call the GDB(); macro in your code, compile it with gcc -g, simply run your program in GDB, and wait for the macro to be called :)</p>
<p><strong><em>/Enjoy gdb</em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/393.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mbed Ethernet connection</title>
		<link>http://www.larsen-b.com/Article/385.html</link>
		<comments>http://www.larsen-b.com/Article/385.html#comments</comments>
		<pubDate>Sun, 07 Nov 2010 14:19:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[mbed]]></category>
		<category><![CDATA[rj45]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=385</guid>
		<description><![CDATA[I just received my mbed module. This little ARM device is pretty cool, and the associated tools works quite nice. Of course they cost a lot of money, I received mine for free for the mbed contest. Really kool no ? ;)
After the classic blink test, I decided to go for a network test. But [...]]]></description>
			<content:encoded><![CDATA[<p>I just received my <a href="http://mbed.org">mbed</a> module. This little ARM device is pretty cool, and the associated tools works quite nice. Of course they cost a lot of money, I received mine for free for the mbed contest. Really kool no ? ;)</p>
<p>After the classic blink test, I decided to go for a network test. But I don&#8217;t have any magnetic Ethernet module right now (In fact, I should have one, but I&#8217;m unable to find it). So let&#8217;s go for a magnetic less ! <a href="http://mbed.org/cookbook/Ethernet-RJ45">The doc on the mbed dedicated page</a> say that should be fine. I decided to pull the RJ45 socket from an old broken WRT54.</p>
<p>The main issue is to figure out how to solder this RJ45 on a veroboard. Here comes the fun part, I remembered that radio-amateur use a technique called &#8220;dead bug soldering&#8221;. Check this <a href="http://workmanship.nasa.gov/lib/insp/2%20books/links/sections/303_deadbugs.html">guidelines from the NASA</a> for examples.</p>
<p>I decided to give it a try :</p>
<p><img class="alignnone" title="RJ45 dead bug" src="http://jkx.larsen-b.com/photos/blog/PA245231_resized.sized.jpg" alt="" width="640" height="489" /></p>
<p>Just glue the RJ45 on the veroboard and use a common wrapping technique : Not so bad ;)</p>
<p>The next step is to flash a <a href="http://mbed.org/users/donatien/programs/">network example</a> to test.</p>
<p>That&#8217;s really fun, the mbed works pretty well. I secretly hopes that somebody will come with a mbed like with opensource hardware and software.</p>
<p><strong>Enjoy wired networks ;)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/385.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Really cheap USB to TTL on Atmega : 1.70$</title>
		<link>http://www.larsen-b.com/Article/370.html</link>
		<comments>http://www.larsen-b.com/Article/370.html#comments</comments>
		<pubDate>Sat, 11 Sep 2010 16:58:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[atmega]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[rs232]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=370</guid>
		<description><![CDATA[One of the most common way to interface a microcontroler to a computer used to be serial port. But right now, serial port have been replaced with USB on most computers. A common way to fix this issue is to use a USB to TTL converter or a USB to RS232 converter + MAX232. That&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most common way to interface a microcontroler to a computer used to be serial port. But right now, serial port have been replaced with USB on most computers. A common way to fix this issue is to use a USB to TTL converter or a USB to RS232 converter + MAX232. That&#8217;s fine but :</p>
<ul>
<li>USB to TTL PCB cost a bit of money : you can find some on Ebay around 7€ (shipped) and 15$ on Sparfun !!!  That&#8217;s about 2 or 5 times the cost of the microcontoler !</li>
<li>USB to RS232 cost 1.70$ (shipped) but need some extra level shifting and doesn&#8217;t really feet on a PCB (need a DB9 connector &#8230;)</li>
</ul>
<p style="text-align: left;">In fact, USB to RS232 is a mass product, and the cost is really low. I decided to order a couple of this, just to look if I can use this stuff on a PCB. So I bought a 1.70$ USB to RS232 on Ebay.</p>
<p style="text-align: left;">
<p style="text-align: center;"><img class="aligncenter" title="USB to RS232" src="http://jkx.larsen-b.com/photos/blog/USB_to_RS_232_Cable.jpg" alt="" width="324" height="282" /></p>
<p>I decided to rip the plastic off the DB9 and discovered a really tiny PCB. I removed the DB9, and decided to pass this little PCB to a scope session. How the hell do they manage to do a USB to RS232 with only a couple of external components ? They is no big capacitor for level shifter  (remember  RS232 is a +12/-12v ) ? The answer is simple, they don&#8217;t !!</p>
<p>This device isn&#8217;t RS232 compliant at all, the signals on the DB9 are TTL compliant, but not RS232. The ouput is between 0/5V and the input can handle -12/+12V but works great with a 0/5V too. I simply removed used pads on one side and added a couple on pins.</p>
<p style="text-align: center;">
<p style="text-align: center;"><img class="aligncenter" title="USB to TTL cheap" src="http://jkx.larsen-b.com/photos/blog/usb_ttl_1.sized.jpg" alt="" width="460" height="640" /></p>
<p style="text-align: left;">
<p style="text-align: left;">Please note that RX pin is missing on this pix but needed of course. The next step : How can I use this with an AVR Atmega (I used a Atmega8 but any will do the trick). Serial connection on a micro is TTL like this board, but the TTL signal is just inverted. A &#8220;1&#8243; on the RS232 side is a -12V and +5V on a TTL, and a 0 on the RS232 side is a + 12V and a 0v on the TTL. You can find all the information <a href="http://www.arcelect.com/rs232.htm">here</a>.</p>
<p style="text-align: left;">In fact MAX232 do both level shitting and inverting, but as I&#8217;m to lazy to wire a MAX232 (and will destroy the cheap aspect of this hack), I decided to handle this by software. This mean, I won&#8217;t be able to use the Atmega serial builtin port but need to write some additional code, to do the RS232 encoding/decoding by hand. Let&#8217;s give it a try :</p>
<p style="text-align: left;">
<p style="text-align: left;"><img class="aligncenter" title="USB to RS232 Atmega" src="http://jkx.larsen-b.com/photos/blog/P9115024.sized.jpg" alt="" width="640" height="609" /></p>
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;">I simply put this on a verroboard, connect VCC to USB Vcc, GND, RX and TX  to random pins on the AVR and let&#8217;s go to RS232 software serial. This can be done easily in fact, and I managed to handle 19200bauds with the internal 8Mhz clock of the Atmega. Above you will find the popular uart_putc() and uart_getc() ..</p>
<pre><a name="line1"> 1</a> <span style="color: #0000ff;"><strong>#define UART_TX	D,1</strong></span>
<a name="line2"> 2</a> <span style="color: #0000ff;"><strong>#define UART_RX	D,2</strong></span>
<a name="line3"> 3</a> <span style="color: #0000ff;"><strong>#define UART_DELAY	52 // 1/9600 = 104uS : 1/19200 = 52uS</strong></span>
<a name="line4"> 4</a>
<a name="line5"> 5</a>
<a name="line6"> 6</a> <strong>void</strong> <span style="color: #2040a0;">uart_putc</span><span style="color: #4444ff;">(</span><strong>char</strong> <span style="color: #2040a0;">c</span><span style="color: #4444ff;">)</span>
<a name="line7"> 7</a> <span style="color: #4444ff;"><strong>{</strong></span>
<a name="line8"> 8</a>   <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">;</span>
<a name="line9"> 9</a>   <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">temp</span><span style="color: #4444ff;">;</span>
<a name="line10">10</a>
<a name="line11">11</a>   // <span style="color: #2040a0;">start</span>
<a name="line12">12</a>   <span style="color: #2040a0;">set_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line13">13</a>   <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line14">14</a>   <span style="color: #2040a0;">clr_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line15">15</a>
<a name="line16">16</a>   <strong>for</strong><span style="color: #4444ff;">(</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">=</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">&lt;</span><span style="color: #ff0000;">8</span><span style="color: #4444ff;">;</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">+</span><span style="color: #4444ff;">+</span><span style="color: #4444ff;">)</span>
<a name="line17">17</a>   <span style="color: #4444ff;"><strong>{</strong></span>
<a name="line18">18</a>     <span style="color: #2040a0;">temp</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">c</span><span style="color: #4444ff;">&amp;</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">;</span>
<a name="line19">19</a>     <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">temp</span><span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">)</span>
<a name="line20">20</a>       <span style="color: #2040a0;">set_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line21">21</a>     <strong>else</strong>
<a name="line22">22</a>       <span style="color: #2040a0;">clr_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line23">23</a>     <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line24">24</a>
<a name="line25">25</a>      <span style="color: #2040a0;">c</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">c</span> <span style="color: #4444ff;">&gt;</span><span style="color: #4444ff;">&gt;</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">;</span>
<a name="line26">26</a>   <span style="color: #4444ff;"><strong>}</strong></span>
<a name="line27">27</a>
<a name="line28">28</a>   // <span style="color: #2040a0;">stop</span>
<a name="line29">29</a>   <span style="color: #2040a0;">set_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line30">30</a>   <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line31">31</a>   <span style="color: #2040a0;">clr_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line32">32</a>
<a name="line33">33</a>   <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line34">34</a> <span style="color: #4444ff;"><strong>}</strong></span>
<a name="line35">35</a>
<a name="line36">36</a> <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">uart_getc</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<a name="line37">37</a> <span style="color: #4444ff;"><strong>{</strong></span>
<a name="line38">38</a>   <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">;</span>
<a name="line39">39</a>   <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">ib</span> <span style="color: #4444ff;">=</span> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span>
<a name="line40">40</a>   <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">currentChar</span><span style="color: #4444ff;">=</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span>
<a name="line41">41</a>
<a name="line42">42</a>   <strong>while</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">ib</span> <span style="color: #4444ff;">!</span><span style="color: #4444ff;">=</span> <span style="color: #ff0000;">1</span><span style="color: #4444ff;">)</span>
<a name="line43">43</a>     <span style="color: #2040a0;">ib</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">get_input</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_RX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line44">44</a>
<a name="line45">45</a>   <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span>/<span style="color: #ff0000;">2</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> // <span style="color: #2040a0;">middle</span> <span style="color: #2040a0;">of</span> <span style="color: #2040a0;">the</span> <span style="color: #2040a0;">start</span> <span style="color: #2040a0;">bit</span>
<a name="line46">46</a>   <strong>for</strong><span style="color: #4444ff;">(</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">=</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">&lt;</span><span style="color: #ff0000;">8</span><span style="color: #4444ff;">;</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">+</span><span style="color: #4444ff;">+</span><span style="color: #4444ff;">)</span>
<a name="line47">47</a>     <span style="color: #4444ff;"><strong>{</strong></span>
<a name="line48">48</a>       <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line49">49</a>       <span style="color: #2040a0;">ib</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">get_input</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_RX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line50">50</a>
<a name="line51">51</a>       <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">ib</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">)</span>
<a name="line52">52</a> 	<span style="color: #2040a0;">currentChar</span> <span style="color: #4444ff;">|</span><span style="color: #4444ff;">=</span> <span style="color: #ff0000;">1</span><span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">;</span> // <span style="color: #2040a0;">this</span> <span style="color: #2040a0;">is</span> <span style="color: #2040a0;">a</span> <span style="color: #ff0000;">1</span>
<a name="line53">53</a>     <span style="color: #4444ff;"><strong>}</strong></span>
<a name="line54">54</a>   <strong>return</strong> <span style="color: #2040a0;">currentChar</span><span style="color: #4444ff;">;</span>
<a name="line55">55</a> <span style="color: #4444ff;"><strong>}</strong></span></pre>
<p style="text-align: left;">
<p style="text-align: left;">Nothing more to say, this hack works really great, and I can now build a bunch of USB board without paying so much. The only drawback of this approach is that you can&#8217;t use an interrupt for the uart_getc() so you have deal with that in your code. Another approach would use a single transistor for the RX pin to make the RX compliant w/ the AVR serial builtin routine.</p>
<p style="text-align: left;">
<p style="text-align: left;">You can find the whole project C files + Makefile in a zip <a href="http://www.larsen-b.com/wp-content/uploads/avr-soft-serial.zip">here</a>. I think this little hack is really useful, so please send it to all to your DIYer friends, this can save them money, time &#8230;</p>
<p style="text-align: left;">
<p style="text-align: left;"><strong>// Enjoy cheap USB ? :)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/370.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Boosting IR remote video sender (Thomson VS360U)</title>
		<link>http://www.larsen-b.com/Article/364.html</link>
		<comments>http://www.larsen-b.com/Article/364.html#comments</comments>
		<pubDate>Sat, 21 Aug 2010 14:21:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[diy]]></category>
		<category><![CDATA[infrared]]></category>
		<category><![CDATA[transistor]]></category>
		<category><![CDATA[video sender]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=364</guid>
		<description><![CDATA[In my home, I have a bad TV antenna, so we use only the cable receiver to watch TV. But I have two TV sets. I decided to buy a video sender a couple of months ago, but never managed to get it working nicely. I bought a Thomson VS360U video sender. This one is [...]]]></description>
			<content:encoded><![CDATA[<p>In my home, I have a bad TV antenna, so we use only the cable receiver to watch TV. But I have two TV sets. I decided to buy a video sender a couple of months ago, but never managed to get it working nicely. I bought a Thomson VS360U video sender. This one is really cheap, 24 €, works on the 2.4Ghz for the audio/video and 433Mhz for remote.</p>
<p><img class="alignnone" title="Thomson video sender" src="http://jkx.larsen-b.com/photos/blog/L2210.jpg" alt="" width="250" height="150" /></p>
<p>At the first test, I discovered that the transceiver come with a couple of IR leds. I have to glue each IR led in front of each part of your equipment I want to drive. For me, the cable receiver, the DVD, the Dvico, and the AV amp .. I tried this, but that&#8217;s a mess, each led is soldered on a single string, and tend to move. Not really a nice experience. This is simple to crappy to be use.</p>
<p>I decided to mod it to be able to use a single IR led, with a better gain. The first step is to find the right place to place my mod. Just open the transceiver, locate the power supply (Vcc/Gnd) and the IR transistor. I was quite easy, the only trick is to solder the wire for the IR transistor just before the base resistor. Here is the result.</p>
<p><img class="alignnone" title="Thomson video sender hack-1" src="http://jkx.larsen-b.com/photos/blog/P6113410_contrast.sized.jpg" alt="" width="640" height="575" /></p>
<p>You can find a better pix, in the <a href="http://jkx.larsen-b.com/gallery/blog/P6113410_contrast">gallery.</a> I used a scope to find the IR transistor, but this can be done without.</p>
<p>Let&#8217;s build a simple IR booster, that&#8217;s connect to this pins, and everything will be fine. I used an common BC547 but any common transistor will do the job.</p>
<p><img class="alignnone" title="IR booster schematic" src="http://jkx.larsen-b.com/photos/blog/vs_schem.png" alt="" width="285" height="335" /></p>
<p>The result :</p>
<p><img class="alignnone" title="video sender final" src="http://jkx.larsen-b.com/photos/blog/vs_final.sized.jpg" alt="" width="506" height="640" /></p>
<p>As you can see, this is small. I placed this near my cable receiver and every is working nicely. I can now control every equipment (cable, DVD, Dvico) for my room without any lag, or IR lost signal.</p>
<p>I managed to fix this cheap video sender without to much effort, I&#8217;m happy. This kind of hack can be used in a couple video sender device. The hardest part is to find the IR transistor, the rest is simply the same.</p>
<p><em><strong>Enjoy TV from bed ;) </strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/364.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>From Python to Vala for 1wire monitoring w/ Munin</title>
		<link>http://www.larsen-b.com/Article/352.html</link>
		<comments>http://www.larsen-b.com/Article/352.html#comments</comments>
		<pubDate>Mon, 26 Jul 2010 16:44:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[1wire]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[munin]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[vala]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=352</guid>
		<description><![CDATA[Recently I decided to daily switch my main computer off. This computer was usually on all time, and consume a lot of electricity. So, I switched to a really small computer for common task: ssh-server, wake on lan (for my main computer), VPN access and mail relay. This new computer consume 7watts but his specs [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I decided to daily switch my main computer off. This computer was usually on all time, and consume a lot of electricity. So, I switched to a really small computer for common task: ssh-server, wake on lan (for my main computer), VPN access and mail relay. This new computer consume 7watts but his specs are : Geode CPU at 300Mhz, 128Mb of RAM, and 40Go of HD. Yes, that&#8217;s really low, but far enough for attributed tasks. I randomly log on this for external to access all computer inside my home network.</p>
<p>The main issue here, is that I used my main computer to monitor an 1wire network of external, heating and rooms temperature. I used a small Arduino card and a couple of <a href="http://www.python.org">Python</a> scripts to populate some munin graph, like this one:</p>
<p><img class="aligncenter" title="munin temperature" src="http://jkx.larsen-b.com/photos/blog/localhost_localdomain_jkx_temp_week.png" alt="" width="495" height="319" /></p>
<p>As you can see on this graph, I use a reference temperature from Guipavas. This stuff is public, and I use the <a href="http://www.weather.com">Weather.com</a> for the info. All works fine for about an year now. But when I switched to my new little box (300Mhz..) the python script used to monitor the 1wire network and gather weather.com reference was a bit heavier than excepted for this little box.</p>
<p>I first thought to rewrite this in pure C, but having to deal w/ xml parsing (libxml) and Posix serial in C .. That&#8217;s the little story, I decided to rewrite this script (and other) in <a href="http://live.gnome.org/Vala">Vala</a>. I will not dump the Vala introduction here, but to be short it&#8217;s a new language that produce C used by Gnome Desktop. The syntax tend to be a C# like, and it has a lot of libraries and doesn&#8217;t need the bloat of an interpreter (nor VM). My first test was to listen to the Arduino serial port.</p>
<pre>public void run()
{
ser = new Serial.POSIX();
loop = new GLib.MainLoop();
ser.speed=Serial.Speed.B38400;
ser.received_data.connect(parseSerial);
loop.run();
}</pre>
<p><br/><br />
I used a Serial.vala wrapper found on the net, this is simple and neat. Just added some string parsing, and I get my Arduino 1wire network working w/ Vala .. The next is the Weather.com parsing which will be covered in a future post.<br />
To conclude, the Vala result is fine. The result binary is small 38KB, it has quite a lot of dependencies (libsoup,glib, pthread, gobject..) and consume more memory than my python script. Python interpreter + Elementtree (xml parsing) + pyserial eat around 8.9MB of RAM, while the my Vala code eat 12.3MB. But keep in mind that&#8217;s this is with all the shared libraries. So, if you use a couple of script like me, this memory isn&#8217;t a big deal, because it will be used across different process without any overhead.</p>
<p>In meantimes, the main difference between the two version is the speed, here come some results with the time command of the weather.com functions only (I dropped the serial IO stuff for this test) :</p>
<pre>jkx@brick:~$ time python weather.py
Temp:    20
Pres:    1021.0 hPa
Wind:    19 km/s

real    0m2.105s
user    0m1.468s
sys     0m0.216s</pre>
<pre>jkx@brick:~$ time ./weather
Temp:    20 deg
Pres:    1021.0 hPa
Wind:    19 km/s

real    0m0.427s
user    0m0.084s
sys     0m0.032s</pre>
<p><br/></p>
<p>Ok, Python takes 4x the Vala time for the same stuff. Of course this piece of code isn&#8217;t exactly the same, and evolve an network access, but I tested this a couple of times, and the result is always ~ the same, so I decide to look closer, and found that despite Python interpreter load quite speedy, ElementTree + urllib2 take 1.35sec to import</p>
<p>I get it, this system has a really small CPU and importing libs from harddrive takes times .. which doesn&#8217;t occur with my Vala code, the binary is small, and all dependency are already loaded by the OS itself. To conclude, Python is still my favorite language but running python script on small system has an overhead which I must take care, and avoiding loading / unloading libs is the key. A single python process, with some script loaded will be a better choice. And for small custom apps used on this kind of system, Vala seems to be a good alternative.</p>
<p><strong>// Enjoy the sun</strong></p>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/352.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disable HAL in Xorg on Debian / Ubuntu</title>
		<link>http://www.larsen-b.com/Article/341.html</link>
		<comments>http://www.larsen-b.com/Article/341.html#comments</comments>
		<pubDate>Sat, 04 Jul 2009 08:18:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[hal]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[x11]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=341</guid>
		<description><![CDATA[Ok, let&#8217;s go for another big issue on the road to build a complex distro .. Maintainers tend to include one feature after one .. and now Debian is getting closer to bloat ..
Anyway, sometime ago the HAL was introduced in Xorg. This allow you to hotplug mouse / keyboard &#8230; But if for a [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, let&#8217;s go for another big issue on the road to build a complex distro .. Maintainers tend to include one feature after one .. and now Debian is getting closer to bloat ..</p>
<p>Anyway, sometime ago the HAL was introduced in Xorg. This allow you to hotplug mouse / keyboard &#8230; But if for a reason, your HAL is buggy .. you can&#8217;t use a keyboard or a mice in Xorg. That&#8217;s a bullshit ! I discover a bug in RAID + HAL, and HAL is now segfaulting on my computer .. so I need to get ride of this Xorg / HAL &#8230;</p>
<p>First you must modify /etc/X11/Xorg.conf with something like this :</p>
<pre>Section "ServerFlags"
    Option "AutoAddDevices" "False"
    Option "AllowEmptyInput" "False"
EndSection</pre>
<p>This disable the hal support, but if you want to have the keyboard and mice, you must install the following packages :</p>
<ul>
<li>xserver-xorg-input-kbd</li>
<li>xserver-xorg-input-mouse</li>
</ul>
<p>That&#8217;s it&#8230; no HAL support Xorg anymore, that works fine &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/341.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Howto resize a libvirt (kvm/qemu) disk image</title>
		<link>http://www.larsen-b.com/Article/329.html</link>
		<comments>http://www.larsen-b.com/Article/329.html#comments</comments>
		<pubDate>Tue, 28 Apr 2009 14:32:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Utils]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=329</guid>
		<description><![CDATA[I&#8217;m using kvm for a while at work. Everything works quite fine, but today I needed to grow a disk image. I found some informations, but none are really clear so here the result :
First create a empty image file .. with this command (don&#8217;t use dd,  qemu-img is really quicker than dd):
qemu-img create -f [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using kvm for a while at work. Everything works quite fine, but today I needed to grow a disk image. I found some informations, but none are really clear so here the result :</p>
<p>First create a empty image file .. with this command (don&#8217;t use dd,  qemu-img is really quicker than dd):</p>
<pre>qemu-img create -f raw temp.img 10G</pre>
<p>Next simply your image file + the temp one, in a biggest one ..</p>
<pre>cat foo.img temp.img &gt; bar.img</pre>
<p>You will get a new image file which is 10G bigger than the original one .. Now you can boot your OS, and discover (via cfdisk for example), that your system has a additionnal 10G unused space .. So next step:</p>
<ul>
<li>Just create a new partition, and mount it in the normal way</li>
<li>Boot your kvm OS from a ISO file containing Gparted</li>
</ul>
<p>I tried the second approach, and used a ubuntu install to boot (using virt-manager, this is really easy to do). And resized the partition to my need .. simply reboot and &#8220;tada&#8221; :)</p>
<p><strong>Enjoy disk ?</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/329.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
