IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Arduino bar programmation moteur PAP et gestion de vitesse


Sujet :

Arduino

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Juillet 2015
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Juillet 2015
    Messages : 12
    Points : 9
    Points
    9
    Par défaut Arduino bar programmation moteur PAP et gestion de vitesse
    Bonjour tout le monde.

    Je suis actuellement en cour de fabrication d'une machine a cocktail gérer par arduino.
    Pour l'instant j'ai fabriqué la partie qui servira a actionner les doseurs et une des deux translations.
    Les moteurs PAP sont piloté par 2 cartes L298N.
    (Voir vidéo çà sera plus simple à comprendre)



    Mes 2 problèmes :

    -Peut t-on modifier la vitesse d'un moteur PAP sans toucher à la mécanique *? (car la translation linéaire axe y avance pas).
    -Avez vous des exemples de code pour actionner 2 moteur PAP en même temps.
    (J'ai essayé ce tuto http://www.horlogerie49.fr/tutorielarduino03.html en ayant programmer 2 moteurs, mais les translations ne sont pas simultanée.


    Et voici mon code actuel qui actionne bien les 2 moteurs ensemble mais un peut lourd a mon gout.
    J'ai dû bidouiller les stepDelay car dès que je fais fonctionner 2 moteurs çà me ralenti les moteurs.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
     
    //Moteur
    int motor1inA1 = 10; // input 1 moteur doseur
    int motor1inA2 = 11; // input 2 
    int motor1inB1 = 12; // input 3 
    int motor1inB2 = 13; // input 4 
    int motor2inA1 = 6; // input 1 moteur
    int motor2inA2 = 7; // input 2 
    int motor2inB1 = 8; // input 3 
    int motor2inB2 = 9; // input 4 
    int stepDelay = 2; // Delay between steps in milliseconds
    int stepDelay1 = 1; // Delay between steps in milliseconds
    //Bouton
    const int buttonPin = 53; //input 53 button on
    int buttonState = 0;
     
    void setup() { *
    //Moteur *
     pinMode(motor1inA1, OUTPUT); * * 
     pinMode(motor1inA2, OUTPUT); * * 
     pinMode(motor1inB1, OUTPUT); * * 
     pinMode(motor1inB2, OUTPUT); 
     pinMode(motor2inA1, OUTPUT); * * 
     pinMode(motor2inA2, OUTPUT); * * 
     pinMode(motor2inB1, OUTPUT); * * 
     pinMode(motor2inB2, OUTPUT); *
    //Bouton
     pinMode(buttonPin, INPUT);
    }
     
    void step1() {
     digitalWrite(motor1inA1, LOW); * 
     digitalWrite(motor1inA2, HIGH); * 
     digitalWrite(motor1inB1, HIGH); * 
     digitalWrite(motor1inB2, LOW);
     
     }
    void step11() { *
     digitalWrite(motor2inA1, LOW); * 
     digitalWrite(motor2inA2, HIGH); * 
     digitalWrite(motor2inB1, HIGH); * 
     digitalWrite(motor2inB2, LOW); * * 
     
    }
    void step2() {
     digitalWrite(motor1inA1, LOW); * 
     digitalWrite(motor1inA2, HIGH); * 
     digitalWrite(motor1inB1, LOW); * 
     digitalWrite(motor1inB2, HIGH);
     
     *}
    void step12() { *
     digitalWrite(motor2inA1, LOW); * 
     digitalWrite(motor2inA2, HIGH); * 
     digitalWrite(motor2inB1, LOW); * 
     digitalWrite(motor2inB2, HIGH); * * 
     
    }
    void step3() {
     digitalWrite(motor1inA1, HIGH); * 
     digitalWrite(motor1inA2, LOW); * 
     digitalWrite(motor1inB1, LOW); * 
     digitalWrite(motor1inB2, HIGH); 
     
     *}
    void step13() { *
     digitalWrite(motor2inA1, HIGH); * 
     digitalWrite(motor2inA2, LOW); * 
     digitalWrite(motor2inB1, LOW); * 
     digitalWrite(motor2inB2, HIGH); * 
     
    }
    void step4() {
     digitalWrite(motor1inA1, HIGH); * 
     digitalWrite(motor1inA2, LOW); * 
     digitalWrite(motor1inB1, HIGH); * 
     digitalWrite(motor1inB2, LOW);
     
     * }
    void step14() { 
     digitalWrite(motor2inA1, HIGH); * 
     digitalWrite(motor2inA2, LOW); * 
     digitalWrite(motor2inB1, HIGH); * 
     digitalWrite(motor2inB2, LOW); * * 
     
    }
    void stopMotor() {
     digitalWrite(motor1inA1, LOW); * 
     digitalWrite(motor1inA2, LOW); * 
     digitalWrite(motor1inB1, LOW); * 
     digitalWrite(motor1inB2, LOW); *
     digitalWrite(motor2inA1, LOW); * 
     digitalWrite(motor2inA2, LOW); * 
     digitalWrite(motor2inB1, LOW); * 
     digitalWrite(motor2inB2, LOW); * 
    }
     
    void loop() {
     buttonState = digitalRead(buttonPin);
     if (buttonState == HIGH) { 
     
     *for (int i=0; i<=400; i++){ 
     * step11(); 
     * delay(stepDelay); *
     * step12();
     * delay(stepDelay);
     * step13();
     * delay(stepDelay);
     * step14();
     * delay(stepDelay);
     } *
     * 
     for (int i=0; i<=800; i++){ 
     * step1(); 
     * delay(stepDelay1);
     * step11(); 
     * delay(stepDelay1);
     * step2();
     * delay(stepDelay1);
     * step12();
     * delay(stepDelay1);
     * step3();
     * delay(stepDelay1);
     * step13();
     * delay(stepDelay1);
     * step4();
     * delay(stepDelay1);
     * step14();
     * delay(stepDelay1);
     } 
     
     
     for (int i=0; i<=200; i++){ 
     * step1(); 
     * delay(stepDelay); *
     * step2();
     * delay(stepDelay);
     * step3();
     * delay(stepDelay);
     * step4();
     * delay(stepDelay);
     }
     for (int i=0; i<=200; i++){
     * step4(); 
     * delay(stepDelay);
     * step3();
     * delay(stepDelay);
     * step2();
     * delay(stepDelay);
     * step1();
     * delay(stepDelay);
     }
     
     
     for (int i=0; i<=800; i++){
     * step4(); 
     * delay(stepDelay1);
     * step14(); 
     * delay(stepDelay1);
     * step3();
     * delay(stepDelay1);
     * step13();
     * delay(stepDelay1);
     * step2();
     * delay(stepDelay1);
     * step12();
     * delay(stepDelay1);
     * step1();
     * delay(stepDelay1);
     * step11();
     * *delay(stepDelay1);
     }
     
    for (int i=0; i<=400; i++){ 
     * step14(); 
     * delay(stepDelay); *
     * step13();
     * delay(stepDelay);
     * step12();
     * delay(stepDelay);
     * step11();
     * delay(stepDelay);
     } 
     stopMotor();
     delay(2000);
    }
    }
    Merci si vous avez lu ce topique jusque-là je suis ouvert à tous aides, ou proposition de tuto et même si vous avez des questions ou quoi que ce soit hésiter pas.

  2. #2
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Juillet 2015
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Juillet 2015
    Messages : 12
    Points : 9
    Points
    9
    Par défaut RE
    RE

    Bon j'ai réussi à alléger mon code pour le fonctionnement des 2 moteurs PAP en simultanée.
    Je vous le fait partager.

    Il me reste juste le problème de vitesse a régler si vous avez des idées :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
     
    #include <Stepper.h>
    int stepDelay = 2;
    Stepper moteur1(200, 10, 11, 12, 13); //Moteur1 doseur
    Stepper moteur2(200, 6, 7, 8, 9);  //Moteur2 translation
    const int buttonPin = 53; //input 53 button on
    int buttonState = 0;
     
    void setup()
    {
    moteur1.setSpeed(200);
    moteur2.setSpeed(200);
    pinMode(buttonPin, INPUT);
    }
     
    void loop()
    {
    buttonState = digitalRead(buttonPin);
        if (buttonState == HIGH) {
     
              for (int i=0; i<=2000; i++){
              moteur2.step(1);
              delay(stepDelay);
              }
     
     
              for (int i=0; i<=2000; i++){
              moteur1.step(1);
              moteur2.step(1);
              delay(stepDelay);
              }
     
              for (int i=0; i<=2000; i++){ 
              moteur1.step(-1);
              moteur2.step(-1);
              delay(stepDelay);
              }
     
              for (int i=0; i<=2000; i++){
              moteur2.step(-1);
              delay(stepDelay);
              }          
        }
    }

  3. #3
    Modérateur

    Avatar de Vincent PETIT
    Homme Profil pro
    Consultant en Systèmes Embarqués
    Inscrit en
    Avril 2002
    Messages
    3 191
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Consultant en Systèmes Embarqués
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Avril 2002
    Messages : 3 191
    Points : 11 577
    Points
    11 577
    Par défaut
    Ce n'est pas cette fonction qui gère la vitesse de rotation de ton moteur ?
    moteur1.setSpeed(200);

    Tu as essayé de mettre 800 au lieu de 200 pour voir si il y a une différence ?
    La science ne nous apprend rien : c'est l'expérience qui nous apprend quelque chose.
    Richard Feynman

  4. #4
    Expert éminent sénior
    Avatar de Auteur
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    7 648
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 7 648
    Points : 11 137
    Points
    11 137
    Par défaut
    Bonjour,

    compte-tenu de ton montage je ne suis pas sûr qu'utiliser la bibliothèque stepper.h soit une bonne idée à cause de la fonction step() qui est bloquante. Une recherche sur le net m'a permis de trouver ces exemples (le module Vellemann utilise des L298P). Sans garantie, à tester.

    J'ai également trouvé ce tutoriel.

  5. #5
    Responsable Arduino et Systèmes Embarqués


    Avatar de f-leb
    Homme Profil pro
    Enseignant
    Inscrit en
    Janvier 2009
    Messages
    12 621
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 12 621
    Points : 56 869
    Points
    56 869
    Billets dans le blog
    40
    Par défaut
    Bonjour,

    En effet, d'après https://www.arduino.cc/en/Reference/StepperStep :
    Turns the motor a specific number of steps, at a speed determined by the most recent call to setSpeed(). This function is blocking; that is, it will wait until the motor has finished moving to pass control to the next line in your sketch.

  6. #6
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Juillet 2015
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Juillet 2015
    Messages : 12
    Points : 9
    Points
    9
    Par défaut Bonsoir
    Re

    La fonction step est en effet assez gênante car il faut attendre la fin du temps pour passez à une autre action.
    Mais j'ai réussi a la contourner avec ce code du coup mes moteurs fonctionne bien
    et cela me permet d'avoir un code plus léger avec la bibliothèque "stepper".


    for (int i=0; i<=2000; i++){
    moteur1.step(1);
    moteur2.step(1);
    delay(stepDelay);
    }

    Il me reste le problème de vitesse mais j'ai eu beau essayer plein de tuto rien à y faire je vais optez pour changer le pas de la vis sans fin si je ne trouve pas de solution.

  7. #7
    Modérateur
    Avatar de sevyc64
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    10 193
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 10 193
    Points : 28 077
    Points
    28 077
    Par défaut
    La vitesse d'un moteur pas à pas se règle par la fréquence à laquelle on lui fait passer les pas. Plus vite tu lui fera passer les pas (donc moins tu aura de delai entre chaque pas) plus vite tourneras ton moteur. Attention, ces moteurs ont des limites en vitesses assez faible, si tu vas un peu trop vite ils ont tendance à décrocher et rater des pas.

    Pour te former lire les cours et tutoriels Arduino : https://arduino.developpez.com/cours/
    --- Sevyc64 ---

    Parce que le partage est notre force, la connaissance sera notre victoire

Discussions similaires

  1. Programme Access pour la gestion de camping
    Par yanna dans le forum Autres
    Réponses: 0
    Dernier message: 15/12/2008, 20h44
  2. Réponses: 1
    Dernier message: 12/11/2008, 15h32
  3. Quelle solution pour programmer une application de gestion élève ?
    Par LouReed dans le forum Langages de programmation
    Réponses: 10
    Dernier message: 19/05/2008, 14h50
  4. Réponses: 3
    Dernier message: 28/08/2006, 13h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo