L298N Stepper Motor Driver Controller Board for Arduino: Difference between revisions
Jump to navigation
Jump to search
(→Liens) |
No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Image:Motor-driver-controller-board-for-arduino-120542.jpg|thumb|right|300px|Motor Driver Controller Board for Arduino SKU 120542]] |
[[Image:Motor-driver-controller-board-for-arduino-120542.jpg|thumb|right|300px|Motor Driver Controller Board for Arduino SKU 120542 driving one High Torque 30RPM 12V DC Geared Motor (SKU 91627) with a Mystery 11.1V 2200mAh Lithium Polymer Rechargeable Battery (SKU 46058)]] |
||
[[Image:WildTrumper_arduino_120542.jpg|thumb|right|300px|Motor Driver Controller Board for Arduino SKU 120542 driving Wild Trumper]] |
|||
[[Image:LynxMotion_A4WD1_arduino_120542.jpg|thumb|right|300px|Motor Driver Controller Board for Arduino SKU 120542 driving driving Robotic Base LynxMotion A4WD1]] |
|||
[[Image:LynxMotionA4WD1c.jpg|300px|thumb|right|Base robot LynxMotion A4WD1]] |
|||
[[Image:Robair_configuration1-photo1.jpg|300px|thumb|right|Configuration 1]] |
|||
Line 10: | Line 18: | ||
<pre> |
<pre> |
||
ENA : Commande PWM du moteur A |
|||
ENA : ?? |
|||
IN1 : Entrée de commande de sens du pont A |
|||
IN1 : ?? |
|||
IN2 : Entrée de commande de sens du pont A |
|||
IN2 : ?? |
|||
IN3 : Entrée de commande de sens du pont B |
|||
IN3 : ?? |
|||
IN4 : Entrée de commande de sens du pont B |
|||
IN4 : ?? |
|||
ENB : Commande PWM du moteur B |
|||
ENB : ?? |
|||
GND : |
GND : Masse |
||
+5V : |
+5V : Sortie régulée en 5V |
||
</pre> |
</pre> |
||
==Programme de test== |
|||
Code de test d'après http://mchobby.be/wiki/index.php?title=Pont-H_L298N |
Code de test d'après http://mchobby.be/wiki/index.php?title=Pont-H_L298N |
||
<pre> |
<pre> |
||
// from http://mchobby.be/wiki/index.php?title=Pont-H_L298N |
|||
//-- MOTEUR A -- |
//-- MOTEUR A -- |
||
int ENA=5; //Connecté à Arduino pin 5(sortie pwm) |
int ENA=5; //Connecté à Arduino pin 5(sortie pwm) |
||
Line 33: | Line 44: | ||
int IN3=4; //Connecté à Arduino pin 4 |
int IN3=4; //Connecté à Arduino pin 4 |
||
int IN4=7; //Connecté à Arduino pin 7 |
int IN4=7; //Connecté à Arduino pin 7 |
||
int curDirA=0; // 1=forward, -1=reverse |
|||
int curSpeedA=0; |
|||
int curDirB=0; // 1=forward, -1=reverse |
|||
int curSpeedB=0; |
|||
int batteryLevel; |
|||
int batteryNominalLevel=111; // 11.1V with Mystery 11.1V 2200mAh Lithium Polymer Rechargeable Battery (SKU 46058) |
|||
int MAX_SPEED=200; |
|||
int curAccelerationStep=32; |
|||
void setup() { |
void setup() { |
||
configAB(); |
|||
pinMode(ENA,OUTPUT);//Configurer les broches comme sortie |
|||
} |
|||
void loop() { |
|||
int i; |
|||
stopAB(); |
|||
delay(1000); |
|||
forwardA(); |
|||
reverseB(); |
|||
for(i=0; i<255; i+=32) { |
|||
speedA(i); |
|||
speedB(i); |
|||
delay(500); |
|||
} |
|||
delay(5000); |
|||
for(i=255; i>0; i-=32) { |
|||
speedA(i); |
|||
speedB(i); |
|||
delay(500); |
|||
} |
|||
stopAB(); |
|||
delay(1000); |
|||
forwardB(); |
|||
reverseA(); |
|||
for(i=0; i<255; i+=32) { |
|||
speedA(i); |
|||
speedB(i); |
|||
delay(500); |
|||
} |
|||
delay(5000); |
|||
for(i=255; i>0; i-=32) { |
|||
speedA(i); |
|||
speedB(i); |
|||
delay(500); |
|||
} |
|||
} |
|||
void configAB() { |
|||
pinMode(ENA,OUTPUT); |
|||
pinMode(ENB,OUTPUT); |
pinMode(ENB,OUTPUT); |
||
pinMode(IN1,OUTPUT); |
pinMode(IN1,OUTPUT); |
||
Line 41: | Line 100: | ||
pinMode(IN3,OUTPUT); |
pinMode(IN3,OUTPUT); |
||
pinMode(IN4,OUTPUT); |
pinMode(IN4,OUTPUT); |
||
} |
|||
digitalWrite(ENA,LOW);// Moteur A - Ne pas tourner (désactivation moteur) |
|||
digitalWrite(ENB,LOW);// Moteur B - Ne pas tourner (désactivation moteur) |
|||
void stopA() { |
|||
// Direction du Moteur A |
|||
digitalWrite(ENA,LOW);// Moteur A - Ne pas tourner (désactivation moteur) |
|||
} |
|||
void stopB() { |
|||
digitalWrite(ENB,LOW);// Moteur B - Ne pas tourner (désactivation moteur) |
|||
} |
|||
void stopAB() { |
|||
stopA(); |
|||
stopB(); |
|||
//delay(??); |
|||
} |
|||
void forwardA() { |
|||
if(curDirA==1) return; |
|||
stopA(); |
|||
curDirA=1; |
|||
digitalWrite(IN1,LOW); |
digitalWrite(IN1,LOW); |
||
digitalWrite(IN2,HIGH); |
digitalWrite(IN2,HIGH); |
||
} |
|||
void reverseA() { |
|||
if(curDirA==-1) return; |
|||
stopA(); |
|||
curDirA=-1; |
|||
digitalWrite(IN1,HIGH); |
|||
digitalWrite(IN2,LOW); |
|||
} |
|||
void forwardB() { |
|||
if(curDirB==1) return; |
|||
stopB(); |
|||
curDirB=1; |
|||
digitalWrite(IN3,LOW); |
|||
digitalWrite(IN4,HIGH); |
|||
} |
|||
void reverseB() { |
|||
// Direction du Moteur B |
|||
if(curDirB==-1) return; |
|||
// NB: en sens inverse du moteur A |
|||
digitalWrite(IN3,HIGH); |
|||
stopB(); |
|||
curDirB=-1; |
|||
digitalWrite(IN3,HIGH); |
|||
digitalWrite(IN4,LOW); |
digitalWrite(IN4,LOW); |
||
} |
} |
||
void |
void speedA(int speed) { |
||
if(curDirA==0) return; |
|||
// Moteur A - Plein régime |
|||
curSpeedA=(speed>=MAX_SPEED)?MAX_SPEED:speed; |
|||
analogWrite(ENA,255); |
|||
analogWrite(ENA,curSpeedA); |
|||
} |
|||
void speedB(int speed) { |
|||
// Moteur B - Mi-régime |
|||
if(curDirB==0) return; |
|||
analogWrite(ENB,128); |
|||
curSpeedB=(speed>=MAX_SPEED)?MAX_SPEED:speed; |
|||
analogWrite(ENB,curSpeedB); |
|||
} |
} |
||
</pre> |
|||
void speedAB(int speed) { |
|||
speedA(speed); |
|||
speedB(speed); |
|||
} |
|||
void rotate() { |
|||
forwardA(); |
|||
reverseB(); |
|||
} |
|||
void antirotate() { |
|||
forwardB(); |
|||
reverseA(); |
|||
} |
|||
</pre> |
|||
==Pilotage via le moniteur série de l'IDE Arduino== |
==Pilotage via le moniteur série de l'IDE Arduino== |
||
Line 76: | Line 194: | ||
* 4 |
* 4 |
||
* 5 |
* 5 |
||
* |
|||
<pre> |
|||
</pre> |
|||
==Test== |
|||
* [http://dx.com/p/high-torque-30rpm-12v-dc-geared-motor-91627 High Torque 30RPM 12V DC Geared Motor (SKU 91627)] (works fine) |
|||
* [[Base robot LynxMotion A4WD1 Aluminium]] (works fine) |
|||
* [[Wild Thumper]] (not enough powerful) |
|||
==Projets @ AIR== |
|||
* [[RobAIR 2013 Configuration 1]] |
|||
==Liens== |
==Liens== |
Latest revision as of 09:06, 10 May 2013
http://www.dealextreme.com/p/l298n-stepper-motor-driver-controller-board-for-arduino-120542
AKA Keyes L298
Montage
ENA : Commande PWM du moteur A IN1 : Entrée de commande de sens du pont A IN2 : Entrée de commande de sens du pont A IN3 : Entrée de commande de sens du pont B IN4 : Entrée de commande de sens du pont B ENB : Commande PWM du moteur B GND : Masse +5V : Sortie régulée en 5V
Programme de test
Code de test d'après http://mchobby.be/wiki/index.php?title=Pont-H_L298N
// from http://mchobby.be/wiki/index.php?title=Pont-H_L298N //-- MOTEUR A -- int ENA=5; //Connecté à Arduino pin 5(sortie pwm) int IN1=2; //Connecté à Arduino pin 2 int IN2=3; //Connecté à Arduino pin 3 //-- MOTEUR B -- int ENB=6; //Connecté à Arduino pin 6(Sortie pwm) int IN3=4; //Connecté à Arduino pin 4 int IN4=7; //Connecté à Arduino pin 7 int curDirA=0; // 1=forward, -1=reverse int curSpeedA=0; int curDirB=0; // 1=forward, -1=reverse int curSpeedB=0; int batteryLevel; int batteryNominalLevel=111; // 11.1V with Mystery 11.1V 2200mAh Lithium Polymer Rechargeable Battery (SKU 46058) int MAX_SPEED=200; int curAccelerationStep=32; void setup() { configAB(); } void loop() { int i; stopAB(); delay(1000); forwardA(); reverseB(); for(i=0; i<255; i+=32) { speedA(i); speedB(i); delay(500); } delay(5000); for(i=255; i>0; i-=32) { speedA(i); speedB(i); delay(500); } stopAB(); delay(1000); forwardB(); reverseA(); for(i=0; i<255; i+=32) { speedA(i); speedB(i); delay(500); } delay(5000); for(i=255; i>0; i-=32) { speedA(i); speedB(i); delay(500); } } void configAB() { pinMode(ENA,OUTPUT); pinMode(ENB,OUTPUT); pinMode(IN1,OUTPUT); pinMode(IN2,OUTPUT); pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); } void stopA() { digitalWrite(ENA,LOW);// Moteur A - Ne pas tourner (désactivation moteur) } void stopB() { digitalWrite(ENB,LOW);// Moteur B - Ne pas tourner (désactivation moteur) } void stopAB() { stopA(); stopB(); //delay(??); } void forwardA() { if(curDirA==1) return; stopA(); curDirA=1; digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH); } void reverseA() { if(curDirA==-1) return; stopA(); curDirA=-1; digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW); } void forwardB() { if(curDirB==1) return; stopB(); curDirB=1; digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH); } void reverseB() { if(curDirB==-1) return; stopB(); curDirB=-1; digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); } void speedA(int speed) { if(curDirA==0) return; curSpeedA=(speed>=MAX_SPEED)?MAX_SPEED:speed; analogWrite(ENA,curSpeedA); } void speedB(int speed) { if(curDirB==0) return; curSpeedB=(speed>=MAX_SPEED)?MAX_SPEED:speed; analogWrite(ENB,curSpeedB); } void speedAB(int speed) { speedA(speed); speedB(speed); } void rotate() { forwardA(); reverseB(); } void antirotate() { forwardB(); reverseA(); }
Pilotage via le moniteur série de l'IDE Arduino
Liste des commandes sur 1 octet
- s or S
- f
- x
- l
- r
- 1
- 2
- 3
- 4
- 5
Test
- High Torque 30RPM 12V DC Geared Motor (SKU 91627) (works fine)
- Base robot LynxMotion A4WD1 Aluminium (works fine)
- Wild Thumper (not enough powerful)