Partical.grt
Published in

Partical.grt

TouchDesigner Send Data to Arduino — Tutorial in TouchDesigner

TouchDesigner connect Arduino : Arduino Receive Data from TouchDesigner sending

TouchDesigner Side

Like sending data from Arduino to TouchDesigner. Get a Serial (DAT) first. And I used the One Per Byte here because of the case needed. (In the Serial (DAT) panel, the parameter “Row/Callback Format”)

Also, need to setup Port & Serial Baud Rate. You can refer

Script of sending data out.

def onStart():
op(‘forArduinoOutput’).send('n', terminator='\n')
return

I used onStart() function because I link Execute (DAT) to trigger that script.

forArduinoOutput” is my Serial (DAT) name, and using send() to send the data out.

n” is what string you want to send. “terminator=’\n’ ” let receiver knows the string is end and create a new line.

Arduino Side

Full Code

void setup() {
Serial.begin(9600);
}
void loop() {
String s = "";
while (Serial.available()) {
char c = Serial.read();
if (c != '\n') {
s += c;
}
}
if (s != "") {
if (s == "word") {
// Execute Something
}
}
}

Explain

We setup Serial Baud Rate “9600” first.

void setup() {
Serial.begin(9600);
}

In the loop() function, we have to checking the Serial whether connect or not.

while (Serial.available()) {}

Once connected, reading the data from Serial. But now we got are the byte data. We have to re-connect them to be a string. And adding if to know where is the end of string. That’s why we add “\n” to the all string in TouchDesigner.

char c = Serial.read();
if (c != '\n') {
s += c;
}

Last step, you can use the data to run any script you want. For example, I checked if the data equal to “word”, then execute something.

if (s != "") {
if (s == "word") {
// Execute Something
}
}

--

--

--

Just some the tips and tutorials on my creating journey. I think you will find something useful. 😉 Instagram: https://www.instagram.com/partical.grt/. TouchDesigner Snippet & Works: https://partical.notion.site

Recommended from Medium

Remove and Optimizing Your Conda Environment

Python Learn by Python Projects & Python Quizzes in 2021

Kubernetes monitoring with Prometheus in 15 minutes

Fetching Emails from GitHub

Your Guide to Flexibility in Creativity

Handling database password change at runtime with Entity Framework in ASP.Net Core

Commercialization and Open Source Code — Accelerating Development in the Materials Science…

Acqua Vst Plugins

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Partical Weng

Partical Weng

A person love new things and extremely futurism.

More from Medium

Local admin access to Windows 10 given physical access to the system

Using etckeeper on Gentoo for github

ssh-keygen

Rethinking the spreadsheet: data entry

First experience writing code in VR (SimulaVR + Valve Index on Ubuntu SteamVR)