I’m trying to connect a oled display module with an encoder and two buttons.

the first time i tried the code the encoder and the back button all worked fine, later on the encoder stopped working and the value was only 0 or 1, and all the buttons, except the encoder button always read as pressed.
this is the code:
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include <ESP32Encoder.h>
#define OLED_SDA 17
#define OLED_SCL 19
#define BTN_BAK 26
#define BTN_CON 14
#define ENC_PSH 21
#define ENC_TRA 18
#define ENC_TRB 20
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
ESP32Encoder encoder;
void setup() {
Serial.begin(115200);
Wire.begin(OLED_SDA, OLED_SCL);
u8g2.begin();
ESP32Encoder::useInternalWeakPullResistors = puType::up;
encoder.attachHalfQuad(ENC_TRA, ENC_TRB);
encoder.setCount(0);
pinMode(BTN_BAK, INPUT_PULLUP);
pinMode(BTN_CON, INPUT_PULLUP);
pinMode(ENC_PSH, INPUT_PULLUP);
}
void loop() {
long posizione = encoder.getCount();
bool b_bak = digitalRead(BTN_BAK) == LOW;
bool b_con = digitalRead(BTN_CON) == LOW;
bool b_psh = digitalRead(ENC_PSH) == LOW;
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x12_tr);
u8g2.drawStr(0, 10, "DIAGNOSTICA U8G2");
u8g2.drawHLine(0, 12, 128);
u8g2.setFont(u8g2_font_7x14_tr);
u8g2.setCursor(0, 30);
u8g2.print("BACK: "); u8g2.print(b_bak ? "PREMUTO" : "-");
u8g2.setCursor(0, 45);
u8g2.print("CONF: "); u8g2.print(b_con ? "PREMUTO" : "-");
// Valore Encoder (Font grande e centrato)
u8g2.setFont(u8g2_font_helvB14_tr);
u8g2.setCursor(0, 64);
u8g2.print("VAL: ");
u8g2.print(posizione);
if(b_psh) {
u8g2.drawDisc(110, 55, 6);
}
u8g2.sendBuffer();
delay(20);
}