RotaryEncoder LPD3806 ESP32 no but Arduino Uno yes? Wiring?

Hey folks.

The Rotary Encoder works on the Arduino Uno. But on the ESP32 not. I tried the Ky40 instead and recognized accidently, when BOTH Rotary keys on the same pins are connected, the LPD3806 works, but only the LPD3806 not?

Whats wrong with my wiring?

Code should work, because the ky040 rotary encoder works and also with both parts connected, i got values

#include <Arduino.h>
#include "AiEsp32RotaryEncoder.h"

#define ROTARY_ENCODER_A_PIN 26		 // clk
#define ROTARY_ENCODER_B_PIN 25		 // DT
#define ROTARY_ENCODER_BUTTON_PIN 33 // SW nicht genutzt
#define ROTARY_ENCODER_VCC_PIN -1	 /* 27 put -1 of Rotary encoder Vcc is connected directly to 3,3V; else you can use declared output pin for powering rotary encoder */
#define ROTARY_ENCODER_STEPS 1

AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, ROTARY_ENCODER_VCC_PIN, ROTARY_ENCODER_STEPS);

float getFrequency()
{
    return (float)rotaryEncoder.readEncoder() / 10.0;
}

void rotary_onButtonClick()
{


    Serial.print("Radio station set to ");
    Serial.print(getFrequency());
    Serial.println(" MHz ");
}

void IRAM_ATTR readEncoderISR()
{
    rotaryEncoder.readEncoder_ISR();
}

void setup()
{
    Serial.begin(115200);
    rotaryEncoder.begin();
    rotaryEncoder.setup(readEncoderISR);
   // rotaryEncoder.setBoundaries(88 * 10, 104 * 10, true); //minValue, maxValue, circleValues true|false (when max go to min and vice versa)
   // rotaryEncoder.setAcceleration(50);
   // rotaryEncoder.setEncoderValue(92.1 * 10); //set default to 92.1 MHz
    Serial.println("FM Radio");
    Serial.print("Radio station initially set to ");
    Serial.print(getFrequency());
    Serial.println(" MHz. Tune to some other station like 103.2... and press button ");
}

void loop()
{
    if (rotaryEncoder.encoderChanged())
    {
        Serial.print(getFrequency(), 1);
        Serial.println(" MHz ");
    }
    if (rotaryEncoder.isEncoderButtonClicked())
    {
        rotary_onButtonClick();
    }
}

thanks for your help

Putting 5V on the 3V3 GPIO pins might be an issue.

You have wired the encoders in parallel, why?

1 Like

When parallel connected, the LPD works, that was I found out accidently.
I just want to have the LPD Rotary

The LPD Rotary needs 5V.

But the ESP32 GPIOs do not tolerate 5V

1 Like

Output:
AB two-phase output rectangular orthogonal pulse, the circuit output is NPN open collector output type, this output type can be directly connected with single-chip microcomputer or PLC with internal pull-up resistor.

What does that tell you.

Does the library set internal pull up, or do you have external pull up resistors to 3.3volt.
Leo..

1 Like

Thank you for the answer! I've added now a logic level shifter and now everything works fine!

Many Thanks!

The real solution was that you had to add two (1k) pull up resistors between the outputs and the 3.3volt pin. Not a level shifter.
Leo..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.