Skip to content

Interface and Application Programming

Group Assignment

✔️ Compare as many tool options as possible

Individual Assignment

✔️ write an application that interfaces a user with an input &/or output device that you made

Servo Slider

For this week, I want to explore the interface implication in TouchDesigner and use it to communicate with my board and control the peripherals.

Process

1. Serial Output from Touchdesigner to Board

  1. Create a Serial DAT.
  2. Create a CHOP Excute DAT, and write the following code. Note only the last part functions for this comunication.
Python
# me - this DAT
# 
# channel - the Channel object which has changed
# sampleIndex - the index of the changed sample
# val - the numeric value of the changed sample
# prev - the previous sample value
# 
# Make sure the corresponding toggle is enabled in the CHOP Execute DAT.

def onOffToOn(channel, sampleIndex, val, prev):
    return

def whileOn(channel, sampleIndex, val, prev):
    return

def onOnToOff(channel, sampleIndex, val, prev):
    return

def whileOff(channel, sampleIndex, val, prev):
    return

def onValueChange(channel, sampleIndex, val, prev):
    op('serial1').send(int(val), terminator='\n')
    print(int(val))
    return

2. Servo Motor Coding in Arduino IDE

  1. Receiving Data in Arduino IDE.
  2. Map it to to the angle of servo motor.
Text Only
/* Sweep
  by BARRAGAN <http://barraganstudio.com>
  This example code is in the public domain.

  modified 8 Nov 2013
  by Scott Fitzgerald
  https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(3);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600); // begin serial comunication and set baud rate
}

void loop() {

  while (Serial.available() > 0) {
    pos = Serial.parseInt();


    if (Serial.read() == '\n') {
      myservo.write(pos);


    }




    //for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    // myservo.write(pos);              // tell servo to go to position in variable 'pos'
    //delay(0);                       // waits 15 ms for the servo to reach the position
  }
  //  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
  //    myservo.write(pos);              // tell servo to go to position in variable 'pos'
  //   delay(15);                       // waits 15 ms for the servo to reach the position
}

3. Input Interfaces Design in TouchDesign

  1. Create a Slider COMP.
  2. Remap the values with Math CHOP.
  3. Use Null CHOP to connect value output to serial sender in order to keep it modular and organized.

After uploading the Arduino code tothe board, now I can control the servo motor with a software slider in realtime.

Resources

Programming the Programmer / Installing Bootloader

Programming a SAMD Chip

OpenOCD Setup and Workflow

Resources

⬇️ Download Project Files and Assets