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
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
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.
When you open the Arduino Module you will need to connect the following:
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.
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.
jit.playlistcode from the Help File (Playback tab) and paste it in your Patcher.
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
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
if-statementyou can now use the 2nd switch to play/stop the 2nd video in the playlist. BUT DONT FORGET THE
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.