[English version] Processing + Arduino + touchOSC

[singlepic id=746 w=320 h=240 float=center]

Today we will see how to communicate your mobile device android / iphone / iphone / iphone with our PC, through a protocol known as OSC (Open Sound Control) , this protocol is commonly used to control luminaires and devices such as strobes, sequencers and other things used in the musical world, one could say that is the replacement of the MIDI. OSCinternet protocol uses UDP for communication, which is why we need a requirement that the devices are on the same network, know your IP address and open a communication port.

Need for the next act: processing , arduino , LED RGB device TouchOSC installed. But we’ll do exactly?? … We will create a custom template with TouchOSC editor, which we use as a control to vary the intensity of an RGB LED and color combinations to create, we will open a communication link between processing and TouchOSC, finally send all information received to an Arduino board connected to the serial port and see the result obtained in the RGB LED at the end of all this we have the following result:

For start, the first thing to do is create our template for the TouchOSC and charge it to the device, for this we use the TouchOSC Editor a tool created by Hexl that you can download from here , we will use three  fader controls with a resolution of one byte (0 – 255) to vary the intensity of the LED, for this follow the next steps in the video tutorial:

Now it’s time to open processing, but before you start throwing lines of code you need to install a specific library for communication with OSC, use the library oscP5 created by Andreas Schlegelwe can download it here, then decompress it and move its contents to documents / processing / libraries, once installed now open a new sketch.

We create a fader class that will be used as a control and to display the interaction with the mobile device, this control will be the closest thing to fader and with the same properties we use in our template, the final class for the Fader is as follows:

[code language=java]
class Fader {

int val, valMap;
int px, py;
final int h=300, w=70;
color[] col;

color[] red= {
color(#DE1D2A), color(#131010), color(#501515)
color[] green= {
color(#3B811C), color(#111410), color(#25451A)
color[] blue= {
color(#1C2D81), color(#0D0D10), color(#0C1233)

Fader(int px, int py, char c) {

switch(c) {
case ‘R’:
case ‘G’:
case ‘B’:

void draw() {
rect(px, py, w, h);
rect(px, py+(h-valMap), w, valMap);

if (mousePressed && (mouseX>=px && mouseX=py && mouseY< =py+h)) {
setValue((int)map((h-(mouseY-py)), 0, h, 0, 255));

void setValue(int val) {
valMap=int(map(val, 0, 255, 0, h));

int getValue() {
return val;

After we create our custom template, for this we will use vectors with the addresses of each of our controls, these addresses are url type, we define this addresses in our template with the editor. The class of our template is as follows:

[code language=java]
class RGBLayout {

//Define the addresses
//We defined it before in touchOSC Editor
//Addresses are url type /Page/Address
String[] Addr= {

//create a vector to store recieved data
//creates as many variables as addresses have our templete
float[] Data= new float[Addr.length];

//by default touchOSC use the "f" typetag as identifier
String Typetag="f";

//this method check if the received data must be processed
void check(OscMessage theOscMessage) {

//for each address in our template
for (int i = 0; i 0) {
//read incoming byte
inByte = Serial.read();

//if the command expects a value
if (commandFlag){
//modify current led intensity
//reset the flag and led indicator
digitalWrite(ledCom, LOW);
//if expects a command
//select led to modify
//then make the command flag true
switch (inByte){
case 114://r ascii
digitalWrite(ledCom, HIGH);
case 103://g ascii
digitalWrite(ledCom, HIGH);
case 98://b ascii
digitalWrite(ledCom, HIGH);

Post your comments and suggestions. 😉

Adrian MB

Me gusta la electrónica, programación y todo lo relacionado. Ing. en Mecatronica de la UPIITA del IPN y estudiante de Diseño Industrial en la UAM. @adrianmtzb http://adrianmb.mx

También te podría gustar...

  • hey guys

    I also use processing, arduino, rgb leds and osc.

    I did an opensource project which only needs an arduino (no processing needed) called StripInvaders : http://pixelinvaders.ch/?page_id=396

    my other project PixelInvaders use PureData as OSC interface…

  • Cesar

    El codigo me da un error ? me podrias ayudar por favor.