Trigger midi note and/or sample. What is the best way?

benjamin vyger's icon

Hi,
To illustrate the movement of my artistic installation of 5 motors shifting from each other in several forms, that you can see here:
https://youtu.be/JnCD7ezMawk
I need to be guided to know:
From the position data of my 5 motors (from 0 to 360 °) coming from the Arduino:
Declare a midi note (C for example) when the data of each motor is equal to 0. At the beginning of position 0, 5 motors release the same note. The sounds are shifted in the same way that my engines are shifted.
Then, it should be able to trigger different midi notes (C, D,E,F,G for example) when the average position of each motor is equal to 180 °.

Finally, it would be necessary to be able to send these midi notes in Live to use virtual instruments of Ableton Live (synthesizer or / and sampler).

Thanks for all the solutions!

Source Audio's icon

depends on speed - reliability of motor positions
reported from Arduino.
Simplest thing would be to use select 0 180 on each of 5
unpack outlets and trigger whatever event when exact that numbers get received.
But there starts the above question ...
If You are only interested to trigger events on that 2 positions,
You could write arduino code that only reports that 2 positions.
I would first check if using select 0 180 works or not.
Any question about Live is not my cup of tea.

Soundwise, it would maybe be better to output
each motor's notes to different midi channels,
and so have option to use different sounds.

benjamin vyger's icon
Hi,
you're wright it depends on speed.
For the moment I just want to trig midi out when the position is 0.
But, when I move too quickly datas, the sound can not be trigged.
So, how can I trig sound each time my motor make a round?


Max Patch
Copy patch and select New From Clipboard in Max.



Source Audio's icon

Reduce data sent from arduino
You are sending data without any delay, and
also as int32.
You should at least make /2771 * 360 calculation in arduino sketch
and send only degrees 0 - 360 ( if You need to know
full rotation position)
If not put if statement in arduino to check when motor
sits at 0 degree, and send only that
to serial.
Also qmetro drops data if too much is received.
try using metro instead

benjamin vyger's icon

Hi,
I have converted positions of my motors in degrees like this in the setup of Arduino
int degreRotation (uint8_t moteur) {
return position[moteur] * (int)360/ int (2771);
}
I print data like this without delay otherwise I don't have enough actualised datas.

for(uint8_t i = 0; i < NBMOTEURS; i++) { Serial.print(degreRotation(i)); Serial.print(" ");
}
Serial.println();
//delay(1);
}
Here some data of Arduino
353 35 84 130 177
4 47 95 141 188
15 58 106 153 199
26 69 117 164 211
37 80 128 175 222
47 91 140 186 234
58 102 151 198 245
69 113 162 209 256
80 124 173 220 268
90 135 185 232 279
101 146 196 243 291
112 157 207 254 302
122 169 218 265 314
133 180 229 277 325
143 191 241 288 337
154 202 252 299 348
165 213 263 311 0
175 224 274 322 11
186 235 285 333 22
196 246 296 345 34
207 258 307 356 45
218 269 318 7 56
228 280 329 19 68
239 291 340 30 79
250 302 351 41 91
260 313 2 53 102
271 324 14 64 113
281 335 25 75 125
292 347 36 87 136
303 358 47 98 148
313 8 58 109 159
324 19 69 120 171
334 30 81 132 182
345 41 92 143 194
356 53 103 154 205
6 63 114 166 217

As you can datas of motor 1 go direct from 353° to 4 ° and the next round from 356° to 6 °
motor 2
go direct to 358° to 8 °....

So which test in Max would be great to trigger sound when motors make a round???

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

You have to capture more data from max output, and check
how much from flow 0 - 360 gets lost.
To start with, replace qmetro with metro,
and also reduce 10 ms to less, try 2 ms.
Also, If anything else gets sent from Arduino,
beside Serial.print(degreRotation(i));
remove it, I remember in the whole sketch You had also
other stuff sent to serial.
That might reduce lost values.
If all that still fails, one could try to use split
instead of select, and set range which is safe to detect
wished motor position.
Or do more work in arduino,
and create if statement for each motor position,
like if motor position = 0, send 1 to serial,
otherwise send 0.

benjamin vyger's icon

Hi,
I changed my program Arduino to send datas as you tell me.
I receive in Max 0 and 1and sounds are well trigged when it receive 0.
I show the of my program in order you tell me if there is better idea to send data when a motor make a round that add several range as I did!

if ((degreRotation(i)>345 && degreRotation(i)<361) || (degreRotation(i)>340 && degreRotation(i)<356) ||(degreRotation(i)>335 && degreRotation(i)<351) )


Thanks so much!!

for(uint8_t i = 0; i < NBMOTEURS; i++) { 

 //  Serial.print(int (position[i]/2771.0*360.0)); 
  //    Serial.print ( log (degreRotation(i)));
  //    Serial.print(" ");
      
   //   } 
      
   //   Serial.println(); 

     if ((degreRotation(i)>345 && degreRotation(i)<361) || (degreRotation(i)>340 && degreRotation(i)<356) ||(degreRotation(i)>335 && degreRotation(i)<351) ) { 

 // degreRotation(i)=0;
 degreTrigger[i]=0;  
}

      else

    //  degreTrigger[i]=!degreTrigger[i];
    degreTrigger[i]=1;

 Serial.print (degreTrigger[i]);
 Serial.print (" ");
      
      } 
      
      Serial.println(); 
     
} 
delay (50);
}
Source Audio's icon

More I look at the captured values, things become clearer.
10 ms qmetro of course outputs received data in 10 ms
interval, which explains progress between values per
motor which vary between 10 - 11 or 12.
Now depending on speed of the motors rotation,
one can say that 1 degree of rotation takes so many ms.
From that, You can figure out if You will ever be able to
receive exact position in full 360 degrees resolution.
Lets say motor takes 1 sec to make full rotation,
1000 / 360 = 2.777... ms per degree.
With high baud rate and metro 2
it should be possible to report full scale.
with 1 ms metro max allowed speed would be
360 ms or simply 1 ms - 1 degree.
More and more I think You should do that in Arduino.
Would also make max patch simpler.
It could look like this :
unsigned long degreRotation[6] = {0,0,0,0,0,0};
unsigned long MPos[6] = {0,0,0,0,0,0};

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

void loop() {for(uint8_t i = 0; i < 6; i++) { MPos[i] = degreRotation[i];
if (MPos[0] == 0) {Serial.print(0); }
if (MPos[1] == 0) {Serial.print(1); }
if (MPos[2] == 0) {Serial.print(2); }
if (MPos[3] == 0) {Serial.print(3); }
if (MPos[4] == 0) {Serial.print(4); }
}}

MPos would be variable for rotation position,
and if first motor (which is MPos[0]) is at position 0,
than 0 gets sent to serial.
So You send only motor's ID when it's position matches
set number.
when second motor ( MPos[1] ) is at it's set position, 1 gets sent to serial
and so on for remaining motors.
Only missing part from above sketch is reading degreeRotation
so You have to include that into loop.
In max all You need after serial object is itoa followed by fromsymbol
and select 0 1 2 3 4.
With that You can trigger whatever event You want.
And only 1 motor ID gets sent at a time, allowing much higher motor speeds.

Source Audio's icon

P.S.
You can also report several positions for each motor,
just add more if stuff and ID's, like
if (MPos[0] == 0) {Serial.print(0); } if (MPos[0] == 180) {Serial.print(1); }
if (MPos[1] == 0) {Serial.print(2); } if (MPos[1] == 180) {Serial.print(3); }

I think You get the idea

benjamin vyger's icon

Hi,
I changed the program in Arduino but I'm afraid that it doesn't change the problem.

for(uint8_t i = 0; i < NBMOTEURS; i++) {

degreRotation[i]=position[i]/2771.0*360.0;

// MPos[i] = degreRotation[i];

Serial.print ( degreRotation[i]);

Serial.print(" ");

}
Serial.println();

for(uint8_t i = 0; i < NBMOTEURS; i++) {

degreRotation[i]=position[i]/2771.0*360.0;

MPos[i] = degreRotation[i];

//if ((MPos[i] == 0)) {Serial.print(0);

if (MPos[0] == 0) {Serial.print(0); }
if (MPos[1] == 0) {Serial.print(1); }
if (MPos[2] == 0) {Serial.print(2); }
if (MPos[3] == 0) {Serial.print(3); }
if (MPos[4] == 0) {Serial.print(4); }

}
Serial.println();
}
}
I do not have at every moment the exact degree. Should the data be smoothed by averaging?

To do simpler, i improved the speed of the baud rate at 250000. I have those data with a step of ten.
I tried a baud of 500000 but the Serial monitor of Arduino send bugs. Datas are unreadable.

So what to do?

0 89 181 269 359 
00000
11 101 192 281 10 
22 112 203 292 22 
33 123 214 304 33 
44 134 225 315 45 
54 145 236 326 56 
65 156 247 337 68 
76 167 258 349 79 
87 179 269 0 91 
33
98 190 281 11 102 
333
109 201 292 22 113 
120 212 303 34 125 
131 223 314 45 136 
142 234 325 56 148 
153 245 336 68 159 
164 256 347 79 170 
175 267 358 90 182 
186 278 10 102 193 
197 289 21 113 205 
208 300 32 124 216 
219 311 43 136 228 
230 322 54 147 239 
241 334 65 158 250 
252 344 77 170 262 
263 355 88 181 273 
274 6 99 192 285 
285 17 110 203 296 
295 28 121 215 308 
306 40 132 226 319 
317 51 143 237 330 
328 62 154 249 342 
339 73 166 260 353 
350 84 176 271 5 
0 95 187 282 16 
00000
11 106 198 294 27
Source Audio's icon

I think You missed what I suggested.
If arduino is scanning motor position and detects when 1 motor
is at set position You SHOULD NOT send
Serial.print ( degreRotation[i]);

It is supposed to send ONLY 1 number at a time , indicating which
motor is at set position.
And don't print space or line feed, ONLY THIS :
for(uint8_t i = 0; i < NBMOTEURS; i++) {
degreRotation[i]=position[i]/2771.0*360.0; MPos[i] = degreRotation[i];
if (MPos[0] == 0) {Serial.print(0); }
if (MPos[1] == 0) {Serial.print(1); }
if (MPos[2] == 0) {Serial.print(2); }
if (MPos[3] == 0) {Serial.print(3); }
if (MPos[4] == 0) {Serial.print(4); }
-------------
In Max You don't get a list with 5 values, but only 1 value,
indicating motor number.
So remove zl group and unpack, insert select 0 1 2 3 4.

Source Audio's icon

And that /2771.0 * 360.0 ?
why 2771 ?
You have 2771 rotation steps ?
You need simple int 0 - 359, no float
to proprerly detect motor's position.
If You have 2771 steps of rotation,
than divide it by 2771 int and multiply by 360 int

benjamin vyger's icon

Yes I have 2771 tick / rotation.

But if I do that:
degreRotation[i]=int (position[i]/2771*359);
I have nothing in the Arduino's monitor.
So I have to write degreRotation[i]=int (position[i]/2771.0*359);

I did Serial.print ( degreRotation[i]); in order you can see the data in degree
and to see that 0,1,2,3,4 are not trigged at each rotation.

With your last program in Arduino I have this:

14:54:50.272 -> 4
14:54:50.297 -> 4444
14:54:50.331 -> 
14:54:50.364 -> 
14:54:50.399 -> 
14:54:50.433 -> 
14:54:50.467 -> 
14:54:50.501 -> 
14:54:50.535 -> 
14:54:50.571 -> 
14:54:50.605 -> 
14:54:50.641 -> 
14:54:50.675 -> 
14:54:50.712 -> 
14:54:50.749 -> 
14:54:50.782 -> 
14:54:50.821 -> 
14:54:50.849 -> 
14:54:50.888 -> 
14:54:50.922 -> 
14:54:50.955 -> 
14:54:50.993 -> 
14:54:51.032 -> 
14:54:51.060 -> 
14:54:51.098 -> 
14:54:51.137 -> 
14:54:51.165 -> 
14:54:51.204 -> 
14:54:51.246 -> 
14:54:51.280 -> 
14:54:51.314 -> 
14:54:51.353 -> 
14:54:51.381 -> 
14:54:51.423 -> 
14:54:51.456 -> 
14:54:51.489 -> 
14:54:51.529 -> 
14:54:51.567 -> 
14:54:51.596 -> 
14:54:51.635 -> 
14:54:51.669 -> 
14:54:51.702 -> 
14:54:51.741 -> 
14:54:51.785 -> 
14:54:51.819 -> 
14:54:51.852 -> 
14:54:51.892 -> 
14:54:51.892 -> 
14:54:51.951 -> 
14:54:51.987 -> 
14:54:52.025 -> 
14:54:52.059 -> 
14:54:52.092 -> 
14:54:52.126 -> 
14:54:52.160 -> 
14:54:52.197 -> 
14:54:52.234 -> 
14:54:52.267 -> 
14:54:52.306 -> 
14:54:52.346 -> 
14:54:52.346 -> 
14:54:52.408 -> 
14:54:52.445 -> 
14:54:52.478 -> 4
14:54:52.514 -> 4444
14:54:52.551 -> 
14:54:52.588 -> 
14:54:52.624 -> 
14:54:52.658 -> 
14:54:52.692 -> 
14:54:52.727 -> 
14:54:52.764 -> 
14:54:52.807 -> 
14:54:52.807 -> 
14:54:52.849 -> 
14:54:52.880 -> 
14:54:52.919 -> 
14:54:52.954 -> 
14:54:52.986 -> 
14:54:53.025 -> 
14:54:53.059 -> 
14:54:53.092 -> 00000
14:54:53.130 -> 
14:54:53.169 -> 
14:54:53.197 -> 
14:54:53.239 -> 
14:54:53.278 -> 
14:54:53.311 -> 
14:54:53.345 -> 
14:54:53.384 -> 
14:54:53.411 -> 
14:54:53.450 -> 
14:54:53.488 -> 
14:54:53.517 -> 
14:54:53.555 -> 
14:54:53.588 -> 
14:54:53.621 -> 
14:54:53.661 -> 
14:54:53.694 -> 
14:54:53.727 -> 
14:54:53.774 -> 
14:54:53.812 -> 
14:54:53.848 -> 
14:54:53.883 -> 
14:54:53.919 -> 
14:54:53.958 -> 
14:54:53.958 -> 
14:54:53.989 -> 
14:54:54.025 -> 
14:54:54.095 -> 1111
14:54:54.129 -> 1
14:54:54.129 -> 
14:54:54.165 -> 
14:54:54.203 -> 
14:54:54.239 -> 
14:54:54.271 -> 
14:54:54.307 -> 
14:54:54.342 -> 
14:54:54.378 -> 
14:54:54.413 -> 
14:54:54.451 -> 
14:54:54.481 -> 
14:54:54.520 -> 
14:54:54.554 -> 
14:54:54.588 -> 
14:54:54.628 -> 
14:54:54.662 -> 
14:54:54.696 -> 
14:54:54.735 -> 
14:54:54.783 -> 
14:54:54.814 -> 
14:54:54.848 -> 
14:54:54.887 -> 
14:54:54.915 -> 
14:54:54.956 -> 
14:54:54.990 -> 
14:54:55.024 -> 
14:54:55.062 -> 
14:54:55.095 -> 
14:54:55.131 -> 
14:54:55.171 -> 
14:54:55.204 -> 
14:54:55.239 -> 
14:54:55.281 -> 
14:54:55.320 -> 
14:54:55.336 -> 
14:54:55.375 -> 
14:54:55.419 -> 
14:54:55.453 -> 
14:54:55.487 -> 
14:54:55.522 -> 
14:54:55.554 -> 
14:54:55.593 -> 
14:54:55.628 -> 
14:54:55.662 -> 
14:54:55.700 -> 
14:54:55.741 -> 
14:54:55.741 -> 
14:54:55.778 -> 
14:54:55.812 -> 
14:54:55.851 -> 
14:54:55.886 -> 
14:54:55.919 -> 
14:54:55.959 -> 33
14:54:55.988 -> 333

Source Audio's icon

The thing is - I know nothing about the code You use to rotate the motors
and report their position.I also have no time or interest to look after that.
If arduino is not capable of detecting position within 360 steps, and report it,
than trouble must be somewhere else.
You could try to start from sketch, use only 1 motor, report it's
position in degrees and see if You can report when single motor crosses set position.
-----------
The code I posted :
void loop() {for(uint8_t i = 0; i < 6; i++) { MPos[i] = degreRotation[i];
if (MPos[0] == 0) {Serial.print(0); }
if (MPos[1] == 0) {Serial.print(1); }
if (MPos[2] == 0) {Serial.print(2); }
if (MPos[3] == 0) {Serial.print(3); }
if (MPos[4] == 0) {Serial.print(4); } }}

assumes that array, degreRotation[i]
scans 5 motor positions expressed in degrees, and
reports when any of the motors reaches set position.
That is the way it works.
You have to make sure that array degreRotation[i] gets wanted values within main loop using whatever functions.
EDIT :
The problem for me is that I dont know if snippets of code You send
are within main loop or not:
If :
degreRotation[i]=int (position[i]/2771.0*359);
is in main loop, than You don't need extra array - MPos,
You can use :
if (degreRotation[0] == 0) {Serial.print(0); }
if (degreRotation[1] == 0) {Serial.print(1); }
and so on

Source Audio's icon

Here is simplest test, using counter and reporting count hit maximum
over serial:

int count;

void setup()
{Serial.begin(115200); count=0; }

void loop()
{count=count+1;
delayMicroseconds(100);
if (count == 359) {    Serial.print(0); count =0;}
}

Timing is 36 ms per report ( 360 * 0.1 miliseconds )

benjamin vyger's icon

degreRotation[i]=int (position[i]/2771.0*359);
is on the main loop

Here the result of the test with 115200 bauds 
17:48:40.952 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.069 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.164 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.193 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.269 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.385 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.475 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.584 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.642 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.742 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.803 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.869 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:41.938 -> 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583591
17:48:42.075

I have 12 counts until 359 per second with 115200 and i
I have 24 counts until 359with 250000 bauds

What does it mean?

benjamin vyger's icon

How to trigger a '0' every time my engines go through the 0 degree?
How to do when the position captured goes from 355 direction at 6 ° for example?

Source Audio's icon

I am sorry, but I don't know what You are capturing and where You get this numbers.
If You used detection of position '0' of 5 motors, only numbers sent
could be 0 1 2 3 4 for 5 motors.
So where are higher numbers coming from ?

Source Audio's icon

I am not sure if all infos and suggestions from my side
really help You or do the opposite.
I tried to explain a bit what could be done to avoid
loss of information, sent over serial when very fast data capturing is involved.
One can in fact calculate more or less precisely what speed can be achieved,
and then set limits etc.
You need to make decisions about how many positions per motor
have to be detected and some events triggered in max,
multiplied by 5 for 5 motors.
------
Taking array path - means allways sending a string of 5 positions
which then Max needs to deal with, can work till speed of transmission
and polling of serial buffer gets to it's limits.
Disadvantage is that in such scenario one needs to send at least 11 bytes.
5 values, 5 spaces and new line at the end.
If one goes other path - arduino detects motor positions and reports only matching results,
much higher motor speeds can be achieved, because only 1 byte get's sent at a time.
-------
If You look at test I posted - a simple counter, progressing in 100 ms tempo
and reporting 359 (max count), You should have noticed that a single count
lasts 100 ms , and so gets reported many times, till count reaches next number in a loop.
Same way, You can expect that if You say:
report when 1 motor is at position 0, or position 100 or whatever,
that this number will be reported as many times, as speed of the loop,
serial transmission etc allow, and You will get maybe 2 maybe 20
reports in Max, for a single thing.
To prevent this , one needs to go step further, and
report matched value only once, similar as using change object in Max.
So You need to declare current state and previous state variable for same thing
and report only when current state is different from previous state = value changed.
Only so You have a real chance to get this under control at high speeds.
------------
In addition, arduino model, timers and libs used to control motors
can influence the speed of execution of main loop,
so all of that has to be taken into calculation for possible max
speed of detection and trigger events in Max.

I hope that this few infos can help You.

Source Audio's icon

Here is new tester showing one example of avoiding
reporting data several times :

int count; int EXcount;

void setup()
{Serial.begin(115200); count=0; EXcount = 0;}

void loop()
{count=count+1; delayMicroseconds(10);
if (count == 359 and count != EXcount)
{Serial.print(0); count = 0; count= EXcount; }
}


--------
Now the speed is higher - 0.01 ms
means the whole loop is 3.6 ms long