Introduction: Adafruit Motor Shield Use
Hello friends,I mention robotic applications in motor drive, one of the most widely used card adafruit L293d company that developed the integrated bar from Adafruit motor shield motor driver card. The main reason for the preference because of the connection can be installed on the arduino is provided in a practical way. First, the library board to look at the overall structure of the pin and then use the card and I'll explain the meaning of the function. Using the library card is also a great advantage in terms of software.
Step 1: Adafruit Motor Shield Overview
The nature of the way we look at Pins 4 dc motor as can be seen, 2 servo motors and 2 stepper motors can take.That is just not designed to drive DC motors. This aspect is also advantageous. arduino we wear the pins on the Arduino UNO is closed no matter where in addition we need to get out of the arduino has additional pins on the shield. So these pins are used as normal arduino pins. As to be seen in figure analog 0 to 5 and digital 0 to 13 contain additional pins. Furthermore, the supply pins are given a separate output. These models are no pins in addition defined as the change in some shield. In this case, you can get the same output pin to an additional cable while installing the shield i pins. It has a working voltage between 5-12v. Each channel provides 600 mAh flow.
Step 2: Adafruit Shield Library
As is known, this card uses the library.You can download the library here >> AFmotor Library dowland
Library to call #include <AFMotor.h> or call the library Add menu.
Step 3: DC Motor Control Functions:
- AF_DCMotor : This function is performed by the DC motor description.
There are two issues in driving dc motor. First channel number, and the second is the PWM frequency.
Frequency identification for of 1 and 2 channel ;
MOTOR12_1KHZ >> 1khz frequency
MOTOR12_2KHZ >> 2khz frequency
MOTOR12_8KHZ >>8khz frequency
MOTOR12_64KHZ >> 64khz frequency
Frequency identification for of 3 and 4 channel ;
MOTOR34_1KHZ >> 1khz frequency
MOTOR34_8KHZ >>8khz frequency
MOTOR34_64KHZ >> 64khz frequency
There are two ways you can make the engine definitions.
AF_DCMotor motor1(1);Here, It returns the number of channel numbers in parentheses. Outside the "motor1" if the definition is the name we assign the number 1 channel. In this way we define a default frequency value as we enter the PWM frequency will be defined as 1kHz.
AF_DCMotor left_motor(1, MOTOR12_64KHZ); Here, we describe the channel 1 again. Channel name "left_motor" as we have defined.We entered in this frequency identification değerimizi. the first portion of the channel name in parentheses is our frequency value and the second part.
- If you choose High frequency less revenue from motor humming but decrease the torque of the motor.
Speed Function of Engine:
- "setSpeed" Function >> With this function, you can set the engine speed from 0 to 255 values.
- motor1.setSpeed(180); >> In this way the "motor1" We have set the pace with which we enter values in parentheses is the engine channels.
Motion Function of Engine:
- "Run" function: This function back and forth and the stopping process of the engine occurs.
Direction processing functions are provided with English terms.
- FORWARD - forward
- BACKWARD - back
- RELEASE - stop
- motor1.run(FORWARD); >> In this way the "motor1" has been set to the forward direction of the motor is channel.
motor.run(BACKWARDS); // Go back
motor.run(RELEASE); // Stop
Step 4: Stepper Motor Control Functions
Two stepper motors can take. 1 and 2 with a first step, the second step 3rd and 4th channel engine allows us to control.
- AF_Stepper: This function makes the definition of stepper motor.
- AF stepper motor_name (step, channel number) >> This function is a general description of the structure of the stepper motor.
- AF_Stepper >> It calls the stepper motor function
- motor_name >> This section is the name you give to your stepper motor.
- step >> The number of steps of a stepper motor speed is entered in this section.
- channel number) >> Stepper motors In this section we want to connect to that channel which channel number is entered.So the left side right side was 2 channel 1 channel. We must enter 1 or 2.
- Sample identification: AF_Stepper Stepper1(200, 1); >> With this definition of "Stepper1" called the 200 steps of the stepper motor information 1 indicates that the defined channel
- step >> Here few steps back to the engine information is entered.
- direction >>The motor direction of rotation is entered here. Aspect functions "FORWARD" and "BACKWARD" is defined as.
- mode >> Here the movement of the stepper motor type is entered. These;
- SINGLE : It operates the motor with energizing a coil. Power saving is useful in places that require but is not very common. It gives less torque motor.
- DOUBLE: Run the motor with energizing the two coils. Engine gives full torque.
- INTERLEAVE : Coil simultaneously to reduce by half the pitch angle, giving energy.This results in increased resolution and doubles the number of steps. For example, step 200 engine with 1.8 degrees, 0.9 degrees 400 steps, this function takes the value.
- MICROSTEP:Smooth motor for driving. Commonly used functions. It provides a smooth transition between steps. But decreases torque.
- Example function: Stepper1.setSpeed(10); >> In this way, "Stepper1" We define value is the speed of the engine.
- Example function: Stepper1.onestep(FORWARD, DOUBLE); >> In this way "Stepper1" is the direction of the engine and advanced mode "DOUBLE" We specify.
- Example function: Stepper1.release(); >> In this way, "Stepper1" the engine is stops.
Step 5: Servo Motor Control
Drive over 2 servo input located on.The driver to drive the servo does not have its own library functions. You can control servos using the normal servo library. Servo1 entry by arduino digital pins on the 9th,Servo2 is connected to the input pins by the arduino's 10.dijital. Whether the user's convenience it made 2 servo input.
- servo1.attach(10); or servo1.attach(9); >> You can introduce a servo motor to this entry.