Pages: [1]   Go Down
Author Topic: Max MSP serial communication  (Read 2023 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I just started using Arduino, so I don't know much. I have managed to piece together my first sketch to control a DC motor's speed and direction. Now I want to control the motor from Max MSP.

I have no idea how to do this. I will post what I coded for Arduino but I feel it isn't close to what I should have done:

http://pastebin.com/LUsSk9Ub

I was wondering if anyone could direct me to a tutorial with in depth description of how to control Arduino from Max MSP. All I can find online so far is how to get information from the Arduino. A lab or something to take me through the steps as I am not at level where just discussing concepts helps.

I would start slow with Arduino but I just started using it to realize a project I already had in my head.

Thanks
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

2nd hit in google - arduino max msp  ...

- http://www.soundplusdesign.com/?p=1305 -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the link, I was checking out maxuino but I was curious how to do this without it.

The thing I don't understand is ...

1) How to properly send information to the arduino, and how to even tell if it is receiving any information from max.

2) What to write codewise for the arduino in order to distribute the information I am sending from max to the arduino. I am trying to send two numbers to the code, one to control the motor's speed and another to indicate HIGH or LOWin order to switch the direction of the motor.

What kind of code do you write to tell the arduino where to put the numbers you are sending it?

 
analog write controls the motor's speed so I was trying to write the code so that the first set of numbers I send from max are to control the speed.

I can type in a number from 0 to 255 and upload it to change the speed but I want to use max so I can vary the speed from the computer. My only idea was to define a variable called "thespeed" based off of the information coming from the serial port. But I don't know if the arduino is receiving any numbers from max let alone knowing what to do with them.

analogWrite(enablePin,thespeed);


I found information on parsing the numbers you send in a string and I tried to use that information in my code to define the numbers the arduino is recieving but I don't know if it is close to what is the proper thing to do, I am just guessing . I did this ....


      while (Serial.available() >0) {
       
        int thespeed = Serial.parseInt();
        int thedirection = Serial.parseInt();
       
        if (Serial.read() == '\n') {
         
          thespeed = 255 - constrain(thespeed, 0, 255);
          thedirection = 255 - constrain(thedirection, 0, 255);
         
         analogWrite(enablePin,thespeed);
         
        }

Does this look close to right? I am looking into maxuino but if I could do this without it I'd really prefer to, just so I have more of a chance to understand how the arduino itself works.

Logged

Pages: [1]   Go Up
Jump to: