<?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>josh kopeček &#187; Interface</title>
	<atom:link href="http://joshkopecek.co.uk/tag/interface/feed/" rel="self" type="application/rss+xml" />
	<link>http://joshkopecek.co.uk</link>
	<description>electric music - a notekeeping of my musical habits</description>
	<lastBuildDate>Fri, 18 May 2012 06:21:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Arduinos, MIDI and real apps</title>
		<link>http://joshkopecek.co.uk/2009/04/arduinos-midi-and-real-apps/</link>
		<comments>http://joshkopecek.co.uk/2009/04/arduinos-midi-and-real-apps/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 23:46:16 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[Interface]]></category>
		<category><![CDATA[Live]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.joshkopecek.co.uk/blog/?p=58</guid>
		<description><![CDATA[Since it&#8217;s really been a while since I posted here, I&#8217;m going to publish my research on getting an Arduino based interface to talk directly to something else via MIDI. This project could easily be expanded to more complex solutions (i.e. not just two momentary switches), could easily use OSC, channel MIDI data across a [...]]]></description>
			<content:encoded><![CDATA[<p>Since it&#8217;s really been a while since I posted here, I&#8217;m going to publish my research on getting an Arduino based interface to talk directly to something else via MIDI. This project could easily be expanded to more complex solutions (i.e. not just two momentary switches), could easily use OSC, channel MIDI data across a network, have a more complex user interface. The point with this stage in the project was to get a framework to build new projects from.</p>
<p>When I first started working with Ruby and Cocoa, the RubyCocoa project was pretty elementary, but many leaps and bounds have been made. Thanks go out to <a title="bleything" href="http://blog.bleything.net/" target="_blank">bleything</a> and and the <a href="http://rubycocoa.sourceforge.net/HomePage" target="_blank">RubyCocoa team</a> without whose wonderful work this would not be possible.</p>
<p><strong>Making an interface from scratch with the Arduino at its core</strong></p>
<p>Equipment needed:</p>
<ul>
<li>arduino (diecimila or equivalent)</li>
<li>wire + wire cutters</li>
<li>breadboard</li>
<li>selection of resistors (10k preferable)</li>
<li>switches (any sort, I used momentary)</li>
<li>computer &#8211; mac, linux or pc (mac preferable)</li>
<li>box of some sort &#8211; optional</li>
<li>soldering iron &#8211; only necessary for finishing the project</li>
</ul>
<p><a href="http://www.joshkopecek.co.uk/wp-content/uploads/2009/04/dscf0199.jpg"></a><a href="http://www.joshkopecek.co.uk/wp-content/uploads/2009/04/dscf01991.jpg"><img class="alignleft size-medium wp-image-61" title="Inside the FootStompBox" src="http://www.joshkopecek.co.uk/wp-content/uploads/2009/04/dscf01991-225x300.jpg" alt="Inside the FootStompBox" width="225" height="300" /></a></p>
<p># Wire a switch &#8211; one side to ground and the other to digital input 6. Use the breadboard.<br />
# Put a resistor between the side of the switch connected to ground and +5v.<br />
This is called a pullup resistor and makes the current default to &#8216;on&#8217; or +5v when the switch is closed. When the switch is open, the voltage remains at 0v.</p>
<p>If you want additional switches, follow the two steps above making sure you use a new resistor each time.</p>
<p>Difficult bit: find a nice box and glue the whole lot into it and plug in a usb cable.</p>
<p><a href="http://www.joshkopecek.co.uk/wp-content/uploads/2009/04/dscf0196.jpg"><img class="alignleft size-medium wp-image-59" title="FootStompArduinoBox" src="http://www.joshkopecek.co.uk/wp-content/uploads/2009/04/dscf0196-300x225.jpg" alt="FootStompArduinoBox" width="300" height="225" /></a></p>
<p><strong>Getting your computer prepared to talk to the Arduino</strong></p>
<p>If you are comfortable with using the terminal, and want a one-step install for the various packages required for this tutorial, try:</p>
<p><strong>MacPorts</strong></p>
<p>To install: go to the <a href="http://www.macports.org/">MacPorts website</a> and install using the installer there.<br />
Check everything is working by firing up a terminal and typing</p>
<pre style="padding-left: 30px;">port version</pre>
<p>which should return</p>
<pre style="padding-left: 30px;">Version: 1.710</pre>
<p><strong>Preparing Ruby</strong></p>
<p>All the below are necessary before continuing</p>
<p><strong>Installing (upgrading) Ruby</strong><br />
Ruby is already included in MacOSX, but for compatibility reasons, it&#8217;s best to upgrade. If you&#8217;re happy with your installation, just continue as is until you come up against any errors. Please note the Ruby included with 10.4 is very old, and possibly broken.<br />
Fire up a terminal (if it isn&#8217;t already open from above) and type</p>
<pre style="padding-left: 30px;">sudo port upgrade ruby</pre>
<p><strong>Rubygems &#8212; required to use the below libraries</strong><br />
Fire up a terminal (if it isn&#8217;t already open from above) and type</p>
<pre style="padding-left: 30px;">sudo port install rb-rubygems</pre>
<p style="padding-left: 30px;">
<p><strong>MIDIator &#8212; Ruby MIDI library</strong><br />
MIDIator allows us to use Ruby to easily create MIDI messages in a simple and comprehensible fashion<br />
Fire up a terminal (if it isn&#8217;t already open from above) and type</p>
<pre style="padding-left: 30px;">sudo gem install midiator</pre>
<p style="padding-left: 30px;">
<p><strong>Serialport &#8212; Ruby Serial Port library</strong><br />
This is installed by default as part of Ruby, but best to upgrade:</p>
<pre style="padding-left: 30px;">sudo gem upgrade ruby-serialport</pre>
<p>Easy! Just sit back and watch incomprehensible lines of text scroll by.</p>
<p><strong>Arduino code</strong></p>
<p>The Arduino itself requires code to run. This tells the Arduino what to do with incoming and outgoing data. The language is called Wiring.</p>
<p>Make sure you have the Arduino programming environment installed (from <a href="http://arduino.cc">http://arduino.cc</a>)</p>
<p>Use the following code:<br />
To explain, the first block initialises the pins we will use.<br />
The <em>setup()</em> method initialises the pins and serial connection and tells us that they are sending data <strong>in</strong> to the Arduino.</p>
<p>The <em>loop()</em> method reads the pins every cycle, stores the data in variables and decides what to do with it. In this case, it sends a different value to the computer if the pin is up or down. The <em>swi</em> variable checks if it&#8217;s already been sent, and prevents doubling the &#8216;note on&#8217; value. i.e. it can&#8217;t send a note off before it&#8217;s sent a note on and vice versa.</p>
<pre> /*</pre>
<pre> sends serial data over usb to be converted by ruby to MIDI..</pre>
<pre> */</pre>
<pre>int inPin1 = 6;   // choose the input pin (for a pushbutton)
 int inPin2 = 7;
 int val1 = 0;     // variable for reading the pin status
 int val2 = 0;
 boolean swi1 = false;
 boolean swi2 = false;</pre>
<pre>void setup() {
 Serial.begin(9600);
 pinMode(inPin1, INPUT);    // declare pushbutton as input
 }</pre>
<pre>void loop(){
 val1 = digitalRead(inPin1);  // read input val1ue
 val2 = digitalRead(inPin2);</pre>
<pre>if (val1 == HIGH &amp;&amp; swi1 == false) {         // check if the input is HIGH (button released)
 swi1 = true;
 Serial.println(89, DEC);
 delay(100);
 }</pre>
<pre>if (val1 == LOW &amp;&amp; swi1 == true){            // check if the input is low and it's just been high
 swi1 = false;
 Serial.println(90, DEC);
 delay(100);
 }</pre>
<pre>if (val2 == HIGH &amp;&amp; swi2 == false) {         // check if the input is HIGH (button released)
 swi2 = true;
 Serial.println(91, DEC);
 delay(100);
 }</pre>
<pre>if (val2 == LOW &amp;&amp; swi2 == true){            // check if the input is low and it's just been high
 swi2 = false;
 Serial.println(92, DEC);
 delay(100);
 }</pre>
<pre>}</pre>
<p><strong>Building a simple communication script in Ruby</strong></p>
<p>Download the <a href="http://www.joshkopecek.co.uk/code/RubyMIDI.zip">RubyMIDI.zip</a> file and look in the <em>lib</em> folder at <em>usbchecker.rb</em>. This checks to see if the Arduino is present. In short, OSX creates a list of all the USB devices on your computer at <em>/dev/</em>. This script checks for one in the correct syntax for an Arduino, and passes it back to our main program.</p>
<p>Look in the main folder at <em>BasicMIDI.rb</em>. This contains all the information to communicate with the Arduino and change it to MIDI data.  The <em>require</em> functions at the top load in the libraries we installed earlier &#8211; rubygems, midiator, serialport and the file we&#8217;ve just looked at, <em>usbchecker.rb.</em> The first paragraph runs the <em>usbchecker.rb</em> and passes the identity of the Arduino back and initialises it (turns it on and starts communicating with it).</p>
<p>The next paragraph creates a MIDI device with Midiator and tells it to send all MIDI data to CoreMIDI on OSX, also known as the IAC Driver (Load up Audio MIDI setup and have a look).</p>
<p>The whole of the next section is a bit boring, and merely consists in grabbing data from the serial port and converting it into a meaningful format rather than the incomprehensible rubbish that comes across normally. <em>sp.getc.chr</em> grabs a character (<em>getc</em>) from the serial port (<em>sp</em>), and converts it into a real character (<em>chr</em>). The next loop puts it into a string.</p>
<p>Then, if it has something, it decides which one it&#8217;s received from the Arduino (see above that we&#8217;re sending different numbers according to what&#8217;s happening) and sends either a midi note on (<em>midi.note_on(89, 1, 100)</em>) or note off (<em>midi.note_off(89, 1, 0)</em>).</p>
<p>The other parts are failsafes for if it receives a line-end or newline character &#8211; the Arduino sends these after each transmission as part of the <em>Serial.println()</em> method.</p>
<p><strong>Magic, that&#8217;s all the code explained</strong></p>
<p>We can run this script by opening a terminal, typing <em>ruby</em> and dragging and dropping the BasicMIDI.rb file into the window, then hitting return. It will fail if there isn&#8217;t an Arduino present.</p>
<p><strong>Integrating your Ruby script into a fully fledged native MacOSX application</strong></p>
<p>First, go and download Xcode from <a href="http://developer.apple.com">http://developer.apple.com</a> and install it. This will take a <em>while.</em></p>
<p>You&#8217;ll notice there&#8217;s another folder called <em>RubyCocoaUSBApp</em> which contains lots of files and folders and a file ending <em>.xcodeproj</em> which has our Xcode project in it. Open this, and Xcode will open the project. You&#8217;ll notice the <em>lib</em> folder is still there, and that <em>AppController.rb</em> has the same code as <em>BasicMIDI.rb</em> above. It&#8217;s not necessary to know the structure of the rest of the folders, just that there&#8217;s lots of necessary stuff in there that it&#8217;s unwise to touch. Just modify the <em>AppController.rb</em> with your code and link it into the<em> MainMenu.nib</em> using Interface Builder &#8211; I won&#8217;t explain here because it&#8217;ll take ages, unless people need me to? Easy peasy.</p>
<p>Next step: Build and Run (Command-R).<br />
This should launch our fully fledged application, which runs when we click on the button. It will display &#8216;Ready&#8217; when connected and sending MIDI.</p>
<p>Simply connect any MIDI client to the built-in IAC Driver on OSX and away we go.</p>
<p>Oh, and before I forget, <a href="http://www.joshkopecek.co.uk/code/ArdToMidi.zip">here&#8217;s</a> the fully fledged application in case you&#8217;re having problems compiling using Xcode.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshkopecek.co.uk/2009/04/arduinos-midi-and-real-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Geekdom</title>
		<link>http://joshkopecek.co.uk/2008/08/geekdom/</link>
		<comments>http://joshkopecek.co.uk/2008/08/geekdom/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 23:00:36 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[Interface]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.joshkopecek.co.uk/blog/?p=23</guid>
		<description><![CDATA[I have officially ventured wholesale into geekdom. That is, I have been toying with Ubuntu and Fedora, two flavours of Linux. Whilst they certainly aren&#8217;t for the shy computer user, neither are the installations of any other operating system. What makes it great is that when they&#8217;re set up, anyone could use them. They make [...]]]></description>
			<content:encoded><![CDATA[<p>I have officially ventured wholesale into geekdom. That is, I have been toying with Ubuntu and Fedora, two flavours of Linux. Whilst they certainly aren&#8217;t for the shy computer user, neither are the installations of any other operating system. What makes it great is that when they&#8217;re set up, anyone could use them. They make a potentially slow computer (running Windoze) into a lighting fast machine that looks great. I&#8217;m particularly taken with the stylings of Fedora, and there are some great applications available to replace your standard office features and internet applications. Nothing really to sway me from the stable, well supported os that is osx, though.</p>
<p>I&#8217;ve been working hard on something new for Concrete Moniker, and it&#8217;s taking just so much longer than it should do, especially when I&#8217;ve got got more than a few things to write. I&#8217;m just starting to get used to using my current setup, but am bemoaning the lack of really good AudioUnit instruments and effects that are available in VST format, something that has hung over from the time I changed from PC to Mac, and which I&#8217;m not sure is going to be solved from use of Linux.</p>
<p>I&#8217;ve also been thinking about what really I would like to do with a live setup again, and I&#8217;ve just come to the conclusion that a lot of the things are fundamental principles which haven&#8217;t been solved yet. I&#8217;d really like to be able to make sudden changes, and gradual changes in sound. Of course this is possible at the moment, but a unified interface that provided a <em>subtle</em> graduation and a <em>choice</em> of change is absolutely imperative. I want to be able to predict where I&#8217;m going, and revisit that place if I want to, something that&#8217;s absolutely possible with conventional instruments, but very difficult or impossible with current technology.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshkopecek.co.uk/2008/08/geekdom/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

