Home

codesys.com Ingo Falk
Attachments
PLC_PRG.PNG (14146 bytes)
There is a newer version of this page. You can find it here.

How to bind a Rotary Encoder

Hardware

This library supports currently only the rotary encoder KY040. But it should support more in the future.

Usage

The exact usage of the driver depends on the hardware and the implementation of the driver. As this varies a bit, every driver has its own documentation.

As an example we will use the Raspberry Pi 1 Model B. You also have to install CODESYS Control for Raspberry Pi SL.

Now connect the outputs of the first KY040 with the Raspberry Pi like this:
CLK --> GPIO 0
DT --> GPIO 1
SW --> GPIO 3
+ --> 5.0 VDC Power
GND --> 0 V (Ground)

At this point you could install another KY040 if you want to play for example "retro-games" .

Step 1: In your CODESYS Development System open or create a project.
Step 2: Go to Tools -> Library Repository and Install the RotaryEncoder.library
Step 3: Now you can start programming.

On the picture below you can see an example of the retro-games project. As a sample if you insert a "Box" out of your ToolBox it is very easy to program it.
Image