<?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>Limina.Log</title>
	<atom:link href="http://log.liminastudio.com/feed" rel="self" type="application/rss+xml" />
	<link>http://log.liminastudio.com</link>
	<description>Research &#38; Development at Limina.Studio</description>
	<lastBuildDate>Fri, 10 May 2013 18:44:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Strange Loop Talk Online: &#8220;Getting Physical&#8221;</title>
		<link>http://log.liminastudio.com/events/strange-loop-talk-online-getting-physical</link>
		<comments>http://log.liminastudio.com/events/strange-loop-talk-online-getting-physical#comments</comments>
		<pubDate>Fri, 10 May 2013 18:44:40 +0000</pubDate>
		<dc:creator>Tedb0t</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[WiFi]]></category>

		<guid isPermaLink="false">http://log.liminastudio.com/?p=1099</guid>
		<description><![CDATA[I just found out that my talk from the Strange Loop conference last year, &#8220;Getting Physical: Networked Hardware with Node.js&#8221; is online.  Check it out here!]]></description>
				<content:encoded><![CDATA[<p>I just found out that my talk from the Strange Loop conference last year, &#8220;Getting Physical: Networked Hardware with Node.js&#8221; is online.  <a href="http://www.infoq.com/presentations/Hardware-Nodejs-WiFi-XBee">Check it out here</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://log.liminastudio.com/events/strange-loop-talk-online-getting-physical/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sublime Tunnel of Love: How to Edit Remote Files With Sublime Text via an SSH Tunnel</title>
		<link>http://log.liminastudio.com/writing/tutorials/sublime-tunnel-of-love-how-to-edit-remote-files-with-sublime-text-via-an-ssh-tunnel</link>
		<comments>http://log.liminastudio.com/writing/tutorials/sublime-tunnel-of-love-how-to-edit-remote-files-with-sublime-text-via-an-ssh-tunnel#comments</comments>
		<pubDate>Mon, 04 Feb 2013 21:35:39 +0000</pubDate>
		<dc:creator>Tedb0t</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Sublime Text]]></category>
		<category><![CDATA[System Administration]]></category>

		<guid isPermaLink="false">http://log.liminastudio.com/?p=1093</guid>
		<description><![CDATA[Eventually you will need to edit a file in-place on a server, for one reason or another (i.e. working on a Javascript front-end that requires templating from a backend); this is partly what Emacs and Vim are for (and they&#8217;re both very good at what they do). There&#8217;s nothing wrong with learning either of those [...]]]></description>
				<content:encoded><![CDATA[<p>Eventually you will need to edit a file in-place on a server, for one reason or another (i.e. working on a Javascript front-end that requires templating from a backend); this is partly what Emacs and Vim are for (and they&#8217;re both very good at what they do).</p>
<p>There&#8217;s nothing wrong with learning either of those tools, but if you really don&#8217;t want to, there are options.  If the server is running FTP, you can use something like Transmit to open the file in a local editor and saves will be automatically uploaded to the server.  Unfortunately, FTP is a very old and VERY insecure protocol that should not be used anymore.  What else can we do?</p>
<p>Using Secure Shell (SSH) Tunneling, we can establish an SSH session that routes arbitrary traffic through it to a specified port for any use we want.  Thanks to a <a href="https://github.com/Drarok/rsub">nifty set of scripts called rsub</a>, modified originally from <a href="http://erniemiller.org/2011/12/12/textmate-2-rmate-awesome/">TextMate&#8217;s rmate</a>, we can run a little utility server on our local machine that interacts with your remote server for you and lets you open up remote files and save them back, all through an encrypted channel.</p>
<h3>What Do I Do?</h3>
<ol>
<li>As of writing, these instructions work only for Sublime Text 2.  If I get a chance I&#8217;ll look into forking rsub for the newly released ST3 (which runs Python3).</li>
<li><span style="line-height: 13px;">If you don&#8217;t already have Sublime Text&#8217;s wonderful package manager, <a href="http://wbond.net/sublime_packages/package_control/installation">install it</a>.</span></li>
<li>Hit Ctrl+Shift+P, start typing &#8220;install&#8221; and select &#8220;Install Package&#8221;</li>
<li>Start typing &#8220;rsub&#8221; and select it.</li>
<li>Once it&#8217;s installed, get on your terminal and do
<pre>nano ~/.ssh/config</pre>
</li>
<li>Paste the following lines:
<pre>Host your_remote_server.com
    RemoteForward 52698 127.0.0.1:52698</pre>
</li>
<li>Save (ctrl+w) and SSH into your server (ssh username@your_remote_server.com).</li>
<li>&#8216;Install&#8217; the rsub remote script:
<pre>sudo wget -O /usr/local/bin/rsub https://raw.github.com/aurora/rmate/master/rmate</pre>
</li>
<li>Make that script executable:
<pre>sudo chmod +x /usr/local/bin/rsub</pre>
</li>
<li>Lastly, run rsub on the remote file you want to edit locally:
<pre>rsub ~/my_project/my_file.html</pre>
<p>and it should magically open in Sublime Text!</li>
</ol>
<p>Let me know if this works for you! Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://log.liminastudio.com/writing/tutorials/sublime-tunnel-of-love-how-to-edit-remote-files-with-sublime-text-via-an-ssh-tunnel/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Updating a Mailchimp mailing list with past EventBrite attendees</title>
		<link>http://log.liminastudio.com/programming/updating-a-mailchimp-mailing-list-with-past-eventbrite-attendees</link>
		<comments>http://log.liminastudio.com/programming/updating-a-mailchimp-mailing-list-with-past-eventbrite-attendees#comments</comments>
		<pubDate>Tue, 29 Jan 2013 18:44:16 +0000</pubDate>
		<dc:creator>Tedb0t</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[EventBrite]]></category>
		<category><![CDATA[Mailchimp]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://log.liminastudio.com/?p=1091</guid>
		<description><![CDATA[At Kitchen Table Coders we use EventBrite to sell tickets and Mailchimp to email fans about new classes.  Every time we do a new class I wanted to update our main mailing list with the new attendee email addresses, so I wrote this simple Python script to do it automatically.  Usage details are in the [...]]]></description>
				<content:encoded><![CDATA[<p>At <a href="http://kitchentablecoders.com/">Kitchen Table Coders</a> we use EventBrite to sell tickets and Mailchimp to email fans about new classes.  Every time we do a new class I wanted to update our main mailing list with the new attendee email addresses, so I wrote <a href="https://github.com/virgildisgr4ce/EventbriteAttendeesToMailchimp">this simple Python script</a> to do it automatically.  Usage details are in the readme.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://log.liminastudio.com/programming/updating-a-mailchimp-mailing-list-with-past-eventbrite-attendees/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Batch convert files to PDFs in OSX Mountain Lion</title>
		<link>http://log.liminastudio.com/programming/batch-convert-files-to-pdfs-in-osx-mountain-lion</link>
		<comments>http://log.liminastudio.com/programming/batch-convert-files-to-pdfs-in-osx-mountain-lion#comments</comments>
		<pubDate>Wed, 12 Dec 2012 22:38:13 +0000</pubDate>
		<dc:creator>Tedb0t</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://log.liminastudio.com/?p=1086</guid>
		<description><![CDATA[Today I needed to convert a bunch of RTF files (I know, what?) to PDFs.  After stumbling through a bunch of dead ends, I realized this—like most things—could be done incredibly easily in Bash: #!/bin/bash for file in *.rtf ; do filename=$(basename "$file") /usr/sbin/cupsfilter "$file" &#62; "$filename.pdf" done]]></description>
				<content:encoded><![CDATA[<p>Today I needed to convert a bunch of RTF files (I know, what?) to PDFs.  After stumbling through a bunch of dead ends, I realized this—like most things—could be done incredibly easily in Bash:</p>
<pre>#!/bin/bash
for file in *.rtf ; do
filename=$(basename "$file") /usr/sbin/cupsfilter "$file" &gt; "$filename.pdf"
done</pre>
]]></content:encoded>
			<wfw:commentRss>http://log.liminastudio.com/programming/batch-convert-files-to-pdfs-in-osx-mountain-lion/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Physical: Workshop Notes</title>
		<link>http://log.liminastudio.com/programming/getting-physical-workshop-notes</link>
		<comments>http://log.liminastudio.com/programming/getting-physical-workshop-notes#comments</comments>
		<pubDate>Sat, 22 Sep 2012 21:30:09 +0000</pubDate>
		<dc:creator>Tedb0t</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Ethernet]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[RN-XV]]></category>
		<category><![CDATA[Strange Loop]]></category>
		<category><![CDATA[WiFly]]></category>
		<category><![CDATA[Workshop]]></category>

		<guid isPermaLink="false">http://log.liminastudio.com/?p=1075</guid>
		<description><![CDATA[Here are some notes and links for my Strange Loop workshop, &#8220;Getting Physical.&#8221; Getting started with the RN-XV WiFi Module &#38; Node.js WiFi Joystick GitHub Repo Using the RN-XV WiFi Module as a Remote Switch]]></description>
				<content:encoded><![CDATA[<p>Here are some notes and links for my <a href="https://thestrangeloop.com/sessions/getting-physical-networked-hardware-with-nodejs">Strange Loop workshop</a>, &#8220;Getting Physical.&#8221;</p>
<ul>
<li><a href="http://log.liminastudio.com/programming/getting-started-with-the-rn-xv-wifi-module-node-js">Getting started with the RN-XV WiFi Module &amp; Node.js</a></li>
<li><a href="https://github.com/KitchenTableCoders/node-pong">WiFi Joystick GitHub Repo</a></li>
<li><a href="http://log.liminastudio.com/itp/physical-computing/using-the-rn-xv-wifi-module-as-a-remote-switch">Using the RN-XV WiFi Module as a Remote Switch</a></li>
<li><iframe src="http://www.slideshare.net/slideshow/embed_code/14486812?hostedIn=slideshare&amp;page=upload" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="476" height="400"></iframe></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://log.liminastudio.com/programming/getting-physical-workshop-notes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slides for TimesOpen &#8220;Sockets &amp; Streams&#8221;</title>
		<link>http://log.liminastudio.com/itp/physical-computing/slides-for-timesopen-sockets-streams</link>
		<comments>http://log.liminastudio.com/itp/physical-computing/slides-for-timesopen-sockets-streams#comments</comments>
		<pubDate>Thu, 13 Sep 2012 19:12:53 +0000</pubDate>
		<dc:creator>Tedb0t</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://log.liminastudio.com/?p=1070</guid>
		<description><![CDATA[Last night at the New York Times &#8220;TimesOpen&#8221; event, I gave a presentation on internet-enabled bubble guns, wireless joysticks for browser games, and how the &#8220;Internet of Things&#8221; is better understood as an Internet Ecology: Thanks to everyone for coming and to Brad Stenger and everyone at the Times for inviting me!]]></description>
				<content:encoded><![CDATA[<p>Last night at the New York Times &#8220;TimesOpen&#8221; event, I gave a presentation on internet-enabled bubble guns, wireless joysticks for browser games, and how the &#8220;Internet of Things&#8221; is better understood as an Internet Ecology:</p>
<p><iframe src="http://www.slideshare.net/slideshow/embed_code/14279348?hostedIn=slideshare&amp;page=upload" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="476" height="400"></iframe></p>
<p>Thanks to everyone for coming and to Brad Stenger and everyone at the Times for inviting me!</p>
]]></content:encoded>
			<wfw:commentRss>http://log.liminastudio.com/itp/physical-computing/slides-for-timesopen-sockets-streams/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino: A new &amp; improved Button library with some handy features</title>
		<link>http://log.liminastudio.com/itp/physical-computing/arduino-a-new-improved-button-library-with-some-handy-features</link>
		<comments>http://log.liminastudio.com/itp/physical-computing/arduino-a-new-improved-button-library-with-some-handy-features#comments</comments>
		<pubDate>Thu, 02 Aug 2012 23:54:47 +0000</pubDate>
		<dc:creator>Tedb0t</dc:creator>
				<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[Prototyping]]></category>

		<guid isPermaLink="false">http://log.liminastudio.com/?p=1062</guid>
		<description><![CDATA[By Ted Hayes, from code originally by Alexander Brevig &#38; Tom Igoe The Arduino Button library (Github Repo) makes it easy to do some very common but rather tedious tasks. Usually when you interact with a button (such as a momentary switch), you mainly want to detect the state change, not just the current state. [...]]]></description>
				<content:encoded><![CDATA[<p><em>By Ted Hayes, from code originally by Alexander Brevig &amp; Tom Igoe</em></p>
<p>The Arduino Button library (<a href="https://github.com/virgildisgr4ce/Button">Github Repo</a>) makes it easy to do some very common but rather tedious tasks. Usually when you interact with a button (such as a momentary switch), you mainly want to detect the state change, not just the current state. You have to do something like:</p>
<pre>int lastState = 0;
void loop(){
    int currentState = digitalRead(11);
    if(currentState != lastState){
        // do something
    }
    lastState = currentState;
}</pre>
<p>It&#8217;s not hard, just tedious. This new and improved Button library makes this much simpler but adds so much more. Now you can do it this way:</p>
<pre>Button button = Button(12);

void onPress(Button&amp; b){
	Serial.print("onPress: ");
	Serial.println(b.pin);
	// will print out "onPress: 12"
}

void setup(){
  Serial.begin(9600);
  // Assign callback function
  button.pressHandler(onPress);
}

void loop(){
  // update the buttons' internals
  button.process();
}</pre>
<h2>Features</h2>
<ul>
<li>Object-oriented design
<pre>Button myButton(11);</pre>
</li>
<li>Automatic pull-up setting
<pre>Button myButton(11, BUTTON_PULLUP_INTERNAL);</pre>
</li>
<li>Simplified state-change detection:
<pre>if(button.isPressed()) ...</pre>
</li>
<li>Callback model
<pre>button.pressHandler(onPress)</pre>
</li>
<li>Built-in debouncing
<pre>// Sets 50ms debounce duration
Button button = Button(12, BUTTON_PULLUP_INTERNAL, true, 50);</pre>
</li>
</ul>
<h2>Installing</h2>
<p>To install, <a href="https://github.com/virgildisgr4ce/Button/zipball/master">download the library</a>, extract it to ~/Documents/Arduino/libraries and rename the folder &#8220;Button.&#8221; (Github generates a different name for the zip link.) Restart Arduino if it was already open.</p>
<p>I hope you find this useful! Please report any bugs using the <a href="https://github.com/virgildisgr4ce/Button/issues">Github issue tracker</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://log.liminastudio.com/itp/physical-computing/arduino-a-new-improved-button-library-with-some-handy-features/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Arduino: How to Read and Write EEPROM values</title>
		<link>http://log.liminastudio.com/itp/physical-computing/arduino-how-to-read-and-write-eeprom-values</link>
		<comments>http://log.liminastudio.com/itp/physical-computing/arduino-how-to-read-and-write-eeprom-values#comments</comments>
		<pubDate>Wed, 01 Aug 2012 21:16:00 +0000</pubDate>
		<dc:creator>Tedb0t</dc:creator>
				<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[EEPROM]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://log.liminastudio.com/?p=1060</guid>
		<description><![CDATA[When you reset an Arduino, the state of any variables you might have will be lost. So what if you want to keep a value even after it&#8217;s been powered off? Luckily, ATmega chips have an area of memory called EEPROM, or &#8220;Electrically Erasable Programmable Read-Only Memory.&#8221;  This allows you to store persistent values, and [...]]]></description>
				<content:encoded><![CDATA[<p>When you reset an Arduino, the state of any variables you might have will be lost. So what if you want to keep a value even after it&#8217;s been powered off? Luckily, ATmega chips have an area of memory called <a href="http://en.wikipedia.org/wiki/EEPROM">EEPROM</a>, or &#8220;Electrically Erasable Programmable Read-Only Memory.&#8221;  This allows you to store persistent values, and Arduino ships with an EEPROM library that makes it easy to use.</p>
<p>Here&#8217;s an example Arduino sketch that demonstrates how to read from and write to this part of memory:</p>
<script>document.write('<link href=\"https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css\" media=\"screen\" rel=\"stylesheet\" />')
document.write('<div id=\"gist3230109\" class=\"gist\">\n      <div class=\"gist-file\">\n        <div class=\"gist-data gist-syntax\">\n\n\n\n  <div class=\"file-data\">\n    <table cellpadding=\"0\" cellspacing=\"0\" class=\"lines highlight\">\n      <tr>\n        <td class=\"line-numbers\">\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L1\" rel=\"file-eeprom_rw_test-ino-L1\">1<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L2\" rel=\"file-eeprom_rw_test-ino-L2\">2<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L3\" rel=\"file-eeprom_rw_test-ino-L3\">3<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L4\" rel=\"file-eeprom_rw_test-ino-L4\">4<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L5\" rel=\"file-eeprom_rw_test-ino-L5\">5<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L6\" rel=\"file-eeprom_rw_test-ino-L6\">6<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L7\" rel=\"file-eeprom_rw_test-ino-L7\">7<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L8\" rel=\"file-eeprom_rw_test-ino-L8\">8<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L9\" rel=\"file-eeprom_rw_test-ino-L9\">9<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L10\" rel=\"file-eeprom_rw_test-ino-L10\">10<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L11\" rel=\"file-eeprom_rw_test-ino-L11\">11<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L12\" rel=\"file-eeprom_rw_test-ino-L12\">12<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L13\" rel=\"file-eeprom_rw_test-ino-L13\">13<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L14\" rel=\"file-eeprom_rw_test-ino-L14\">14<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L15\" rel=\"file-eeprom_rw_test-ino-L15\">15<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L16\" rel=\"file-eeprom_rw_test-ino-L16\">16<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L17\" rel=\"file-eeprom_rw_test-ino-L17\">17<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L18\" rel=\"file-eeprom_rw_test-ino-L18\">18<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L19\" rel=\"file-eeprom_rw_test-ino-L19\">19<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L20\" rel=\"file-eeprom_rw_test-ino-L20\">20<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L21\" rel=\"file-eeprom_rw_test-ino-L21\">21<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L22\" rel=\"file-eeprom_rw_test-ino-L22\">22<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L23\" rel=\"file-eeprom_rw_test-ino-L23\">23<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L24\" rel=\"file-eeprom_rw_test-ino-L24\">24<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L25\" rel=\"file-eeprom_rw_test-ino-L25\">25<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L26\" rel=\"file-eeprom_rw_test-ino-L26\">26<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L27\" rel=\"file-eeprom_rw_test-ino-L27\">27<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L28\" rel=\"file-eeprom_rw_test-ino-L28\">28<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L29\" rel=\"file-eeprom_rw_test-ino-L29\">29<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L30\" rel=\"file-eeprom_rw_test-ino-L30\">30<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L31\" rel=\"file-eeprom_rw_test-ino-L31\">31<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L32\" rel=\"file-eeprom_rw_test-ino-L32\">32<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L33\" rel=\"file-eeprom_rw_test-ino-L33\">33<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L34\" rel=\"file-eeprom_rw_test-ino-L34\">34<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L35\" rel=\"file-eeprom_rw_test-ino-L35\">35<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L36\" rel=\"file-eeprom_rw_test-ino-L36\">36<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L37\" rel=\"file-eeprom_rw_test-ino-L37\">37<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L38\" rel=\"file-eeprom_rw_test-ino-L38\">38<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L39\" rel=\"file-eeprom_rw_test-ino-L39\">39<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L40\" rel=\"file-eeprom_rw_test-ino-L40\">40<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L41\" rel=\"file-eeprom_rw_test-ino-L41\">41<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L42\" rel=\"file-eeprom_rw_test-ino-L42\">42<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L43\" rel=\"file-eeprom_rw_test-ino-L43\">43<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L44\" rel=\"file-eeprom_rw_test-ino-L44\">44<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L45\" rel=\"file-eeprom_rw_test-ino-L45\">45<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L46\" rel=\"file-eeprom_rw_test-ino-L46\">46<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L47\" rel=\"file-eeprom_rw_test-ino-L47\">47<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L48\" rel=\"file-eeprom_rw_test-ino-L48\">48<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L49\" rel=\"file-eeprom_rw_test-ino-L49\">49<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L50\" rel=\"file-eeprom_rw_test-ino-L50\">50<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L51\" rel=\"file-eeprom_rw_test-ino-L51\">51<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L52\" rel=\"file-eeprom_rw_test-ino-L52\">52<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L53\" rel=\"file-eeprom_rw_test-ino-L53\">53<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L54\" rel=\"file-eeprom_rw_test-ino-L54\">54<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L55\" rel=\"file-eeprom_rw_test-ino-L55\">55<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L56\" rel=\"file-eeprom_rw_test-ino-L56\">56<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L57\" rel=\"file-eeprom_rw_test-ino-L57\">57<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L58\" rel=\"file-eeprom_rw_test-ino-L58\">58<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L59\" rel=\"file-eeprom_rw_test-ino-L59\">59<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L60\" rel=\"file-eeprom_rw_test-ino-L60\">60<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L61\" rel=\"file-eeprom_rw_test-ino-L61\">61<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L62\" rel=\"file-eeprom_rw_test-ino-L62\">62<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L63\" rel=\"file-eeprom_rw_test-ino-L63\">63<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L64\" rel=\"file-eeprom_rw_test-ino-L64\">64<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L65\" rel=\"file-eeprom_rw_test-ino-L65\">65<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L66\" rel=\"file-eeprom_rw_test-ino-L66\">66<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L67\" rel=\"file-eeprom_rw_test-ino-L67\">67<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L68\" rel=\"file-eeprom_rw_test-ino-L68\">68<\/span>\n          <span class=\"line-number\" id=\"file-eeprom_rw_test-ino-L69\" rel=\"file-eeprom_rw_test-ino-L69\">69<\/span>\n        <\/td>\n        <td class=\"line-data\">\n          <pre class=\"line-pre\"><div class="line" id="file-eeprom_rw_test-ino-LC1"><span class="cm">/******************************************************<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC2">&nbsp;<\/div><div class="line" id="file-eeprom_rw_test-ino-LC3"><span class="cm">    Arduino EEPROM Read-Write Test<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC4"><span class="cm">    by Ted Hayes 2012<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC5"><span class="cm">    ted.hayes@liminastudio.com<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC6"><span class="cm">    <\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC7"><span class="cm">    Demonstrates the usage of the EEPROM Library for checking the state of a single value,<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC8"><span class="cm">    changing it, and resetting it.  To use:<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC9"><span class="cm">    <\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC10"><span class="cm">    1) Put a momentary switch between ground and pin 11 on your Arduino.<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC11"><span class="cm">    2) Upload this program to it.<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC12"><span class="cm">    3) Open the serial monitor<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC13"><span class="cm">    4) You should see:<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC14"><span class="cm">    Starting; current EEPROM value is 0<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC15"><span class="cm">    EEPROM byte not set yet; Writing...<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC16"><span class="cm">    Done.<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC17"><span class="cm">    5) Now press the reset button on your Arduino and keep the serial monitor open.<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC18"><span class="cm">    You should see:<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC19"><span class="cm">    Starting; current EEPROM value is 1<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC20"><span class="cm">    EEPROM byte was set!<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC21"><span class="cm">    Done.<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC22"><span class="cm">    6) Press your momentary switch, and you should see:<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC23"><span class="cm">    Resetting EEPROM value<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC24"><span class="cm">    7) Now press the reset button one more time, and you should see:<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC25"><span class="cm">    Starting; current EEPROM value is 0<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC26"><span class="cm">    EEPROM byte not set yet; Writing...<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC27"><span class="cm">    Done.<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC28"><span class="cm">    <\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC29"><span class="cm">    That&#39;s it!  Remember that the EEPROM on ATmega chips has a specified life of 100,000<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC30"><span class="cm">    write/erase cycles, so be careful about putting writes/erases in loops, etc..<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC31">&nbsp;<\/div><div class="line" id="file-eeprom_rw_test-ino-LC32"><span class="cm">******************************************************/<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC33">&nbsp;<\/div><div class="line" id="file-eeprom_rw_test-ino-LC34"><span class="cp">#include &lt;EEPROM.h&gt;<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC35">&nbsp;<\/div><div class="line" id="file-eeprom_rw_test-ino-LC36"><span class="cp">#define PIN_SWITCH 11<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC37">&nbsp;<\/div><div class="line" id="file-eeprom_rw_test-ino-LC38"><span class="kt">int<\/span> <span class="n">lastSwitch<\/span> <span class="o">=<\/span> <span class="n">HIGH<\/span><span class="p">;<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC39"><span class="n">boolean<\/span> <span class="n">didReset<\/span> <span class="o">=<\/span> <span class="nb">false<\/span><span class="p">;<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC40">&nbsp;<\/div><div class="line" id="file-eeprom_rw_test-ino-LC41"><span class="kt">void<\/span> <span class="nf">setup<\/span><span class="p">(){<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC42">  <span class="n">Serial<\/span><span class="p">.<\/span><span class="n">begin<\/span><span class="p">(<\/span><span class="mi">9600<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC43">  <span class="n">pinMode<\/span><span class="p">(<\/span><span class="n">PIN_SWITCH<\/span><span class="p">,<\/span> <span class="n">INPUT<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC44">  <span class="n">digitalWrite<\/span><span class="p">(<\/span><span class="n">PIN_SWITCH<\/span><span class="p">,<\/span> <span class="n">HIGH<\/span><span class="p">);<\/span> <span class="c1">// set internal pull-up resistor<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC45">  <\/div><div class="line" id="file-eeprom_rw_test-ino-LC46">  <span class="kt">int<\/span> <span class="n">val<\/span> <span class="o">=<\/span> <span class="n">EEPROM<\/span><span class="p">.<\/span><span class="n">read<\/span><span class="p">(<\/span><span class="mi">0<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC47">  <span class="n">Serial<\/span><span class="p">.<\/span><span class="n">print<\/span><span class="p">(<\/span><span class="s">&quot;Starting; current EEPROM value is &quot;<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC48">  <span class="n">Serial<\/span><span class="p">.<\/span><span class="n">println<\/span><span class="p">(<\/span><span class="n">val<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC49">  <\/div><div class="line" id="file-eeprom_rw_test-ino-LC50">  <span class="k">if<\/span><span class="p">(<\/span><span class="n">val<\/span> <span class="o">!=<\/span> <span class="mi">1<\/span><span class="p">){<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC51">    <span class="n">Serial<\/span><span class="p">.<\/span><span class="n">println<\/span><span class="p">(<\/span><span class="s">&quot;EEPROM byte not set yet; Writing...&quot;<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC52">    <span class="n">EEPROM<\/span><span class="p">.<\/span><span class="n">write<\/span><span class="p">(<\/span><span class="mi">0<\/span><span class="p">,<\/span> <span class="mi">1<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC53">  <span class="p">}<\/span> <span class="k">else<\/span> <span class="k">if<\/span> <span class="p">(<\/span><span class="n">val<\/span> <span class="o">==<\/span> <span class="mi">1<\/span><span class="p">){<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC54">    <span class="n">Serial<\/span><span class="p">.<\/span><span class="n">println<\/span><span class="p">(<\/span><span class="s">&quot;EEPROM byte was set!&quot;<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC55">  <span class="p">}<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC56">  <span class="n">Serial<\/span><span class="p">.<\/span><span class="n">println<\/span><span class="p">(<\/span><span class="s">&quot;Done.&quot;<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC57"><span class="p">}<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC58">&nbsp;<\/div><div class="line" id="file-eeprom_rw_test-ino-LC59"><span class="kt">void<\/span> <span class="nf">loop<\/span><span class="p">(){<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC60">  <span class="kt">int<\/span> <span class="n">currentSwitch<\/span> <span class="o">=<\/span> <span class="n">digitalRead<\/span><span class="p">(<\/span><span class="n">PIN_SWITCH<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC61">  <span class="k">if<\/span><span class="p">(<\/span><span class="n">currentSwitch<\/span> <span class="o">==<\/span> <span class="n">LOW<\/span> <span class="o">&amp;&amp;<\/span> <span class="n">lastSwitch<\/span> <span class="o">!=<\/span> <span class="n">currentSwitch<\/span> <span class="o">&amp;&amp;<\/span> <span class="o">!<\/span><span class="n">didReset<\/span><span class="p">){<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC62">    <span class="c1">// switch has changed state<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC63">    <span class="c1">// didReset is a simple form of debouncing, which prevents<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC64">    <span class="c1">// this from being run too many times<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC65">    <span class="n">Serial<\/span><span class="p">.<\/span><span class="n">println<\/span><span class="p">(<\/span><span class="s">&quot;Resetting EEPROM value&quot;<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC66">    <span class="n">EEPROM<\/span><span class="p">.<\/span><span class="n">write<\/span><span class="p">(<\/span><span class="mi">0<\/span><span class="p">,<\/span> <span class="mi">0<\/span><span class="p">);<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC67">    <span class="n">didReset<\/span> <span class="o">=<\/span> <span class="nb">true<\/span><span class="p">;<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC68">  <span class="p">}<\/span><\/div><div class="line" id="file-eeprom_rw_test-ino-LC69"><span class="p">}<\/span><\/div><\/pre>\n        <\/td>\n      <\/tr>\n    <\/table>\n  <\/div>\n\n        <\/div>\n\n        <div class="gist-meta">\n          <a href="https://gist.github.com/virgildisgr4ce/3230109/raw/198747ac34e39e650509bb180e4fe84c0722ea93/eeprom_rw_test.ino" style="float:right">view raw<\/a>\n          <a href="https://gist.github.com/virgildisgr4ce/3230109#file-eeprom_rw_test-ino" style="float:right; margin-right:10px; color:#666;">eeprom_rw_test.ino<\/a>\n          <a href="https://gist.github.com/virgildisgr4ce/3230109">This Gist<\/a> brought to you by <a href="http://github.com">GitHub<\/a>.\n        <\/div>\n      <\/div>\n<\/div>\n')
</script><div style='margin-bottom:1em;padding:0;'><noscript><code><pre style='overflow:auto;margin:0;padding:0;border:1px solid #DDD;'>/******************************************************

    Arduino EEPROM Read-Write Test
    by Ted Hayes 2012
    ted.hayes@liminastudio.com
    
    Demonstrates the usage of the EEPROM Library for checking the state of a single value,
    changing it, and resetting it.  To use:
    
    1) Put a momentary switch between ground and pin 11 on your Arduino.
    2) Upload this program to it.
    3) Open the serial monitor
    4) You should see:
    Starting; current EEPROM value is 0
    EEPROM byte not set yet; Writing...
    Done.
    5) Now press the reset button on your Arduino and keep the serial monitor open.
    You should see:
    Starting; current EEPROM value is 1
    EEPROM byte was set!
    Done.
    6) Press your momentary switch, and you should see:
    Resetting EEPROM value
    7) Now press the reset button one more time, and you should see:
    Starting; current EEPROM value is 0
    EEPROM byte not set yet; Writing...
    Done.
    
    That's it!  Remember that the EEPROM on ATmega chips has a specified life of 100,000
    write/erase cycles, so be careful about putting writes/erases in loops, etc..

******************************************************/

#include &lt;EEPROM.h&gt;

#define PIN_SWITCH 11

int lastSwitch = HIGH;
boolean didReset = false;

void setup(){
  Serial.begin(9600);
  pinMode(PIN_SWITCH, INPUT);
  digitalWrite(PIN_SWITCH, HIGH); // set internal pull-up resistor
  
  int val = EEPROM.read(0);
  Serial.print(&quot;Starting; current EEPROM value is &quot;);
  Serial.println(val);
  
  if(val != 1){
    Serial.println(&quot;EEPROM byte not set yet; Writing...&quot;);
    EEPROM.write(0, 1);
  } else if (val == 1){
    Serial.println(&quot;EEPROM byte was set!&quot;);
  }
  Serial.println(&quot;Done.&quot;);
}

void loop(){
  int currentSwitch = digitalRead(PIN_SWITCH);
  if(currentSwitch == LOW &amp;&amp; lastSwitch != currentSwitch &amp;&amp; !didReset){
    // switch has changed state
    // didReset is a simple form of debouncing, which prevents
    // this from being run too many times
    Serial.println(&quot;Resetting EEPROM value&quot;);
    EEPROM.write(0, 0);
    didReset = true;
  }
}</pre></code></noscript></div>
]]></content:encoded>
			<wfw:commentRss>http://log.liminastudio.com/itp/physical-computing/arduino-how-to-read-and-write-eeprom-values/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: How to use your Raspberry Pi like an Arduino</title>
		<link>http://log.liminastudio.com/writing/tutorials/tutorial-how-to-use-your-raspberry-pi-like-an-arduino</link>
		<comments>http://log.liminastudio.com/writing/tutorials/tutorial-how-to-use-your-raspberry-pi-like-an-arduino#comments</comments>
		<pubDate>Fri, 15 Jun 2012 22:39:03 +0000</pubDate>
		<dc:creator>Tedb0t</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[RaspberryPi]]></category>

		<guid isPermaLink="false">http://log.liminastudio.com/?p=1039</guid>
		<description><![CDATA[Finally got to experiment with the Raspberry Pi&#8217;s GPIO (General Purpose Input/Output) pins.  I tried three methods: Python, Bash and C, and will describe each.  But first, here&#8217;s some setup information. Connecting to the RPi&#8217;s GPIO header: I used an old floppy disk drive IDE ribbon cable.  It has 34 pins, but the RPi&#8217;s header [...]]]></description>
				<content:encoded><![CDATA[<p><img class="size-medium wp-image-1040 alignleft" title="IMG_2776" src="http://log.liminastudio.com/wp-content/uploads/2012/06/IMG_2776-300x224.jpg" alt="" width="300" height="224" />Finally got to experiment with the Raspberry Pi&#8217;s GPIO (General Purpose Input/Output) pins.  I tried three methods: Python, Bash and C, and will describe each.  But first, here&#8217;s some setup information.<span id="more-1039"></span></p>
<ul>
<li><strong>Connecting to the RPi&#8217;s GPIO header:</strong> I used an old floppy disk drive IDE ribbon cable.  It has 34 pins, but the RPi&#8217;s header is only 26 pins, so part of the connector is unused. I soldered some breadboard-friendly header pins onto the other end, which is working pretty well so far. Bear in mind that some IDE cables may be <a href="http://en.wikipedia.org/wiki/Parallel_ATA#Differences_between_connectors_on_80-conductor_cables">more complicated than they look</a>. Before powering anything up, make sure you check that each conductor is indeed separate and you&#8217;re not accidentally grounding or shorting anything. You can always make your own by getting some <a href="http://www.mouser.com/ProductDetail/3M-Electronic-Solutions-Division/D89126-0101HK/?qs=IDj0%2fmHVFfYp9MYtSAMqnFNo3vgyVqeS2OzUnKmFU8w%3d">26-conductor IDC connectors</a> and using a vice to crimp it onto a piece of ribbon cable.<br />
<a href="http://log.liminastudio.com/wp-content/uploads/2012/06/IMG_2778.jpg"  rel="lightbox[roadtrip]"><img class="alignnone size-medium wp-image-1042" title="IMG_2778" src="http://log.liminastudio.com/wp-content/uploads/2012/06/IMG_2778-224x300.jpg" alt="" width="224" height="300" /></a> <a href="http://log.liminastudio.com/wp-content/uploads/2012/06/IMG_2777.jpg"  rel="lightbox[roadtrip]"><img class="alignnone size-medium wp-image-1041" title="IMG_2777" src="http://log.liminastudio.com/wp-content/uploads/2012/06/IMG_2777-224x300.jpg" alt="" width="224" height="300" /></a></li>
<li><strong>Pin Connections:</strong> &#8230;are confusing! There&#8217;s a <a href="http://elinux.org/RPi_BCM2835_GPIOs">master table here</a>, and a <a href="http://elinux.org/RPi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29">diagram here</a>.  Looking at the diagram, my breakout header starts with 3.3V and moves left to right, top to bottom.  Here are the pin connections from my header as pictured:
<ul>
<li>Pin 2: 5V</li>
<li>Pin 3: &#8220;GPIO0&#8243;. Connected to one end of the switch (the other end is connected to ground, since this GPIO pin has an internal <a href="http://en.wikipedia.org/wiki/Pull-up_resistor">pull-up resistor</a>.  This means that when the switch is not closed, the pin reads as &#8220;High,&#8221; and when closed, &#8220;Low.&#8221;</li>
<li>Pin 6: GND (note that it&#8217;s jumpered to my ground rail on my breakout board)</li>
<li>Pin 7: &#8220;GPIO4&#8243;. The anode of the LED through a 220-ohm resistor.</li>
</ul>
</li>
<li>I&#8217;ll use this breakout board setup for all the following examples.  Different libraries/tools use different pin numbers, adding to the confusion, so I&#8217;ll try to clear it up.  Also note that I&#8217;m doing this through an SSH session, so there&#8217;s no monitor attached to the RPi. See my <a href="http://log.liminastudio.com/writing/tutorials/getting-started-with-the-raspberry-pi">beginning instructions here</a> if you don&#8217;t already have an SSH connection to your Pi.</li>
<li><strong>Important Note:</strong> The RPi Wiki takes pains to remind you that these GPIO pins are unbuffered and unprotected, so if you short something out, you could fry your whole Pi, so be careful!  There are a number of other breakout boards being developed that should make this safer.</li>
<li><strong>Important Note:</strong> Any program that accesses the GPIO pins must be run as root, so if you get an error, remember to &#8220;sudo&#8221; your command.</li>
<li>Python: One of my preferred languages, so I figured I&#8217;d try it out. First, install pip (Python package installer):
<ul>
<li>
<pre>sudo curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python</pre>
</li>
<li>Next, install the <a href="http://pypi.python.org/pypi/RPi.GPIO">RPi.GPIO Python module</a>:</li>
<li>
<pre>sudo pip install rpi.gpio</pre>
</li>
<li>Now, you can enter the python interpreter (sudo python) and do stuff like:</li>
<li>
<pre>import RPi.GPIO as GPIO
GPIO.setup(7, GPIO.OUT)
GPIO.output(7, True)
GPIO.output(7,False)</pre>
</li>
</ul>
</li>
<li><strong>Bash: </strong>Something I&#8217;ve always loved about Unix is the idea that everything is a file.  On the Raspberry Pi, <a href="http://elinux.org/RPi_Low-level_peripherals#GPIO_Driving_Example_.28Shell_script.29">the GPIO pins are files too</a>! With the pictured breadboard setup, we can do the following to turn the LED on and off (note that this uses the &#8220;BCM&#8221; pin numbering but the breadboard stays the same!):
<ul>
<li>(You can&#8217;t just put sudo before each command because the second command that the output is directed to would not be run as root. So, for simplicity, we drop into root first.)
<pre>sudo su -
echo "4" &gt; /sys/class/gpio/export
echo "4" &gt; /sys/class/gpio/export
echo "out" &gt; /sys/class/gpio/gpio4/direction
echo "1" &gt; /sys/class/gpio/gpio4/value
echo "0" &gt; /sys/class/gpio/gpio4/value</pre>
</li>
<li>To read from an input, &#8216;cat&#8217; it like any other file!
<pre>echo "0" &gt; /sys/class/gpio/export
echo "in" &gt; /sys/class/gpio/gpio0/direction
cat /sys/class/gpio/gpio0/value</pre>
</li>
</ul>
</li>
<li><strong>C:</strong> Good old C.  The <a href="http://elinux.org/RPi_Low-level_peripherals#GPIO_Driving_Example_.28C.29">native example</a> for C is really hairy, but luckily a plucky fellow named Gordon wrote an <a href="https://projects.drogon.net/raspberry-pi/wiringpi/">Arduino-like library</a> just for the Raspberry Pi!  Here&#8217;s what you need to do:
<ul>
<li>Download and install the library:
<pre>cd /tmp
wget http://project-downloads.drogon.net/files/wiringPi.tgz

tar xfz wiringPi.tgz
cd wiringPi/wiringPi
make
sudo make install
cd ../gpio
make
sudo make install</pre>
</li>
<li>Your Pi&#8217;s system now has the wiringPi library installed, so we can write a little program that uses it.
<pre>cd ~
nano blink.c</pre>
</li>
<li>Type or paste in this program:<br />
<script>document.write('<link href=\"https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css\" media=\"screen\" rel=\"stylesheet\" />')
document.write('<div id=\"gist2939020\" class=\"gist\">\n      <div class=\"gist-file\">\n        <div class=\"gist-data gist-syntax\">\n\n\n\n  <div class=\"file-data\">\n    <table cellpadding=\"0\" cellspacing=\"0\" class=\"lines highlight\">\n      <tr>\n        <td class=\"line-numbers\">\n          <span class=\"line-number\" id=\"file-blink-c-L1\" rel=\"file-blink-c-L1\">1<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L2\" rel=\"file-blink-c-L2\">2<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L3\" rel=\"file-blink-c-L3\">3<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L4\" rel=\"file-blink-c-L4\">4<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L5\" rel=\"file-blink-c-L5\">5<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L6\" rel=\"file-blink-c-L6\">6<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L7\" rel=\"file-blink-c-L7\">7<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L8\" rel=\"file-blink-c-L8\">8<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L9\" rel=\"file-blink-c-L9\">9<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L10\" rel=\"file-blink-c-L10\">10<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L11\" rel=\"file-blink-c-L11\">11<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L12\" rel=\"file-blink-c-L12\">12<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L13\" rel=\"file-blink-c-L13\">13<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L14\" rel=\"file-blink-c-L14\">14<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L15\" rel=\"file-blink-c-L15\">15<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L16\" rel=\"file-blink-c-L16\">16<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L17\" rel=\"file-blink-c-L17\">17<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L18\" rel=\"file-blink-c-L18\">18<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L19\" rel=\"file-blink-c-L19\">19<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L20\" rel=\"file-blink-c-L20\">20<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L21\" rel=\"file-blink-c-L21\">21<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L22\" rel=\"file-blink-c-L22\">22<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L23\" rel=\"file-blink-c-L23\">23<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L24\" rel=\"file-blink-c-L24\">24<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L25\" rel=\"file-blink-c-L25\">25<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L26\" rel=\"file-blink-c-L26\">26<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L27\" rel=\"file-blink-c-L27\">27<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L28\" rel=\"file-blink-c-L28\">28<\/span>\n          <span class=\"line-number\" id=\"file-blink-c-L29\" rel=\"file-blink-c-L29\">29<\/span>\n        <\/td>\n        <td class=\"line-data\">\n          <pre class=\"line-pre\"><div class="line" id="file-blink-c-LC1"><span class="cm">/*<\/span><\/div><div class="line" id="file-blink-c-LC2"><span class="cm"> * blink.c:<\/span><\/div><div class="line" id="file-blink-c-LC3"><span class="cm"> *      Simple test program to blink an LED on pin 7<\/span><\/div><div class="line" id="file-blink-c-LC4"><span class="cm"> */<\/span><\/div><div class="line" id="file-blink-c-LC5">&nbsp;<\/div><div class="line" id="file-blink-c-LC6"><span class="cp">#include &lt;wiringPi.h&gt;<\/span><\/div><div class="line" id="file-blink-c-LC7"><span class="cp">#include &lt;stdio.h&gt;<\/span><\/div><div class="line" id="file-blink-c-LC8">&nbsp;<\/div><div class="line" id="file-blink-c-LC9"><span class="kt">int<\/span> <span class="nf">main<\/span> <span class="p">(<\/span><span class="kt">void<\/span><span class="p">)<\/span><\/div><div class="line" id="file-blink-c-LC10"><span class="p">{<\/span><\/div><div class="line" id="file-blink-c-LC11">  <span class="kt">int<\/span> <span class="n">pin<\/span> <span class="o">=<\/span> <span class="mi">7<\/span><span class="p">;<\/span><\/div><div class="line" id="file-blink-c-LC12">  <span class="n">printf<\/span><span class="p">(<\/span><span class="s">&quot;Raspberry Pi wiringPi blink test<\/span><span class="se">\\n<\/span><span class="s">&quot;<\/span><span class="p">);<\/span><\/div><div class="line" id="file-blink-c-LC13">&nbsp;<\/div><div class="line" id="file-blink-c-LC14">  <span class="k">if<\/span> <span class="p">(<\/span><span class="n">wiringPiSetup<\/span><span class="p">()<\/span> <span class="o">==<\/span> <span class="o">-<\/span><span class="mi">1<\/span><span class="p">)<\/span><\/div><div class="line" id="file-blink-c-LC15">    <span class="n">exit<\/span> <span class="p">(<\/span><span class="mi">1<\/span><span class="p">);<\/span><\/div><div class="line" id="file-blink-c-LC16">&nbsp;<\/div><div class="line" id="file-blink-c-LC17">  <span class="n">pinMode<\/span><span class="p">(<\/span><span class="n">pin<\/span><span class="p">,<\/span> <span class="n">OUTPUT<\/span><span class="p">);<\/span><\/div><div class="line" id="file-blink-c-LC18">&nbsp;<\/div><div class="line" id="file-blink-c-LC19">  <span class="k">for<\/span> <span class="p">(;;){<\/span><\/div><div class="line" id="file-blink-c-LC20">    <span class="n">printf<\/span><span class="p">(<\/span><span class="s">&quot;LED On<\/span><span class="se">\\n<\/span><span class="s">&quot;<\/span><span class="p">);<\/span><\/div><div class="line" id="file-blink-c-LC21">    <span class="n">digitalWrite<\/span><span class="p">(<\/span><span class="n">pin<\/span><span class="p">,<\/span> <span class="mi">1<\/span><span class="p">);<\/span><\/div><div class="line" id="file-blink-c-LC22">    <span class="n">delay<\/span><span class="p">(<\/span><span class="mi">250<\/span><span class="p">);<\/span><\/div><div class="line" id="file-blink-c-LC23">    <span class="n">printf<\/span><span class="p">(<\/span><span class="s">&quot;LED Off<\/span><span class="se">\\n<\/span><span class="s">&quot;<\/span><span class="p">);<\/span><\/div><div class="line" id="file-blink-c-LC24">    <span class="n">digitalWrite<\/span><span class="p">(<\/span><span class="n">pin<\/span><span class="p">,<\/span> <span class="mi">0<\/span><span class="p">);<\/span><\/div><div class="line" id="file-blink-c-LC25">    <span class="n">delay<\/span><span class="p">(<\/span><span class="mi">250<\/span><span class="p">);<\/span><\/div><div class="line" id="file-blink-c-LC26">  <span class="p">}<\/span><\/div><div class="line" id="file-blink-c-LC27">&nbsp;<\/div><div class="line" id="file-blink-c-LC28">  <span class="k">return<\/span> <span class="mi">0<\/span><span class="p">;<\/span><\/div><div class="line" id="file-blink-c-LC29"><span class="p">}<\/span><\/div><\/pre>\n        <\/td>\n      <\/tr>\n    <\/table>\n  <\/div>\n\n        <\/div>\n\n        <div class="gist-meta">\n          <a href="https://gist.github.com/virgildisgr4ce/2939020/raw/8947fa7dd4fb9fc4f54895fbe5fb52e55fcef62c/blink.c" style="float:right">view raw<\/a>\n          <a href="https://gist.github.com/virgildisgr4ce/2939020#file-blink-c" style="float:right; margin-right:10px; color:#666;">blink.c<\/a>\n          <a href="https://gist.github.com/virgildisgr4ce/2939020">This Gist<\/a> brought to you by <a href="http://github.com">GitHub<\/a>.\n        <\/div>\n      <\/div>\n<\/div>\n')
</script><div style='margin-bottom:1em;padding:0;'><noscript><code><pre style='overflow:auto;margin:0;padding:0;border:1px solid #DDD;'>/*
 * blink.c:
 *      Simple test program to blink an LED on pin 7
 */

#include &lt;wiringPi.h&gt;
#include &lt;stdio.h&gt;

int main (void)
{
  int pin = 7;
  printf(&quot;Raspberry Pi wiringPi blink test\n&quot;);

  if (wiringPiSetup() == -1)
    exit (1);

  pinMode(pin, OUTPUT);

  for (;;){
    printf(&quot;LED On\n&quot;);
    digitalWrite(pin, 1);
    delay(250);
    printf(&quot;LED Off\n&quot;);
    digitalWrite(pin, 0);
    delay(250);
  }

  return 0;
}</pre></code></noscript></div></li>
<li>And compile it:
<pre>cc -o blink blink.c -L/usr/local/lib -lwiringPi</pre>
</li>
<li>And run it:
<pre>sudo ./blink</pre>
</li>
<li>You should have a happily blinking LED. Yay! Now for something more interesting:<br />
<script>document.write('<link href=\"https://gist.github.com/assets/embed-17ab34a51711628d8f5449c4663a9318.css\" media=\"screen\" rel=\"stylesheet\" />')
document.write('<div id=\"gist2939039\" class=\"gist\">\n      <div class=\"gist-file\">\n        <div class=\"gist-data gist-syntax\">\n\n\n\n  <div class=\"file-data\">\n    <table cellpadding=\"0\" cellspacing=\"0\" class=\"lines highlight\">\n      <tr>\n        <td class=\"line-numbers\">\n          <span class=\"line-number\" id=\"file-buttonled-c-L1\" rel=\"file-buttonled-c-L1\">1<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L2\" rel=\"file-buttonled-c-L2\">2<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L3\" rel=\"file-buttonled-c-L3\">3<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L4\" rel=\"file-buttonled-c-L4\">4<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L5\" rel=\"file-buttonled-c-L5\">5<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L6\" rel=\"file-buttonled-c-L6\">6<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L7\" rel=\"file-buttonled-c-L7\">7<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L8\" rel=\"file-buttonled-c-L8\">8<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L9\" rel=\"file-buttonled-c-L9\">9<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L10\" rel=\"file-buttonled-c-L10\">10<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L11\" rel=\"file-buttonled-c-L11\">11<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L12\" rel=\"file-buttonled-c-L12\">12<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L13\" rel=\"file-buttonled-c-L13\">13<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L14\" rel=\"file-buttonled-c-L14\">14<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L15\" rel=\"file-buttonled-c-L15\">15<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L16\" rel=\"file-buttonled-c-L16\">16<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L17\" rel=\"file-buttonled-c-L17\">17<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L18\" rel=\"file-buttonled-c-L18\">18<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L19\" rel=\"file-buttonled-c-L19\">19<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L20\" rel=\"file-buttonled-c-L20\">20<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L21\" rel=\"file-buttonled-c-L21\">21<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L22\" rel=\"file-buttonled-c-L22\">22<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L23\" rel=\"file-buttonled-c-L23\">23<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L24\" rel=\"file-buttonled-c-L24\">24<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L25\" rel=\"file-buttonled-c-L25\">25<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L26\" rel=\"file-buttonled-c-L26\">26<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L27\" rel=\"file-buttonled-c-L27\">27<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L28\" rel=\"file-buttonled-c-L28\">28<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L29\" rel=\"file-buttonled-c-L29\">29<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L30\" rel=\"file-buttonled-c-L30\">30<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L31\" rel=\"file-buttonled-c-L31\">31<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L32\" rel=\"file-buttonled-c-L32\">32<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L33\" rel=\"file-buttonled-c-L33\">33<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L34\" rel=\"file-buttonled-c-L34\">34<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L35\" rel=\"file-buttonled-c-L35\">35<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L36\" rel=\"file-buttonled-c-L36\">36<\/span>\n          <span class=\"line-number\" id=\"file-buttonled-c-L37\" rel=\"file-buttonled-c-L37\">37<\/span>\n        <\/td>\n        <td class=\"line-data\">\n          <pre class=\"line-pre\"><div class="line" id="file-buttonled-c-LC1"><span class="cm">/*<\/span><\/div><div class="line" id="file-buttonled-c-LC2"><span class="cm"> * buttonLED.c:<\/span><\/div><div class="line" id="file-buttonled-c-LC3"><span class="cm"> *      Simple test program to change the blinking rate of an LED when a button is pressed<\/span><\/div><div class="line" id="file-buttonled-c-LC4"><span class="cm"> */<\/span><\/div><div class="line" id="file-buttonled-c-LC5">&nbsp;<\/div><div class="line" id="file-buttonled-c-LC6"><span class="cp">#include &lt;wiringPi.h&gt;<\/span><\/div><div class="line" id="file-buttonled-c-LC7"><span class="cp">#include &lt;stdio.h&gt;<\/span><\/div><div class="line" id="file-buttonled-c-LC8">&nbsp;<\/div><div class="line" id="file-buttonled-c-LC9"><span class="kt">int<\/span> <span class="nf">main<\/span> <span class="p">(<\/span><span class="kt">void<\/span><span class="p">)<\/span><\/div><div class="line" id="file-buttonled-c-LC10"><span class="p">{<\/span><\/div><div class="line" id="file-buttonled-c-LC11">  <span class="kt">int<\/span> <span class="n">pin_LED<\/span> <span class="o">=<\/span> <span class="mi">7<\/span><span class="p">;<\/span>    <span class="c1">// GPIO7 / header pin 7<\/span><\/div><div class="line" id="file-buttonled-c-LC12">  <span class="kt">int<\/span> <span class="n">pin_switch<\/span> <span class="o">=<\/span> <span class="mi">8<\/span><span class="p">;<\/span> <span class="c1">// SDA0 / header pin 3<\/span><\/div><div class="line" id="file-buttonled-c-LC13">  <span class="kt">int<\/span> <span class="n">del<\/span> <span class="o">=<\/span> <span class="mi">250<\/span><span class="p">;<\/span><\/div><div class="line" id="file-buttonled-c-LC14">&nbsp;<\/div><div class="line" id="file-buttonled-c-LC15">  <span class="n">printf<\/span> <span class="p">(<\/span><span class="s">&quot;Raspberry Pi wiringPi button LED test<\/span><span class="se">\\n<\/span><span class="s">&quot;<\/span><span class="p">)<\/span> <span class="p">;<\/span><\/div><div class="line" id="file-buttonled-c-LC16">&nbsp;<\/div><div class="line" id="file-buttonled-c-LC17">  <span class="k">if<\/span> <span class="p">(<\/span><span class="n">wiringPiSetup<\/span><span class="p">()<\/span> <span class="o">==<\/span> <span class="o">-<\/span><span class="mi">1<\/span><span class="p">)<\/span><\/div><div class="line" id="file-buttonled-c-LC18">    <span class="n">exit<\/span> <span class="p">(<\/span><span class="mi">1<\/span><span class="p">);<\/span><\/div><div class="line" id="file-buttonled-c-LC19">&nbsp;<\/div><div class="line" id="file-buttonled-c-LC20">  <span class="n">pinMode<\/span><span class="p">(<\/span><span class="n">pin_LED<\/span><span class="p">,<\/span> <span class="n">OUTPUT<\/span><span class="p">);<\/span><\/div><div class="line" id="file-buttonled-c-LC21">  <span class="n">pinMode<\/span><span class="p">(<\/span><span class="n">pin_switch<\/span><span class="p">,<\/span> <span class="n">INPUT<\/span><span class="p">);<\/span><\/div><div class="line" id="file-buttonled-c-LC22">&nbsp;<\/div><div class="line" id="file-buttonled-c-LC23">  <span class="k">for<\/span> <span class="p">(;;){<\/span><\/div><div class="line" id="file-buttonled-c-LC24">    <span class="k">if<\/span> <span class="p">(<\/span><span class="n">digitalRead<\/span> <span class="p">(<\/span><span class="mi">8<\/span><span class="p">)<\/span> <span class="o">==<\/span> <span class="mi">0<\/span><span class="p">){<\/span> <span class="c1">// button pressed<\/span><\/div><div class="line" id="file-buttonled-c-LC25">      <span class="n">del<\/span> <span class="o">=<\/span> <span class="mi">100<\/span><span class="p">;<\/span><\/div><div class="line" id="file-buttonled-c-LC26">    <span class="p">}<\/span> <span class="k">else<\/span> <span class="p">{<\/span><\/div><div class="line" id="file-buttonled-c-LC27">      <span class="n">del<\/span> <span class="o">=<\/span> <span class="mi">250<\/span><span class="p">;<\/span><\/div><div class="line" id="file-buttonled-c-LC28">    <span class="p">}<\/span><\/div><div class="line" id="file-buttonled-c-LC29">&nbsp;<\/div><div class="line" id="file-buttonled-c-LC30">    <span class="n">digitalWrite<\/span><span class="p">(<\/span><span class="n">pin_LED<\/span><span class="p">,<\/span> <span class="mi">1<\/span><span class="p">);<\/span><\/div><div class="line" id="file-buttonled-c-LC31">    <span class="n">delay<\/span><span class="p">(<\/span><span class="n">del<\/span><span class="p">);<\/span><\/div><div class="line" id="file-buttonled-c-LC32">    <span class="n">digitalWrite<\/span><span class="p">(<\/span><span class="n">pin_LED<\/span><span class="p">,<\/span> <span class="mi">0<\/span><span class="p">);<\/span><\/div><div class="line" id="file-buttonled-c-LC33">    <span class="n">delay<\/span><span class="p">(<\/span><span class="n">del<\/span><span class="p">);<\/span><\/div><div class="line" id="file-buttonled-c-LC34">  <span class="p">}<\/span><\/div><div class="line" id="file-buttonled-c-LC35">&nbsp;<\/div><div class="line" id="file-buttonled-c-LC36">  <span class="k">return<\/span> <span class="mi">0<\/span> <span class="p">;<\/span><\/div><div class="line" id="file-buttonled-c-LC37"><span class="p">}<\/span><\/div><\/pre>\n        <\/td>\n      <\/tr>\n    <\/table>\n  <\/div>\n\n        <\/div>\n\n        <div class="gist-meta">\n          <a href="https://gist.github.com/virgildisgr4ce/2939039/raw/ad27ae2f7c8981dfee11aea610fa2e4dcc6292be/buttonLED.c" style="float:right">view raw<\/a>\n          <a href="https://gist.github.com/virgildisgr4ce/2939039#file-buttonled-c" style="float:right; margin-right:10px; color:#666;">buttonLED.c<\/a>\n          <a href="https://gist.github.com/virgildisgr4ce/2939039">This Gist<\/a> brought to you by <a href="http://github.com">GitHub<\/a>.\n        <\/div>\n      <\/div>\n<\/div>\n')
</script><div style='margin-bottom:1em;padding:0;'><noscript><code><pre style='overflow:auto;margin:0;padding:0;border:1px solid #DDD;'>/*
 * buttonLED.c:
 *      Simple test program to change the blinking rate of an LED when a button is pressed
 */

#include &lt;wiringPi.h&gt;
#include &lt;stdio.h&gt;

int main (void)
{
  int pin_LED = 7;    // GPIO7 / header pin 7
  int pin_switch = 8; // SDA0 / header pin 3
  int del = 250;

  printf (&quot;Raspberry Pi wiringPi button LED test\n&quot;) ;

  if (wiringPiSetup() == -1)
    exit (1);

  pinMode(pin_LED, OUTPUT);
  pinMode(pin_switch, INPUT);

  for (;;){
    if (digitalRead (8) == 0){ // button pressed
      del = 100;
    } else {
      del = 250;
    }

    digitalWrite(pin_LED, 1);
    delay(del);
    digitalWrite(pin_LED, 0);
    delay(del);
  }

  return 0 ;
}</pre></code></noscript></div></li>
</ul>
</li>
<li><strong>Where&#8217;s my analogRead?</strong>  Sadly, unlike an Arduino, the RPi doesn&#8217;t have an onboard ADC (Analog to Digital Converter). However, some of the breakout boards being designed will include an external ADC, such as the <a href="http://www.raspberrypi.org/archives/411">Gertboard</a>.  You can add your own external ADC, <a href="http://www.newark.com/jsp/search/productdetail.jsp?sku=23C2842">such as this one</a>, by using the <a href="http://arduino.cc/en/Reference/SPI">SPI bus</a> on the RPi (the MOSI, MISO and SCK pins).</li>
<li>That&#8217;s all for now! Hope this helps, and as always, let me know if it works or you run into any problems.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://log.liminastudio.com/writing/tutorials/tutorial-how-to-use-your-raspberry-pi-like-an-arduino/feed</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
		<item>
		<title>How to build Pd-extended on the Raspberry Pi</title>
		<link>http://log.liminastudio.com/writing/tutorials/how-to-build-pd-extended-on-the-raspberry-pi</link>
		<comments>http://log.liminastudio.com/writing/tutorials/how-to-build-pd-extended-on-the-raspberry-pi#comments</comments>
		<pubDate>Thu, 14 Jun 2012 18:17:30 +0000</pubDate>
		<dc:creator>Tedb0t</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PureData]]></category>
		<category><![CDATA[RaspberryPi]]></category>

		<guid isPermaLink="false">http://log.liminastudio.com/?p=1029</guid>
		<description><![CDATA[It was quite an ordeal, but I managed to build Pd-extended (Puredata with a bunch of externals) on my Raspberry Pi running Debian Squeeze.  I also uploaded my finished package (.deb) to puredata.info, see below for details.  Here&#8217;s what you need to do: Firstly, your SD card&#8217;s partition is probably not large enough to accomodate [...]]]></description>
				<content:encoded><![CDATA[<p>It was quite an ordeal, but I managed to build Pd-extended (Puredata with a bunch of externals) on my Raspberry Pi running Debian Squeeze.  I also uploaded my finished package (.deb) to <a href="http://download.puredata.info/pd-extended-rpi/releases/1.0/Pd-0.43.1-extended-20120606.deb/view">puredata.info</a>, see below for details.  Here&#8217;s what you need to do:<span id="more-1029"></span></p>
<ol>
<li>Firstly, your SD card&#8217;s partition is probably not large enough to accomodate all the files we&#8217;ll need, so we have to expand it to fit your card first.  From a terminal session on your Pi:
<ol>
<li>
<pre>printf "d\n3\nd\n2\nn\np\n2\n157696\n\nw\n" | sudo fdisk -cu /dev/mmcblk0</pre>
</li>
<li>
<pre>sudo reboot</pre>
</li>
<li>
<pre>sudo resize2fs /dev/mmcblk0p2</pre>
</li>
</ol>
</li>
<li>We need to add the repositories for the source to aptitude:
<pre>sudo nano /etc/apt/sources.list</pre>
<p>Move to the bottom and paste this in and save (ctrl+o):</p>
<pre>deb-src http://ftp.uk.debian.org/debian/ squeeze main
deb http://backports.debian.org/debian-backports squeeze-backports main</pre>
</li>
<li>Update your aptitude cache:
<pre>sudo apt-get update</pre>
</li>
<li>We&#8217;ll need  to install a whole bunch of dependencies for building Pd and all the various externals.  This took like 4 days to manually figure out:
<pre>sudo apt-get install rsync autoconf libfftw3-dev liblua5.1-0-dev swig libvorbis-dev ladspa-sdk libspeex-dev libmp3lame-dev lua5.1</pre>
</li>
<li>Copy the source:
<pre>rsync -av --delete rsync://128.238.56.50/distros/pd-extended/ pd-extended/</pre>
</li>
<li>Since it will take a while, you may want to use this command to detach the process from your terminal session and log the output to a file:
<pre>nohup rsync -av --delete rsync://128.238.56.50/distros/pd-extended/ pd-extended/ &gt; rsync.log &amp;</pre>
</li>
<li>Build the main Pd dependencies:
<pre>sudo apt-get build-dep puredata gem pdp</pre>
</li>
<li>For some reason I had to change one of the externals&#8217; makefile to get it to build correctly. Open /externals/OSCx/src/Makefile (I used nano), go to line 20 and remove &#8220;-lpd&#8221; so it looks like this:
<pre>LIBS = -L../../../pd/bin -lc -lm</pre>
</li>
<li>OK, we&#8217;re now ready to actually start building. This will take a long time, hours most likely. I did it piecemeal so I can&#8217;t say for sure how long it takes from start to finish.</li>
<li>
<pre>cd pd-extended/packages/linux_make</pre>
</li>
<li>
<pre>nohup make install &gt; makeinstall.log &amp;</pre>
</li>
<li>While you&#8217;re still logged in, you can monitor that logfile by doing
<pre>tail -f makeinstall.log</pre>
</li>
<li>Once that finishes, you should see &#8220;linux_make install succeeded!&#8221; Yay! If you encounter any errors please post them here and we&#8217;ll see what I missed.</li>
<li>Now we can make the actual Debian package that you can install like any other program:
<pre>nohup make package &gt; makepackage.log &amp;</pre>
</li>
<li>If you previously installed Puredata vanilla (as per <a href="http://log.liminastudio.com/programming/running-puredata-on-the-raspberry-pi">my previous post</a>), you&#8217;ll need to uninstall that first:
<pre>sudo apt-get --purge remove puredata</pre>
</li>
<li>For convenience I <a href="http://download.puredata.info/pd-extended-rpi/releases/1.0/Pd-0.43.1-extended-20120606.deb">uploaded this package to puredata.info</a>.  All you have to do is download that file to your RPi:
<pre>wget -O Pd-0.43.1-extended-20120606.deb http://download.puredata.info/pd-extended-rpi/releases/1.0/Pd-0.43.1-extended-20120606.deb</pre>
</li>
<li>Finally, let&#8217;s install it:
<pre>sudo dpkg -i Pd-0.43.1-extended-20120606.deb</pre>
</li>
<li>If everything goes well, you now have Pd-extended on your Raspberry Pi! <a href="http://log.liminastudio.com/wp-content/uploads/2012/06/testPatchExtended.pd_.zip">Here&#8217;s a new test patch</a> that uses Freeverb~ for you to test, like so:
<pre>pd-extended -nogui -noadc -alsa testPatchExtended.pd</pre>
</li>
<li>Presently, I&#8217;m getting some serious noise and I think it has something to do with the ALSA driver still being in beta. Looking into it. If any other linux hackers have any ideas, please let me know!</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://log.liminastudio.com/writing/tutorials/how-to-build-pd-extended-on-the-raspberry-pi/feed</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
	</channel>
</rss>
