<?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>cyberz.org &#187; I2C</title>
	<atom:link href="http://www.cyberz.org/blog/tag/i2c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cyberz.org/blog</link>
	<description>Andrea Leofreddi's homepage</description>
	<lastBuildDate>Tue, 10 Aug 2010 17:19:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Some applications using I2C</title>
		<link>http://www.cyberz.org/blog/2009/06/08/some-applications-using-i2c/</link>
		<comments>http://www.cyberz.org/blog/2009/06/08/some-applications-using-i2c/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 21:49:43 +0000</pubDate>
		<dc:creator>andrea</dc:creator>
				<category><![CDATA[All/News]]></category>
		<category><![CDATA[Domotics]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[I2C]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Parport]]></category>

		<guid isPermaLink="false">http://www.cyberz.org/blog/?p=64</guid>
		<description><![CDATA[Parallel and serial ports are]]></description>
			<content:encoded><![CDATA[<p>Parallel and serial ports are disappearing from today&#8217;s pc making life harder for the people who wants to connect their home-made devices to a pc. The USB bus seems to be very appealing but it has the drawback of complexity while the I<sup>2</sup>C bus is very easy to implement and it&#8217;s widely supported by many devices, with the drawback of no direct pc connection (to be honest it&#8217;s used inside the pc, so somewhere on the motherboard there is a I<sup>2</sup>C bus, but yet I haven&#8217;t found any decent connection to the external world to use it &#8211; no, i won&#8217;t solder things on memory modules). Since the first way to start experimenting with I<sup>2</sup>C is building an I<sup>2</sup>C port, I&#8217;ve built a parport-to-i<sup>2</sup>c interface implementing the <a href="http://www.kosma.pl/hardware/i2c-parport/">I<sup>2</sup>C schematic made by Kosma Moczek</a> with the idea of replacing it with a more modern USB-to-I<sup>2</sup>C solution in the future.</p>
<p>So here it is the prototype of the parport to I<sup>2</sup>C interface:</p>
<p style="text-align: center;"><img class="size-medium wp-image-70 aligncenter" title="The i2c board" src="http://www.cyberz.org/blog/wp-content/uploads/2009/05/090520091-300x225.jpg" alt="The i2c board" width="300" height="225" /></p>
<p><span id="more-64"></span>To test the interface bus, some I<sup>2</sup>C device was needed. A common 24c04 eeprom was very easy to find, so I just setup some wires to have the 24c04 connect the bus (note the power cord powers up the parport board too). That is the result:</p>
<p style="text-align: center;"><img class="size-medium wp-image-73 aligncenter" title="The 24c04 eeprom" src="http://www.cyberz.org/blog/wp-content/uploads/2009/05/090520090011-300x225.jpg" alt="The 24c04 eeprom" width="300" height="225" /></p>
<p>Using the i2cdetect from lmsensors with the 24c04 unplugged, I was able to scan the I<sup>2</sup>C bus without results as expected:</p>
<p><code>[root@thufir ~]# i2cdetect -a 3<br />
WARNING! This program can confuse your I2C bus, cause data loss and worse!<br />
I will probe file /dev/i2c-3.<br />
I will probe address range 0x00-0x7f.<br />
Continue? [Y/n] y<br />
0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f<br />
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
[root@thufir ~]#</code></p>
<p>Plugging the 24c04 eeprom in the i2c bus, a probe finds out something:</p>
<p><code>[root@thufir ~]# i2cdetect -a 3<br />
WARNING! This program can confuse your I2C bus, cause data loss and worse!<br />
I will probe file /dev/i2c-3.<br />
I will probe address range 0x00-0x7f.<br />
Continue? [Y/n] y<br />
0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f<br />
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
50: 50 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
[root@thufir ~]#</code></p>
<p>The eeprom has been found at 0&#215;50-1 address, which is as expected (the 24c04 has the &#8217;1010 E2 E1 A8&#8242; address scheme, so in my case E2 and E1 were ground producing 1010000 and 1010001).</p>
<p>To be sure about the functionality of the port, I used the <a href="http://codesink.org/eeprog.html">eeprog program by Stefano Barbato</a> to test the 24c04.</p>
<p>Writing &#8220;hello world\n&#8221; on the first 12 bytes of the eeprom was fine:</p>
<p><code>[root@thufir eeprog-0.7.6]# echo hello world | ./eeprog -f /dev/i2c-3 0x50 -w 0:12<br />
eeprog 0.7.6, a 24Cxx EEPROM reader/writer<br />
Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.<br />
Bus: /dev/i2c-3, Address: 0x50, Mode: 8bit<br />
Writing stdin starting at address 0x0<br />
............</code></p>
<p>&#8230;and so was reading what&#8217;s inside the first 12 bytes of the eeprom (the &#8220;hello world\n&#8221; string which we have just written).</p>
<p><code><br />
[root@thufir eeprog-0.7.6]# ./eeprog -f /dev/i2c-3 0x50 -r 0:12<br />
eeprog 0.7.6, a 24Cxx EEPROM reader/writer<br />
Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.<br />
Bus: /dev/i2c-3, Address: 0x50, Mode: 8bit<br />
Reading 12 bytes from 0x0<br />
hello world<br />
[root@thufir eeprog-0.7.6]#<br />
</code></p>
<p>The i2c eeprom is working as expected. The eeprom was connected with a 3 meters cable. As of today I still have to buy some PCF8574 to start experimenting with some other circuits.</p>
<p><strong><em>(Update 26 June 2010)</em></strong>: I bought some PCF8574 but unfortunately I lost my I2C parport adapter, so I had to build a new one from scratch. This time I managed to fit it into the parallel cable box and I used a mini molex connector to have a common connection for all the I2C boards I plan to build.</p>
<p><a style="text-decoration: none;" href="http://www.cyberz.org/blog/wp-content/uploads/2009/06/26062010085.jpg"><img class="aligncenter size-medium wp-image-178" title="I2C Parport adapter (PCB front)" src="http://www.cyberz.org/blog/wp-content/uploads/2009/06/26062010085-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><a style="text-decoration: none;" href="http://www.cyberz.org/blog/wp-content/uploads/2009/06/26062010088.jpg"><img class="aligncenter size-medium wp-image-181" title="I2C Parport adapter (complete)" src="http://www.cyberz.org/blog/wp-content/uploads/2009/06/26062010088-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><a href="http://www.cyberz.org/blog/wp-content/uploads/2009/06/27062010090.jpg"><img class="aligncenter size-medium wp-image-188" title="Mini molex I2C connections" src="http://www.cyberz.org/blog/wp-content/uploads/2009/06/27062010090-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>Since my purpose is to use I2C for domotics, cable length is very important. On the internet you may see that maximum length for I2C connections may vary depending on how many devices you connect and cable length, I was able to manage some tests with the 24C04 eeprom and everything worked fine with a 13 meters cable.</p>
<p>Then I assembled a test circuit for PCF8574 to test the bus with 2 devices connected (again with 13 meters cable). The PCF8574 board features a dip switch to select the address and 4 LED/bit connected to the lsb data output (in this case I was not interested in using the chip as an input).</p>
<p><a href="http://www.cyberz.org/blog/wp-content/uploads/2009/06/27062010091.jpg"><img class="aligncenter size-medium wp-image-189" title="PCF8574 &quot;demo&quot; board" src="http://www.cyberz.org/blog/wp-content/uploads/2009/06/27062010091-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>The whole thing worked fine (with both 24C04 and PCF8574 connected), as shown by i2cdetect:</p>
<p><code>[root@kynes ~]# i2cdetect -a 1<br />
WARNING! This program can confuse your I2C bus, cause data loss and worse!<br />
I will probe file /dev/i2c-1.<br />
I will probe address range 0x00-0x7f.<br />
Continue? [Y/n] y<br />
0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f<br />
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --<br />
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
50: 50 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --<br />
[root@kynes ~]#<br />
</code></p>
<p>To check the PCF8574, the following &#8220;counter&#8221; script was executed:</p>
<p><code>A=0; while :; do ((A=A+1)); printf "%b", $A &gt; /sys/bus/i2c/devices/1-0027/write; echo Wrote $A; sleep 1; done</code></p>
<p>Leds were correcly blinking showing the binary representation of the bytes sent by the counter script.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberz.org/blog/2009/06/08/some-applications-using-i2c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
