Get Started with Motor Drives for Robotics Applications Using Arduino Hardware and Simulink
This example shows how to use Simulink® Support Package for Arduino® Hardware and a Arduino hardware board to get started with interfacing the motor drives for robotics applications.
Simulink Support Package for Arduino Hardware enables you to interface motor drives with Arduino hardware board for robotics applications. To provide regulated power supply and control the directionality, you need to use motor shields based on advanced chips such as L293D or PCA9685. These sheilds based on chips such as L293D or PCA9685 power the motors using an external power supply source and control the motors based on the signals from the Arduino.
This example shows you how to interface DC motors to Arduino through motor shields to control the power, speed, and direction of the motor for robotics applications.
To run this example, you will need the following hardware.
Arduino hardware board
Motor shields based on L293D or PCA9685 chip
Connect the DC motor to the Arduino hardware board through driver hardware. This example uses PCA9685 or the L293D chip based motor shields for the setup and you can use any driver hardware of your choice. In this example, one DC motor is connected to the Arduino hardware board through the PCA9685 or L293D chip based motor shield and then it is powered using batteries.
Connect the enable pin, input A and input B of the motor shield to GPIO pins of the Arduino hardware board. The enable pin must be connected to one of the supported PWM pins. For more information on pin mapping, refer to Pin Mapping for Arduino Timer Dependent Blocks.
The enable pins of the driver hardware control the speed of the motor and the input A and input B pins control direction of the motor. You can drive the motor forward or backward using these pins.
arduino_robotics_motors_gettingstarted Simulink model.
The model is divided into two areas based on the functionality in each area.
Motors driven by shield based on L293D chip
You can choose the Motors driven by the L293D shield subsystem and comment out the other if you choose to interface the DC motor with the Arduino through L293D chip based motor shield. You can use the L293D DC motor block for the L298 motor shield. The readily available L293D DC Motor block from the Simulink Support Package for Arduino Hardware is used in this model to represent the connection of the motor to the Arduino Hardware board.
Motors driven by shield based on PCA9685 chip
You can choose the PCA9685 based Motors subsystem and comment out the other if you choose to use interface the DC motor with the Arduino through PCA9685 chip based motor shield. You can use the PCA9685 DC motor block for the Arduino Motor Shield V2. The readily available PCA9685 DC Motor block from the Simulink Support Package for Arduino™ Hardware is used in this model to represent the connection of the motor to the Arduino Hardware board.
Run Simulink Model in Connected IO mode
You can run the model in connected IO mode where the model communicates with the hardware without any code generation in the hardware.
Follow these steps to run the Simulink model in connected IO mode.
1. Open arduino_robotics_motors_gettingstarted model.
2. On the Modeling tab of the model, click Model Settings. In the Configuration Parameters dialog box, click Hardware Implementation on the left pane and set the Hardware board parameter to Arduino.
3. On the Hardware tab of the model, in the Mode section, click Run with IO.
Run Model on Monitor & Tune Mode
On the Hardware tab of your Simulink model, click Monitor & Tune to run the model on the Arduino hardware board.
Other Things to Try
Try deploying the model on the Arduino hardware board by clicking Build, Deploy & Start in the Deploy section of the Hardware tab of your Simulink model.