Forums > MaxMSP

Send integer on Serial to Arduino.

October 16, 2009 | 10:48 pm

hey. Need some help here.
Doing a project where were going to control a standard rc car using a iPhone 3g, 1 arduino (possably 2), and some RF modules.
we are going to read the accelerometer data on the iphone and turning them in to throttle/turn commands.

I’ve managed to get the accelerometer data in to my max-patch(8 bit) so now I have 2 8-bit integers in number boxes which i don’t know how to send out on the serial port and to the arduino.

I need help to make the rest of the patch, so that i can send the two (continuously changing) 8-bit integers to the arduino.

Just imagine a blank patch with only two number boxes on it. the number in the boxes change continously(whole numbers, no decimals) and i want to send them to the arduino…
How do i do that ?
since this is real-time control, it needs do update at least 10 times a second.

Anyone have an idea of what to do ?
I think this is a pretty basic thing to do, but i have almost no experience with the max 5 program!

thanks for reading, and thanks again for all help.

Daniel Aaroe


October 17, 2009 | 4:40 am

Try the [serial] object, and run the integers through [itoa] before they go in. or try [spell]. Some combination should get the Arduino to recognize them. You’ll have to send them as two-element lists, each with an index number that the Arduino code listens for (and then sends to the right place), or send them as a pair, with a start code for the Arduino to see. It’ll take a bit of fiddling but it should be fine. The key is the formatting for [serial].


October 17, 2009 | 9:10 am

Thanks, I’ve looked at it, but due to my lack of skills in the program, i can’t really make sense of it. It looks like the [serial] makes the "integer" to "binary". But I dont really know anything for sure.

I’ll just upload the program, and whoever wants to, can take a look. I have not tried it yet. Don’t know if it does what it should. Left a few short comments there. And one long one.


October 18, 2009 | 12:09 pm

hi,

maybe this can halp you. the arduino code is not tested..

—–

char id; //max pak input 1( pak 0 1)
int data = 0; //max pak input data (pak 0 number)

void setup() {

Serial.begin(9600);

}

void loop()

{
while ((Serial.available() > 1)){

id = Serial.read();
data = Serial.read();

if (id == 2){

if (data != 0){
digitalWrite(12, HIGH);
}
else{
digitalWrite(12, LOW);
}

}
if (id == 3){

if (data != 0){
digitalWrite(13, HIGH);
}
else{
digitalWrite(13, LOW);
}
}

}

}

}

——

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 314 242 132 196617 this is your id number>>>>;
#P toggle 476 212 15 0;
#P newex 443 239 43 196617 pak 2 0;
#P comment 487 243 132 196617 < <<< this is your data input;
#P toggle 266 115 15 0;
#P newex 238 139 43 196617 pak 2 0;
#P comment 284 114 100 196617 enable;
#P toggle 86 135 15 0;
#P newex 86 104 44 196617 loadbang;
#P newex 86 160 46 196617 metro 1;
#P toggle 184 78 15 0;
#P newex 156 102 38 196617 pak 3 0;
#P newex 129 201 98 196617 serial a 9600 8 1 0;
#P comment 202 77 100 196617 directions;
#P connect 12 0 11 1;
#P connect 9 0 8 1;
#P connect 3 0 2 1;
#P connect 8 0 1 0;
#P connect 2 0 1 0;
#P connect 4 0 1 0;
#P connect 6 0 4 0;
#P connect 5 0 6 0;
#P window clipboard copycount 14;


October 18, 2009 | 12:23 pm

Thanks. I shall look at it more closely tonight. Did’nt quite figure out where to input the two integers. Even though it might look like it was at the [pak 2.0].

I see you made som arduino code as well. That was not necessary but I think it will help a lot when i start to write the arduino code. thanks again Very Happy


October 18, 2009 | 2:03 pm

this is should be more clear:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 71 90 132 196617 this is your id number>>>>;
#P number 200 89 34 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 322 91 168 196617 < <<< this is your data input 0 - 255;
#P number 278 89 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 293 117 132 196617 < <<< this is your data input;
#P newex 200 121 88 196617 pak 2 0;
#P toggle 37 100 15 0;
#P newex 37 69 44 196617 loadbang;
#P newex 37 125 46 196617 metro 1;
#P newex 129 201 98 196617 serial a 9600 8 1 0;
#P connect 8 0 4 0;
#P connect 6 0 4 1;
#P connect 2 0 3 0;
#P connect 3 0 1 0;
#P connect 1 0 0 0;
#P connect 4 0 0 0;
#P window clipboard copycount 10;


October 18, 2009 | 2:53 pm

yes it was. will try this. thanks man Very Happy


October 18, 2009 | 3:51 pm

Do i put both the data inputs in the same [pak].

The id number, is that there to seperate the two integers from each other ?(if so, i thought i should just mux/demux the ints to send them on the same serial without identifiers)…

sorry if the questions are stupid. I’m new at this.

I tried that, and this is how it looks like. Think this could work?
(have not used the id number box. have not muxed them either!)

thanks.


October 18, 2009 | 7:02 pm

hi

use for each data stream one [pak] object and give as first argument another id number.

#P user multiSlider 170 49 17 79 0. 255. 1 2665 47 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 237 47 17 79 0. 255. 1 2665 47 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 200 144 43 196617 pak 2 0;
#P toggle 39 124 15 0;
#P newex 39 93 44 196617 loadbang;
#P newex 39 149 46 196617 metro 1;
#P newex 141 147 38 196617 pak 3 0;
#P newex 129 201 98 196617 serial a 9600 8 1 0;
#P connect 7 0 1 1;
#P connect 6 0 5 1;
#P connect 3 0 4 0;
#P connect 4 0 2 0;
#P connect 2 0 0 0;
#P connect 1 0 0 0;
#P connect 5 0 0 0;
#P window clipboard copycount 8;


Viewing 9 posts - 1 through 9 (of 9 total)