Linking Arduino to Another Application Using OSC Communication Part 1

Linking Arduino to Another Application Using OSC Communication Part 1

DSC_0002-1024x576
With several parts and shields available, I think that Arduino is clearly a very stand alone device for development. Taking it one step further this time, I’d like to test a method for Arduino to communicate with an external application called OSC. By communicating with external applications and electronic parts like switches and volume, you’ll be able to control them on screen visually and further expand your expression abilities!

Today’s Electronic Recipe

Expected time to complete: 90 minutes

Parts needed:

What is OSC Communication?

What kind of communication method is OSC? Here’s what we found on Wikipedia.

Open Sound Control – Wikipedia
Open Sound Control (OSC) is a protocol for networking sound synthesizers, computers, and other multimedia devices for purposes such as musical performance or Show control. Bringing the benefits of modern networking technology to the world of electronic musical instruments, OSC’s advantages include interoperability, accuracy, flexibility, and enhanced organization and documentation.

So, why should we use OSC communication with Arduino even if we aren’t dealing with music? Because of its flexibility, there are many cases where we can use OSC besides music. Moreover, it’s used in many different kinds of software.

How OSC Works?

Let’s see how OSC works. OSC has a very simple structure. OSC has two kinds of messages, and communication is done by exchanging them with other applications.

OSC

Figure 1. OSC communication method

  • Message: Displays the type of message. By separated them with “/,” you can create a multi-layered structure, so it’s possible to make a complex communication format into something easy to understand.
  • Arguments: The contents of the message. Data from a character string can be transferred using a numerical value (int / float).

Requirements to Use OSC on Arduino?

To use OSC on an Arduino, you need to have a network. So, you’ll use an ethernet shield.

DSC_0002-1024x576

Picture 1. Arduino Ethernet shield

Also, you will need a library in order to use OSC communication on Arduino. There are several libraries you can use for OSC on Arduino, but for now we will use ArdOSC (there is a possibility it won’t work correctly with a recent version of Arduino, so please use a different OSC library in that case). After adding a library, write the following transmission program (refer to the previous instructions on how to add a library).

OSC transmission test program


Once Arduino has been set up, we’ll set up the application. We’ll use Processing for the external application this time.
Processing is an open source programming language for media art and visual design. You could say it’s a language, specialized for graphics, which can be easily handled by beginners much like Arduino. Select “Download Processing” on the Processing website to download and install it.

scr3

Figure 2. Processing website

Once Processing has finished installing, open it.

ro

Figure 3. Processing icon

processing

Figure 4. Processing startup screen

Once you have opened it, a screen similar to Arduino’s will be displayed. Like Arduino, in the center, you can find buttons to start and stop a program. The example sketch and way to use the library are mostly the same as Arduino’s, so I think you’ll be able to use it without any problem.

OSC receiving program (Processing)

Once you launch Processing, if you see a message displayed in the console at the bottom describing Processing when starting Arduino, it means that you’ve succeeded.

osc23

Figure 5. The results of launching Processing

Temperature and Humidity Test with an External Application

Let’s try sending information from Arduino’s temperature measurements to an external application using OSC communication.

We’ll use DHT11 for measuring temperature and humidity.
DHT11 is already in the Arduino’s library, so I’ll add DHT11’s library.

DSC_0004-1024x576

Picture 2. DHT11 temperature and humidity sensor

There is a sample in DHT11’s library, so you can use it to see if DHT11 is measuring correctly or not.

2b39c90cc55c77f843965a9af1b6e597

Figure 6. Temperature and humidity sensor circuit

Temperature and humidity measuring program

est

Figure 7. Results of implementation

If it’s measuring correctly, let’s alter the program to use it with OSC communication.

Temperature and humidity OSC communication program

Receiver program (Processing)

When launching both programs, if the temperature and humidity are displayed repeatedly under the Processing display, you’ve succeeded.

scr

Figure 8. OSC communication launch results

Summary

This time, I introduced one method to make an Arduino communicate with an external application. There are unique applications that let you choose a protocol and communicate even without using OSC communication. But by using OSC, you can connect to a large number of different software. Next time, I’d like to show you a wider usage of Arduino by developing the basics we’ve learned about OSC communication.