Send non sensor values from arduino to max, again sorry.

Sep 3, 2011 at 5:48pm

Send non sensor values from arduino to max, again sorry.

Hi all.
I would like to send values from arduino to max.
Values like random for instance, not values from sensors…

Here’s my kind of hello world arduino sketch !

int testvalue;
int ledpin=13;

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

void loop() {
delay(500);
testvalue= random(255);
digitalWrite(ledpin, 1);
Serial.println(testvalue,DEC);
delay(500);
digitalWrite(ledpin,0);
}

Is there a simple way to recover this random value into max ?
Would you have some tutorials wich explain the serial data structure to send to max ??

Thx you in advance.

Fratzen

#58748
Sep 3, 2011 at 9:06pm

Hi
the quickest solution would be to amend your code as follows:

int testvalue;
int ledpin=13;

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

void loop() {
delay(500);
testvalue= random(255);
digitalWrite(ledpin, 1);
Serial.print(testvalue, BYTE); //change println to print
delay(500);
digitalWrite(ledpin,0);
}
// some prefer to use the [atoi] and [fromsymbol] objects in Max. but not me.

Just poll the [serial] object in Max with a [metro]; obviously, you must ensure that the serial port argument (usually a, b, c, or d) and baud rate (here it is 9600) are correct

Brendan

#211164
Sep 3, 2011 at 9:25pm

Thx you !! That does the trick.
Two more questions to understand correctly the things !
Is this possible to send values like float, negative values ? Values greater than 255 ?
Does the process change ?
And if I want to send 2 values from arduino ?
I try the same thing with unpack after the serial object, but it does keep only one last value… Is there some end Byte and start byte to deal with ?

Thank you
Fratzen

#211165
Sep 3, 2011 at 9:46pm

Yes, for example,

Serial.print(1, DEC);
Serial.print(someVariable, BYTE)
etc

See my blog for this type of thing:

http://brendan-admi.blogspot.com/2011/07/diy-fsr-matrix-part-1-parsing-multiple.html

and read this for serial formats info:

http://www.arduino.cc/en/Serial/Print

Brendan

#211166
Sep 3, 2011 at 9:57pm

Thx you !
Very clear !!
I’ll find the way to send for instance -1023 from arduino to max.
Cheers !
Fratzen

#211167
Sep 4, 2011 at 10:19am

Oh yes
I forgot to answer some of your other questions, sorry.
I always scale my sensor values down to <255 in Arduino, simply because I don't yet understand bit-shifting fully, or how to reconstitute the LSB and MSB in Max....but there are a few pointers here:

http://cycling74.com/forums/topic.php?id=19297

http://www.arduino.cc/en/Reference/Bitshift

If you work out how to do this (values >255 into Max) it would be very helpful if you could post your results here, as I find it a BIT of a mystery,

Brendan

#211168

You must be logged in to reply to this topic.