<?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>Paint Your Dragon</title>
	<atom:link href="http://www.paintyourdragon.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.paintyourdragon.com</link>
	<description>Art, Technology, Giant Reptiles</description>
	<lastBuildDate>Tue, 13 Nov 2012 18:53:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Maker Faire Bay Area 2012</title>
		<link>http://www.paintyourdragon.com/?p=276</link>
		<comments>http://www.paintyourdragon.com/?p=276#comments</comments>
		<pubDate>Tue, 15 May 2012 18:00:14 +0000</pubDate>
		<dc:creator>pburgess</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[adalight]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[bamf]]></category>
		<category><![CDATA[faire]]></category>
		<category><![CDATA[led]]></category>
		<category><![CDATA[maker]]></category>
		<category><![CDATA[makerfaire]]></category>
		<category><![CDATA[pov]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[spectro]]></category>

		<guid isPermaLink="false">http://www.paintyourdragon.com/?p=276</guid>
		<description><![CDATA[SPECTRO UPDATE: this has been delayed due to a laser cutter malfunction followed by the hurricane damage in NYC (where Adafruit is headquartered). Company is running again, and laser work will be outsourced to a local business, so expect Spectro soon!
I’ve participated in Maker Faire every year since its inception — first as a helper [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin-right: 2em; margin-bottom: 1em;" src="http://www.paintyourdragon.com/wordpress/wp-content/uploads/title.png" alt="" width="240" height="67" align="left" /><b>SPECTRO UPDATE: this has been delayed due to a laser cutter malfunction followed by the hurricane damage in NYC (where Adafruit is headquartered). Company is running again, and laser work will be outsourced to a local business, so expect Spectro soon!</b></p>
<p>I’ve participated in <a href="http://makerfaire.com/">Maker Faire</a> every year since its inception — first as a helper for the <a href="http://electricgiraffe.com/">Electric Giraffe</a> crew, then later reporting for the <a href="http://hackaday.com/">Hack a Day</a> blog. <em>Exhibiting</em> as a maker was long overdue, and I’m finally there on the 2012 roster. You’ll find me in Fiesta Hall…the Big Dark Room…with a collection of projects simply called “Stuff I’ve Done.”</p>
<p><span id="more-276"></span></p>
<p>The title is a bit of a misnomer. Most of what I selected to bring are either collaborations or showcasing others’ work…but the name was already in print by then. Ah well.</p>
<hr />
<h3>What’s On Display</h3>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td align="right" valign="top" style="padding-bottom: 1em;"><strong>Adalight:</strong> this adds ambient wall lighting effects to video content from a PC, creating a more immersive experience…think of it as a <em>subwoofer for your eyes.</em> <a href="https://www.adafruit.com/products/461">Adalight</a> was my first collaboration with <a href="http://adafruit.com/">Adafruit Industries</a>, and still the most popular…I think because it ties the otherwise abstract Arduino platform into something “real” that people enjoy doing anyway: watching movies.</td>
<td valign="top"><img style="margin-left: 2em; margin-bottom: 1em;" src="http://www.paintyourdragon.com/wordpress/wp-content/uploads/adalight.jpg" alt="" width="320" height="200" /></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-bottom: 1em;"><strong>Spectro:</strong> it’s a music visualizer! It’s a clock! It’s programmable…make it whatever you want! My latest collaboration with Adafruit is being unveiled at Maker Faire. I designed most of the software and the laser-cut enclosure, while Limor Fried designed the custom Arduino shield that makes this a solder-free kit!</td>
<td valign="top"><img style="margin-left: 2em; margin-bottom: 1em;" src="http://www.paintyourdragon.com/wordpress/wp-content/uploads/spectro.jpg" alt="" width="320" height="280" /></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-bottom: 1em;"><strong>Bill Bell’s <em>Foureyes LightStick:</em></strong> not my work, but this holds a special place and I wanted to showcase it. Artist <a href="http://www.subliminaryartworks.com/">Bill Bell</a> invented the LightStick “saccadic persistence of vision” illusion in the 1980s, and one of his early displays famously hung in San Francisco’s <a href="http://www.exploratorium.edu/">Exploratorium</a> museum. The idea influenced my early impression of technology: that it’s not all bits and bytes, that an engaging user experience may draw from disparate fields as biology, psychology, art and theatre. 25 years later, I found one of Bell’s LightStick prototypes in a thrift store just a few blocks from my home. I’m displaying it at Maker Faire in the hope that it might likewise inspire the next generation.</td>
<td valign="top"><img style="margin-left: 2em; margin-bottom: 1em;" src="http://www.paintyourdragon.com/wordpress/wp-content/uploads/lightstick.jpg" alt="" width="320" height="180" /></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-bottom: 1em;"><strong><em>Creatures</em> Persistence of Vision Display:</strong> a piece inspired by Bill Bell’s LightSticks. The original Exploratorium illusion later gave way to a sophisticated display leading the viewer’s gaze across <em>multiple concurrent LightSticks.</em> This miniature model follows the same principle using an Arduino microcontroller and other easily-sourced components. (Pixel art creatures were created by the talented <em><a href="http://www.neogeen.com/index.php">Neogeen</a></em>.)</td>
<td valign="top"><img style="margin-left: 2em; margin-bottom: 1em;" src="http://www.paintyourdragon.com/wordpress/wp-content/uploads/pov.jpg" alt="" width="320" height="115" /></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-bottom: 1em;"><strong>LED Arrays:</strong> these LED “pixels” were originally developed for outdoor signs, but their simplicity and low cost makes them suited to other creative endeavors. They’re like the ultimate Christmas lights…link up as many or as few as needed, each one individually addressable in software. What will you create?</td>
<td valign="top"><img style="margin-left: 2em; margin-bottom: 1em;" src="http://www.paintyourdragon.com/wordpress/wp-content/uploads/led-array.jpg" alt="" width="320" height="150" /></td>
</tr>
</table>
<hr />
<h3>Where to Find Stuff</h3>
<p>I’m <strong>not selling kits</strong> at Maker Faire, just demonstrating the ideas. I encourage anyone intrigued by electronics and computers — geek and artist alike — to pick up a soldering iron and start playing with these things. Experiment and allow yourself to make mistakes, it’s all part of learning. Here’s where to find some of the items on display:</p>
<ul>
<li><strong><a href="http://adafruit.com/">Adafruit Industries</a></strong>: <em>not</em> just because I’m working with them…their tech support really is first-rate! Aside from the kits, Adafruit is an excellent source for additional LED pixels and related bits and bobs: microcontrollers, power supplies, breadboards and tools. They’re major proponents of open source hardware and software, with their designs and code <a href="https://github.com/adafruit">all freely available online</a>. The basic Adalight kit is also offered via the <a href="http://www.makershed.com/Adalight_DIY_Ambient_Monitor_Lighting_Project_Pack_p/mkad32.htm">Maker Shed</a> online.</li>
<li><strong><a href="http://www.coolneon.com/">Cool Neon Lighting</a></strong>: their <em>Total Control Lighting</em> system is another good choice for LED pixels. The ready-made controllers may be a better fit if you’re seeking a plug-and-play solution vs. full software control using your own code. An interesting variety of accessories and other <em>blinkenlights</em> make this bay area business a perennial favorite for the Burning Man crowd.</li>
<li><strong><a href="http://www.sparkfun.com/">SparkFun Electronics</a></strong>: more LEDs and interesting parts and sensors. Another champion of open source with schematics and CAD files available for many of their products, their blog is always an interesting read with some pretty good tutorials.</li>
<li><strong><a href="http://arduino.cc/">Arduino</a></strong> is currently the most popular hobbyist microcontroller, and is used in most of my Maker Faire demos. The software is free to download, cross-platform, and the site includes tutorials and a support forum. This <a href="http://arduino.cc/en/Tutorial/ShiftOut">ShiftOut Tutorial</a> explains the basic principles used by the <em>Creatures</em> LED persistence of vision demo. Arduino boards are available from many sources, even Radio Shack now.</li>
<li><strong><a href="http://processing.org/">Processing</a></strong> is a programming environment with an emphasis on multimedia — graphics, sound and interactivity — and is geared toward first-time programmers. This also is free and cross-platform, and is used in several of the Maker Faire exhibits.</li>
</ul>
<hr />
<h3>Frequently Asked Questions</h3>
<p><strong>Q:</strong> Will the Adalight software work with my computer?<br />
<strong>A:</strong> Most likely, yes. Most of the code uses the cross-platform <a href="http://processing.org/">Processing</a> environment, which runs equally well on Windows, Mac (Intel only) and Linux PCs.</p>
<p><strong>Q:</strong> When will Spectro be available, and how much will it cost?<br />
<strong>A:</strong> Watch for it this summer on Adafruit.com. The price is still being worked out as we decide what to include with the kit, but expect it to be more than $100 and less than $200.</p>
<p><strong>Q:</strong> Will Spectro work with an Arduino Mega?<br />
<strong>A:</strong> No…the shield is pretty tightly coupled to the Arduino Uno design.</p>
<p>(Additional Q&#038;A will be posted following Maker Faire, once we know <em>which Questions are actually Frequently Asked!</em>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paintyourdragon.com/?feed=rss2&amp;p=276</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cheap-Ass PC Interface for Digital LED Pixels</title>
		<link>http://www.paintyourdragon.com/?p=225</link>
		<comments>http://www.paintyourdragon.com/?p=225#comments</comments>
		<pubDate>Sat, 02 Jul 2011 01:22:56 +0000</pubDate>
		<dc:creator>pburgess</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bitbang]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[cool neon]]></category>
		<category><![CDATA[ftdi]]></category>
		<category><![CDATA[led]]></category>
		<category><![CDATA[leds]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[pixels]]></category>
		<category><![CDATA[rgb]]></category>
		<category><![CDATA[total control lighting]]></category>
		<category><![CDATA[totalcontrol]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.paintyourdragon.com/?p=225</guid>
		<description><![CDATA[I have an unhealthy obsession with LEDs. I also have an unhealthy obsession with frugality…
Total Control Lighting is a system of individually-addressible full-color LED “pixels” that can be shaped into any display imaginable. It’s a new offering from Funhouse Productions, who’ve been marketing their Cool Neon electroluminescent wire to creative types for years now, practically [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin-right: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/img/p9813/led-array.jpg" alt="" width="240" height="150" align="left" />I have an unhealthy obsession with LEDs. I also have an unhealthy obsession with frugality…</p>
<p><em>Total Control Lighting</em> is a system of individually-addressible full-color LED “pixels” that can be shaped into any display imaginable. It’s a new offering from Funhouse Productions, who’ve been marketing their <a href="http://www.coolneon.com/">Cool Neon</a> electroluminescent wire to creative types for years now, practically <em>defining</em> the after-dark aesthetic of the Burning Man arts festival.</p>
<p>The appeal of the Total Control Lighting system is that it scales linearly…just chain one strand of LEDs after the next, like Christmas lights. One end plugs into a controller box, which can issue preprogrammed color sequences, or others can load animation data from an SD card. In more sophisticated setups, the controller in turn connects to a computer, which can then command every LED individually and in real time. That’s where this project comes in…</p>
<p><span id="more-225"></span>These controller boxes offer some fine features, and come as a tidy, pre-packaged solution. They can run unattended, without any computer attached, streaming data from an SD card. Or they can be situated remotely on a network, far away from the computer actually generating the display. They also cost <em>money,</em> which I’d rather pour into buying <em>more LEDs!</em> Fortunately, for the technically-minded, we can cobble together our own home-built alternative for about fifteen bucks.</p>
<p>Some folks are already using an Arduino as a PC-to-LED bridge, and that works great up to a point. But when you start getting into larger displays and faster frame rates (such as video and persistence-of-vision displays), it’s like trying to funnel the traffic from an eight lane highway down a narrow gravel path. This alternate controller uses an FTDI USB-to-serial adapter, along with a C library to run it using “bitbang mode,” which is explained in <a href="http://hackaday.com/2009/09/22/introduction-to-ftdi-bitbang-mode/">this article at Hack a Day</a>. The bitbang FTDI route can provide <em>significantly</em> higher throughput.</p>
<p>That’s the good news. The bad news, perhaps, is that this is just a low-level C library. You’ll still need to write the code to make it actually <em>do</em> anything. If the existing controllers already handle everything you need, be it pleasing color patterns or playing back animation sequences from an SD card, that extra investment might save you a lot of headache. But if hacking a Kinect controller for an interactive POV display is more your style, or anything else weird and unexpected, this might be just the thing you need. The code is open-source, and works on Mac, Linux and Windows.</p>
<p>Some outwardly identical-looking LED pixels are offered from other sources such as <a href="http://www.bliptronics.com/">Bliptronics</a> and <a href="http://www.adafruit.com/products/322">Adafruit</a>. Without getting into the all the geeky details, while these other types work <em>fantastically well</em> with a microcontroller, they just can’t be driven by the FTDI adapter without unsightly flicker. What distinguishes the Total Control Lighting pixels is the use of a newer LED driver chip — the P9813 — that’s essentially immune to the small timing issues of the FTDI approach. The code unfortunately will not work with those other pixels.</p>
<p>The library is available for download from <a href="https://github.com/PaintYourDragon/p9813">this GitHub repository</a>. Until I can get around to providing better documentation here, the README file included with the code explains its use and depicts the hardware setup with awful ASCII art. Any significant progress will also be posted on <a href="http://www.youtube.com/user/PaintYourDragon">this YouTube channel</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paintyourdragon.com/?feed=rss2&amp;p=225</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Old Mandrills Never Die&#8230;</title>
		<link>http://www.paintyourdragon.com/?p=207</link>
		<comments>http://www.paintyourdragon.com/?p=207#comments</comments>
		<pubDate>Thu, 17 Dec 2009 08:54:21 +0000</pubDate>
		<dc:creator>pburgess</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[cg]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[computer graphics]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[retrocomputing]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[vintage]]></category>

		<guid isPermaLink="false">http://www.paintyourdragon.com/?p=207</guid>
		<description><![CDATA[Are you a &#8220;retrocomputing&#8221; geek? Do salvaged bits of computer history turn you on? You might appreciate the VintageCG channel on YouTube, containing over 100 videos of early computer graphics and user interface research.
The selections were culled from about 80 total hours of footage, a collection I&#8217;ve been meaning to digitize for years now. Even [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.youtube.com/user/VintageCG "><img style="margin-right: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/img/cg/title.jpg" alt="" width="240" height="180" align="left" /></a>Are you a &ldquo;retrocomputing&rdquo; geek? Do salvaged bits of computer history turn you on? You might appreciate the <i>VintageCG</i> channel on YouTube, containing over 100 videos of early computer graphics and user interface research.</p>
<p>The selections were culled from about 80 total hours of footage, a collection I&rsquo;ve been meaning to digitize for <i>years</i> now. Even the plan itself is vintage: 100MHz PowerPC Macs and the VideoCD format were cutting edge when the scheme was first hatched, but the process proved so tedious on then-current hardware that the idea was shelved until the source tapes resurfaced during a recent cleaning. Fortunately all but a couple still played. <i>So</i> glad I waited! Not only is the process now painless, but resources like YouTube&mdash;with bandwidth and capacity beyond anything we could imagine at the time&mdash;make it possible to share these clips with the world.</p>
<p>Rather than blindly upload the kitchen sink, I&rsquo;ve tried to select particularly historical, unusual or prescient work, and wherever possible have included a bit of background or even some interesting trivia in the video descriptions; quality over quantity.</p>
<p><b><a href="http://www.youtube.com/user/VintageCG">Visit the VintageCG channel on YouTube.</a></b></p>
]]></content:encoded>
			<wfw:commentRss>http://www.paintyourdragon.com/?feed=rss2&amp;p=207</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FTDI Serial Adapter as a Simple Digital Interface</title>
		<link>http://www.paintyourdragon.com/?p=192</link>
		<comments>http://www.paintyourdragon.com/?p=192#comments</comments>
		<pubDate>Wed, 23 Sep 2009 06:50:21 +0000</pubDate>
		<dc:creator>pburgess</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[adapter]]></category>
		<category><![CDATA[bit bang]]></category>
		<category><![CDATA[bitbang]]></category>
		<category><![CDATA[ftdi]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hackaday]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[interfacing]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[serial]]></category>
		<category><![CDATA[spi]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://www.paintyourdragon.com/?p=192</guid>
		<description><![CDATA[I&#8217;ve had the good fortune to be accepted as an occasional contributor to the Hack&#160;a&#160;Day blog. (Hack being slang for an informal method of engineering, not criminal acts!)
My first substantive tutorial for the site describes the use of FTDI Bitbang Mode, a method of using a common, inexpensive USB-to-serial adapter as a quick &#38; dirty [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin-right: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/img/ftdi/title.jpg" alt="" width="240" height="190" align="left" />I&rsquo;ve had the good fortune to be accepted as an occasional contributor to the <a href="http://hackaday.com/">Hack&nbsp;a&nbsp;Day</a> blog. (<i>Hack</i> being slang for an informal method of engineering, not criminal acts!)</p>
<p>My first substantive tutorial for the site describes the use of <i>FTDI Bitbang Mode</i>, a method of using a common, inexpensive USB-to-serial adapter as a quick &amp; dirty GPIO interface. This facilitates the sort of prototyping typically done using microcontrollers, but in the comfortable and unconstrained development environment of mainstream PCs. The technique is particularly well-suited to SPI-type protocols; I&rsquo;ve had this communicating with shift registers, LED driver chips and even video overlay ICs, as well as reading various optical rotary and linear encoders.</p>
<p><b><a href="http://hackaday.com/2009/09/22/introduction-to-ftdi-bitbang-mode/">You can read the full article over at hackaday.com.</a></b></p>
]]></content:encoded>
			<wfw:commentRss>http://www.paintyourdragon.com/?feed=rss2&amp;p=192</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking the Microchip Explorer 16 Development Board</title>
		<link>http://www.paintyourdragon.com/?p=51</link>
		<comments>http://www.paintyourdragon.com/?p=51#comments</comments>
		<pubDate>Sun, 09 Nov 2008 05:50:05 +0000</pubDate>
		<dc:creator>pburgess</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[explorer 16]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[microchip]]></category>

		<guid isPermaLink="false">http://www.paintyourdragon.com/wordpress/?p=51</guid>
		<description><![CDATA[Disclaimer and caution: some of the changes outlined in this article involve soldering and modifications to a fairly costly circuit board, which always runs some small risk of damage or mayhem. While I suspect that most anyone with the inclination to buy and use one of these boards is well-versed in soldering and related precautions, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Disclaimer and caution:</strong> some of the changes outlined in this article involve soldering and modifications to a fairly costly circuit board, which always runs some small risk of damage or mayhem. While I suspect that most anyone with the inclination to buy and use one of these boards is well-versed in soldering and related precautions, maybe that’s not actually the case, and I assume no liability for any damage that might occur to the board, yourself or your belongings.</p>
<p><img style="margin-right: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/img/explorer16/title.jpg" alt="" width="240" height="240" align="left" />The <strong><a href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en024858">Explorer 16 Development Board</a></strong> is Microchip’s mainline trainer/project board for 16-bit (and lately now, 32-bit) microcontrollers. The modular design of this board allows use of three different microcontroller families along with add-ons for networking, storage, audio, LCD graphics and more, and providing a common point of reference that allows Microchip to provide working example software templates for these different types of projects.</p>
<p>For all its virtues, this is not to say the experience can’t be improved. What follows are a few simple tidbits I’ve learned for enhancing the functionality of this kit.</p>
<p><span id="more-51"></span></p>
<p><br clear="left"/><img style="margin-left: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/uc/explorer16/standard.jpg" alt="" width="320" height="320" align="right" />A typical Explorer 16 development setup (shown at right) is comprised of several parts:</p>
<ol>
<li>The Explorer 16 board itself, containing a microcontroller PIM (plug-in module) and any optional attached peripherals.</li>
<li>A Microchip programmer/debugger such as the PICkit 2, ICD2 or ICD3, or RealICE. (Having something of a Mac inclination, I tend toward the entry-level PICkit 2 as there’s at least portable open-source software available for this programmer. For amateur or student use, this is often perfectly adequate.)</li>
<li>An RJ-11 to ICSP adapter cable connects the PICkit 2 to the Explorer 16 programming socket. Other programmers use a cable with an RJ-11 plug at both ends.</li>
<li>A 9 to 15 volt DC power supply drives the board and any attached peripherals.</li>
</ol>
<p>Implied in this setup but not specifically highlighted are the host development system running the MPLAB IDE development environment (or alternate software as detailed in my other articles), and a USB connection between this system and the PICkit 2 or other programmer device.</p>
<p>Collectively this makes for a great deal of clutter on one’s desk, and the assorted parts can be frustrating to travel with. My frugal nature would also have preferred any opportunity to avoid unnecessary expense. Let’s see what can be done to fix this…</p>
<h2>Hack #1: Lose the RJ-11 to ICSP Cable, Save $10</h2>
<p><img style="margin-left: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/uc/explorer16/header.jpg" alt="" width="320" height="230" align="right" /> This hardly even qualifies as a “hack,” since the feature is built-in and documented. But there’s a right way and a wrong way to go about it…</p>
<p>Situated adjacent to the PICtail™ Plus slot connector (or between the two, if you’ve soldered on a second), position J14 is a 6-pin ICSP header to which a PICkit 2 can connect directly. Earlier Explorer 16 boards have plated vias where a 6-pin row connector can optionally be added, but more recent supplies of the board already have this connector soldered in place — there’s nothing to add.</p>
<p style="clear:both"><img style="margin-left: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/uc/explorer16/pk2installed.jpg" alt="" width="320" height="320" align="right" /> There’s just one small problem: the silkscreen on the face of the board is incorrect — the ICSP header is turned around, and where they’ve marked pin 1 is actually pin 6! First-time users will often try this connector as labeled, then give up in disgust after it doesn’t work and go back to using the cable. Perhaps the silkscreen will be fixed on future boards by the time you’re reading this; in either case, use the photo at right as an indication of how the PICkit 2 is <em>supposed</em> to attach, with the top face and button facing the procesor PIM.</p>
<p><br clear="right"/><br />
<h2>Hack #2: Lose the PICkit 2, Save $35</h2>
<p>Appendix B in the <span style="text-decoration: underline;">Explorer 16 Development Board User’s Guide</span> describes a tremendously useful feature that unfortunately was never implemented: the intent was to allow an auxiliary PIC18 chip on the Explorer 16 board to perform the same functions as the separate PICkit 2, using the board’s USB connector to permit downloading code without a separate programmer device. All the necessary components are still present on the board, but they sit idle as the necessary firmware was never written and the feature was dropped. You can ignore that entire chapter of the manual.</p>
<p>The good news is that one enterprising user, Rafal Waniurski, has taken it upon himself to implement the firmware that enables this missing capability, and has given permission to repost his work here. Once this firmware is installed, any host-side software that works with a regular PICkit 2 will also work with the Explorer 16 board directly via USB; no separate programmer is needed. If you have a colleague or instructor with another device programmer you can borrow, then you can set up your board this way and avoid the expense and additional clutter of a separate PICkit 2.</p>
<p><img style="margin-left: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/uc/explorer16/jumper.jpg" alt="" width="320" height="250" align="right" />The process works like this:</p>
<ol>
<li>Download this firmware file:<br />
<strong><a href="/downloads/PK2_Explorer16_V0210007-BL.hex">PK2_Explorer16_V0210007-BL.hex</a></strong>.</li>
<li>Move the jumper at position J7 (<em>not</em> the switch directly above it) to the “F4550” position (two left pins).</li>
<li>Connect PICkit 2 to ICSP header (or other Microchip programmer to the RJ-11 jack).</li>
<li>Write firmware as appropriate to the device programmer and operating system in use; for a PICkit 2 and Windows, run the PICkit 2 application, select “Import Hex” from the File menu and choose the previously-downloaded firmware file, then click the “Write” button. For Mac or Linux using the command-line <tt>pk2cmd</tt> program, type:
<p><tt>pk2cmd -PPIC18F4550 -M -F ./PK2_Explorer16_V0210007-BL.hex -R</tt></p>
<p><strong>Note:</strong> if the above method ‘hangs’ after writing the firmware, try using Microchip’s Windows-based PICkit 2 program (via Boot Camp or virtualization) to download the hex file to the Explorer 16.</li>
<li>Move jumper J7 back to the “PIC24” position.</li>
<li>Party!</li>
</ol>
<p style="clear:both"><img style="margin-left: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/uc/explorer16/usb.jpg" alt="" width="320" height="180" align="right" />Once configured as above, there are still a couple of differences from a normal PICkit 2:</p>
<ol>
<li>The Explorer 16 uses a USB “B” connector, versus a “Mini-B” on the PICkit 2, so be sure to pack the right cable.</li>
<li>The board must be powered from an external DC supply before it will show up on the USB bus (unlike the PICkit 2, which is entirely bus-powered). But see Hack #3 for more on this…</li>
<li>Contrary to what’s printed in the aforementioned manual, <em>never attempt to update the board with any regular PICkit 2 firmware!</em> Use only this custom firmware and follow this same procedure if applying updates. I will keep tabs on the state of the firmware development and provide the current version here.</li>
</ol>
<h2>Hack #3: Lose the Power Supply, Save $24</h2>
<p>This tip also arrived by way of Rafal Waniurski, who developed the PICkit 2-masquerading firmware:</p>
<p>The Explorer 16 has a barrel-jack connector for an external 9 to 15 volt DC power supply. Rummaging through my collection of “wall warts” I was fortunate enough to find one of the right voltage, polarity and plug diameter (from a Maxtor external hard drive), but if you’re unable to turn up something suitable then purchasing the correct one directly from Microchip will set you back a ludicrous $24.00.</p>
<p><img style="margin-left: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/uc/explorer16/diagram.jpg" alt="" width="320" height="280" align="right" />With a simple modification it’s possible to power the Explorer 16 board from a USB port. This requires soldering one or two Schottky diodes of type <strong>1N5817</strong> or <strong>1N5819</strong> between specific points on the back of the board. Schottky diodes are required as they have a very low voltage drop; combined with the 5 volts from the USB port, it’s just enough overhead to allow the 3.3 volt regulator on the board to operate.</p>
<p>The diagram at right shows the placement and polarity of the two diodes. Looking at the back side of the board, with the barrel jack under the bottom-right corner, the anode side of both diodes should connect to the 5 volt supply from the USB connector — this is the lower-left of the four pin cluster near the center right edge of the board. The cathode end (with a silver mark) of one diode connects to the cathode end of the existing diode at the corner of the board, adjacent to the power jack, while the other connects to the nearby +5 volt test point. Both diodes pass by a number of exposed contacts on the back of the board, so it’s absolutely essential to cover the bare leads of the diodes with heat-shrink tubing or a length of insulation stripped from 24 gauge wire. After soldering, I also like to use a few dots of hot-melt glue to help secure things in case the board gets knocked around.</p>
<p style="clear: right"><img style="margin-left: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/uc/explorer16/diodes.jpg" alt="" width="320" height="280" align="right" />Drawing from the USB port means that available current is limited to about 200 milliamps — enough for a modestly-populated board, but not higher-current accessories such as the Graphics PICtail board — and it’s necessary to use a powered USB hub or connect directly to a port on the computer. The “9V” points on the breadboard section will only provide about 4.8 volts in this configuration. If any of these are inadequate for a specific situation, it’s still possible to connect an external DC power source when needed.</p>
<p>With all of the modifications complete, basic Explorer 16 development requires only the board and a single USB cable (as seen at the top of the page), leaving the rest of one’s desk space free for reference books, test equipment, lunch or a collection of small plastic dinosaurs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paintyourdragon.com/?feed=rss2&amp;p=51</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Microchip PIC Development Using Mac OS X or Linux</title>
		<link>http://www.paintyourdragon.com/?p=45</link>
		<comments>http://www.paintyourdragon.com/?p=45#comments</comments>
		<pubDate>Sun, 20 Jul 2008 05:47:14 +0000</pubDate>
		<dc:creator>pburgess</dc:creator>
				<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[microchip]]></category>
		<category><![CDATA[pic]]></category>

		<guid isPermaLink="false">http://www.paintyourdragon.com/wordpress/?p=45</guid>
		<description><![CDATA[Developing code for Microchip 8-bit PIC microcontrollers using any alternative to Microsoft Windows used to be a frustrating and often futile proposition. Fortunately this situation has since changed, and everyone can now jump on the PIC bandwagon regardless of their operating system of choice.
This article is not a comprehensive survey of every Microchip PIC development [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://members.dslextreme.com/users/paintyourdragon/img/pic/title.jpg" width="240" height="280" align="left" style="margin-right: 2em; margin-bottom: 1em;" />Developing code for Microchip 8-bit PIC microcontrollers using any alternative to Microsoft Windows used to be a frustrating and often futile proposition. Fortunately this situation has since changed, and everyone can now jump on the PIC bandwagon regardless of their operating system of choice.</p>
<p>This article is <i>not</i> a comprehensive survey of every Microchip PIC development option for Mac and Linux, just a summary of the particular hardware and a few software choices I&rsquo;ve found that most reliably meet my own criteria.</p>
<p><span id="more-45"></span><br />
<br clear="left" /></p>
<h3>Important Update:</h3>
<p><strong>This article is now enormously obsolete</strong>…and I couldn’t be happier! Microchip has begun supporting cross-platform development in earnest. Their <a href="http://www.microchip.com/MPLABX/">MPLAB X</a> development environment runs equally well on Windows, Mac and Linux and supports the full range of PIC chips and programmers/debuggers. Though still in a beta state, this tool is working quite well and continues to improve with every release. I’ll be deleting this article in the future; just keeping it around in the interim should the information still be of use to anyone.</p>
<hr />
<h3>The Issues:</h3>
<ul>
<li>Many inexpensive or homebrew PIC programmers have been based on legacy I/O ports (serial or parallel), but all modern Macintosh systems (and increasingly PCs, especially netbooks and small form-factor systems) are &ldquo;legacy free,&rdquo; eschewing these older ports in favor of USB.</li>
<li>Adapters for USB to serial or parallel are available but introduce their own issues, as does emulation or virtualization software.</li>
<li>Low-cost USB PIC programmers are on the rise, but support for non-Windows systems has been spotty.</li>
<li>Many existing PIC-on-Mac (or Linux) sites contain obsolete information or dead links.</li>
</ul>
<h3>The Desired Outcome:</h3>
<p>An affordable hardware and software toolchain closest to the native physical interfaces and operating system, minimizing or eliminating the use of adapters, emulators and other stopgap measures that add cost, bulk, complexity and compromise the stability of the development process.</p>
<hr />
<h2>Hardware</h2>
<p>There are many devices and methods of getting code onto a PIC. Later articles might detail some of these options, but at present, for the hobbyist or casual developer, Microchip&rsquo;s <b><a href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&#038;nodeId=1406&#038;dDocName=en023805">PICkit&nbsp;2</a></b> &mdash; their entry-level programmer &mdash; seems the most generically useful choice:</p>
<p><center><img src="http://members.dslextreme.com/users/paintyourdragon/uc/osxpic/pickit2.jpg" width="240" height="180" /></center></p>
<table cellpadding="3">
<tr>
<td align="right" valign="top"><b>Device:</b></td>
<td valign="top">Microchip PICkit&trade; 2 Development Programmer/Debugger.</td>
</tr>
<tr>
<td align="right" valign="top"><b>Pros:</b></td>
<td valign="top">
<ul>
<li>USB native; no serial or parallel adapter is required.</li>
<li>Affordable ($35 USD and up).</li>
<li>Physically small; travels well.</li>
</ul>
</td>
</tr>
<tr>
<td align="right" valign="top"><b>Cons:</b></td>
<td valign="top">
<ul>
<li>Support for newly-released chips often lags behind Microchip&rsquo;s professional device programmers.</li>
<li>No native support for debugging or logic tool functionality on non-Windows systems; this is a device programmer only.</li>
</ul>
</td>
</tr>
</table>
<p>This is available in a variety of bundles:</p>
<ul>
<li><b>PICkit&nbsp;2</b> (Microchip part number PG164120, $35) &#8211; this is the standalone programmer with no additional parts; bring your own PIC microcontroller.</li>
<li><b>PICkit&nbsp;2&nbsp;Starter&nbsp;Kit</b> (part number DV164120, $50) &#8211; this bundles the PICkit&nbsp;2 programmer with Microchip&rsquo;s Low Pin Count Demo Board containing a socketed 20-pin PIC16F690, four LEDs and one switch and potentiometer. Other 8-, 14- and 20-pin PICs can be used in this socket.</li>
<li><b>PICkit&nbsp;2&nbsp;Debug&nbsp;Express</b> (DV164121, $50) &#8211; bundles a 44-pin Demo Board containing a nonremovable PIC16F887, eight LEDs and the same switch and potentiometer as above. Don&rsquo;t be misled by the &ldquo;Debug Express&rdquo; name of this particular kit. <i>All</i> versions of the PICkit&nbsp;2 are equally capable of debugging with most PIC microcontrollers (though currently only when used with Windows systems).</li>
<li><b>PIC18F4xK20&nbsp;Starter&nbsp;Kit</b> (DV164124, $100) &#8211; this bundle includes an elaborate demo board containing a more capable PIC18 microcontroller, a small OLED display, analog audio in and out jacks, a serial EEPROM, daughterboard connector and other doodads. Wow!</li>
</ul>
<p>A demo board is not a requirement &mdash; any PICkit&nbsp;2 can program PIC microcontrollers on a breadboard or in-circuit &mdash; but the starter kits are reasonably priced and the included projects are a good way for beginners to learn the ropes.</p>
<p>A number of &ldquo;compatible&rdquo; third-party programmers have since come to market, some undercutting Microchip&rsquo;s product by a few dollars&hellip;but I&rsquo;ve read reports of unreliable behavior from some of the cheap imported models. Given the modest cost of the official starter kits, it makes sense to simply buy directly <a href="http://www.microchipdirect.com/">from the source</a> or their distributors (<a href="http://www.digikey.com/">DigiKey</a>, <a href="http://mouser.com/">Mouser</a>, <a href="http://www.newark.com/">Newark</a>, etc.).</p>
<p>Microchip has since released a PICkit&nbsp;3, but this is not backwardly-compatible with the PICkit&nbsp;2 and will not work on non-Windows systems. The PICkit&nbsp;2 is currently the only official programmer with solid open source support.</p>
<hr />
<h2>Software</h2>
<p>If using a Windows-based system, this is a trivial matter: install the development software included with the PICkit&nbsp;2 and get started. For alternative operating systems, things are not so cut-and-dried, and one must choose an approach most suited to their own development and usage patterns:</p>
<h3>Option 1: Virtualization or Dual-Booting</h3>
<p>MPLAB IDE &mdash; Microchip&rsquo;s Windows-based development environment &mdash; works reasonably well under virtualization software such as VMware <a href="https://www.vmware.com/products/ws/">Workstation</a> or <a href="http://vmware.com/products/fusion/">Fusion</a>, <a href="http://www.parallels.com/en/desktop/">Parallels Desktop</a> or the fantastic open-source <a href="http://www.virtualbox.org/">VirtualBox</a>&hellip;or alternately by &ldquo;dual booting&rdquo; a system for native Windows operation. Of course this is only an option for x86-based systems (not PowerPC), and is not without its share of issues.</p>
<table cellpadding="3">
<tr>
<td align="right" valign="top"><b>Software:</b></td>
<td valign="top">Microchip MPLAB IDE (running Microsoft Windows via virtualization or by dual-booting).</td>
</tr>
<tr>
<td align="right" valign="top"><b>Pros:</b></td>
<td valign="top">
<ul>
<li>Extensive graphical IDE is included free with PICkit&nbsp;2 or can be downloaded from Microchip&rsquo;s web site.</li>
<li>Most Microchip tutorials and sample code are written with this compiler and environment in mind.</li>
<li>Straightforward installation (assuming Windows is already loaded).</li>
<li>Frequent updates for new devices and features, including 16- and 32-bit microcontrollers.</li>
</ul>
</td>
</tr>
<tr>
<td align="right" valign="top"><b>Cons:</b></td>
<td valign="top">
<ul>
<li>Added expense of acquiring Windows operating system and/or virtualization software.</li>
<li>Considerable system resources consumed by virtualization, or &mdash; if dual-booting &mdash; no concurrent access to preferred applications in primary operating system.</li>
<li>Productivity lost to booting and maintaining a second OS.</li>
<li>PowerPC users are out of luck.</li>
</tr>
</table>
<p>If you choose the virtualization route, something to watch out for is that downloading code to chips using the PICkit&nbsp;2 directly from within MPLAB&nbsp;IDE is horribly unreliable. The solution is to run both MPLAB&nbsp;IDE and Microchip&rsquo;s small PICkit&nbsp;2 utility concurrently, using the former program to compile the code and the latter to burn it to the chip (an &ldquo;Auto Import&rdquo; mode in the latter makes this easy).</p>
<p>So virtualization does let us develop PIC code on Mac or Linux systems, but it falls short of an optimal &ldquo;shortest path&rdquo; solution.</p>
<h3>Option 2: HI-TECH C Compiler</h3>
<p>Third-party commercial compilers produced by <a href="http://www.htsoft.com/">HI-TECH Software</a> have been available for a number of years now. While they claimed Mac and Linux support, for the longest time this was rather dodgy &mdash; broken links, crashing software, a confusing product lineup among other things. HI-TECH has since been acquired by Microchip, and the outlook for this software has improved considerably.</p>
<p>The compilers are available for Windows, Linux and Mac OS X and offer different licensing options:</p>
<ul>
<li>The &ldquo;Lite&rdquo; mode is free (even for commercial use) but optimization options are seriously curtailed. Still, it&rsquo;s perfectly adequate for training and student use and is not impaired in any other way (code size, etc.).</li>
<li>A &ldquo;Pro&rdquo; evaluation install is fully functional &mdash; optimization and all &mdash; for a period of 45 days.</li>
<li>The full-on &ldquo;Pro&rdquo; license &mdash; which, at $1195, is clearly intended for actual professional developers &mdash; remains fully functional and includes a year of priority technical support.</li>
</ul>
<p>The HI-TECH compilers include their own IDE which is based on <a href="http://eclipse.org/">Eclipse</a>. Personally I&rsquo;m not especially fond of IDEs, and Eclipse is among the most elephantine of the genre&hellip;but if you&rsquo;re familiar with this environment from prior development work, well hey, you&rsquo;re all set. If text-based development is more your style, the HI-TECH compilers can also be invoked from the command line.</p>
<table cellpadding="3">
<tr>
<td align="right" valign="top"><b>Software:</b></td>
<td valign="top">HI-TECH C compilers.</td>
</tr>
<tr>
<td align="right" valign="top"><b>Pros:</b></td>
<td valign="top">
<ul>
<li>&ldquo;Lite&rdquo; mode is free (as in beer).</li>
<li>Same tools are available on Windows, Linux and Mac OS X (PowerPC or Intel) &mdash; native and without virtualization &mdash; great for classrooms and other &ldquo;mixed use&rdquo; environments.</li>
<li>Includes Eclipse-based IDE, or can be used from command line if that&rsquo;s more your style.</li>
</ul>
</td>
</tr>
<tr>
<td align="right" valign="top"><b>Cons:</b></td>
<td valign="top">
<ul>
<li>The full &ldquo;Pro&rdquo; license is costly, and the PIC18 compiler is a separate product from the PIC12/14/16 &mdash; professional development for both will cost twice as much.</li>
<li>Does not interface directly with the PICkit&nbsp;2 for downloading code to the microcontroller. Additional software and steps are required (see next section).</li>
<li>Certain features, such as processor configuration, are handled differently from Microchip&rsquo;s original compilers; source code brought over will likely need some modification.</li>
</tr>
</table>
<h3>Option 3: Open Source Tools</h3>
<p>Community-developed tools for PIC development likewise started out quite rough but have since crossed a threshold of viability. A complete development toolchain consists of three parts:</p>
<ul>
<li><a href="http://gputils.sourceforge.net/">GPUTILS</a> (GNU PIC Utilities) includes an assembler (<tt>gpsasm</tt>) that aims to be fully source compatible with Microchip&rsquo;s own tools, and my own experiences have borne this out; code taken directly from MPLAB projects works with <tt>gpasm</tt> without modification. The project page does mention a handful of esoteric incompatibilities and bugs but I have never encountered these in regular use.</li>
<li><a href="http://sdcc.sourceforge.net/">SDCC</a> (Small Device C Compiler) supports a variety of microcontroller platforms; 8-bit PIC support is a recent addition and still a work in progress. I&rsquo;ve tested simple student-level programs against it with no trouble at all, but at present there&rsquo;s the risk it may be unsuited to more complex tasks.</li>
<li><tt>PK2CMD</tt> is Microchip&rsquo;s open-source tool for downloading code to a microcontroller using the PICkit&nbsp;2.</li>
</ul>
<p>These tools are all command line operated at present; there is no GUI or IDE. Savvy users might be able to integrate them with a development environment such as Eclipse; I&rsquo;ve not figured this out because I&rsquo;m an old fart and <i>like</i> developing on the command line. Uphill. In the snow.</p>
<table cellpadding="3">
<tr>
<td align="right" valign="top"><b>Software:</b></td>
<td valign="top">Open Source Command Line Tools</td>
</tr>
<tr>
<td align="right" valign="top"><b>Pros:</b></td>
<td valign="top">
<ul>
<li>Free (as in speech) &mdash; no crippled features or restrictions on use.</li>
<li>Lightweight and fast, even on vintage PowerPC Macs, small netbooks, etc.</li>
<li>Assembler is fully compatible with Microchip&rsquo;s own; no additional porting effort.</li>
<li>Supports a few other microcontroller architectures as well.</li>
</ul>
</td>
</tr>
<tr>
<td align="right" valign="top"><b>Cons:</b></td>
<td valign="top">
<ul>
<li>PIC support in SDCC is a work in progress with some known bugs. Perfectly adequate for training and hobbyist use, but complex projects could conceivably run into issues.</li>
<li>No technical support &mdash; if trouble arises, you&rsquo;re on your own (though community support tends to be pretty good).</li>
<li>No GUI/IDE, if you&rsquo;re inclined that way.</li>
</ul>
</td>
</tr>
</table>
<h4>Installing GPUTILS</h4>
<table cellpadding="3">
<tr>
<td valign="top" align="right"><b>Windows:</b></td>
<td valign="top">An <tt>.exe</tt> installer is available from the project&rsquo;s <a href="http://sourceforge.net/projects/gputils/files/">download page</a>.</td>
</tr>
<tr>
<td valign="top" align="right"><b>Linux:</b></td>
<td valign="top">You can install via Synaptic Package Manager (you may need to enable third-party repositories) &mdash; search for <tt>gputils</tt>. This can also be done from the command line using <tt>apt-get</tt>:</p>
<blockquote><p>sudo apt-get install gputils</p></blockquote>
<p>Alternately, if you have <tt>gcc</tt> installed, retrieve the <tt>.tar.gz</tt> file from the <a href="http://sourceforge.net/projects/gputils/files/">download page</a> and compile using the directions below.</td>
</tr>
<tr>
<td valign="top" align="right"><b>Mac OS X:</b></td>
<td valign="top">There is no precompiled package available; you will need to build from source. This requires the <tt>gcc</tt> compiler, which is part of Xcode &mdash; an optional installer on your original Mac OS X DVD-ROM or can be downloaded from Apple&rsquo;s <a href="http://developer.apple.com/mac/">developer site</a>. Retrieve the GPUTILS source code <tt>.tar.gz</tt> file from the project&rsquo;s <a href="http://sourceforge.net/projects/gputils/files/">download page</a>. Once this archive is extracted, open Terminal.app, <tt>cd</tt> to the source directory and it&rsquo;s a simple three step process to build:</p>
<blockquote><p><tt>
<p>./configure</p>
<p>make</p>
<p>sudo make install</p>
<p></tt></p></blockquote>
</td>
</tr>
</table>
<p>This takes just a few minutes to complete, and the resulting executable will be installed in <tt>/usr/local/bin</tt>. Make sure this directory is added to your <tt>PATH</tt> environment variable.</p>
<h4>Installing SDCC</h4>
<p>Couldn&rsquo;t be simpler &mdash; pre-built installers for all the major operating systems are available on the project&rsquo;s <a href="http://sourceforge.net/projects/sdcc/files/">download page</a>. It&rsquo;s also available in package format for Linux users; use Synaptic or <tt>apt-get</tt> to install the package <tt>sdcc</tt>. If for some reason you need to build this from the source code, the procedure to compile and install this uses the exact sequence of commands previously shown for GPUTILS.</p>
<h4>Installing PK2CMD</h4>
<p>This is also available as a precompiled installer for various operating systems, or can be built from source. The links for these are buried amidst the <a href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&#038;nodeId=1406&#038;dDocName=en023805">PICkit&nbsp;2 product page</a> (the &ldquo;Download&rdquo; box second from the bottom).</p>
<p>If compiling from source, the build process for PK2CMD is slightly different than the other tools. After extracting the source archive, the <tt>./configure</tt> step isn&rsquo;t necessary. Instead, just type the appropriate <tt>make</tt> command for your operating system:</p>
<table cellpadding="3">
<tr>
<td valign="top" align="right"><b>Mac OS X 10.5:</b></td>
<td valign="top"><tt>make&nbsp;mac105</tt></td>
</tr>
<tr>
<td valign="top" align="right"><b>Mac OS X 10.4:</b></td>
<td valign="top"><tt>make&nbsp;mac104</tt></td>
</tr>
<tr>
<td valign="top" align="right"><b>Linux:</b></td>
<td valign="top"><tt>make&nbsp;linux</tt></td>
</tr>
<tr>
<td valign="top" align="right"><b>Linux (older 2.4 kernel):</b></td>
<td valign="top"><tt>make&nbsp;linux-old</tt></td>
</tr>
</table>
<p>Next type:</p>
<blockquote><p>sudo&nbsp;make&nbsp;install</p></blockquote>
<p>&hellip;and then make sure both <tt>/usr/local/bin</tt> <b><u>and</u></b> <tt>/usr/share/pk2</tt> are in your <tt>PATH</tt> environment variable. e.g. in <tt>~/.profile,</tt> add this line:</p>
<blockquote><p>export&nbsp;PATH=$PATH:/usr/local/bin:/usr/share/pk2</p></blockquote>
<h4>Using the Open Source Tools</h4>
<p>One aspect of SDCC initially had me confused: the documentation refers to the &ldquo;pic14&rdquo; and &ldquo;pic16&rdquo; ports of the compiler, but it turns out these do <i>not</i> correspond to Microchip&rsquo;s part naming conventions. Rather, each refers to the instruction word size (in bits) on the midrange and high performance microcontrollers; in other words, you compile for the PIC16 using the pic14 option, and PIC18 using the pic16 option. Once that was cleared up, everything proceeded smoothly.</p>
<p>In addition to the documentation included with each, all three tools offer command-line help:</p>
<blockquote><p>sdcc &#8211;help<br />
gpasm &#8211;help<br />
pk2cmd -?</p></blockquote>
<p>In order to avoid a lot of repetitive typing (and having to remember all of the fiddly options for <tt>pk2cmd</tt>), I&rsquo;ll usually group all of the files related to a single project into one folder and then create a Makefile that includes common operations such as &ldquo;<tt>make&nbsp;write</tt>&rdquo; or &ldquo;<tt>make&nbsp;on</tt>&rdquo;, like this:</p>
<blockquote><p># Example makefile for open source PIC toolchain<br />
# Specific microcontroller type:<br />
DEVICE=pic18f2620<br />
# C compiler, assembler, device programmer:<br />
CC=sdcc -mpic16<br />
AS=gpasm -p$(DEVICE)<br />
PK2=pk2cmd -P$(DEVICE)</p>
<p>All: foo.hex</p>
<p>foo.hex: foo.c foo.h<br />
&nbsp;&nbsp;&nbsp;&nbsp;$(CC) foo.c</p>
<p>write:<br />
&nbsp;&nbsp;&nbsp;&nbsp;$(PK2) -M -Ffoo.hex</p>
<p>on:<br />
&nbsp;&nbsp;&nbsp;&nbsp;$(PK2) -T</p>
<p>off:<br />
&nbsp;&nbsp;&nbsp;&nbsp;$(PK2) -W</p>
<p>erase:<br />
&nbsp;&nbsp;&nbsp;&nbsp;$(PK2) -E</p>
<p>clean:<br />
&nbsp;&nbsp;&nbsp;&nbsp;rm -f *.o *.cod *.hex *.lst *.err</p></blockquote>
<hr />
]]></content:encoded>
			<wfw:commentRss>http://www.paintyourdragon.com/?feed=rss2&amp;p=45</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>The 25&#162; I2C Adapter</title>
		<link>http://www.paintyourdragon.com/?p=43</link>
		<comments>http://www.paintyourdragon.com/?p=43#comments</comments>
		<pubDate>Wed, 02 Apr 2008 05:43:59 +0000</pubDate>
		<dc:creator>pburgess</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[ddc]]></category>
		<category><![CDATA[dvi]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[hdmi]]></category>
		<category><![CDATA[i2c]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vga]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.paintyourdragon.com/wordpress/?p=43</guid>
		<description><![CDATA[This project demonstrates a novel repurposing of the existing display control lines present on many graphics cards as an inexpensive method of interfacing computers with a variety of sensors and devices.
I2C (Inter-Integrated Circuit) is a two-wire serial bus typically used inside computers for low-level communication between components, but it&#8217;s also seen in robotics and hobbyist [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin-right: 2em; margin-bottom: 1em;" src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/title.jpg" alt="" width="240" height="280" align="left" />This project demonstrates a novel repurposing of the existing display control lines present on many graphics cards as an inexpensive method of interfacing computers with a variety of sensors and devices.</p>
<p>I<sup>2</sup>C (Inter-Integrated Circuit) is a two-wire serial bus typically used inside computers for low-level communication between components, but it&rsquo;s also seen in robotics and hobbyist electronics for interfacing all manner of sensors, displays and actuators. I<sup>2</sup>C connections are often readily available on microcontrollers and esoteric embedded systems, but there’s traditionally little call for end-user access to this bus on mainstream personal computers. Lately though, netbooks and other small form-factor systems are increasingly being put to use as the high-powered “brains” of many homebrew projects. To sense and react in the physical world, a USB to I<sup>2</sup>C adapter (or “bridge”) device is typically used, often at considerable expense.</p>
<p><span id="more-43"></span>DDC, supported by most graphics cards and monitors produced since the late 1990s, is a communication channel within a video cable that allows the computer and monitor to negotiate mutually compatible resolutions and permit software control of functions normally accessed with physical buttons on the display.</p>
<p>DDC is, in fact, simply an implementation of an I<sup>2</sup>C bus with a few established rules. By tapping into this connection between the computer and monitor (or better yet, making use of the DDC lines on an spare unused video port, such as the external monitor connection on a laptop), one can interface with many I<sup>2</sup>C devices at virtually no expense, bypassing the usual need for an adapter device entirely.</p>
<p>Commercial USB to I<sup>2</sup>C adapters can cost $100, $250, sometimes even more, and driver support is spotty for systems outside the popular Windows fold. Using an Arduino or other USB-capable microcontroller as an intermediary is one affordable alternative. But the method outlined here requires nothing more than a modified video cable…I just bought one at a garage sale for 50 cents, and that’s enough to make <em>two</em> such adapters!</p>
<p>Being a quick and dirty hack, there are some limitations to this approach:</p>
<ol>
<li>Most significantly, it <strong>does not work in Windows at present.</strong> I’ve pursued a number of avenues but have yet to produce a working equivalent for that operating system. Please see the notes at the end of this article regarding the current state of Windows affairs.</li>
<li>Even among Macintosh and Linux systems, the compatible range of hardware is limited. The graphics card driver will determine whether application code is allowed access to the DDC lines at all.
<ul>
<li>On the Mac, systems with Intel integrated graphics or ATI chipsets appear to support this scheme, while those with NVIDIA graphics are out of luck. As nearly the entire current Mac lineup has now transitioned to NVIDIA graphics, the usefulness of this hack is relegated mostly to earlier Mac models and just a handful of current iMac and Mac Pro configurations.</li>
<li>I’ve had few opportunities to test with Linux systems thus far, but ATI and NVIDIA graphics seem to show solid support while Intel integrated (e.g. GMA 910) was a no-go.</li>
</ul>
<table class="vis">
<tr>
<th>Compatibility<br />Matrix</td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/logo-ati.gif" width="43" height="29"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/logo-nvidia.gif" width="48" height="35"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/logo-intel.gif" width="47" height="31"></td>
</tr>
<tr>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/logo-windows.png" width="65" height="57"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/compat-no.png" width="65" height="59"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/compat-no.png" width="65" height="59"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/compat-no.png" width="65" height="59"></td>
</tr>
<tr>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/logo-linux.gif" width="53" height="65"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/compat-yes.png" width="72" height="51"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/compat-yes.png" width="72" height="51"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/compat-no.png" width="65" height="59"></td>
</tr>
<tr>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/logo-apple.gif" width="50" height="62"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/compat-yes.png" width="72" height="51"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/compat-no.png" width="65" height="59"></td>
<td align="center" valign="middle"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/compat-yes.png" width="72" height="51"></td>
</tr>
</table>
</li>
<li>Not all I<sup>2</sup>C devices are compatible with this approach, and the selection varies somewhat by operating system. There seems to be some variation in the allowable range of serial timings sent or received by both the host and I<sup>2</sup>C device, and in some combinations these ranges just don’t overlap. For example, a Nintendo Wii Nunchuk controller will work with Linux but not Mac OS X.</li>
<li>This is limited to being a “single-master” I<sup>2</sup>C bus; one can poll devices for their state, but there’s no means for the computer to respond to events that originate elsewhere on the bus. And available power is limited to 5 volts at a scant 50 milliamps.</li>
<li>There’s always the possibility of damage by incorrect wiring or misplaced voltages. Attempting this hack at all is likely a warranty-voiding operation and I assume no liability for damage inflicted, so tread forth carefully and <em>always mount a scratch monkey!</em></li>
</ol>
<p>There are still plenty of fun projects that can be attempted, so with those caveats out of the way, let’s proceed! All that’s required is a modified video cable, or, if tapping an unused video port, simply the appropriate end connector (but it’s often cheaper to simply buy the full cable and cut it in half). If the port will still be used for a monitor connection, it’s necessary to create a “Y” or “hydra” cable that allows one’s I<sup>2</sup>C device(s) and the monitor to be attached at the same time (sharing the DDC lines).</p>
<table class="vis">
<tr>
<th>Single-Ended Cable</th>
<th>“Y” Cable</th>
</tr>
<tr>
<td align="center" valign="middle" style="border-bottom: 0;"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/cable-laptop.png" width="145" height="100" /></td>
<td align="center" valign="middle" style="border-bottom: 0;"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/cable-desktop.png" width="225" height="90" /></td>
</tr>
<tr>
<td align="center" valign="top" style="border-top: 0;">Connects to an unused video port.</td>
<td align="center" valign="top" style="border-top: 0;">Shares video port among monitor and I<sup>2</sup>C device(s).</td>
</table>
<p>When modifying an existing cable, after removing just the outer shielding, the DDC wires are usually visible at this point, while the lines carrying video signals are wrapped inside further-shielded bundles. A multimeter or continuity tester will help correlate wires to pins. DDC establishes four wires: +5VDC, ground, serial data and serial clock, the pin numbers of which will vary depending on the type of video port used. Refer to pinouts.ru, Wikipedia or other sources if you need more help than the diagrams below can provide.</p>
<p>The pins of interest are as follows:</p>
<table class="vis" style="position: relative; left: -15px;">
<tr>
<th colspan="2">VGA:</th>
<th colspan="2" style="border-left: 2px solid; border-right: 2px solid;">DVI:</th>
<th colspan="2">HDMI (Type A):</th>
</tr>
<tr>
<td colspan="2" align="center"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/port-vga.png" width="92" height="46"/></td>
<td colspan="2" align="center" style="border-left: 2px solid; border-right: 2px solid;"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/port-dvi.png" width="150" height="46" /></td>
<td colspan="2" align="center"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/port-hdmi.png" width="150" height="56"/></td>
</tr>
<tr>
<th>Pin</th>
<th>Description</th>
<th style="border-left: 2px solid;">Pin</th>
<th style="border-right: 2px solid;">Description</th>
<th>Pin</th>
<th>Description</th>
</tr>
<tr>
<td align="right">5</td>
<td><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-gray.gif" width="12" height="12" align="right" />Ground</td>
<td align="right" style="border-left: 2px solid;">6</td>
<td style="border-right: 2px solid;"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-yellow.gif" width="12" height="12" align="right" />Clock</td>
<td align="right">15</td>
<td><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-yellow.gif" width="12" height="12" align="right" />Clock</td>
</tr>
<tr>
<td align="right">9<sup>*</sup></td>
<td><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-red.gif" width="12" height="12" align="right" />+5VDC</td>
<td align="right" style="border-left: 2px solid;">7</td>
<td style="border-right: 2px solid;"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-blue.gif" width="12" height="12" align="right" />Data</td>
<td align="right">16</td>
<td><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-blue.gif" width="12" height="12" align="right" />Data</td>
</tr>
<tr>
<td align="right">12</td>
<td><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-blue.gif" width="12" height="12" align="right" />Data</td>
<td align="right" style="border-left: 2px solid;">14</td>
<td style="border-right: 2px solid;"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-red.gif" width="12" height="12" align="right" />+5VDC</td>
<td align="right">17</td>
<td><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-gray.gif" width="12" height="12" align="right" />Ground</td>
</tr>
<tr>
<td align="right">15</td>
<td><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-yellow.gif" width="12" height="12" align="right" />Clock</td>
<td align="right" style="border-left: 2px solid;">15</td>
<td style="border-right: 2px solid;"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-gray.gif" width="12" height="12" align="right" />Ground</td>
<td align="right">18</td>
<td><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/spot-red.gif" width="12" height="12" align="right" />+5VDC</td>
</tr>
</table>
<p>* Note that on some VGA cables (perhaps even a majority), pin 9 is not present (occasionally others as well). Just examime the male end connector to see if it’s even worth dissecting — the missing pins are quite apparent. You’ll want to use a cable with the full complement of pins, or work from just a bare D-sub 15 connector (if scrounging at the local swap meet for cheap cables is not your style, these connectors can be found at Radio Shack for $1.99).</p>
<p>The DDC clock and data lines correspond directly to I<sup>2</sup>C clock and data. Pull-up resistors are not required — that’s already implemented in the graphics card — so it’s just the cable, your I<sup>2</sup>C device(s) and a bit of wire.</p>
<p>Connect the corresponding I<sup>2</sup>C lines to your device as required, and the other end of the cable to the desired video port. If using a “Y” splitter cable with a monitor connected, one’s power budget should be trimmed by a few extra milliamps to ensure enough power for the DDC chip within the display. There should be enough current to drive a microcontroller and an LED or possibly two…but if the I<sup>2</sup>C device(s) to be connected are going to use any substantial amount of current, it may be wise to power the circuit externally and use a I<sup>2</sup>C buffer or, if the device operates at a different voltage, a logic level converter (such as SparkFun part <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8745">BOB-08745</a>). Also, if using with a display connected, two I<sup>2</sup>C addresses are reserved for the monitor and should not be used: 0&#215;37 and 0&#215;50.</p>
<p>While the gritty details of the I<sup>2</sup>C protocol are taken care of by the <tt>i2c.o</tt> library (provided below) and the OS-specific libraries on which it in turn depends, the specific message sequence required by any given device must be implemented within one’s own code and will vary from one device to the next; the library does not automatically handle all this. Manufacturers’ datasheets will document the I<sup>2</sup>C messages needed, and the amount of code required is not onerous. Several short example programs are included: reading a Nintendo Wii Nunchuk controller accessory (currently Linux only), reading a Microchip TCN75A temperature sensor, writing to a Microchip 256 Kbit serial EEPROM, flashing a BlinkM “smart LED,” and another that interfaces with a Mindsensors I2C-SC8 8 channel servo controller.</p>
<table width="400" class="vis">
<tr>
<th colspan="2">Bringing it All Together</th>
</tr>
<tr>
<td style="padding: 0;"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/cold.jpg" width="200" height="220" style="padding: 0;" /></td>
<td style="padding: 0;"><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/hot.jpg" width="200" height="220" style="padding: 0;" /></td>
</tr>
<tr>
<td colspan="2" style="font-size: 85%; line-height: 1.3em;">Here’s a quick test case involving multiple I<sup>2</sup>C devices: the computer (out of frame, to the right) reads the current temperature from a sensor, then updates a hobby servo being used as a makeshift dial indicator. The readings are also logged to EEPROM for posterity. The example code can do all of these functions, plus others.</td>
</tr>
</table>
<h2><a style="text-decoration: underline;" href="http://members.dslextreme.com/users/paintyourdragon/files/i2c.tar.gz">Click to Download C Source Code (tar.gz)</a></h2>
<hr />
<h2>Installation</h2>
<p>No special procedure is required for Mac systems, aside from having GCC installed in order to compile the code. GCC is one component of Xcode, an optional installer on your original Mac OS X DVD-ROM, or can be downloaded from <a href="http://developer.apple.com/mac/">Apple’s developer web site</a>. Rather than get into the whole graphical IDE, I’m simply invoking the compiler from a Terminal window. If you have a supported video card and one of the compatible I<sup>2</sup>C devices attached, simply compile (“<tt>make all</tt>”) and run (e.g. “<tt>./temperature</tt>”). You can skip the rest of these directions and go right to the “Using the Library” section.</p>
<p>While the source code for Linux is simpler, the setup procedure unfortunately is not. You’ll need root access. Frequently. This is how I install it under Ubuntu 7.04 and later:</p>
<ol>
<li>Install the lm-sensors package:<br />
<blockquote><p>sudo apt-get install lm-sensors</p></blockquote>
</li>
<li>Enable kernel modules for I<sup>2</sup>C and the specific video driver:<br />
<blockquote><p>sudo modprobe i2c-dev</p>
<p>sudo modprobe radeonfb</p></blockquote>
<p>The above is for an ATI Radeon. You might need a different module specific to your system. Use the command “<tt>sudo modprobe -l</tt>” (that’s a lowercase <tt>L</tt>, not a one) for a full list of kernel modules, and try to locate one that matches your graphics chip vendor.)</p>
<p>Alternately, to load the I<sup>2</sup>C modules automatically at boot-time, edit the file <tt>/etc/modules</tt> and add these lines:</p>
<blockquote><p>i2c-dev<br />
radeonfb</p></blockquote>
<p>Again, assuming Radeon graphics here; put your actual module name there.</p>
<p>Once the kernel modules are loaded, the files <tt>/dev/i2c-*</tt> will then correspond to each I<sup>2</sup>C bus on the system. Not all of these relate to video out though; some may correspond to internal I<sup>2</sup>C buses in the computer (e.g. system health, RAM controller, etc.). The <tt>i2cdetect</tt> program (installed as part of lm-sensors) will list and briefly describe each I<sup>2</sup>C interface present. Look for the one that matches the desired video port. On the ThinkPad I used for development, <tt>/dev/i2c-2</tt> corresponds to the VGA port. If the output of <tt>i2cdetect</tt> does not mention any video ports (VGA, DVI, or HDMI), then it’s probable that the driver does not support I<sup>2</sup>C and this hack will not work, or a different video card module may simply need to be loaded.</li>
<li>Edit the Makefile, commenting out the Mac-specific lines and enabling the Linux-related flags. Then “<tt>make all</tt>” to build the library and example programs.</li>
<li>Access to the <tt>/dev/i2c-*</tt> devices is normally available only to the root user, so there are a few options for invoking the example programs. The most sensible and controlled is to run each with the <tt>sudo</tt> command, e.g. “<tt>sudo ./nunchuk</tt>”. If you’re on a personal system and can afford to be less pedantic about security, other options include logging in and running the programs as root, chown/chmod-ing the executables to root and enabling the setuid bit, or chmod-ing the <tt>/dev/i2c-*</tt> files to enable read/write access for all users (which would need to be reapplied after each reboot).</li>
</ol>
<hr />
<h2>Using the Library</h2>
<p>The C API is super-basic, with just three functions:</p>
<p class="func">I2Copen()</p>
<p class="api">Opens the I<sup>2</sup>C (DDC) bus for subsequent communication. As some systems may support multiple “heads” and thus have multiple DDC interfaces, the code in <tt>i2c-osx.c</tt> or <tt>i2c-linux.c</tt> may to be adapted to your specific situation. On Macs the code is currently rigged to use the last connection found; on a single-head system (e.g. Mac mini), this would be the single video out port, while on a potentially two-headed system (e.g. MacBook, late-model iMac) this would be the video out port, regardless of whether there’s a monitor attached. Multi-headed systems (e.g. Mac Pro) may require some tweaks to the code to access a specific graphics card and port. For Linux, the code is rigged to open <tt>/dev/i2c-2</tt>, which corresponds to the VGA connector on my ThinkPad system used during development, but you’ll probably want to change this for your particular situation. Review the notes above regarding Linux installation.</p>
<p class="func">I2Cmsg(short address, unsigned char *sendBuf, int sendBytes, unsigned char *replyBuf, int replyBytes)</p>
<p class="api">Issues an I<sup>2</sup>C request and/or reads response over the previously-opened I<sup>2</sup>C bus. The address of the device is often factory-defined, and the size and content of the request data are entirely device-dependent (see the example code for several practical cases). You’ll need to work with the datasheet provided for your specific device.</p>
<p class="api">An important point should be made here regarding the first parameter: there is some disagreement as to just what constitutes a valid I<sup>2</sup>C address. The I<sup>2</sup>C protocol defines data packets in 8-bit chunks, with the first byte of an I<sup>2</sup>C message containing a 7-bit device identifier and one bit indicating whether this is a read or write operation. Most presume the 7-bit value to define the address, but in some implementations they’ll include the read/write bit in referring the address, or — because the R/W flag is the least signficant bit — document the device as having two sequential addresses (one each for reading and writing). Linux and OSX disagree here; this API follows the 7-bit convention and adjusts the value passed as needed for the host operating system. If a device does not seem to be responding at the address given in the datasheet, try dividing the number by two, which shifts off the R/W bit to produce a 7-bit address.</p>
<table width="300" class="vis">
<tr>
<td><img src="http://members.dslextreme.com/users/paintyourdragon/img/i2c/address.png" width="300" height="90" /></td>
</tr>
<tr>
<td style="font-size: 85%; line-height: 1.3em;">This example from a Microchip datasheet shows an 8-bit I<sup>2</sup>C address byte that includes a ‘write’ bit. But other documents (and this API) follow the convention of calling addresses by the 7-bit component only.</td>
</tr>
</table>
<p class="func">I2Cclose()</p>
<p class="api">Closes the previously-opened I<sup>2</sup>C bus.</p>
<p>Return values, defined in <tt>i2c.h</tt>, are currently very limited. All of the functions will return a value of zero (or <tt>I2C_ERR_NONE</tt>) on successful completion. The <tt>I2Copen()</tt> function may return <tt>I2C_ERR_OPEN</tt> if no available DDC bus can be found (or, on Linux, if not running as root). On the Mac, <tt>I2Cmsg()</tt> may return various error values defined in <tt>/System/Library/Frameworks/IOKit.framework/Headers/IOReturn.h</tt> (e.g. <tt>0x2c0</tt> or <tt>kIOReturnNoDevice</tt>).</p>
<p>The library is not especially comprehensive; there are quite a few limitations and assumptions made at present (for example, only one I<sup>2</sup>C bus can be open at a time). Consider this just a starting point for your own code. The core meat-and-potatoes of opening and communicating over the bus can be distilled to just a couple dozen essential lines of code, the rest being error handling, packaging and comments.</p>
<hr />
<h2>Microsoft Windows Status</h2>
<p>As explained earlier in this article, I currently do not have a working implementation of this library available for any version of Windows yet. Honest, this is <em>not</em> just asinine OS bashing! Admittedly the platform is one of the less familiar among my development skills, but I have made several honest attempts, still to no avail. If Windows is your native tongue and you’d like to give it a try, I can offer some possible leads:</p>
<ul>
<li>In my earliest attempts, web searches for information suggested that the Windows API calls for handling DDC (and thus I<sup>2</sup>C) were undocumented and proprietary. More recently, reader S. Manabe brought <a href="http://www.microsoft.com/whdc/archive/i2c.mspx">this article at Windows Hardware Developer Central</a> to my attention. The talk of WDM Streams and minidrivers quickly goes over my head, but perhaps Windows-savvy developers could make use of it.</li>
<li>For users with NVIDIA graphics cards, N. Ekstrom alerted me of the existence of the <a href="http://developer.nvidia.com/object/nvapi.html">NVIDIA API</a> and corresponding <a href="http://http.developer.nvidia.com/nvapi/index.html">documentation</a>. I’ve only had time to briefly dabble with this and have produced no working results yet. The documentation also mentions a Mac version of the API, but it seems no library for that platform is available for download.</li>
<li>Nicomsoft’s <a href="http://www.nicomsoft.com/wini2cddc/">WinI2C-DDC</a> appears to have comprehensively solved this problem across all manner of PC hardware, and continues to be actively developed. Unfortunately it costs $495 for a developer license (the $249 Lite version doesn’t support low-level I<sup>2</sup>C access). A 30-day time-limited evaluation can be downloaded from their web site free of charge. But in the long run, casual tinkerers might prefer a less expensive USB (or even parallel port, if you still have one) hardware solution (or getting the hang of Linux).</li>
<li>On the hardware front: Aside from the obvious Arduino option, <a href="http://www.ftdichip.com/">FTDI</a>’s FT2232H and FT4232H multipurpose USB to Multi-Protocol Synchronous Serial Engine chips may provide an inexpensive hardware connection. Evaluation modules from FTDI and DLP Design can be acquired from the likes of Digi-Key or Mouser for under $30. I’ve not yet experimented with the I<sup>2</sup>C functionality specifically, but the datasheet looks promising and I’ve had tremendous success with other features of FTDI’s chips — watch for a follow-up article at some point.</li>
</ul>
<hr />
<h2>Acknowledgments</h2>
<p>Much thanks to Benny Hsieh for donating development hardware which made the Linux port possible, the authors of ddcci-tool (now ddccontrol) for Linux I<sup>2</sup>C programming insights, and Tod Kurt of ThingM for entrusting me with one of his BlinkMs for testing at the 2008 Bay Area Maker Faire.</p>
<hr />
]]></content:encoded>
			<wfw:commentRss>http://www.paintyourdragon.com/?feed=rss2&amp;p=43</wfw:commentRss>
		<slash:comments>4</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! -->