enjoyneering / rotaryencoder Goto Github PK
View Code? Open in Web Editor NEWThis is small and fast Arduino library for Rotary Encoder with interrupts.
This is small and fast Arduino library for Rotary Encoder with interrupts.
Hi,
Thanks for you work on the library
I noticed in the Sketch
"This sketch uses interrupts, specials pins are required to interface
Board:
Zero, ATSAMD21G18........................ all digital pins, except pin 4"
Do you have an example for the ATSAMD21 or is it a work in progress.
Many thanks
Rupert
Position readings with a 24 step resolution encoder aren't working but a 12 step resolution encoder from the same manufacturer / series works fine with the same code.
Using a blue pill and a BOURNS PEC12R-4130F-S0012 rotary encoder works fine but I accidentally ordered a bunch of the 24 step variation (BOURNS PEC12R-4230F-S0024), the closest I can get them to working is by un-commenting the '2 counts per click' for the fast MCU (lines 139 + 149 in RotaryEncoder.cpp) but this results in the position jumping between 0 and 1.
The data sheet for both is here if that is any help.
Any help you could give would be much appreciated.
Hi, I've tested it, debounced encoder, it has this issue.
I've tried ESPRotary and it works ok. WHere can I correct your code? Thanks
Hi, nice looking library.
I'd really like to use it with STM144 H723ZG, but does not work :(
Is there any way to fix it?
(It works 'ok' on some other libraries, but really want to try this one. All connections and pin definitions are good.)
Cheers !!!
Hello,
Could you add a license information on this repository?
Thanks,
Ercan
You declared allmost all getters / setter as inline but impemnted them in a seperate *.cpp file; so the linker fails! Maybe you will change the header like that:
RotaryEncoder(uint8_t encoderA, uint8_t encoderB, uint8_t encoderButton);
void begin(void);
void readAB(void);
void readPushButton(void);
int16_t getPosition(void);
bool getPushButton(void);
void setPosition(int16_t position);
void setPushButton(bool state);
... and ...
RotaryEncoderAdvanced(uint8_t encoderA, uint8_t encoderB, uint8_t encoderButton, T stepsPerClick, T minValue, T maxValue);
T getValue(void);
void setValue(T value);
T getStepsPerClick(void);
void setStepsPerClick(T value);
T getMinValue(void);
void setMinValue(T value);
T getMaxValue(void);
void setMaxValue(T value);
void setValues(T currValue, T stepsPerClick, T minValue, T maxValue);
So the compiler succeeds. Otherwise transfer the code into the header, please.
Thak's for your patience!
Joerg
Hello,
I had a problem getting three different encoders working with your library. It's the kind of encoder, which contains pullups and capacitors for immediate use. Checked the encoder with oscilloscope, all three are working fine, without any chatter/bouncing, perfect squares. I tested them with an esp8266, a bluepill and a nano, but no success.
Then I dived into your source, and found out, that all this encoders are not compatible with the current encoder logic.
The encoders keep in idle state both pins high, and produce the following states, when turning one step clockwise:
11
10
00 <- this change triggers interrupt
01
11 <- this change triggers interrupt
and when turning counterclockwise, it will look like this:
11
01 <- this change triggers interrupt
00
10 <- this change triggers interrupt
11
this leads to the consequence, that the current switch-statements in the readAB() method do not trigger.
When I changed it to:
case 0b1100: // case 0b0011:
_counter++;
break;
case 0110: // case 0b1101:
_counter--;
break;
it triggers.
Currently I struggle however with the two respective four cases statements in your code, as for me one statement is enough, to get 1 count per step/click. With two statements i receive two counts on all tested platforms.
From the core logic four statements make no sense at all, as the irq-handler is tied to pin A, so there are not more than two possibilities, as changes on pinB are meaningless.
I would like to create an pull-request for a more general solution, but I would like to understand before, if I am on the right way, or if I miss some aspects of other hardware.
i`m working on e6b2-cwz1x (incremental) which fast continuously rotates.
as the speed is very fast arduino uno starts drops ticks in serial console.
so i moved to nodemcu v.3 and found this library.
can it helps ? how to adapt the code ?
Hello, and thanks for this library !
In the examples, you include RotaryEncoderAdvanced.cpp
Templates have to live in header files (inline functions only). The contents of RotaryEncoderAdvanced.cpp should be declared in RotaryEncoderAdvanced.h, and not in a separate cpp file that will never get compiled. Never compiled = never linked. (the preprocessor cannot know what type to use, it is defined in another file)
In a template class, everything must be in one file. (usually, the functions are defined in the class itself, not outside)
Have a look to the STL : no cpp files ! Only headers (that don't even have the h or hpp extension, but gcc does not like files with no extension)
Therefore everything has to be in RotaryEncoderAdvanced.h, and RotaryEncoderAdvanced.cpp has to be removed. And it will compile and link just fine
I modified your code and repacked it :
RotaryEncoder.zip
Compiling examples using VSCode with platformio on ESP8266 wemos D1 mini I get the following error
main.cpp:(.text.loop+0x2d): undefined reference to `RotaryEncoder::getPosition()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.