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 :

Problème de servo-moteur avec Arduino Mega et esp8266-01


Sujet :

Arduino

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2017
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2017
    Messages : 14
    Points : 7
    Points
    7
    Par défaut Problème de servo-moteur avec Arduino Mega et esp8266-01
    j'ai un probleme de servo moteur avec l'arduino mega et esp8266-01 la page web et fonctionner bien mais le servo ne tourne pas voici le code
    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
    #include "WiFiEsp.h"
    #include <Servo.h>
    Servo myServo;
    // Emulate Serial1 on pins 6/7 if not present
    #ifndef HAVE_HWSERIAL1
    #include "SoftwareSerial.h"
    SoftwareSerial Serial1(18, 19); // RX, TX
    #endif
     
    char ssid[] = "DJAWEB_0D19C";            // your network SSID (name)
    char pass[] = "**********";        // your network password
    int status = WL_IDLE_STATUS;
     
    int ledStatus = LOW;
    int led1 = 9;
     
     
    WiFiEspServer server(80);
     
    // use a ring buffer to increase speed and reduce memory allocation
    RingBuffer buf(8);
     
    void setup()
    {
      pinMode(9, OUTPUT);
      myServo.attach(12); //servo pin
      myServo.write(0);
     
      pinMode(LED_BUILTIN, OUTPUT);	// initialize digital pin LED_BUILTIN as an output.
      Serial.begin(115200);   // initialize serial for debugging
      Serial1.begin(9600);    // initialize serial for ESP module
      WiFi.init(&Serial1);    // initialize ESP module
     
      // check for the presence of the shield
      if (WiFi.status() == WL_NO_SHIELD) {
        Serial.println("WiFi shield not present");
        // don't continue
        while (true);
     
      }
     
      // attempt to connect to WiFi network
      while (status != WL_CONNECTED) {
        Serial.print("Attempting to connect to WPA SSID: ");
        Serial.println(ssid);
        // Connect to WPA/WPA2 network
        status = WiFi.begin(ssid, pass);
      }
     
      Serial.println("You're connected to the network");
      printWifiStatus();
     
      // start the web server on port 80
      server.begin();
    }
     
     
    void loop()
    {
      WiFiEspClient client = server.available();  // listen for incoming clients
     
      if (client) {                               // if you get a client,
        Serial.println("New client");             // print a message out the serial port
        buf.init();                               // initialize the circular buffer
        while (client.connected()) {              // loop while the client's connected
          if (client.available()) {               // if there's bytes to read from the client,
            char c = client.read();               // read a byte, then
            buf.push(c);                          // push it to the ring buffer
     
            // printing the stream to the serial monitor will slow down
            // the receiving of data from the ESP filling the serial buffer
            //Serial.write(c);
     
            // you got two newline characters in a row
            // that's the end of the HTTP request, so send a response
            if (buf.endsWith("\r\n\r\n")) {
              sendHttpResponse(client);
              break;
            }
     
            // Check to see if the client request was "GET /H" or "GET /L":
            if (buf.endsWith("GET /H")) {
              Serial.println("Turn led ON");
              ledStatus = HIGH;
              digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
            }
            else if (buf.endsWith("GET /L")) {
              Serial.println("Turn led OFF");
              ledStatus = LOW;
              digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
            }
            else if (buf.endsWith("GET /m")) {
              Serial.println("Turn led OFF");
              led1 = HIGH;
              digitalWrite(9, HIGH);    // turn the LED off by making the voltage LOW
            }
            else if (buf.endsWith("GET /g")) {
              Serial.println("Turn led OFF");
              //ledStatus = LOW;
              digitalWrite(9, LOW);    // turn the LED off by making the voltage LOW
            }
            //--------------------------------------------------------------------------------------------------
                    if (buf.endsWith("GET /OPEN_P")) {
            myServo.write(90);                      
     
     } //else if 
                    if (buf.endsWith("GET /CLOSE_P")) {
            myServo.write(0);               
     }//else if 
    //--------------------------------------------------------------------------------------------------
          }
        }
     
        // close the connection
        client.stop();
        Serial.println("Client disconnected");
      }
     
    }
     
     
    void sendHttpResponse(WiFiEspClient client)
    {
      // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
      // and a content-type so the client knows what's coming, then a blank line:
      client.println("HTTP/1.1 200 OK");
      client.println("Content-type:text/html");
      client.println();
     
      // the content of the HTTP response follows the header:
      client.print("The LED is ");
      client.print(ledStatus);
      client.println("<br>");
      client.println("<br>");
     
      client.println("Click <a href=\"/H\">here</a> turn the LED on<br>");
      client.println("Click <a href=\"/L\">here</a> turn the LED off<br>");
     
      client.println("Click <a href=\"/m\">here</a> turn the LED on<br>");
      client.println("Click <a href=\"/g\">here</a> turn the LED off<br>");
     
      client.println("Click <a href=\"/OPEN_P\">here</a> The door is Open<br>");
      client.println("Click <a href=\"/CLOSE_P\">here</a> The door is Closed<br>");
     
      // The HTTP response ends with another blank line:
      client.println();
    }
     
    void printWifiStatus()
    {
      // print the SSID of the network you're attached to
      Serial.print("SSID: ");
      Serial.println(WiFi.SSID());
     
      // print your WiFi shield's IP address
      IPAddress ip = WiFi.localIP();
      Serial.print("IP Address: ");
      Serial.println(ip);
     
      // print where to go in the browser
      Serial.println();
      Serial.print("To see this page in action, open a browser to http://");
      Serial.println(ip);
      Serial.println();
    }

  2. #2
    Membre émérite
    Avatar de jpbbricole
    Homme Profil pro
    Retraité des réseaux informatiques
    Inscrit en
    Février 2013
    Messages
    1 012
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Retraité des réseaux informatiques
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2013
    Messages : 1 012
    Points : 2 341
    Points
    2 341
    Par défaut
    Bonjour tarekovitche

    Essaies de modifier légèrement ton programme pour voire si arrives bien dans ton test:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    				//--------------------------------------------------------------------------------------------------
    				if (buf.endsWith("GET /OPEN_P")) {
    Serial.println("GET /OPEN_P");
    					myServo.write(90);
     
    				} //else if
    				if (buf.endsWith("GET /CLOSE_P")) {
    Serial.println("GET /CLOSE_P");
    					myServo.write(0);
    				}//else if
    Cordialement
    jpbbricole
    L'expérience est la seule chose qu'il ne faut acheter que d'occasion!

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2017
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2017
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    bonjour jpbbricole

    est ce que le probleme dans l'expression buf ?

  4. #4
    Membre émérite
    Avatar de jpbbricole
    Homme Profil pro
    Retraité des réseaux informatiques
    Inscrit en
    Février 2013
    Messages
    1 012
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Retraité des réseaux informatiques
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2013
    Messages : 1 012
    Points : 2 341
    Points
    2 341
    Par défaut
    Bonjour tarekovitche
    Citation Envoyé par tarekovitche Voir le message
    le probleme dans l'expression buf ?
    Non pas forcément, mais le petit test que je te propose permet de bien voire si buf se termine bien par "GET /OPEN_P" ou par "GET /CLOSE_P".
    Si rien ne s'affiche dans la console, c'est que ta condition n'est jamais vraie.
    Attention au caractères cachés comme \n et \r (New Line et Carriage return), s'il s'en trouvent en fin de buf, ta condition n'est plus vraie.
    Pour contrôler ceci, il faut faire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
      Serial.println(buf);
      Serial.println(buf.length());
    Si le chiffre du 2ème print ne correspond pas au nombre de caractère "visibles" de buf, c'est qu'il y a des caractères cachés, certainement en fin de variable.

    Cordialement
    jpbbricole
    L'expérience est la seule chose qu'il ne faut acheter que d'occasion!

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2017
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2017
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    oui l'operation se termine bien par "GET /OPEN_P" et "GET /CLOSE_P" avec les led's ça fonctionne bien et le led s'allume

  6. #6
    Membre émérite
    Avatar de jpbbricole
    Homme Profil pro
    Retraité des réseaux informatiques
    Inscrit en
    Février 2013
    Messages
    1 012
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Retraité des réseaux informatiques
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2013
    Messages : 1 012
    Points : 2 341
    Points
    2 341
    Par défaut
    Bonjour tarekovitche

    Citation Envoyé par tarekovitche Voir le message
    oui l'operation se termine bien par "GET /OPEN_P" et "GET /CLOSE_P" avec les led's ça fonctionne bien et le led s'allume
    Je ne vois pas de led's dans la condition qui pose problème.

    Cordialement
    jpbbricole
    L'expérience est la seule chose qu'il ne faut acheter que d'occasion!

  7. #7
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2017
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2017
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    oui le problemme dans la partie du servo moteur , j'ai cherche dans google mais auccune solution

  8. #8
    Membre émérite
    Avatar de jpbbricole
    Homme Profil pro
    Retraité des réseaux informatiques
    Inscrit en
    Février 2013
    Messages
    1 012
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Retraité des réseaux informatiques
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2013
    Messages : 1 012
    Points : 2 341
    Points
    2 341
    Par défaut
    Citation Envoyé par tarekovitche Voir le message
    oui le problemme dans la partie du servo moteur , j'ai cherche dans google mais auccune solution
    Oui, je pense bien, as-tu fait le test que je t'ai proposé dans le post #2?

    Cordialement
    jpbbricole
    L'expérience est la seule chose qu'il ne faut acheter que d'occasion!

  9. #9
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2017
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2017
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    j'ai essayé mais il y a une erreur dans les 2 expressions

  10. #10
    Membre émérite
    Avatar de jpbbricole
    Homme Profil pro
    Retraité des réseaux informatiques
    Inscrit en
    Février 2013
    Messages
    1 012
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Retraité des réseaux informatiques
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2013
    Messages : 1 012
    Points : 2 341
    Points
    2 341
    Par défaut
    Bonsoir tarekovitche

    On va changer de méthode.
    Modifies tes 2 conditions ainsi
    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
    				//--------------------------------------------------------------------------------------------------
    				if (buf.endsWith("GET /OPEN_P")) {
    					myServo.write(90);
     
    				} //else if
    				if (buf.endsWith("GET /CLOSE_P")) {
    					myServo.write(0);
    				}//else if
    // en
    				//--------------------------------------------------------------------------------------------------
    				if (buf.lastIndexOf("GET /OPEN_P")) {
    					myServo.write(90);
     
    				} //else if
    				if (buf.lastIndexOf("GET /CLOSE_P")) {
    					myServo.write(0);
    				}//else if
    				//--------------------------------------------------------------------------------------------------
    Cordialement
    jpbbricole
    L'expérience est la seule chose qu'il ne faut acheter que d'occasion!

  11. #11
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2017
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2017
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    'class RingBuffer' has no member named 'lastIndexOf'
    n'est declarer dans la class Ring Buffer

  12. #12
    Membre émérite
    Avatar de jpbbricole
    Homme Profil pro
    Retraité des réseaux informatiques
    Inscrit en
    Février 2013
    Messages
    1 012
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Retraité des réseaux informatiques
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2013
    Messages : 1 012
    Points : 2 341
    Points
    2 341
    Par défaut
    Bonsoir tarekovitche

    Oupsss! j'avais pas vu la déclaration (RingBuffer buf(8), j'avais fait comme une string
    Je ne connaissais pas cette bête!
    Avec une taille de 8, avec des chaînes comme GET /OPEN_P (11) et GET /CLOSE_P (12), cette taille est-elle suffisante?

    Deux solutions à essayer:
    Augmenter la taille avec RingBuffer buf(8);
    ou changer la taille des chaînes à tester.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    				//--------------------------------------------------------------------------------------------------
    				if (buf.lastIndexOf("/OPEN_P")) {
    					myServo.write(90);
     
    				} //else if
    				if (buf.lastIndexOf("/CLOSE_P")) {
    					myServo.write(0);
    				}//else if
    Je serais pour la 2ème, le texte testé m'a l'aire suffisant.
    Mais pas essayé.

    Cordialement
    jpbbricole
    L'expérience est la seule chose qu'il ne faut acheter que d'occasion!

  13. #13
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2017
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2017
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    j'ai changer la taille de buffer à 16 le servo ça marche mais l'operation de la page html ne termine pas avec les led est terminé mais avec le servo non
    ou le probleme ? est ce que je augmente le buffer encore ?

  14. #14
    Membre émérite
    Avatar de jpbbricole
    Homme Profil pro
    Retraité des réseaux informatiques
    Inscrit en
    Février 2013
    Messages
    1 012
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Retraité des réseaux informatiques
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2013
    Messages : 1 012
    Points : 2 341
    Points
    2 341
    Par défaut
    Bonsoir tarekovitche


    J'ai pas tout compris, si ce n'est que le servo fonctionne. Le problème de la led existait aussi avant le passage de 8 à 16.

    Cordialement
    jpbbricole
    L'expérience est la seule chose qu'il ne faut acheter que d'occasion!

  15. #15
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2017
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2017
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    quand j'ai écrit par exemple 192.168.1.21/H l'operasion terminé est la led s'allume , mais quand j'ai écrit 192.168.1.21/open_p le serrvo moteur tourne mais l'operation de la page ne termine pas et reste tourné meme la led blue de l'esp8266-01 reste clignonter

  16. #16
    Membre émérite
    Avatar de jpbbricole
    Homme Profil pro
    Retraité des réseaux informatiques
    Inscrit en
    Février 2013
    Messages
    1 012
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Retraité des réseaux informatiques
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2013
    Messages : 1 012
    Points : 2 341
    Points
    2 341
    Par défaut
    reBonsoir tarekovitche

    Pour contrôler si ce n'est pas l'opération sur les servo qui bloque, remplace tes ordres myServo.write(xx);
    par des opération sur des led, comme allumer, éteindre une led, ainsi tu pourras voire si ta "mécanique " est ok.

    Bonne soirée
    Cordialement
    jppbbricole
    L'expérience est la seule chose qu'il ne faut acheter que d'occasion!

  17. #17
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2017
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2017
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    d'accord merci beaucoup

Discussions similaires

  1. Problème de compilation arduino mega 2560
    Par patoune08 dans le forum Arduino
    Réponses: 2
    Dernier message: 23/12/2017, 00h10
  2. Réponses: 3
    Dernier message: 12/12/2017, 14h51
  3. Contrôle de la vitesse de rotation d'un moteur avec Arduino
    Par capteurtipe dans le forum Arduino
    Réponses: 6
    Dernier message: 09/06/2017, 12h38
  4. Problème avec ARDUINO MEGA
    Par cip.maldonado dans le forum Arduino
    Réponses: 3
    Dernier message: 26/04/2016, 08h55

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