Resolved:Receive more than 3 datas from Arduino!?
Hi,
I'm a noob, and I would like to receive at least 6 data from Arduino.
With those datas, I will have to trigger sounds, and modulate a pitch.
For the moment I 'm blocked, I can only receive 3 datas.
Thanks for helping!
Later i will have to combine 2 datas to trigger different sound in a sampler or sequencer. Thanks for your attention
You have to upload arduino sketch and paste
compressed max patch for further assistance.
For the moment, on Arduino, I send only 5 datas by printing them to the serial monitor.
Max/msp can receive 3 data because I'm based with the patch given on basic example from Arduino.
My Arduino sketch with 5 data printed (send)
Here the patch to receive 3 data, and I would like to receive 5 data, or 6 and even 10.
Thanks u
French is definitely not my choice of language when it comes
to anything dealing with programming language of any kind.
After deleting all unactive parts of the arduino sketch,
to be able to see what remains,
one gets 2 things that get sent via serial:
--------
for(uint8_t i = 0; i < NBMOTEURS; i++) {
Serial.print(vitesseSortieRPM(i));
Serial.print(", ");
}
Serial.println("");
for(uint8_t i = 0; i < NBMOTEURS; i++) {
Serial.print(position[i]);
Serial.print(", ");
}
Serial.println();
}
-------------
Sent arrays are simple numbers, separated with comma and space
and at the end of each transmission, newline gets sent.
--------
From Max point of view, that ", " comma separation of messages is nonesense,
and should be removed.
Also You will not be able to distinguish between first "portion" of data sent
and second, because they both end with linefeed.
So You first need to sort that out in arduino.
Simply said :
If data You send from arduino have no other indentifier,
and can be grouped and separated only by newline message at the end of transmission,
You will not be able to route that messages to separate destinations.
Is that understandable ?
-----------
What can be done ?
NBMOTEURS whatever that means is array of 5 numbers.
You use that to count and send 2 times comma separated messages over serial.
that would mean 10 numbers in total.
If You remove all commas, and send newline only once at the end,
zl group in Max would give You a list of 10 numbers,
which one could unpack, route or whatever needed
----------
If You made that arduino sketch, than You should know how to do it...
ok for this can you change the patch in max?
This thread might help: https://cycling74.com/forums/how-to-separate-analog-inputs-from-arduino-in-maxmsp
for(int i = 0; i < NBMOTEURS; i++) {Serial.print(vitesseSortieRPM(i));
for(int i = 0; i < NBMOTEURS; i++) {Serial.print(position[i]); }
Serial.println();
-------------------
in max You get 2 arrays (each having 5 values in that sketch) as a list of 10 values.
If You need to combine the 2 lists of 5 values in some way,
there are several options, look into unpack, zl objects
For the moment, I want to have only position of my 5 motors so in Arduino I did
for(int i = 0; i < NBMOTEURS; i++) {Serial.print(position[i]); }
Serial.println();
I have tested my patch with
zl group 5 and I didn't change unpack but I receive datas only on the first output of unpack
So I put again a coma between my 5 values in Arduino
for(uint8_t i = 0; i < NBMOTEURS; i++) {
Serial.print(position[i]);
Serial.print(", ");
}
Serial.println();
And I have 2 datas, on the first and third output of unpack,
so I delete the 5 of zl group and I have 3 datas on the first, third and fifth output of unpack.
I don't understand I don't have my 5 values, and why the 3 datas don't output from the 3 firsts output of unpack???
Could you change the patch, please?
Main mistake with the arduino sketch and max patch is
mismatch of serial Baud Rate.
In Arduino sketch You posted it is set to 115200
in max patch 9600.
That can't work, data You receive will be corrupt.
So first fix that.
You have to give zl group larger number as argument,
it will anyway collect everything till bang from new line
happens.
-------
I have problem downloading the patch You posted,
so either zip compress it, or select all in the patch and select copy compressed
from file menu in Max.
That can be pasted here.
------------
I have no time to debug that arduino sketch.
Here is simple tester which reads 6 analog inputs into array
and sends them to serial port and Max.
Max patch is set to read that.
and arduino sketch :
unsigned long Sensor[6] = {0,0,0,0,0,0};
void setup() { Serial.begin(115200); }
void loop() {
for(int i=0; i<6; i++) {Sensor[i] = analogRead(i);
Serial.print(Sensor[i]); Serial.println();
delay(100);
}}
Hi,
I have tried many option by changing zl group 5 or 100, select 10 13 or select 13 10.
In Arduino I changed the way of print (with or without coma and with or without delay).
The best result is with this patch and this way of printed data in Arduino.
It based on the example of "virtual color mixer" in Arduino sending data like this
void loop() {
Serial.print(random(1,255));
Serial.print(",");
Serial.print(random(1,255));
Serial.print(",");
Serial.print(random(1,255));
}
and the patch Max/msp given with. I have added two output on unpack.
And the way I send data from Arduino
for(uint8_t i = 0; i < NBMOTEURS; i++) {
Serial.print(position[i]);
Serial.print(", ");
} //Serial.println("");
Serial.println();
}
}
Thanks for your help
Difference between Serial.print and Serial.println is
that Serial.println sends newline or line feed
which is ASCII code 10.
That is why we have sel 10 13 inserted between
serial output and zl group.
13 is because it is ASCII code for return.
If You don't send linefeed from arduino
zl group will not output collected data.
I allready told You that for max comma separation
is not needed and could disturb, because comma in max message
forces separated items to be itered, instead of output
as one list
I took exactly you Arduino Program
unsigned long Sensor[6] = {0,0,0,0,0,0}; void setup() { Serial.begin(115200); }
void loop() { for(int i=0; i<6; i++) {Sensor[i] = analogRead(i); Serial.print(Sensor[i]); Serial.println(); delay(100); }}
and your patch that I adapted a bit ,
but datas go output only to the first output of unpack !!!
Yes , You are right - there was mistake in that example,
I forgot to insert space between single valus in array.
Correct would be :
unsigned long Sensor[6] = {0,0,0,0,0,0};
void setup() { Serial.begin(115200); }
void loop() {
for(int i=0; i < 6; i++) {Sensor[i] = analogRead(i);
Serial.print(Sensor[i]); Serial.print(" "); } Serial.println();
delay(100);
}
The bold section sends 6 values with space in between,
and at the end line feed.
delay(100) is to avoid to much data over serial port.
It could be reduced if finer grain is needed down to 10 ms or so.
---------------
Here is explanation :
for(int i=0; i < 6; i++) {Sensor[i] = analogRead(i);
this is a loop that runs from 0 - 5 ( < 6 means smaller than 6)
and Sensor[i] (i is a count 0 - 5) reads Analog inputs A0 - A5 .
Then :
Serial.print(Sensor[i]); Serial.print(" "); } sends
6 values, each followed by space ( Serial.print(" "); )
and at the end
Serial.println(); ( line feed )
important thing is that line feed gets sent only after iteration 0 - 5
gets sent.
That's why this whole part is enclosed in { } brackets
--------
This could have been done in more readable form like:
Sensor1 = analogRead(A0);
Sensor2 = analogRead)A1);
and so on
Then one would
Serial.print(Sensor1); Serial.print(" "); (space in between)
Serial.print(Sensor2); Serial.print(" "); (space in between)
and so on...
at the end
Serial.println(Sensor5);
One and the same thing would be sent to serial port
in both versions, only with iteration 0 - 5 code gets smaller...
P.S.
If Your arduino allway appears as "port e"
You can initialise serial object:
serial e 115200
so it would not first try to connect to port a, and then reconnect to port e
Also devices can be opened for communication by name ...
One could talk for hours about this stuff ...
Thanks! it works