Pages: [1]   Go Down
Author Topic: Arduino2Max Problems  (Read 1058 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I'm kind of a noob with Arduino.

I'm trying to create an Interface for Max/MSP where I use sensors to read data in and then use PWM outs to feed data out and back into the inputs.

I'm testing it by simply using one input, mapping it to an oscillator and at the same time dimming an LED. This isn't working though.
If anyone can help I'd be eternally grateful.

Cheers, Jan

Arduino:

Code:
/*  
 *  Arduino2Max
 *  Send pin values from Arduino to MAX/MSP
 *  
 *  Arduino2Max.pde
 *  ------------  
 *  This version: .5, November 29, 2010
 *  ------------
 *  Copyleft: use as you like
 *  by Daniel Jolliffe
 *  Based on a sketch and patch by Thomas Ouellet Fredericks  tof.danslchamp.org
 *  
 */
 
//=========================Declare Global Variables====================================
int x = 0;                              // a place to hold pin values
int serialvalue;    //a place to hold the serial.read values
const int ledPin = 9;
//==========================setup()==========================================
void setup()
{
  Serial.begin(9600);               // 115200 is the default Arduino Bluetooth speed
  digitalWrite(13,HIGH);              ///startup blink
  delay(600);
  digitalWrite(13,LOW);
  pinMode(12,OUTPUT);                //Declare all of the pins that you'll use as OUTPUTs here
  pinMode(13,OUTPUT);
  pinMode(9,OUTPUT);
}
//===========================loop()============================================
void loop()

{
  byte brightness;

if (Serial.available() > 0){         // Check serial buffer for characters
    serialvalue = Serial.read();    

  
    if (serialvalue == 'r') {       // If an 'r' is received then read the pins (r = ascii code 114)
    
    
      for (int pin= 0; pin<=5; pin++){      // Read and send analog pins 0-5
          x = map(analogRead(pin), 1023, 0, 0, 1023);
        
          sendValue (x);
          }



      for (int pin= 2; pin<=11; pin++){     // Read and send digital pins 2-11.  Modify this so you're
          x = digitalRead(pin);             // only reading the pins that aren't used below for digital out
          sendValue (x);
          }

        Serial.println();               // Send a carriage returnt to mark end of pin data.
        delay (5);                      // add a delay to prevent crashing/overloading of the serial port
  
  }//end of if (serialvalue == 'r')

      /*------------------------Here we receive the numbers sent from the Max digitalOuts-------------------  
      The digital writes and reads here are meant only as examples.   You can replace what is in these
      and expand this whole section to deal with more incoming numbers.  You can use any number from
      0-255 except 114, since that is the ASCII code for 'r' and is used above
      Be sure any pin you use here is declared in setup() as an OUTPUT and that you're not reading from
      it just above this section.*/
 
        if(serialvalue == 0){
          digitalWrite(12, LOW);
        }
        else if(serialvalue == 1){
          digitalWrite(13, HIGH);
        }
        else if(serialvalue == 2){
          digitalWrite(12, LOW);
        }
        else if(serialvalue == 3){
          digitalWrite(13, HIGH);
        }
        
         if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    brightness = Serial.read();
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
  }
       //--------------------------End of receiving numbers---------------------------------  

 }//end of if (Serial.available() > 0
}

void sendValue (int x){              // function to send the pin value followed by a "space".
 Serial.print(x);
 Serial.write(byte(32));
}



Logged

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

This is what I've done in Max so far just trying to get it to work:

Code:
----------begin_max5_patcher----------
6538.3oc6cs9aiiij+yc+WAWueX2EvcNQp2y8o416ENfF6fsm6vcX5EMTrUb
zzxRFRxclLC16u8kjEksrsDUIaIEEGOORhjskI+UEKVrd9au+cytO8WBymQ9
NxOQd269s2+t2Iuk3FuSc86lsN3WVDGjKeayR1t99vrYygWZSPwhGiRV8krv
EEvig4ytyXNw1xS9KCwOo92YP9apOSzR4CJ89e9C19kOnGRSJRBVGJeo+mvr
kAIA6+Rx3uRQX1WBSBtOV9dLTuFe3DkDGVHGbz82LcaQ4cYU9Jxi9U4GmJFV
vsg2YwyaBgw+rnjhYyIytOHY0LxeS7l96u+8heLGIDkGGsDCDY5KgHF.QVFU
vnxwIy1Y2.89UKRiSyfGgwc9V9Fr409G0h0tF8DdRaB3NOzJI7I9vqbrUD9K
E.HFFywKhAgpAHsDLVyIVNRfzgUBm0N+cqkW66yhBhmU2r2r1YuYc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MloryaQfhsmA6Ww36+Wd0XuH
f0EAaSDpCE4X1ZBwQYfbLaZLsFyXD1v7mViYFlwr2zZLahYL6NsFyVXFyNSq
wrMlw7zY2SWrJdZ6eQ6D4.U8vpWMx6D45gcl5cdyTlgLVpb7f5FSkqF6YpK1
Yp6YNSc7pNSqb0XOScvNScNyCSXVklV8pwdlh8XS1m6wl7qRSqd0XOSwdrIa
6yalZ4TklV8pwdlhU03oy1ENXUM1a5nloCVUiclNpy6z2FIY3GxXEPMcFwVz
Wenrkw.a9LgsBTa0Uw7YllitzQSr5q4wlLTGSrqamPCY69FlOhgRYpYnqrSg
RXK8DmBLBSTr1byT2DkNtiYrVOyzZ5LlwJgxc5XUGrrFSGaMvvdtc2oicnXX
kn6NcrCECqR5tSHdCr6B4NcNXAC61PtSGcwnXkNaMcNLDk12G57X8G8f1BGT
BSTNiUd0HueOE69P9WjeloNtUlnxqF6IJVcD5KOrsO.HzlKYk4QVa4P1u89F
ycLD4MllPr4z7EqsbEqw7DqkbDq17CaVyeIMkWX.HK+oBlOLFSjP0ILH+16a
veDGreaSqyOf8+TNhSrdFnOuHJbkwUg8tq1+EcL+iZBMu6y.WDyfC0V.wL.B
fXKH4GrfIhU0lpQeNCbvLCLZYFziiGqgfmvF3IrcpxSHtZHPT1PLC.t.aW+p
y.wUCvLPxvRaaFXMZ7DtXVkcDrOniGCDiGa+Qa7fYIr8Awk2fNbNZl2OK.Dw
2pjk25fE.VCxB.aCrHZGlALa4R3xVa1tKFhwOhguSCidZuOZrPIR2YzVtfZ7
PGsgCEiVPVimzVJFosV1i23Ai3Mqwi8ghY0kk63MdvvNaMd6FcXOWtowi23M
dPLbNWcG3mj7u+9+AEXDFkA
-----------end_max5_patcher-----------

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50157
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
          x = map(analogRead(pin), 1023, 0, 0, 1023);
This is an expensive way to accomplish:
Code:
x = 1023 - analogRead(pin);

Code:
        if(serialvalue == 0){
          digitalWrite(12, LOW);
        }
        else if(serialvalue == 1){
          digitalWrite(13, HIGH);
        }
        else if(serialvalue == 2){
          digitalWrite(12, LOW);
        }
        else if(serialvalue == 3){
          digitalWrite(13, HIGH);
        }
So, you are sending 0, 1, 2, 3, or 'r'. Really?

Or, are you sending '0', '1', '2', '3', or 'r'?

Code:
void sendValue (int x){              // function to send the pin value followed by a "space".
 Serial.print(x);
 Serial.write(byte(32));
}
Serial.print(" "); would be a whole lot clearer.

You know that this is converting the integer to a string, right? Are you expecting a string in Max?
Logged

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

I don't really know, I just ripped that code out of the example that comes with Max2Arduino. I've barely used Arduino before. I have my sensor built and it is being read into Max just fine (cheers for the tip about inverting values though). I want to use Analog Write instead of the Digital Out stuff, to feed values back from the Max Patch back into the sensors.

Thanks, Jan
Logged

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

I believe it's an integer I'm after since I'm reading the value in an integer box in Max.
Logged

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

I'm still stuck getting Analog Write to work. If I use the 'serial out' part of the patch in isolation it works with Arduino and I can use a Max slider to fade an LED. I believe the example tutorial is called Dimmer. I am essentially trying to integrate this into my project.

I have a sensor that feeds data in to Max from the Arduino this data then needs to be transmitted back to the Arduino in a feedback loop so I can modulate the voltage coming from the sensor (I will run PWM through a LPF to convert to analog voltage once I have it working properly). So I need to use Analog Write on PWM outs. But this isn't working. I have an LED attached to pin 9 then to ground and it is not dimming.

Can someone please help me with the code, I have no idea what I'm doing!  smiley-confuse

 smiley-mr-green
Logged

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

It's ok, I've got it working now. Was simply a matter of me not understanding how serial communication works in Arduino. Hooray for books!
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 229
Intransigent prototyper
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wrote that Arduino2Max code package about five years ago.. It's amazing that people are still using it!

If you're reading this, and know how to code, fix it up and I'll release it as a new version. Otherwise, I'll just enjoy watching.


Daniel
Logged

Pages: [1]   Go Up
Jump to: