Open Sound Control on mbed microcontroller

mbed_eth

I have been playing with the mbed microcontroller, a new platform for rapid prototyping from NXP. I like the mbed because it has a lot of power (32-bit ARM chip at 100Mhz), a lot of I/O (serial, SPI, CAN, I2C, USB, Ethernet, analog and digital…) and is easy to program. The code is C/C++ and the development environment is fully web-based, similar to Google Docs. When you compile the program the browser downloads the .bin file and you just drag and drop it onto the mbed (it mounts like a 2MB flash drive). Very simple.

For independent study in MAT this quarter I sought to implement the Open Sound Control (OSC) protocol on the mbed. This involved getting UDP send and receive working on mbed and then setting up a parsing / callback system that can take an incoming message and delegate it to the proper subsystem. The low-level networking is handled by an mbed port of LWIP and uses their NetServer class to handle DHCP and set up raw UDP receiver callbacks. I used the Make Controller‘s OSC system as inspiration since their code provides a sensible implementation that gives control to the digital I/O and system networking parameters. Each subsystem is independent and custom subsystems that interact with application-specific code can easily be developed.

My initial OSC system can control the four on-board LEDs and turn 8 digital output pins on and off. The Mbed has a lot more than 8 digital pins but some of them overlap with the analog input pins and other interfaces that I want to interact with using OSC so I chose 8 non-interfering pins for now. There is also a /system address space that returns information such as mbed’s IP address and listening port number. It broadcasts this information on startup so that other OSC applications can learn what IP address it has since it can vary between networks.

mbed-osc_layout

I initially tested it using a simple Max patch and also made a custom TouchOSC layout for my iPhone to interact with the mbed without needing a computer. The Max patch has message buttons that made it easy to test individual subsystems and also catches the IP address broadcast packet and routes it to the udpsend automatically so its always sending to the right place. The TouchOSC layout just controls the LEDs and Digital I/O for now but will be expanded in the future to cover more of the I/O.

mbed_osc_max

The mbed OSC code (including code based on the Make Controller, with attributeion) is released on my mbed.org account. It is in-progress as stated-above but may be useful to someone.

posted on Tuesday, March 16th, 2010 by Pehr in MAT Projects