Rotary Encoder funktioniert nicht mit Display

Servus alle zusammen,
Ich bin schon seit einer Weile bei meinem Projekt an einem Punkt, an dem ich nicht weiter komme. Mein Problem ist, dass ich meinen Rotary Encoder nicht zum Funktionieren bekomme, sobald ich das Display mit ein beziehe. Benutzen tue ich einen Arduino Nano und diese Libarys für den Encoder habe ich bereits versucht und bin bei jedem gescheitert.
Libs die ich benutzt habe: https://github.com/mathertel/RotaryEncoder
https://github.com/gfvalvo/NewEncoder
und eine weitere, von der ich den Link nicht mehr habe.
All diese Libarys funktionieren, wenn ich den Encoder für sich betrachte.
Aber wie zuvor erwähnt, sobald die u8g2 lib dazu kommt, bekomme ich keine werte mehr für meinen Encoder. Ich habe bereits andere Pins versucht, aber auch ohne Erfolg.

Das ist mein aktueller Code, aber man beachte, dass der Encoderteil einfach aus dem Beispiel genommen wurde, der Testzwecken wegen.

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
U8G2_SSD1306_128X64_NONAME_2_HW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // All Boards without Reset of the Display

#include "SparkFunHTU21D.h"
//Disp: 0x3C
//Temp: 0x40
HTU21D sensor;

int relais_fan = 6;
int relais_heater_1 = 7;
int relais_heater_2 = 8;

#include "NewEncoder.h"

#define rot_sw 2
#define rot_dt 3
#define rot_clk 4
//int rot_sw = 5;
//int rot_dt = 6;
//int rot_clk = 7;
// Demonstrate how to include an encoder object inside of a class and how to use the
// callback feature to call an instance function of the class
class MyClass {
  public:
    MyClass(uint8_t aPin, uint8_t bPin, int16_t minValue, int16_t maxValue, int16_t initalValue, uint8_t type = FULL_PULSE) :
      encoder { aPin, bPin, minValue, maxValue, initalValue, type } {
    }

    bool begin() {
      NewEncoder::EncoderState state;
      if (!encoder.begin()) {
        return false;
      }
      newValueAvailable = false;
      encoder.getState(state);
      encoderValue = state.currentValue;
      encoder.attachCallback(callBack, this);
      return true;
    }

    bool newDataAvailable() {
      noInterrupts();
      bool temp = newValueAvailable;
      newValueAvailable = false;
      interrupts();
      return temp;
    }

    int16_t getData() {
      int16_t temp;
      noInterrupts();
      temp = encoderValue;
      interrupts();
      return temp;
    }

  private:
    // embedded NewEncoder object
    NewEncoder encoder;

    volatile int16_t encoderValue = 0;
    volatile bool newValueAvailable = false;
    void handleEncoder(const volatile NewEncoder::EncoderState *state);
    static void callBack(NewEncoder *encPtr, const volatile NewEncoder::EncoderState *state, void *uPtr);
};

// Static class callback function. Common to all instances. Uses the uPtr parameter to select the proper
// instance. Then, calls the instance function.
// Be careful, the callback executes in interrupt contexts.
void ESP_ISR MyClass::callBack(NewEncoder *encPtr, const volatile NewEncoder::EncoderState *state, void *uPtr) {
  (void) encPtr;
  MyClass *ptr = (MyClass *) uPtr;
  ptr->handleEncoder(state);
}

// Instance function to handle encoder specific to each object. Called by static callback function.
// This is where instance-specific actions will be taken when the encoder is rotated.
// In this example, we just set a flag and make encoder value available to main code.
// Be careful, the callback executes in interrupt contexts.
void ESP_ISR MyClass::handleEncoder(const volatile NewEncoder::EncoderState *state) {
  if (state->currentValue != encoderValue) {
    encoderValue = state->currentValue;
    newValueAvailable = true;
  }
}

// Pins 2 and 3 should work for many processors, including Uno. See README for meaning of constructor arguments.
// Use FULL_PULSE for encoders that produce one complete quadrature pulse per detnet, such as: https://www.adafruit.com/product/377
// Use HALF_PULSE for endoders that produce one complete quadrature pulse for every two detents, such as: https://www.mouser.com/ProductDetail/alps/ec11e15244g1/?qs=YMSFtX0bdJDiV4LBO61anw==&countrycode=US&currencycode=USD
MyClass myObject { 2, 3, 0, 50, 25, FULL_PULSE };

void setup() {
  Serial.begin(9600);

  u8g2.begin();
  u8g2.setFontPosTop();
  u8g2.setFont(u8g2_font_ncenB10_tr);

  sensor.begin();
  pinMode(relais_fan, OUTPUT);
}

void loop() {
  //Serial.println(Temp());
  float hum = sensor.readHumidity();
  char hum_char[8];
  dtostrf(hum, -6, 2, hum_char);

  float temp = sensor.readTemperature();
  char temp_char[8];
  dtostrf(temp, -6, 2, temp_char);


  Serial.print("myObject: ");
  Serial.println(myObject.getData());

  u8g2.firstPage();
  do {
    u8g2.setCursor(0, 0);
    u8g2.println("Hum: " + String(hum_char));
    u8g2.setCursor(0, u8g2.getMaxCharHeight());
    u8g2.println("Temp: " + String(temp_char));
    u8g2.setCursor(0, u8g2.getMaxCharHeight() * 2);
    u8g2.println("Temp: " + String(temp_char));
  } while ( u8g2.nextPage() );
  //delay(1000);
}

Ich hoffe, mir kann jemand weiter helfen.
Mfg Stephan

Fehlt da ein myObject.begin(); ?

Nein. Wie gesagt, das ist einfach dem Beispiel entnommen und da funktioniert es.

Ich kenne mich mit Klassen nicht aus.
In der Klassen hast du eine begin-function
und die macht auch was.

ist die nur zur Zierde da?

Der Democode kommt ohne Klasse aus.

myObject ist natürlich ein toller Name für das Encoder-Object.

oder könnte es sein dass dein Code in der do-while-Schleife hängen bleibt?

vgs

Auch wenn ich den SPeicherbedarf für den Page buffer mode bei der U8G2-Lib nicht kenne, so ist auf einem Nano doch mit 2KB RAM nicht so wahnsinnig viel Platz.
Hast du einen Blick darauf geworfen (in deinem Gesamt-Projekt)?

@StefanL38, die klasse war nur als Test, um zu sehen, ob es was ändert. Tat es aber nicht. Ich habe unten nun den alten code den ich hatte eingefügt. Aber auch da, der Rotary teil ist eins zu eins dem Beispiel entnommen.

@dsebastian Ich verwende den Pagebuffer da der Fullframebuffer eingies mehr an RAM zieht. Mit FullframBuffer komme ich auf dem nano an die Limits, aber mit Pagebuffer verbrauche ich nur um die 50 %.

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
U8G2_SSD1306_128X64_NONAME_2_HW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // All Boards without Reset of the Display

#include "SparkFunHTU21D.h"
//Disp: 0x3C
//Temp: 0x40
HTU21D sensor;

int relais_fan = 6;
int relais_heater_1 = 7;
int relais_heater_2 = 8;

#include "NewEncoder.h"

#define rot_sw 2
#define rot_dt 3
#define rot_clk 4
//int rot_sw = 5;
//int rot_dt = 6;
//int rot_clk = 7;
NewEncoder encoder(2, 3, -20, 20, 0, FULL_PULSE);
int16_t prevEncoderValue;

/*
#define fan_frame_1_width 40
#define fan_frame_1_height 40
static const unsigned char fan_frame_1[] U8X8_PROGMEM = {
  0x23, 0x64, 0x65, 0x66, 0x69, 0x6E, 0x65, 0x20, 0x46, 0x61, 0x6E, 0x31, 0x53, 0x70, 0x72, 0x69,
  0x74, 0x65, 0x5F, 0x77, 0x69, 0x64, 0x74, 0x68, 0x20, 0x34, 0x30, 0x0A, 0x23, 0x64, 0x65, 0x66,
  0x69, 0x6E, 0x65, 0x20, 0x46, 0x61, 0x6E, 0x31, 0x53, 0x70, 0x72, 0x69, 0x74, 0x65, 0x5F, 0x68,
  0x65, 0x69, 0x67, 0x68, 0x74, 0x20, 0x34, 0x30, 0x0A, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20,
  0x75, 0x6E, 0x73, 0x69, 0x67, 0x6E, 0x65, 0x64, 0x20, 0x73, 0x68, 0x6F, 0x72, 0x74, 0x20, 0x46,
  0x61, 0x6E, 0x31, 0x53, 0x70, 0x72, 0x69, 0x74, 0x65, 0x5F, 0x62, 0x69, 0x74, 0x73, 0x5B, 0x5D,
  0x20, 0x3D, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A,
  0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x33, 0x66, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78,
  0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x63, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x38, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x66, 0x66, 0x65, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x31, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x31, 0x63, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x66, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x33, 0x63, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x37, 0x66, 0x66, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x37, 0x65, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x33, 0x66, 0x66, 0x38, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x66, 0x65, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x31, 0x66, 0x66, 0x38, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C,
  0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x31, 0x66, 0x65, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x66,
  0x66, 0x38, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x33, 0x66,
  0x65, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x37, 0x66, 0x38, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x37, 0x66, 0x65, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x33,
  0x66, 0x38, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30,
  0x78, 0x66, 0x66, 0x65, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x31, 0x66, 0x38, 0x2C, 0x20, 0x30,
  0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x63, 0x30, 0x2C, 0x20, 0x30,
  0x78, 0x30, 0x30, 0x66, 0x39, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30,
  0x78, 0x66, 0x66, 0x63, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x37, 0x62, 0x2C, 0x20, 0x30,
  0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x66, 0x66, 0x38, 0x30,
  0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x33, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30,
  0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x33, 0x66, 0x65, 0x37,
  0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x63, 0x30, 0x30,
  0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x65, 0x37, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30,
  0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66,
  0x66, 0x66, 0x63, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x31, 0x2C, 0x20, 0x30, 0x78, 0x30,
  0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x64, 0x65, 0x2C, 0x20, 0x30, 0x78, 0x30,
  0x30, 0x30, 0x33, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66,
  0x66, 0x39, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x33, 0x2C, 0x0A, 0x20, 0x20, 0x20,
  0x30, 0x78, 0x38, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x31, 0x66, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x37, 0x2C, 0x20, 0x30, 0x78, 0x63, 0x30, 0x30, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x66, 0x65, 0x31, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x37, 0x2C, 0x20,
  0x30, 0x78, 0x65, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x63, 0x31, 0x66, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x37, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x66, 0x30, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x38, 0x31, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x37, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x38, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x30, 0x31,
  0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x37, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x63, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x65, 0x30, 0x31, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x37, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x66, 0x65, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x63, 0x30, 0x30, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x33, 0x2C, 0x20, 0x30, 0x78,
  0x66, 0x66, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x38, 0x30, 0x30, 0x66, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x30, 0x30, 0x33, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x38, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x30, 0x30, 0x37, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x31, 0x2C, 0x0A, 0x20, 0x20,
  0x20, 0x30, 0x78, 0x66, 0x66, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x33, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x63, 0x30, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30,
  0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x20, 0x7D, 0x3B,
  0x0A
};

#define fan_frame_2_width 40
#define fan_frame_2_height 40
static const unsigned char fan_frame_2[] U8X8_PROGMEM = {
  0x23, 0x64, 0x65, 0x66, 0x69, 0x6E, 0x65, 0x20, 0x46, 0x61, 0x6E, 0x32, 0x53, 0x70, 0x72, 0x69,
  0x74, 0x65, 0x5F, 0x77, 0x69, 0x64, 0x74, 0x68, 0x20, 0x34, 0x30, 0x0A, 0x23, 0x64, 0x65, 0x66,
  0x69, 0x6E, 0x65, 0x20, 0x46, 0x61, 0x6E, 0x32, 0x53, 0x70, 0x72, 0x69, 0x74, 0x65, 0x5F, 0x68,
  0x65, 0x69, 0x67, 0x68, 0x74, 0x20, 0x34, 0x30, 0x0A, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20,
  0x75, 0x6E, 0x73, 0x69, 0x67, 0x6E, 0x65, 0x64, 0x20, 0x73, 0x68, 0x6F, 0x72, 0x74, 0x20, 0x46,
  0x61, 0x6E, 0x32, 0x53, 0x70, 0x72, 0x69, 0x74, 0x65, 0x5F, 0x62, 0x69, 0x74, 0x73, 0x5B, 0x5D,
  0x20, 0x3D, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x63, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A,
  0x20, 0x20, 0x20, 0x30, 0x78, 0x38, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x63, 0x30, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x65, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78,
  0x65, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x66, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x65, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x30, 0x30, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x66, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x66, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x66, 0x30, 0x30, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x66, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x66, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x30, 0x30, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C,
  0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x65, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x30,
  0x30, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x65, 0x30,
  0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x65, 0x30, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x37, 0x2C, 0x20, 0x30, 0x78, 0x65, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66,
  0x30, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x66, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30,
  0x78, 0x63, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x38, 0x66, 0x2C, 0x20, 0x30,
  0x78, 0x30, 0x30, 0x31, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x38, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30,
  0x78, 0x66, 0x66, 0x63, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x31, 0x66, 0x2C, 0x20, 0x30,
  0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x65, 0x66, 0x2C, 0x20, 0x30,
  0x78, 0x30, 0x30, 0x31, 0x66, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30,
  0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x66, 0x65, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x33, 0x66,
  0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x65, 0x34,
  0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x33, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x66, 0x63,
  0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x32, 0x37, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30,
  0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x66, 0x66, 0x66, 0x63, 0x2C, 0x20, 0x30, 0x78, 0x30,
  0x30, 0x37, 0x66, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66,
  0x66, 0x66, 0x38, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x66, 0x37, 0x2C, 0x20, 0x30, 0x78, 0x30,
  0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x66, 0x38, 0x2C, 0x20, 0x30, 0x78, 0x30,
  0x31, 0x66, 0x33, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20,
  0x30, 0x78, 0x66, 0x66, 0x66, 0x38, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x33, 0x66, 0x31, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x66, 0x66, 0x66, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x37, 0x66, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x37, 0x66, 0x65, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x37, 0x66, 0x30, 0x2C, 0x20,
  0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x66, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x37, 0x66, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x66, 0x66,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x66, 0x66, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30,
  0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x66, 0x66, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x66, 0x66, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78,
  0x30, 0x37, 0x66, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x37, 0x66, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x37, 0x66, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x33, 0x66, 0x30, 0x2C,
  0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x31, 0x66, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x33, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30,
  0x30, 0x30, 0x2C, 0x0A, 0x20, 0x20, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30,
  0x78, 0x30, 0x30, 0x30, 0x30, 0x2C, 0x20, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x20, 0x7D, 0x3B,
  0x0A
};
*/

void setup() {
  Serial.begin(9600);

  u8g2.begin();
  u8g2.setFontPosTop();
  u8g2.setFont(u8g2_font_ncenB10_tr);

  sensor.begin();
  pinMode(relais_fan, OUTPUT);

  NewEncoder::EncoderState state;
  Serial.println("Starting");

  if (!encoder.begin()) {
    Serial.println("Encoder Failed to Start. Check pin assignments and available interrupts. Aborting.");
    while (1) {
      yield();
    }
  } else {
    encoder.getState(state);
    Serial.print("Encoder Successfully Started at value = ");
    prevEncoderValue = state.currentValue;
    Serial.println(prevEncoderValue);
  }
}

void loop() {
  //Serial.println(Temp());
  float hum = sensor.readHumidity();
  char hum_char[8];
  dtostrf(hum, -6, 2, hum_char);

  float temp = sensor.readTemperature();
  char temp_char[8];
  dtostrf(temp, -6, 2, temp_char);

  int16_t currentValue;
  NewEncoder::EncoderState currentEncoderState;

  if (encoder.getState(currentEncoderState)) {
    Serial.print("Encoder: ");
    currentValue = currentEncoderState.currentValue;
    if (currentValue != prevEncoderValue) {
      Serial.println(currentValue);
      prevEncoderValue = currentValue;
    } else
      switch (currentEncoderState.currentClick) {
        case NewEncoder::UpClick:
          Serial.println("at upper limit.");
          break;

        case NewEncoder::DownClick:
          Serial.println("at lower limit.");
          break;

        default:
          break;
      }
  }

  u8g2.firstPage();
  do {
    u8g2.setCursor(0, 0);
    u8g2.println("Hum: " + String(hum_char));
    u8g2.setCursor(0, u8g2.getMaxCharHeight());
    u8g2.println("Temp: " + String(temp_char));
    u8g2.setCursor(0, u8g2.getMaxCharHeight() * 2);
    u8g2.println("Temp: " + String(temp_char));
  } while ( u8g2.nextPage() );
  //delay(1000);
  //drawLogo();
}
/*
void drawLogo() {
  u8g2.firstPage();
  do {
    u8g2.drawXBMP(0, 0, fan_frame_1_width, fan_frame_1_height, fan_frame_1);
  } while ( u8g2.nextPage() );
}
*/

So und was heisst das jetzt?

Läuft diese Code-Version aus post #6 oder was macht diese code-version für Mucken?

Wenn Sie nicht läuft musst du ja irgendetwas anders machen als der Demo-Code.

Hast du denn den Demo-Code 1 zu 1 aufgespielt und getestet?
vgs

@StefanL38 Ja. Wenn ich den Democode der nur für den rotary ist aufspiele funktioniert er. Soblad ich aber das Beispiel bei mir in meinen code mit dem Display und den anderen I2C Geräten verwende, geht es nicht mehr.

Ok. Um das problem einzugrenzen würde ich jetzt
ausgehend vom funktionierenden Democode in möglichst kleinen Schritten das Programm verändern und nach jeder Änderung testen ob es jetzt immer noch geht.
vgs

Aha! Da könnte ein Problem schlummern... oder auch nicht. Wie auch immer, mit Hilfe eines funktionierenden Demo-Code auf die Fehlerursache eine nicht funktionierenden "Gesamt-"Codes zu schliessen scheint mir, wie @StefanL38 auch angedeutet hat, wenig erfolgversprechend.

Also, setze es Stück für Stück zusammen. Also A, dann B, dann C, dann D, und wenn es bei E nicht mehr funktioniert, hast du es eingegrenzt. Oder wunderst dich möglicherweise, dass es nach Entfernen von C auch mit E geht ... egal: Finde den Code und/oder Hardwareerweiterung, ab dem es nicht mehr geht!

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