Terug

Max Les 4A-Max with Arduino Module

Combine Arduino with Max/MSP

In this lesson we will learn how to connect our Arduino with Max/MSP. In particular this lesson focuses on how to connect to Arduino with a small utility created at CMD, we call it the Arduino Module. Once you

Download : Max Arduino Module

Download the ZIP file. Save the zip file in a safe place where you keep other CMD Module materials. UNZIP the files (Windows users: make sure you extract the contents and not just look into the zip files).

>

When you download the zip file you will see a folder with different files. Your most important files for this lesson are the:
– ArduinoSketchforMaxModule / ArduinoSketchforMaxModule.ino
– Max_Arduino_Module.maxpat


On Arduino

For this lesson you are going to build a basic Arduino setup but you will control it via Max/MSP and vice-versa. For this we expect you to already have Arduino knowledge from your Networked Objects module, if you need to refresh please refer to the online lessons: Network Objects

  1. First you will build the following scematic, it will include:
    • 2 LEDs
    • 2 Switches
    • 1 Continuous Servo motor (FT90R)
    • 1 Light Sensor
  2. Connect the Arduino to your laptop via USB.

  3. You will then upload the Arduino file that is inside the ZIP you downloaded. The file is called ArduinoSketchforMaxModule.ino and you open it with your Arduino program. If you get an error please look at the troubleshooting page here : Troubleshooting

NOTE : You only need to upload this code to your Arduino ONCE, everything is then managed on the Max side.


On Max/MSP

  1. Open your Max_Arduino_Module.maxpat Max patch.
    IMPORTANT : You cannot connect to your Arduino via the Arduino program and Max/MSP at the same time. Upload your Arduino code AND THEN QUIT the program. You only need to upload the Arduino code ONCE.

  2. When you open the Arduino Module you will need to connect the following:

    • Digital Outputs pin2 and pin3 : toggle boxes
    • Analog Outputs A0 : Number Box
    • Digital Inputs pin12 and pin13 : toggle boxes

This is what it should look like:

At this stage if you turned on the Arduino Module you should be able to press the Arduino switches and see the toggle in Max change. The light sensor should also be changing depending on the light. Likewise, clicking the toggles on top should turn on/off the LEDs on the Arduino. If not then you need to go over your setup and find the problem.


Adding the jit.playlist

Now that we have a basic Arduino-via-Max setup, lets try and add the jit.playlist example from the helpfile which we have already practiced on.

  1. As you have done in previous lessons, copy the jit.playlist code from the Help File (Playback tab) and paste it in your Patcher.

  2. We are going to use the Switch buttons to turn on/off videos 1 and 2 from the playlist. At the moment our switches are connected to toggle boxes in Max. The first toggle should work going directly into the playlist since it has two states 1 & 0 (1 plays video 1 and 0 stops all videos). BUT because we are using a continuous stream of numbers coming from the Arduino, the Playlist would be receiving HUNDREDS of messages saying 0 and 1 (the video lesson will explain more in depth). To solve this you need to put a change object in between the toggle and the playlist.

  1. Now we will control the second video. We need to convert the pin3 toggle messages from “1 to 0” into “2 to 0” (since sending a 2 will play video 2 and 0 will stop). We will use an if-statement. Lets make a new object with the following statement and connect it to the toggle at pin3:

    if $i1 == 1 then 2 else 0

  2. If you connect the output of the if-statement you can now use the 2nd switch to play/stop the 2nd video in the playlist. BUT DONT FORGET THE CHANGE OBJECT:


Save this patcher as Opdracht 4A and bring it to your lesson.

Until now you should be able to control the video in Max from Arduino by pressing the switch buttons. If not, you should retrace your steps and debug your code and Arduino.

You will be able to use this same setup for several examples.

Keep your setup and continue to Les 4B.