i'm doing a project involving interfacing matlab and arduino and control servo motors as output.
my project is to drive a robotic arm consist of several motors. At the mean time, i'm trying to drive the servo motor one by one. I can't seems to drive any of them to the desired positions. I need help on this matter.
i have upload adiosrv file into arduino and run arduino.m in matlab. I have used a.servoAttach(1) command but it still does not work. when i attach my servo to pin 10 and get the reading of servo using a.servoRead(1), it gives me random number within the range of 0 -180. FYI, i did not use motor shield in this case, because i need to drive more than 2 servos.
then i use the pulse width modulation config which i have learn in my uni, however, its still does not work.
the following MATLAB code is to drive the servo to reach a 90 degree position and hold it, however it will just rotate to the maximum degree.
%% Start connection with Arduino
clc
clear
a = arduino('Com3');
%% Set your pin # here
%Configure output pins
a.pinMode(9,'Output'); %testing with servo
%configure input pins
a.pinMode(3,'Input'); %switch1
a.pinMode(4,'Input'); %switch2
sw1 = a.digitalRead(3);
sw2 = a.digitalRead(4);
%% Type your command here
while(1)
sw1 = a.digitalRead(3);
sw2 = a.digitalRead(4);
if (sw1==1)
a.digitalWrite(9,1);
pauser(0.0015);
a.digitalWrite(9,0);
pauser(0.0185);
elseif (sw2==1)
break;
end
end
display('done')
%% extra
sw1status = a.digitalRead(3)
sw2status = a.digitalRead(4)
the pauser command is just to make sure it can give a delay which is less than 10 miliseconds. Based on my servo motor that i'm using (http://www.cytron.com.my/viewProduct.php?pid=CCQ1Nhg5Gg8OCBYwEg0fCe5erqikGAdVlLw7bgmtzC0=), the pulse that i need to provide to give a 90 degree position is 1.5ms where this data can be found in this pdf file (http://www.cytron.com.my/usr_attachment/RC_Servo_User_Manual.pdf)
hope you can help me out. Thanks