Giter Club home page Giter Club logo

ky040's Introduction

KY040

An Arduino library for KY-040 rotary encoders. The library has debouncing and works in polling mode, with pin change interrupts or normal interrupts. In polling or pin change interrupt mode you can attach more then one rotary encoder to your Arduino Uno/Nano.

PDF-Documentation

Examples how to use the library

License and copyright

This library is licensed under the terms of the 2-Clause BSD License Copyright (c) 2024 codingABI.

Appendix

Background

KY040 is library for KY-040 rotary encoders. There are a lot of libraries existing for KY-040, but I found no library (at least 12/2023) which

  1. works without the need of interrupt enabled pins for the CLK (aka. A) and DT (aka. B)
  2. and has a stable debouncing using a signal state table (without debouncing the KY-040 rotary encoder is a mess)

So I wrote my own library KY040, which was designed to work on an Arduino Uno/Nano or ATmega328 and could work on other Arduino compatible MCUs too.

The KY040 library can:

  • be used without interrupts in polling mode
  • be used with pin change interrupts
  • control more than one rotary encoders in polling or pin change interrupt mode on an Arduino Uno/Nano
  • use any common pin digital pins for CLK and DT in polling or pin change interrupt mode
  • be used with normal attachInterrupt interrupts (in this case could have to use Pins 2 and 3 on your Arduino Uno/Nano)
  • be used with SLEEP_MODE_PWR_SAVE/SLEEP_MODE_PWR_DOWN sleep mode in combination with pin change interrupts
  • debounce the rotary encoder by filtering out invalid signal sequences

Valid clockwise sequence

        0 1 2 3
    --+   +----   High
CLK   |   |
      +---+       Low
      
    ----+   +--   High
DT      |   |
        +---+     Low
Step Signal level for CLK/DT
0 Low/High
1 Low/Low
2 High/Low
3 High/High

Valid counter-clockwise sequence

       0 1 2 3
    ----+   +---  High
CLK     |   |
        +---+     Low
        
    --+   +-----  High
DT    |   |
      +---+       Low
Step Signal level for CLK/DT
0 High/Low
1 Low/Low
2 Low/High
3 High/High

KY-040 Hardware

Frontside

Pins Comment
GND Ground
+ Vcc
SW Switch button, not covered by this library. You can use digitalRead statements to check SW. Pin is pulled up to Vcc via the 10k pullup resistor R3
DT aka. B, Pin is pulled up to Vcc via the 10k pullup resistor R2
CLK aka. A, Pin is pulled up to Vcc via the 10k pullup resistor R1

Backside

The three 10k resistors R1,R2 and R3 pulls up the SW, CLK and DT pins up to Vcc.

ky040's People

Contributors

codingabi avatar

Stargazers

 avatar

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.