Home

codesys.com Ingo Falk
Attachments
PLC_PRG.PNG (14146 bytes)

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.

Example Project

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

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

At this point you could install another KY040, in the same way but different pinouts like the first one, 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. For example you can insert a "Box" out of your ToolBox which is very easy to program.
Image


Related

Home: KY040