Comments (6)
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.
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.
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.
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.
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.
Ok, Thanks again for your feedback
from encoder.
Related Issues (11)
- ATMega328 not supported? HOT 2
- Bob HOT 3
- ESP32 HOT 4
- Using encoders without pushbutton? HOT 2
- Debouncer class name conflicts with dedicated Debouncer libraries
- Hold? HOT 1
- Adding a ready to compile example-code? HOT 1
- small extra feature?
- using the millis() timer0 alternative
- Please add a License HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from encoder.