This package contains motor driver blocks for 3 Arduino Motor Shields:
1) Adafruit Motor Shield V1.x (DC and Stepper motor drivers)
2) Adafruit Motor Shield V2 (DC and Stepper motor drivers)
3) Arduino Motor Shield R3 (DC motor drivers for ports A and B)
Refer to the readme.txt file for more details and make sure you read AFMotorV2.pdf before using the Adafruit Motor Shield V2.
Giampiero Campa (2021). Motor Shields (https://www.mathworks.com/matlabcentral/fileexchange/46133-motor-shields), MATLAB Central File Exchange. Retrieved .
Inspired by: Device Drivers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
tried on 2019a
How is it possible to run 2 stepper motors on afmotorv1.mdl?
I have been unable to change the mask parameter setting.
Also the code runs repeatedly. I would like to run it only once.
Don't compatible with R2017b.....
@Franky, resetting the hardware board worked for me, and I think the reason this step was needed is that the AFMotor2Setup.m function overwrites the post gen command configuration parameter, and resetting the board fixes that. I was able to deploy a model without the setArduinoDefn post code gen function, which makes me wonder if it's needed for R2017b?
Hello! I cant understand what you mean by< Folder path where Motorshield_2016 is present>. I keep having an error saying matlab cant fina a file called Wire
Thank you for this very nice package.
For use under Matlab 2016b, you will have to follow the following step:
1. Open afmotor_v2.mdl.
2. Go to Configuration Parameters --> Hardware Implementation.
3. Select any hardware board other than the board you are trying to Program
For Example, select Arduino Mega ADK.
Then reselect the board you are trying to program.
For example, select "Arduino Uno" board.
4. Click "Apply".
5. Execute the below commands in MATLAB command line:
modelName = 'afmotor_v2';
set_param(modelName, 'CustomInclude', '<Folder path where Motorshield_2016 is present>\Motorshield_2016\Motorshield_2016;<Folder path where Motorshield_2016 is present>\Motorshield_2016\Motorshield_2016\utility')
set_param(modelName, 'CustomSource', 'Wire.cpp twi.c Adafruit_PWMServoDriver.cpp Adafruit_MotorShield.cpp');
Please make sure you replace text "<Folder path where Motorshield_2016 is present>" with your absolute folder path in the above commands.
Thank you to Pradeep Karikere Siddagangaiah from Matlab in India for his help in this matter.
I have bundled this in some Matlab code that you can put in a script. Just change the name of the directory for your application.
% 1. Open afmotor_v2.mdl.
% 2. Go to Configuration Parameters --> Hardware Implementation.
% 3. Select any hardware board other than the board you are trying to Program
% For Example, select Arduino Mega ADK.
% Then reselect the board you are trying to program.
% For example, select "Arduino Uno" board.
% 4. Click "Apply".
% 5. Execute the below commands in MATLAB command line:
modelName = 'afmotor_v2';
Directory = 'C:\Users\dbr.ECAM\Documents\Ecam\Matlab\Arduino_Matlab\Matlab_2016\Motorshield';
Dir1 = [Directory '\Motorshield_2016\Motorshield_2016'];
Dir2 = [Directory '\Motorshield_2016\Motorshield_2016\utility'];
Dir12 = [Dir1 ';' Dir2];
set_param(modelName, 'CustomInclude', Dir12)
set_param(modelName, 'CustomSource', 'Wire.cpp twi.c Adafruit_PWMServoDriver.cpp Adafruit_MotorShield.cpp');
I hope this is helpful.
Franky De Bruyne