Code Monkey home page Code Monkey logo

Comments (7)

madhephaestus avatar madhephaestus commented on July 16, 2024

If you want to use KY-040 you need to understand mechanical switch bouncing. I bet what you are getting is a bounce that takes longer then the runt filtering built in. You need to add a small capacitor to the switch and only move it SLOWLY. Mechanical encoders are only stable at VERY low speeds, like a knob that someone moves with their fingers.

Check out this document: http://web.engr.oregonstate.edu/~traylor/ece473/lectures/debounce.pdf for more information.

Closing issue because it it an electrical problem.

from esp32encoder.

JM-FRANCE avatar JM-FRANCE commented on July 16, 2024

I understand what bounces are and why I would possibly get tick errors. that's fine
I'm still unclear on the error message I get
E (33) pcnt: pcnt_counter_clear(158): PCNT UNIT ERROR
there are similar messages when I compile your example as well.

from esp32encoder.

madhephaestus avatar madhephaestus commented on July 16, 2024

try removing your encoder from the circuit entirely. Verify with an o-scope (at least 10 Mega-samples/sec) that the lines are clean. If you still get the error after verifying the signals are perfectly clean, let me know.

I can not reproduce the error on my hardware, so i suspect electrical issues.

from esp32encoder.

madhephaestus avatar madhephaestus commented on July 16, 2024

Also, what is the reason for trying to clear the encoder before attaching? Try removing that as well.

from esp32encoder.

JM-FRANCE avatar JM-FRANCE commented on July 16, 2024

Also, what is the reason for trying to clear the encoder before attaching? Try removing that as well.

Good catch - that's because in your example you did it like that :)

I switched the order of the commands

  encoder.attachHalfQuad(encoderDTPin,encoderCLKPin);  // Attach pins for use as encoder pins
  encoder.clearCount();

and now the error message is gone.

--> suggest you fix this in your example as well

thx for the good work and sharing !


working code for an example:

#include <ESP32Encoder.h>
ESP32Encoder encoder;
const uint8_t encoderCLKPin = 13; // encoder CLK
const uint8_t encoderDTPin = 14; // encoder DT
int32_t encoderCntr  = 0L;

void setup() {
  Serial.begin(115200);
  ESP32Encoder::useInternalWeakPullResistors = true; // Enable the weak pull down resistors
  encoder.attachHalfQuad(encoderDTPin,encoderCLKPin);  // Attach pins for use as encoder pins
  encoder.clearCount();
  
  Serial.println(F("Play with your encoder"));
}

void loop()
{
  int32_t currentEncoderCntr = encoder.getCount();
  if (currentEncoderCntr != encoderCntr) {
    if (currentEncoderCntr > encoderCntr) {
      Serial.print(F("tick +  = "));
    } else {
      Serial.print(F("tick - = "));
    }
    encoderCntr = currentEncoderCntr;
    Serial.println(currentEncoderCntr);
  }
}

from esp32encoder.

madhephaestus avatar madhephaestus commented on July 16, 2024

example updated in 0.3.2

from esp32encoder.

JM-FRANCE avatar JM-FRANCE commented on July 16, 2024

thx!

from esp32encoder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.