How to control DC motor with Elegoo mega2560 board and adafruit motorshield V1?

2 次查看(过去 30 天)
Hello,
I just bought an Elegoo Mega2560 board and an Adafruit motorshield V1. I need to control a DC motor, and I did a code like below. The code ran fine and said that the motor is running, but my motor is not running at all. Could anybody please help?
%% Create shield object
% Create an arduino object & include the Adafruit\MotorShieldV2 library to the hardware
a = arduino('COM3','MEGA2560','Libraries','Adafruit\MotorShieldV2')
% Create an add-on shield object by specifying the required library name parameter
shield = addon(a,'Adafruit\MotorShieldV2')
% Create a DC motor object at port 3
dcm3 = dcmotor(shield,3)
start(dcm3)
dcm3.Speed = 0.3 % Set the motor speed to 0.3
pause(2)
stop(dcm3)
clear dcm shield a

回答(1 个)

Prateek
Prateek 2022-11-22
Hi Hannah,
The code shared by you is for Adafruit Motorshield V2 but it seems you’re using Adafruit Motorshield V1. Please note that the V1 has been discontinued for a while and hence not supported by MATLAB.
In case you want to use V1 only, here is a link with instructions on how to create custom support for hardware: Create Custom Arduino Add-On Device, Library, or Code - MATLAB & Simulink - MathWorks India
Hope this helps.
Regards,
Prateek

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by