HowTo: ESPEasy – connect the rotary encoder to the ESP8266 and evaluate it

Especially if your own circuit has a display to show values, the next step is to also connect an operating option.

You can connect buttons or switches. A really cool way to equip your own circuit with an input option is the rotary encoder.

At first glance, a rotary encoder looks like a potentiometer. Unlike the potentiometer, the rotary encoder can be turned infinitely in both directions. In addition, many models are equipped with a button. Connected to a microcontroller, it can ultimately detect how far the device was turned in which direction and also whether the button was pressed.

Thanks to the appropriate plugin, rotary encoders can be read very easily using ESPEasy and react to the input.

How you connect one (or two) rotary encoders to a Wemos D1 Mini or ESP8266 and configure ESPEasy correctly is described in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
Additional tips on ESPEasy can be found in the following articles.

Required tool:

Required material:


Connect the rotary encoder

Below you can see two circuit diagrams showing how you can connect a rotary encoder to the Wemos D1 Mini.

Circuit diagram for connecting a single rotary encoder.

Circuit diagram for connecting two rotary encoders. A WS2812 LED strip is also connected here. In order for this configuration to work, you must deactivate the reservation of the D1 and D2 pins for the I2C bus in ESPEasy.


Configuration of the rotary encoder in ESPEasy

First open the web configuration view of your ESPeasy installation.

You can also find information about how you can open this view in the article Display/find out the IP address of the devices in the network

From there, click on the “Devices” tab.

In the "Devices" tab, click on the "Add" button in one of the empty rows.

You will then be automatically redirected to the view shown...

...and you can now select which device you want to create.

Since you want to create a rotary encoder, select the entry “Switch Input – Rotary Encoder” here.

This will redirect you to an overview page. Here you can make all settings regarding the rotary encoder.

What is important here is that you assign a name, tick “Enabled” and configure the GPIOs as shown.

The “GPIO <- A” and “GPIO <- B” settings correspond to the connections of the rotary encoder, which are shown in the circuit diagram above by the green and blue lines.

For most rotary encoders you can set the “Mode” setting as shown.

By turning the rotary encoder, a counter is later counted up or down. You can configure its lower and upper limit using the settings under “Limit min” and “Limit max”.

Once you have configured everything correctly, you can save the settings by clicking on “Submit”.

In order to evaluate the keystroke on the rotary encoder button, you have to create a separate device.

To do this, click again on the next “free” “Add” button in the devices overview.

In the drop-down list you now select the device “Switch input – Switch”.

You now have to set this device as shown on the left.

It is also important that the GPIO must be set to pin “D5”. This is the connection pin via which the button of the rotary encoder is read out.

Once you have made all the settings, you can save them by clicking on “Submit”.


Test rotary encoder

After you have connected and configured the rotary encoder, you can test the function using the ESPEasy log. Events that have to do with the connected sensors and actuators are also displayed there.

To do this, switch to the “Tools” tab and then click on the “Log” button.

The log output from ESPEasy will then be displayed to you.

If you now turn the rotary encoder, an output with “QEI…” should become visible. The number behind it shows the value of the counter, which you count up or down by turning the rotary encoder.

As soon as you press the encoder button, an entry starting with “SW:…” should be displayed.

You can then further process the keystrokes or operations of the rotary encoder using the rules and thus also trigger actions.

Alternatively, you can also forward it to your SmartHome system via MQTT and, for example, turn a light on or off.


Additional sensors for connection to the ESP8266 / ESP32

An overview of other articles for connecting sensors and actuators to ESPEasy can be found in the following category.


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

4 comments

  1. Hello Fabian
    ..I would like to say THANK YOU - that there is someone like you - from whom a “hobbyist” like me can learn something!!
    ..I learned and recreated a lot of interesting things here – PWM with rotary encoder..
    I use e.g. Currently an ESP8266 as a thermostat with 2 buttons (1 GPIO each) and ESPEASY with a (copied) rule. If necessary, I will also send the/my Rules
    ..I would like to convert this to the rotary encoder instead of the + and – button.
    ..if possible encoder step
    Unfortunately I'm not that fit in Rules and I can't do it.
    ..you probably know an example / link – Rules for ESPEASY ?
    Greetings from Vienna – fossi1

    1. Hi fossi1,
      thanks for your nice words. I'm glad my tips are useful. 🙂
      Write me your current rules. Then I'll take a look and see if you can rebuild/expand them so that you can control them with a rotary encoder. 🙂
      Best regards
      Fabian

      1. Hello Fabian
        Thank you for your answer – I wish you a HAPPY NEW YEAR!!

        For your general information:
        ..I have some esp for various applications, hardware can do it, but I am (unfortunately still) the “copier” in software – so please check my rules..

        ..one of my projects – I want/will build a “smoker control” for my friend.
        Temperature measurement with 4 K sensors, D1mini with EspEasy, OLED + LCD, relay for fan control and 4x MAX31850 (K sensors are read in 1Wire and in EspEasy under D18B20)

        ..the temp measurement of the K-sensor via MAX31850 works
        ..the “rough” display of the temperature of the sensor Currently testing the DS18B20
        ..the real temp display is via OLED and LCD
        ..the setting of the temp (for the fan operation) currently via +/- keys

        ..since the fan speed is supposed to be regulated depending on a K sensor in the temperature range of 100-200 degrees, using buttons is very “tough” - your rotary encoder would be the more convenient solution.

        .. my esp therefore has 3 rules for neopixel display, key query, display
        ..here the rules 2 :
        —————————————————————————–
        /key query - changed 06.02.22Fo

        //esp8266
        //GPIO 0 = button temperature +
        //GPIO 2 = temperature button –
        //GPIO 4 = SDA for Oled
        //GPIO 5 = SCL for Oled
        //GPIO 12 = DATA input from DS18B20
        //GPIO 14 = output S for relay
        //GPIO 15 = output for Neopixel

        on System#Boot do
        TaskValueSet 6,1,25.0 //SetTemp = TARGET Temp
        TaskValueSet 6,2,24.5 //TempLow = lowest temp
        TaskValueSet 6,3,25.5 //TempHigh = highest temp
        gpio,14,1
        endon

        //Key query for temp setting
        //UP = Task7 on D3(GPIO-0) and DOWN = Task7 on D4(GPOI-2)

        on Up#State do
        if [Up#State]=1
        if [Local#SetTemp]5 //Temp. Setting limitation from 5°
        TaskValueSet 6,1,[Local#SetTemp]-1.0
        TaskValueSet 6.2,[Local#SetTemp]-1.0
        TaskValueSet 6.3,[Local#SetTemp]
        endif
        endif
        endon

        //Define switching state

        on T5#temperature do
        if [T5#temperature]+1[Local#TempLow]
        event,TurnOff
        endif
        endon
        ———————————————————
        ..unfortunately I don't have an email address from you, otherwise I can send the txt file
        ..if you need any more information, write me event. by mail

        Greetings from Vienna – fossi1

        1. Hi fossi1,
          sorry that I'm just getting in touch now. I got your message via the contact form. But I was still in the aftermath of my move and then the holidays intervened. :/
          But I'll try to take care of it as soon as possible. wrote it down for me 🙂
          Best regards
          Fabian

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.