I'm building a robot-arm with 4 dc motors and two arduino usb boards (duemilanove). I can control two and two motors on each arduino with for example tera term but I need to control and calculate the motors together to get a robot arm.

I know matlab can communicate with several serial ports (COM) on hardware like:

s = serial('COM1');fopen(s)

but I dont know how to communicate and control the digital pins on the arduinos with matlab. Especially if I allready have some setup-code in the arduino processing language and only want to control the motors together from a more high-level programming/script language.

I have used the arduino processing language to control the motors until now that I need a more complex algorithm to control all the 4 motors together in an arm.

I know about the arduinoTarget scripts for matlab but I had some problems with the installationscript and it looked like the scripts only was for one arduino at the time.

I'm open for suggestions on other software to use for this purpuse but I think matlab is pretty good on calculations as well when I have to calculate the forward and inversekinematics for the robotic arm.

The easiset way is to write a program for the Arduino that listens for commands over the Serial port. When the Arduino receives the correct commands, it should move motors in your arm accordingly. Once that works. you can use MATLAB (or any other language) to send these commands over the Serial port.

I now know how to send simple data fram matlab to arduino but the problem now is that I don't know how to separate the commands/strings from matlab in arduino. i. e.

Matlab:s1 = serial('COM3', 'BaudRate', 9600, 'Parity', 'none', 'DataBits', ;fopen(s1);fprintf(s1, 'Hello World!') - or if I'm going to control 4 motors:fprintf(s1, 100(motorspeed), 1(as in motor no. 1), 0(as in direction 1 of 2 on motor 1)) and perhapsfscanf(s1) - if I'm going to read something from the arduino back to matlab

In Arduino - I know the setup() and loop() methods, this is just some of the code:char info; if(Serial.available()) { info = Serial.read(); } Serial.println('I want to send something back to matlab');

I can for instance send the char '8' from matlab to arduino and let the motors run when char info detects the char '8' but that solves nothing because then all my motors will run and I will not be able to control them separately. I'm thinking on splitting the string I get from matlab and separate the words/integers to each motor but I don't know if it's possible yet.

switch(byteRead){ case 'S': // read until you find a ; // if not a : // speed *= 10; // speed += byte - '0'; break; case 'M': // similar logic for motor, except // you probably will not have 10 or more // motors, so you could just expect one byte break; case 'D': // similar logic for direction break;}

After the switch block ends, do something with the values in speed, direction, and motor.