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
