How to add arudino libraries to matlab
5 views (last 30 days)
Show older comments
a = arduino();
s = servo(a,'D6');
lib = listArduinoLibraries()

Hello!
Now I have [Matlab support package for arduino hardware 21.2.1]
It is installed and there are 11 libraries as shown in the picture above.
I want to use MATLAB to control the angle of the servo motor. Therefore, I want to put "VarSpeedServo.h" into Matlab, but I don't know how to include it.
What I was able to do
1.Angular speed control using "VarSpeedServo.h" with arduino software only (without using MATLAB)
2. Checked simple operation using [Servo] in MATLAB.
Operation confirmed
clear a s
a = arduino('com5', 'Uno', 'Libraries', 'Servo');
s = servo(a, 'D6');
Base_angle = 90;
Min_angle = -30;
Max_angle = 30;
for angle = Min_angle:10:Max_angle
Wangle = (angle+Base_angle)/180;
writePosition(s, Wangle);
current_pos = readPosition(s);
current_pos = current_pos*180;
fprintf('Current motor position is %d degrees\n', current_pos);
pause(1);
end
Wangle = (Base_angle)/180;
writePosition(s, Wangle);
If anyone can help me understand, I'd appreciate it if you could let me know.
I'm glad it's simple grammar!
0 Comments
Accepted Answer
Image Analyst
on 8 Oct 2022
It's hard without us having your servo hardware, but why can't you make the arduino code "VarSpeedServo.h" into a MATLAB function and then call it from your main script (which is something like in your step 2)?
2 Comments
Image Analyst
on 9 Oct 2022
Yeah sorry but my only experience with arduino and MATLAB was a very limited amount many years ago. Call tech support.
More Answers (0)
See Also
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!