Send integer on Serial to Arduino.
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
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].
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.
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);
}
}
}
}
}
------
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
this is should be more clear:
yes it was. will try this. thanks man
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.
hi
use for each data stream one [pak] object and give as first argument another id number.