The code below got lot of errors, how to fix?

Hi all.
the ESP-Rotary encoder sketch can't compiling.
Thanks
Adam

#include "AiEsp32RotaryEncoder.h"
#include "Arduino.h"

/*
connecting Rotary encoder
Rotary encoder side    MICROCONTROLLER side  
-------------------    ---------------------------------------------------------------------
CLK (A pin)            any microcontroler intput pin with interrupt -> in this example pin 32
DT (B pin)             any microcontroler intput pin with interrupt -> in this example pin 21
SW (button pin)        any microcontroler intput pin with interrupt -> in this example pin 25
GND - to microcontroler GND
VCC                    microcontroler VCC (then set ROTARY_ENCODER_VCC_PIN -1) 
***OR in case VCC pin is not free you can cheat and connect:***
VCC                    any microcontroler output pin - but set also ROTARY_ENCODER_VCC_PIN 25 
                        in this example pin 25
*/
#if defined(ESP8266)
#define ROTARY_ENCODER_A_PIN D6
#define ROTARY_ENCODER_B_PIN D5
#define ROTARY_ENCODER_BUTTON_PIN D7
#else
#define ROTARY_ENCODER_A_PIN 32
#define ROTARY_ENCODER_B_PIN 21
#define ROTARY_ENCODER_BUTTON_PIN 25
#endif
#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 */

//depending on your encoder - try 1,2 or 4 to get expected behaviour
//#define ROTARY_ENCODER_STEPS 1
//#define ROTARY_ENCODER_STEPS 2
#define ROTARY_ENCODER_STEPS 4

//instead of changing here, rather change numbers above
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, ROTARY_ENCODER_VCC_PIN, ROTARY_ENCODER_STEPS);

void rotary_onButtonClick()
{
    static unsigned long lastTimePressed = 0;
    if (millis() - lastTimePressed < 500)
        return; //ignore multiple press in that time milliseconds
    lastTimePressed = millis();

    unsigned long acceletation = rotaryEncoder.getAcceleration() + 50;
    if (acceletation > 400)
        acceletation = 0;
    rotaryEncoder.setAcceleration(acceletation);

    Serial.print("new acceleration is ");
    Serial.println(acceletation);
    Serial.print("Try to set value: ");
    Serial.println(random(-999, 999));
    Serial.println("Set as fast as you can. If it is too hard or you suceeded, press the button again.");
}

void rotary_loop()
{
    if (rotaryEncoder.encoderChanged())
    {
        Serial.print("Value: ");
        Serial.println(rotaryEncoder.readEncoder());
    }
    if (rotaryEncoder.isEncoderButtonClicked())
    {
        rotary_onButtonClick();
    }
}

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

void setup()
{
    Serial.begin(115200);
    rotaryEncoder.begin();
    rotaryEncoder.setup(readEncoderISR);
    bool circleValues = false;
    rotaryEncoder.setBoundaries(-1000, 1000, circleValues); //minValue, maxValue, circleValues true|false (when max go to min and vice versa)
    rotaryEncoder.disableAcceleration();                    //acceleration is now enabled by default - disable if you dont need it
    Serial.println("Ready");
    Serial.print("Try to set value: ");
    Serial.println(752);
    Serial.println("If it is too hard press the button.");
}

void loop()
{
    rotary_loop();
    delay(50);
}
Arduino: 1.8.19 (Windows 10), Board: "ESP32S3 Dev Module, Disabled, QIO 80MHz, 4MB (32Mb), Core 1, Core 1, Hardware CDC and JTAG, Enabled, Disabled, Disabled, UART0 / Hardware CDC, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi), 921600, None, Disabled"




C:\Users\Xinzhou\Documents\Arduino\libraries\ai-esp32-rotary-encoder-master\src\AiEsp32RotaryEncoder.cpp:135:1: error: no declaration matches 'AiEsp32RotaryEncoder::AiEsp32RotaryEncoder(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)'

 AiEsp32RotaryEncoder::AiEsp32RotaryEncoder(uint8_t encoder_APin, uint8_t encoder_BPin, uint8_t encoder_ButtonPin, uint8_t encoder_VccPin, uint8_t encoderSteps)

 ^~~~~~~~~~~~~~~~~~~~

In file included from C:\Users\Xinzhou\Documents\Arduino\libraries\ai-esp32-rotary-encoder-master\src\AiEsp32RotaryEncoder.cpp:11:

C:\Users\Xinzhou\Documents\Arduino\libraries\ai-esp32-rotary-encoder-master\src\AiEsp32RotaryEncoder.h:29:7: note: candidates are: 'constexpr AiEsp32RotaryEncoder::AiEsp32RotaryEncoder(AiEsp32RotaryEncoder&&)'

 class AiEsp32RotaryEncoder

       ^~~~~~~~~~~~~~~~~~~~

C:\Users\Xinzhou\Documents\Arduino\libraries\ai-esp32-rotary-encoder-master\src\AiEsp32RotaryEncoder.h:29:7: note:                 'constexpr AiEsp32RotaryEncoder::AiEsp32RotaryEncoder(const AiEsp32RotaryEncoder&)'

C:\Users\Xinzhou\Documents\Arduino\libraries\ai-esp32-rotary-encoder-master\src\AiEsp32RotaryEncoder.h:67:2: note:                 'AiEsp32RotaryEncoder::AiEsp32RotaryEncoder(uint8_t, uint8_t, uint8_t, int8_t, uint8_t)'

  AiEsp32RotaryEncoder(

  ^~~~~~~~~~~~~~~~~~~~

C:\Users\Xinzhou\Documents\Arduino\libraries\ai-esp32-rotary-encoder-master\src\AiEsp32RotaryEncoder.h:29:7: note: 'class AiEsp32RotaryEncoder' defined here

 class AiEsp32RotaryEncoder

       ^~~~~~~~~~~~~~~~~~~~

exit status 1

Error compiling for board ESP32S3 Dev Module.



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

On my phone it is difficult to see, but I think your call to instantiate a variable of class AiESPblabla the class is not correct.
The number of arguments is not matching any of the prototypes. It needs 5 arguments and you have 4.

1 Like

is this how you define an "AiEsp32RotaryEncoder"? (with an "=" sign)?

1 Like

Are you using Platformio?

I believe there's some incompatibility because it can be compiled in Arduino IDE but can't be in PIO.

1 Like

acutally, it is an example from: ai-esp32-rotary-encoder/examples/Esp32RotaryEncoderBasics/Esp32RotaryEncoderBasics.ino at master · igorantolic/ai-esp32-rotary-encoder · GitHub

I'm using Arduino IDE

it's 5

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