Go Down

Topic: synchronizing multiple sensors to MaxMSP; millis? interrupt? (Read 970 times) previous topic - next topic

brendanmccloskey

Hallo all
I'm running 8 FSRs into Arduino Mega, sending serial bytes to Max; the end of the packet is punctuated with a Serial.print(255, BYTE) - it all works fine and my FSR values are arriving in Max independently and in order. However, is there procedure for ensuring that FSR 1(on pin 0) always arrives first? I've looked at a number of prefab solutions such as Maxuino and Arduino2Max and SARCduino (and didn't grasp what the code was doing), but I'm writing my own program in Arduino and need to understand how to implement this myself.

Thanks for any help
Brendan


PaulS

Quote
I'm running 8 FSRs into Arduino Mega, sending serial bytes to Max; the end of the packet is punctuated with a Serial.print(255, BYTE)

You haven't posted any code to show how this is done.

Quote
it all works fine and my FSR values are arriving in Max independently and in order.

Hard to see how this is happening from the code you posted.

Quote
However, is there procedure for ensuring that FSR 1(on pin 0) always arrives first?

Send it first.

Quote
bump?

Where is the bump. Well get the street department out to fix it as soon as possible. The weather this year has been hard on the roads, so it might take a while.

Hi PaulS
1) and 2) apologies; here's the code:
Code: [Select]
//8 FSRs on pins 0-7; pwr/read+gnd via 10kR
//n00bmeister March 2011
//for MaxMSP
int sigVar;//the pin vals

void setup(){
  Serial.begin (57600);
 
}

void loop(){
  //forloop sequentially reads pins 0-7
  for (int n=0; n<8; n++)
  {
  sigVar=analogRead(n);
  sigVar /= 4; //10bit to 8bit
  Serial.print(sigVar, BYTE);
  Serial.print(255, BYTE);
  delay(5);
  }
  //carriage return OUTSIDE the forloop when testing
  //Serial.println();
  delay(5);
}


3) sensor1 always arrives 'first' in the packet, but may not show up as the first; it depends when I initialize the [serial] object in MaxMSP - obviously the code is always running and may therefore arrive sixth (but still first in the packet, as it were) - all 8 sensor values will arive in order, but 'shifted' depending on when I start serial communication.

4) LOL

Thanks for responding

n00bmeister


I just thought that, sending some pseudo-code might help clarify:

What I want Arduino to say to Max is
"here's a signifier for the first sensor value; and here's the end of the packet"

and Max will hear
"oh, this MUST be the first sensor value cos there's the signifier"

and n00meister will say
"Dear Cycling74 forum, what do I do with this signifier?"

thanks
n00bmeister

PaulS

What I would do is add a start of packet marker, each value followed by a separator, in a loop, then an end of packet marker:
<v1, v2, v3, v4, v5, v6, v7, v8>
When reading data, read a character. If it isn't a start of packet marker (<), throw it away. If it is, throw it away, and start another loop.

In that loop, read data. If the character is an end of packet marker, process the string received. If it is not and end of packet marker, add it to the string, unless it is another start of packet marker.

Processing the string involves parsing the tokens, nicely separated by delimiters.

Since you are sending the values as binary data, parsing is not really required, nor is the delimiter. The start and end of packet markers are, though.

Go Up