Arduino, OSC, iPhone and DMX

So what are we making?

The other day I started thinking about how I could design a better lighting desk for our basic lighting needs. The desk we currently have (Behringer EUROLIGHT) is poorly designed with more features than what we really need. I looked to OSC (Open Sound Control) as a protocol that could be used to control the lights via my arduino equipped with an ethernet shield.

NOTE: 25 Nov 2010. I’ve made a change to the Arduino sketch and to the OSC messages below. The DMX channel that is being controlled is now derived from the OSC message itself. ie. /dmx/3 would control DMX channel 3. Make sure to set your alpha channel in the arduino sketch.

Check the diagram below to see what we’ll be making.

Open Sound Control:

If you’ve never heard of Open Sound Control I recommend that you head over to the website to get a little background on it. Basically it’s an open standard that will allow us to send information over a standard network to our target device. You may be asking why use OSC for lighting? Don’t we just have to convert it back to DMX again to make it useful?

The reason OSC was chosen is that there is a bunch of OSC apps for the iPhone. Also it’s well documented with a lot being done in the developer community (check links at the end of this article).

DMX:

DMX is the protocol that most lighting systems use today. It’s quite a old protocol but seems to work for most applications. I won’t go into depth here about the technical details of it. All you need to know is that we’ll be receiving our messages as OSC and using a simple function in our Arduino sketch to convert it to DMX. If you’d like to learn more about DMX check out this page.

Getting Started:

First a list of things we’ll need:

  • Arduino
  • Arduino OSC Library (see below)
  • DMXSimple Library
  • Ethernet Shield
  • LED par can
  • iPhone/iPod touch
  • Wireless Router
  • OSC conrtroller for iPhone (TouchOSC, iOSC, etc)
  • MAX485 or SN75176
  • 100 Ω resistor
  • Female XLR

The Ethernet Shield is not entirely mandatory as you could communicate through serial to processing but I won’t be covering that in this tutorial.  My method will give you a standalone device that will communicate to your lights without the need for a computer.

Arduino Code:

Here’s the code we need to load up on our Arduino. You’ll have to remember to change your network settings. On my particular network I use the address 192.168.100.206. Also make sure to set the ‘alphaCh’ variable to reflect your lights alpha channel.

You’ll notice the OSC and the DMX libraries that are being loaded. Recotana has developed an OSC library for the arduino. I’ve modified the code slightly to allow the use of the OSC messages as variables without the trailing ‘/’. You can make the modification yourself by replacing lines 700-711 from the original OSCClass.cpp (v1.0.1) with the code below:

//Added this in to remove the slashes out of final output
if(d!='/'){
    tempAddress[adrCount][adrMesPos]=d;

    if(packetCount>3)  {
        packetCount=0;
        packetPos+=4;
    }

    adrMesPos++;
}
}
messagePos++;
packetCount++;

or you can download the one I’ve modified and put it in you arduino/libraries folder. The reason I modified the code is that it greatly simplified my arduino code and allowed me to extract the DMX channel from the OSC message and use it as a variable in my sketch.

You can download the DMX library here.

The Circuit:

Here’s a photo of the breadboard layout. I basically just used the schematic from the arduino website. I’ve just added an led and 220Ω resistor on the board to make sure the board is getting power. Those two components are not included on the below schematic. Also ignore the orange wire going to nowhere.

and the schematic:

The iPhone/iPod touch software:

I recommend iOSC because it’s quite configurable. The only downside is that the interfaces it comes with are limited and you cannot build your own like with TouchOSC. In either case you’ll have to setup your program to send out the appropriate OSC messages. Here’s a look at the settings we’ll use:

Label Message Value type min max
Slider 1 /dmx/1 float 0 1.00
Slider 2 /dmx/2 float 0 1.00
Slider 3 /dmx/3 float 0 1.00

Here’s a screenshot of the settings for the red slider:

Make sure your host settings reflect the network settings you set in your Arduino sketch. Here’s a look at my settings using iOSC:

Finishing Up:

Now all we have to do is plug everything in.

  • Hook up you light via XLR to your circuit.
  • Set your LED par can to the same DMX channel as your Arduino sketch settings.
  • Plug your arduino ethernet shield into your network. Make sure it’s on the same network as your iPhone/iPod Touch or it will not work.
  • Turn everything on and try it out. If it works you should be able to control the red, green, and blue channels of your light via your slider controls on your iPhone/iPod Touch.

Resources:

In our next tutorial we’ll throw processing into the mix and show how you can use it to build a mixing interface and accept OSC messages then forward them on to your arduino.