Problemes EC 11

Bonjour j'ai un problème avec mon EC11
Mes branchements sont les suivants
Branche Gauche EC 11 -> résistance 10 k OHM -> D32 de mon esp32
Branche Droit EC 11 -> résistance 10 k OHM -> D33 de mon esp32
Branche du milieu -> GROUND

j'obtiens le moniteur série suivant

21:19:46.011 -> CLK: 0 | DT: 0
21:19:46.243 -> CLK: 0 | DT: 0
21:19:46.409 -> CLK: 0 | DT: 0
21:19:46.652 -> CLK: 0 | DT: 0
21:19:46.839 -> CLK: 0 | DT: 0
21:19:47.023 -> CLK: 0 | DT: 0
21:19:47.209 -> CLK: 0 | DT: 0
21:19:47.415 -> CLK: 0 | DT: 0
21:19:47.648 -> CLK: 0 | DT: 0
21:19:47.833 -> CLK: 0 | DT: 0

avec le code suivant

void setup() {
  Serial.begin(115200);
  pinMode(32, INPUT);  // Pas de pull-up interne ici
  pinMode(33, INPUT);  // Pas de pull-up interne ici
}

void loop() {
  Serial.print("CLK: "); Serial.print(digitalRead(32));
  Serial.print(" | DT: "); Serial.println(digitalRead(33));
  delay(200);
}

Le CLK varie parfois en 1 mais le DT reste tout le temps sur 0
LIEN VERS MES EC11

merci pour vos reponses

Il faut que les 10kΩ tirent les lignes A et B au +5V +3.3V.
Le plus simple d'ailleurs serait de ne pas mettre de résistances et de configurer les entrées en INPUT_PULLUP.

Edit: correction de la tension

Bonjour,

Je pense que @fdufnews n'a pas fait attention que tu avais un esp32.
Si tu mets des résistances de pullup elles doivent être au 3.3V et non au 5V.
Mais comme le dit @fdufnews le mieux est de ne pas mettre de résistance et d'utiliser INPUT_PULLUP.

Bonjour clem28l

Pourquoi ne pas utiliser une bibliothèque comme ESP32Ecoder
image

pour gérer tes EC11?

Cordialement
jpbbricole

j'ai essayé je n'y arrive pas non plus (j'ai aussi essayé avec des résistances internes )
voila mon code et l'output

#include <ESP32Encoder.h>

ESP32Encoder encoder;

void setup() {
  Serial.begin(115200);
  

  encoder.attachHalfQuad(32, 33);  // CLK sur GPIO32, DT sur GPIO33
  

  encoder.setCount(0);
}

void loop() {
  int32_t position = encoder.getCount();
  
  if (position != 0) {
    if (position > 0) {
      Serial.println("Rotation horaire");
    } else {
      Serial.println("Rotation anti-horaire");
    }
    

    encoder.setCount(0);
  }
  
  delay(50);  // Petit délai pour éviter les rebonds
}
:29.529 -> Rotation anti-horaire
19:32:29.565 -> Rotation horaire
19:32:29.683 -> Rotation anti-horaire
19:32:29.718 -> Rotation horaire
19:32:30.729 -> Rotation anti-horaire
19:32:30.814 -> Rotation horaire
19:32:32.168 -> Rotation anti-horaire
19:32:32.211 -> Rotation horaire
19:32:32.396 -> Rotation anti-horaire
19:32:32.501 -> Rotation horaire
19:32:32.699 -> Rotation anti-horaire
19:32:32.779 -> Rotation horaire
19:32:32.966 -> Rotation anti-horaire

j'ai les deux rotation lorsque je tourne d'un coté ou de l'autre

Bonsoir clem28l

J'ai essayé ton code avec un module comme ceci:

et il fonctionne très bien, 4 crans CW et 4 crans CCW:

Rotation anti-horaire
Rotation anti-horaire
Rotation anti-horaire
Rotation anti-horaire
Rotation anti-horaire
Rotation anti-horaire
Rotation anti-horaire
Rotation anti-horaire
Rotation horaire
Rotation horaire
Rotation horaire
Rotation horaire
Rotation horaire
Rotation horaire
Rotation horaire
Rotation horaire

Attention, chaque cran donne 2 transitions. voir l'exemple de la bibliothèque:
SimpleEncoderDemo

A+
jpbbricole

Effectivement merci à vous pour votre investissements et votre temps accordé

Jai changer les port de l esp est tout marche merci

Me revoilà

avec le code que je t'ai envoyé un peu modifié à ma situation et mon projet, j'observe que les sens horaires sont très précis, alors que le sens anti-horaire a du mal et produit des erreurs
Avez-vous une solution ?

merci

Bonjour clem28l

Où est ce code?
Mets la dernière version en ligne.

A+
jpbbricole

tenez

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define LARGEUR_ECRAN 128
#define HAUTEUR_ECRAN 64
#define OLED_RESET -1
Adafruit_SSD1306 ecran(LARGEUR_ECRAN, HAUTEUR_ECRAN, &Wire, OLED_RESET);

// Encoder modifié (GPIO25/26)
#define ENCODEUR_CLK 25
#define ENCODEUR_DT  26

// Boutons (inchangés)
#define BOUTON1 17
#define BOUTON2 16
#define BOUTON3 18
#define BOUTON4 5

// Variables volume
int pourcentageVolume = 50;
const int pasVolume = 4;
const int volumeMin = 0;
const int volumeMax = 100;

// États encodeur
int ancienClk;
unsigned long dernierChangement = 0;
const unsigned long delaiAntiRebond = 2;

// États boutons
bool ancienBouton1 = LOW;
bool ancienBouton2 = LOW;
bool ancienBouton3 = LOW;
bool ancienBouton4 = LOW;

// Textes affichage
String periphTexte = "Periph 1";
String micTexte = "Mic: ON";

void setup() {
  Serial.begin(115200);

  // Configuration encodeur
  pinMode(ENCODEUR_CLK, INPUT_PULLUP);
  pinMode(ENCODEUR_DT, INPUT_PULLUP);
  ancienClk = digitalRead(ENCODEUR_CLK);

  // Configuration boutons
  pinMode(BOUTON1, INPUT);
  pinMode(BOUTON2, INPUT);
  pinMode(BOUTON3, INPUT);
  pinMode(BOUTON4, INPUT);

  // Initialisation écran
  ecran.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  ecran.clearDisplay();
  afficherVolume();
}

void loop() {
  // Gestion encodeur
  int nouveauClk = digitalRead(ENCODEUR_CLK);
  
  if (nouveauClk != ancienClk && (millis() - dernierChangement) > delaiAntiRebond) {
    dernierChangement = millis();
    
    if (digitalRead(ENCODEUR_DT) != nouveauClk) {
      pourcentageVolume += pasVolume;
      if (pourcentageVolume > volumeMax) pourcentageVolume = volumeMax;
      Serial.println("ER1 +");
    } else {
      pourcentageVolume -= pasVolume;
      if (pourcentageVolume < volumeMin) pourcentageVolume = volumeMin;
      Serial.println("ER1 -");
    }
    afficherVolume();
  }
  ancienClk = nouveauClk;

  // Gestion boutons (inchangée)
  bool etatBouton1 = digitalRead(BOUTON1);
  if (etatBouton1 == HIGH && ancienBouton1 == LOW) {
    Serial.println("BTN1");
      periphTexte = "Periph 1";
      animationMessage("periph 1");
  }
  
  ancienBouton1 = etatBouton1;

  bool etatBouton2 = digitalRead(BOUTON2);
  if (etatBouton2 == HIGH && ancienBouton2 == LOW){

    Serial.println("BTN2");
  } 
  ancienBouton2 = etatBouton2;

  bool etatBouton3 = digitalRead(BOUTON3);
  if (etatBouton3 == HIGH && ancienBouton3 == LOW) {
    Serial.println("BTN3");
    animationMessage("periph 1");
    }
  ancienBouton3 = etatBouton3;

  bool etatBouton4 = digitalRead(BOUTON4);
  if (etatBouton4 == HIGH && ancienBouton4 == LOW) {
      micTexte = "Mic: ON";
      animationMessage("mic ON");
    }
  ancienBouton4 = etatBouton4;

  // Gestion messages série (inchangée)
  if (Serial.available()) {
    String message = Serial.readStringUntil('\n');
    message.trim();

    if (message == "p1") {
      periphTexte = "Periph 1";
      animationMessage("periph 1");
    } else if (message == "p2") {
      periphTexte = "Periph 2";
      animationMessage("periph 2");
    } else if (message == "p3") {
      periphTexte = "Periph 3";
      animationMessage("periph 3");
    } else if (message == "mon") {
      micTexte = "Mic: ON";
      animationMessage("mic ON");
    } else if (message == "moff") {
      micTexte = "Mic: OFF";
      animationMessage("mic OFF");
    }
  }

  delay(2);
}


Bonjour clem28l
Pourquoi ne pas utiliser la bibliothèque ESP32Encoder.h?
Sans celle-ci, tu n'arrivera à rien de bon, c'est possible de gérer un codeur incrémental de façon "manuelle", mais très compliqué, alors que c'est si simple avec une bibliothèque.

Inspires toi de ceci:

puisque ça marche :wink:

Bonne soirée
jpbbricole

je n'ai pas réussi non plus avec la bibliothèque malheureusement ...

Montre moi ton essai avec la bibliothèque.

je n'arrive pas à utiliser les résistances internes

AHHHH j'y suis arrivé merci !!!
effectivement ça marche beaucoup mieux (pour le moment)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.