Difference between revisions of "ARDUINO MEGA Functions Motors and Servos"
(Created page with "<yambe:breadcrumb>ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb> <br /> {| |- |''For more examples and explanations, head over to [[VEX2_Moto...") |
|||
(10 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | <yambe:breadcrumb>ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb> | + | {{DISPLAYTITLE:2560 (MEGA) Motor and Servo Functions}} |
+ | <yambe:breadcrumb self="2560 (MEGA) Motor and Servo">ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb> | ||
<br /> | <br /> | ||
− | + | The Arduino MEGA has 12 ports available for PWM generation. These ports can be used control motors and servos to extend the capabilities of your Arduino system. Users can use the "Motors and Sensor Setup" utility (found under the Robot menu) to configure their ports for the various types of motors: | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | '''''Hardware Timing Servo Ports''' - Pin 2, 3, 5, 6, 7, 8, 11, 12 and 13.'' | |
− | + | ||
− | + | '''''Hardware Timing PWM (H-Bridge Friendly) Ports''' - Pin 4, 9 and 10.'' | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | [[File:ArduinoMegaMotorsSensorsSetup.png]] | |
− | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | + | |
+ | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;" width="100%" cellpadding="5%" cellspacing="0" border="0" class="wikiText" | ||
|- | |- | ||
− | + | |<span class="keywordB" id="dataType_TBaudRate">Available Motor Types</span> | |
− | + | {| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:center; font-size:100%; border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000;" cellpadding="5%" | |
− | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align: | + | ! style="text-align:left; border-style: solid; border-width: 0px 0px 1px 0px"|''Motor Type'' |
− | + | ! style="text-align:left; border-style: solid; border-width: 0px 0px 1px 0px"|Comments | |
− | + | ! style="text-align:left; border-style: solid; border-width: 0px 0px 1px 0px"| | |
− | + | ||
− | ! | + | |
− | ! | + | |
− | ! | + | |
|- | |- | ||
− | | style="border-style: solid; border-width: 1px 0px | + | | style="text-align:left; border-style: solid; border-width: 1px 0px 1px 0px"|'''No Servo/Motor''' |
− | | style=" | + | | style="text-align:right; border-style: solid; border-width: 1px 0px 1px 0px"|Generate no PWM from this pin. |
− | + | ||
|- | |- | ||
− | | | + | | style="text-align:left; border-style: solid; border-width: 0px 0px 1px 0px"|'''Audio Speaker''' |
− | + | | style="text-align:right; border-style: solid; border-width: 0px 0px 1px 0px"|Use this Pin to generate Audio output (piezo-electric speaker compatible) | |
− | + | ||
− | + | ||
|- | |- | ||
− | | | + | | style="text-align:left; border-style: solid; border-width: 0px 0px 1px 0px"|'''Servo - Standard''' |
− | + | | style="text-align:right; border-style: solid; border-width: 0px 0px 1px 0px"|Generate a 20ms-based Servo Pulse | |
− | + | ||
− | + | ||
|- | |- | ||
− | + | | style="text-align:left; border-style: solid; border-width: 0px 0px 1px 0px"|'''Servo - Cont. Rotation''' | |
− | + | | style="text-align:right; border-style: solid; border-width: 0px 0px 1px 0px"|Generate a 20ms-based Continuous Rotation Servo Pulse | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
− | | style="border-style: solid; border-width: | + | | style="text-align:left; border-style: solid; border-width: 0px 0px 1px 0px"|'''Ext-HBridge - Single PWM''' |
− | | style=" | + | | style="text-align:right; border-style: solid; border-width: 0px 0px 1px 0px"|Generates a standard PWM pulse and associates a second digital out pin to control the direction. Used for HBridges that have High/Low direction control. |
− | + | ||
|- | |- | ||
− | | style="border-style: solid; border-width: 0px 0px | + | | style="text-align:left; border-style: solid; border-width: 0px 0px 1px 0px"|'''Ext-HBridge - Dual PWM''' |
− | | style=" | + | | style="text-align:right; border-style: solid; border-width: 0px 0px 1px 0px"|Generates a standard PWM pulse on two pins for speed and direction control. Used for HBridges that have PWM based direction control. |
− | + | ||
|- | |- | ||
− | | | + | | style="text-align:left; border-style: solid; border-width: 0px 0px 1px 0px"|'''Variable Intensity LED''' |
− | + | | style="text-align:right; border-style: solid; border-width: 0px 0px 1px 0px"|Generates a standard PWM pulse on a single pin for brightness control of a LED. | |
− | + | ||
− | + | ||
|- | |- | ||
− | | | + | | style="text-align:left; border-style: solid; border-width: 0px 0px 0px 0px"|'''Analog Write''' |
− | + | | style="text-align:right; border-style: solid; border-width: 0px 0px 0px 0px"|Generates a standard PWM pulse on a single pin for analog output. | |
− | + | ||
|- | |- | ||
|} | |} | ||
− | |||
|} | |} | ||
<br /> | <br /> | ||
− | == | + | {{tl|1|1}} |
+ | <br /> | ||
+ | |||
+ | == bMotorReflected == | ||
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
− | | class="variableType"| <span class="bigKeywordBI"> | + | | class="variableType"| <span class="bigKeywordBI">bool </span><span class="bigKeywordB">bMotorReflected</span>''' |
|- | |- | ||
− | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types# | + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_bool|bool]]) Boolean array with one entry for each motor. Indicates that the direction of a motor should be reflected 180 degrees. Useful when mechanical design results in a logical "reversed" condition of a motor. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| | | | ||
Line 125: | Line 61: | ||
|- | |- | ||
|<syntaxhighlight lang="robotc"> | |<syntaxhighlight lang="robotc"> | ||
− | + | bMotorReflected[motor_2] = true; // motor 1 WILL be reflected 180 degrees | |
− | + | bMotorReflected[motor_2] = false; // motor 1 will NOT be reflected 180 degrees | |
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
Line 134: | Line 70: | ||
<br /> | <br /> | ||
− | == | + | == motor == |
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | {| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0" | ||
|- | |- | ||
− | | class="variableType"| <span class="bigKeywordBI"> | + | | class="variableType"| <span class="bigKeywordBI">int </span><span class="bigKeywordB">motor</span><span class="bigCodePunc">[</span><span class="bigCodeBasic">tMotor motor</span><span class="bigCodePunc">]</span> |
|- | |- | ||
− | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types# | + | | style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_int|int]]) An array variable with one element for each of the possible motors. |
+ | |||
+ | When used with a motor, this command is used to set the speed (-127 to +127) for a motor. Negative values are reverse; positive forward. Zero is stopped. | ||
+ | |||
+ | When used with a servo, this command is used to set the position (-127 to +127) of the servo. Zero is the "center" position of the servo, and -127 to +127 is the range of the servo. Note that your servo may not be able to travel the full -127 to +127 range, so please experiment with smaller values to avoid breaking your servo. | ||
|- | |- | ||
| | | | ||
Line 157: | Line 97: | ||
|- | |- | ||
|<syntaxhighlight lang="robotc"> | |<syntaxhighlight lang="robotc"> | ||
− | + | motor[motor_2] = 127; // motor pin 2 is given a power level of 127 (forward) | |
+ | motor[motor_2] = -127; // motor pin 2 is given a power level of -127 (reverse) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- |
Latest revision as of 20:53, 11 May 2012
The Arduino MEGA has 12 ports available for PWM generation. These ports can be used control motors and servos to extend the capabilities of your Arduino system. Users can use the "Motors and Sensor Setup" utility (found under the Robot menu) to configure their ports for the various types of motors:
Hardware Timing Servo Ports - Pin 2, 3, 5, 6, 7, 8, 11, 12 and 13.
Hardware Timing PWM (H-Bridge Friendly) Ports - Pin 4, 9 and 10.
Available Motor Types
|
Contents |
|
bMotorReflected
bool bMotorReflected | |
(bool) Boolean array with one entry for each motor. Indicates that the direction of a motor should be reflected 180 degrees. Useful when mechanical design results in a logical "reversed" condition of a motor. | |
|
motor
int motor[tMotor motor] | ||||||
(int) An array variable with one element for each of the possible motors.
When used with a motor, this command is used to set the speed (-127 to +127) for a motor. Negative values are reverse; positive forward. Zero is stopped. When used with a servo, this command is used to set the position (-127 to +127) of the servo. Zero is the "center" position of the servo, and -127 to +127 is the range of the servo. Note that your servo may not be able to travel the full -127 to +127 range, so please experiment with smaller values to avoid breaking your servo. | ||||||
| ||||||
|