Workshop 7 - Controlling Max MSP

Without giving you a history of Max MSP, this is software designed for visual programming of multimedia projects, programmes are referred to as 'patches' and are built by wiring blocks together. There is a 30 day demo which you can download from Cycling74, but if you don't want to pay for it afterwards there is a free, albeit not quite as developed, alternative called PD. In this instance we are going to look at it as a means to control video via hardware connected to our Arduino. 

  • Download the Max patch
  • Keep the circuit from last time and add a button as below, there are plenty of online apps to work out resistor colour coding like this one for example.
 
potLedButton_bb.png
 

The code is simply the button sketch with a few additions, note the lines beginning with 'Serial'. 

'Serial.begin(9600);' sets up for serial communication and defines the 'baud' rate, the rate of data transfer. 

'Serial.print' will send characters over serial

'Serial.println' will send characters over serial followed by a new line character. 

  • Paste the code into a new Arduino project window and upload it

/*
  Button

 Turns on and off a light emitting diode(LED) connected to digital
 pin 13, when pressing a pushbutton attached to pin 2.


 The circuit:
 * LED attached from pin 13 to ground
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground

 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.


 created 2005
 by DojoDave <http://www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe
 modified for serial output 4 Feb 2016
 by Luke Woodbury

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  // create serial buffer
  Serial.begin(9600);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    // print button state with preceding label "1"
    Serial.print("1 ");
    Serial.println(1); //'println' puts a line space after, new line
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    // print button state with preceding label "1"
    Serial.print("1 ");
    Serial.println(0); //'println' puts a line space after, new line
    
  }
}

  • Now, make sure your Arduino is attached, the serial monitor is closed and open the Max patch
  • Press the 'Reload Port Menu' button
  • Select your Arduino port from the drop down menu
  • Check the baud rate matches your Arduino sketch and press the 'Start Polling Serial Port' toggle
  • Hold the button on your breadboard to make the video play, let go to stop it

Before we move on, lets just examine the Max patch.

Screen Shot 2018-03-19 at 16.38.31.png
  • Click on the button at the bottom of the window that looks like the icon to the right to get into 'patching mode' rather than 'presentation mode', this will show you the workings of the patch
  • Double click on the [p mov] object, this will show you whats inside, anything with a 'p' at the front is a 'sub patch', i.e. just an enclosed bit of patching 

This shows you a very basic way of loading a movie file and playing it in a window, but what if you want to use a projector and even map the projection to a surface. Max has some pre-built modules for working with video and audio that will make things a bit easier for you. Now, lets look at using the knob and button to do something more interesting... 

 

NEXT>>


Workshop 1- Hello World!

Simple use of a button (a digital input) to turn an LED on

Workshop 2 - Analog inputs/outputs

Reading a fader/knob/sensor (analog input) to fade an LED

Workshop 3 - PWM and servo motors

Control a servo motor using Pulse Width Modulation

Workshop 4 - Fritzing! 

Having a look at circuit design using Fritzing

Workshop 5 - Soldering

Some tips on soldering

Workshop 6 - Serial Communication

Exploring how to communicate with the computer via serial

Workshop 7 - Controlling Max MSP

A look at Max MSP and how we can speak to it from Arduino

Workshop 8 - Making a video system

A look at some of the built in video modules of Max and using Arduino to control them

Workshop 9 - Max to Arduino

Going the other way and using a Max user interface to control Arduino hardware