GithubHelp home page GithubHelp logo

enjoyneering / rotaryencoder Goto Github PK

View Code? Open in Web Editor NEW
78.0 78.0 20.0 531 KB

This is small and fast Arduino library for Rotary Encoder with interrupts.

C++ 100.00%
arduino-library encoder interrupts ky-040 rotary rotary-encoder rotaryencoder

rotaryencoder's People

Contributors

enjoyneering avatar raspyweather avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rotaryencoder's Issues

ATSAMD21

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

Reading position with 24 step resolution

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.

Compatibility with STM144 H723ZG

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 !!!

RotaryEncoder

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

incompatible encoders

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.

is it possible to use with e6b2-cwz1x (incremental) ?

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 ?

#include <RotaryEncoderAdvanced.cpp> //for some reason linker can't find the *.cpp :(

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

Wont link

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()

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.