In our team meeting this week, we discussed the technical direction of our project. Up until now, I had been oversimplifying things by using a single Arduino Uno board, physically connected to my computer and sending distance data over the serial port into TouchDesigner. This worked for early tests, but it wasn’t going to scale.
We needed a setup that could support multiple sensors sending data to multiple computers: one machine running TouchDesigner for visuals, and another running Unity, integrated with Wwise, to handle spatial audio. The two systems would be kept in sync using Open Sound Control (OSC)—a protocol built for fast, real-time communication between creative applications.
After that, I had a meeting with Joe Hathaway, who pointed out that the Arduino Uno doesn’t support Wi-Fi. He recommended switching to M5StickC-Plus boards, which have built-in Wi-Fi and are well-suited for sending OSC messages wirelessly over a local network. We worked together to adapt my existing Arduino code to the M5Stick. Rather than printing values to the serial monitor, the device now connects to a personal hotspot and sends real-time OSC messages over UDP.
Code Walkthrough: M5Stick + OSC
Here’s a breakdown of the changes and additions we made in code.
1. Include Libraries and Setup Pins
We import the required libraries for the M5Stick hardware, Wi-Fi, UDP, and OSC. Then we define the trigger and echo pins for the HC-SR04 distance sensor.
#include <M5StickCPlus.h> #include <WiFi.h> #include <WiFiUdp.h> #include <OSCMessage.h> int trigPin = G0; int echoPin = G26;
2. Wi-Fi and OSC Setup
We define the OSC address, SSID and password of the Wi-Fi network, the IP address of the receiving machine (e.g. a laptop running Unity), and the port number.
String address = "/M121/distance"; const char *ssid = "JoesPhone"; const char *password = "12345678"; const IPAddress outIp(10, 42, 218, 255); // Receiving computer IP const unsigned int outPort = 8000; // OSC port
3. Setup Function
The setup() function initializes the M5Stick screen, connects to Wi-Fi, and begins listening on the network.
void setup() { M5.begin(); Serial.begin(115200); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); while (!connectToWiFi()) {} udp.begin(outPort); M5.Lcd.println("Ready\n"); M5.Lcd.println("Sending to:"); M5.Lcd.print("IP: "); M5.Lcd.println(outIp); M5.Lcd.print("Port: "); M5.Lcd.println(outPort); }
4. Loop: Distance Measurement + OSC Sending
This is the main loop that measures distance and sends it as an OSC message.
void loop() { // Trigger the ultrasonic pulse digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Measure echo time float duration = pulseIn(echoPin, HIGH); float inches = (duration * 0.0135) / 2.0; // Send as OSC message OSCMessage msg(address.c_str()); msg.add(inches); udp.beginPacket(outIp, outPort); msg.send(udp); udp.endPacket(); msg.empty(); delay(50); // Small pause to prevent flooding }
5. Wi-Fi Connection Helper
This function connects the M5Stick to the defined Wi-Fi network and prints status updates to the screen.
bool connectToWiFi() { M5.Lcd.print("Connecting"); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); unsigned long startAttemptTime = millis(); while (WiFi.status() != WL_CONNECTED && millis() - startAttemptTime < 30000) { M5.Lcd.print("."); delay(400); } if (WiFi.status() != WL_CONNECTED) { M5.Lcd.println("\nErr: Failed to connect"); delay(2000); return false; } else { M5.Lcd.println("\nConnected to:"); M5.Lcd.println(ssid); M5.Lcd.println(WiFi.localIP()); delay(2000); return true; } }
Next Steps
Now that the M5Stick is sending OSC messages over the network, I plan to test this with my team and work through how to receive those messages in both Unity (for Wwise audio control) and TouchDesigner (for visuals). We’ll also explore setting up multiple M5Sticks on the same network and assigning each one a unique OSC address to keep things organized.
Code and diagrams adapted from Joe Hathaway, Edinburgh College of Art, 2024, used under the MIT License.

