From Cycling '74 Wiki
Revision as of 06:17, 28 April 2013 by ddgcycling74com (Talk | contribs)

Jump to: navigation, search

Create a Test Max Patch

NOTE: Before you start working on the Max patch, you have to exit out of the Arduino application. Since both the Arduino app and Max will try to control the serial port, they will be in contention if you try running both at the same time.

Now let's make a test program to verify that our sketch - and our hardware setup - are all working correctly. We'll do it step-by-step so that each part is clear.

First, we need to create a serial port connection to the Arduino, and build the surrounding application pieces necessary to select a port and to report information from the port:


A few things to note here:

  • The setup of the menu (which contains all of the available serial ports) occurs when the patch is loaded (that's the loadmess object).
  • A qmetro is used to start firing off bang messages, which serve as a polling system for incoming serial bytes.
  • The {maxword|name=serial} object needs to be initialized with the same baud rate that we used in the sketch - 57600 in this case.
  • When working with the Arduino, you never know what the serial port name is going to be - or where it is going to show up in a list of ports. That's why you have to use a menu for port selection.
  • A special {maxword|name=receive} object (called to-serial) is created for us to use in the next step.

Next, we need to put in the pieces that send data to the Arduino and receive values back from the Arduino. Here are those additions, highlighted in red:


You can download this test file (sans the garish red outlines) from here: Media:SimpleSerialConnection.maxpat

If the connection to the Arduino is set up correctly, and our connection sketch is loaded, you should be able to click on each of the "pin" checkboxes to turn the corresponding LEDs on and off. Also, if you turn the potentiometer wired into the Arduino, you should see the value (in a range from 0 to 127) appear in the number box below the {maxword|name=serial} object. We have communication!

Now, let's use this setup to create a simple "light sequencer" to show a more interesting use of this setup.

<Previous: Creating an Arduino sketch> <Next: Create a more interesting Max patch>