synchronize Arduino with [metro] initialization


    Mar 03 2013 | 10:46 am
    Hallo all
    I have the following code running in Arduino, which detects force from multiple FSRs and assigns each a unique ID so I can parse the sensors in Max:
    //read 12 FSRs, convert force value to LED brightness
    int inVal;
    int brightness;
    void setup(){
    Serial.begin(9600);
    //multiple LED pins/////////
    for(int x=2; x pinMode(x, OUTPUT);
    }
    }
    void loop(){
    //multiple FSR pins
    for(int i=0; i inVal = analogRead (i);
    inVal/=3;
    inVal=constrain(inVal, 0, 255);
    brightness=inVal;
    //prepend sensor value with pin# ident
    Serial.write(i);
    Serial.write(brightness);
    analogWrite((i+2), brightness);
    }
    delay(10);
    }
    My problem is the fact that the Arduino code is continually running, sending sensor ID and value - for example, at any time it could be sending "5, 0; 6, 0; 7, 143; 8, 0; when I begin polling the serial port I might get EITHER the sensor value first followed by sensor ident, OR ident then value. I thought that a solution might be to only send the data to MaxMSP when a sensor is pressed. Would the following result in jittery data?
    if sensorVal >0{
    send all the data;
    }
    else{
    blank space here;
    }
    Or is another solution to get Arduino to listen to the serial port and wait for a keystroke or ascii value (from MaxMSP). I know how to send stuff from Arduino to Max, but have no idea how to do this the other way round. What I wish to achieve is a guarantee that whenever I begin polling the serial port I will always get sensor ident FIRST, followed by the associated sensor value.
    Any suggestions?
    Thanks
    Brendan

    • Mar 03 2013 | 12:19 pm
      or offset the sensor ident so they're easier to distinguish? That way you can easily parse.
    • Mar 03 2013 | 1:45 pm
      Hi Wetteberg
      what exactly is meant by "offset"?
      Sensor idents are between 0 and 11; sensor data is between 0-255. Ah yes, do you mean scale idents up to >255? How would I then parse this in Max, to ensure synchronization (ident first, always; value second always)?
      Best regards
      Brendan
      on the Arduino forum, someone suggested sending only data when a sensor changes, not 100% sure how to do that either. I'll have a noodle around and get back.......
    • Mar 03 2013 | 1:59 pm
      well it is a bit more complicated to have to look for value pairs, but [match my_ident_above_255 nn] would get a specific pair and ensure the sync, as far as I can tell.
      And yeah, some filtering is always good before hitting the computer :)