Giter Club home page Giter Club logo

Comments (6)

John-Lluch avatar John-Lluch commented on July 28, 2024

Thank you for your feedback. First of all, please note that I have only tested it on a pro-micro (ATMega32U4), so I can't be 100% sure that it works on a Nano.

However, by looking at your code it seems to me that you have some misunderstanding of the way the library works. The 'delta' function just gives the encoder variation since the last call to it, hence its name, not the actual encoder value. To get the accumulated value try to declare a global int encoderValue variable then put the following on the main loop:

int delta = encoder.delta();
encoderValue = encoderValue + delta; 

This way, you should get the actual encoder value in the encoderValue variable
Hope this helps

from encoder.

brianssparetime avatar brianssparetime commented on July 28, 2024

Thank you for the thoughtful response.

I understand that the delta represents the variation since the last call not an absolute value. I'm using the very-poorly-named variable foo to accumulate the changes here. The delta is subtracted from foo, and then result is checked to keep it within bounds of 0-256, and then that result is saved back to foo for the next iteration.

The problem is that the delta returns a lot of small (and sometimes very large) non-zero values even when the encoder isn't being touched, so I'm filtering out any movements with abs value <=1 or >= 255. If I don't do this, my accumulated value very quickly goes to zero or 255 and gets stuck there.

Do you have caps/resistors involved in your hardware to reduce this noise? Am I correct in supplying ground to the middle pin of the RE, or should I be giving it 5v?

from encoder.

John-Lluch avatar John-Lluch commented on July 28, 2024

Hi Brian,
I do not have any hardware to reduce noise. Just the encoder directly wired to inputs. Please can you try with an even simpler code, like just the code I posted above. (However as said, this is not tested with ATmega328, so maybe there's something wrong in the library itself)

from encoder.

John-Lluch avatar John-Lluch commented on July 28, 2024

Another thought. The library assumes pullup resistors are physically placed on the A, B encoder inputs. The KY-040 Encoder Module have them, so you do not need to do anything else. However if you are using an encoder component (not the encoder module) then you either have to physically wire the resistors, or to set the inputs as "INPUT_PULLUP", look at the Encoder::init() funcion

from encoder.

brianssparetime avatar brianssparetime commented on July 28, 2024

I was not using the KY040 module, just a bare encoder. Adding the pullup resistors indeed fixed the problem perfectly. I just added 10ks from A and B to +5v as you suggested, and now everything works exactly as expected.

Thank you again. This library is a dream to use!

from encoder.

John-Lluch avatar John-Lluch commented on July 28, 2024

Ok, Thanks again for your feedback

from encoder.

Related Issues (11)

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.