brainybrown86

Thank your for very much your reply. Unfortunately I am not completeley sure what you mean or whether your are right.Regarding the Matlab code:

Quote

fprintf(s, '%i',nr); fprintf(s, '%i',position);

I thought, that my code produces integers, because the first parameter (s) just specifies the serial port, whereas the second parameter specifies the format ('%i')? See the doc of the fprintf command. And this is also what seems happen, if you for instance just type

Quote

fprintf('%i',10);

Quote

fprintf('%i','any string');

into your console, thus sending the fprintf command to your console.What was probably wrong with my code was the third parameter, because here I handed over a string, instead of an integer (and this string was then transformed to a loooong integer). However, this fix does not solve the problem.The servos are still not responding.

Regarding the Arduino Code, I do not understand how I can specifically say Arduino that it shall read integers from the serial port and whether they will be unsigned or not Any Ideas, how I have to change the code in either Matlab or Arduino?

Here my slightly adapted codes that I have at the moment:Matlab

Quote

clear allclose alldelete(instrfind('Type', 'serial')); % Assure that no serial port is open anymore

brainybrown86

Hello,unfortunately, I'm still struggling with my real-time control of five servos via Matlab.I have now a code, that does move the servos in the expected manner and if I type in the required values into the Arduino serial monitor, it outputs the values in the right way. Thus, Matlab and Arduino at least seem to speak the same language now.

However my code only works, if I add up a lot of breaks into the Matlab code.

Here is the Matlab code:

Quote

% Commands:% 140 --> attach all servos and bring them to position 40% 000 --> detach all servos% xy --> move servo x to y (y must be an integer between 0 and 180)

clear allclose alldelete(instrfind('Type', 'serial')); % Assure that no serial port is open anymore

// Responds to the following commands:// 140 --> attach all servos and bring them to position 40// 000 --> detach all servos// xy --> move servo x (can be either 2,4,6,8,9 ) to y (y must be an integer between 0 and 180)

As I said, if I remove the pause statements in Matlab, either Matlab crashes or Arduino.Does anybody have an idea how I can improve my code so that I can remove the pause statements in Matlab (or reduce them to a minimum) and get it running more stable and in real-time. Do I need some pause statements in the Arduino code?Or do I have to use a different servo control functions?