Stutchbury / EncoderButton

Lossless event based rotary encoder+button library for Arduino and Teensy
GNU General Public License v2.0
35 stars 8 forks source link

Lib conflict with Adafruit? #6

Closed frher closed 2 years ago

frher commented 2 years ago

Hi, if I insert a constructor like "EncoderButton encBut(encRotPinA, encRotPinB, encButPin);" in an existing/working sketch the display output to the OLED will no longer work. In detail: especially all text drawing functions using variables don't show any output. Im using Adafruits SH110X and GFX libraries on Arduino Uno/Nano together with your EncoderButton lib.

Is this a known issue? Thanks in advance! Frank

Stutchbury commented 2 years ago

Hi Frank

That's an interesting one - not a known issue. I'm using 3 instances of EncoderButton on this project:https://github.com/Stutchbury/Manualmatic-Pendant with Adafruit's GFX library using the ILI9341 display.

If you can supply a minimal test script, I can take a look but I don't think I have a SH110X to test against. Can you check if it the button or the encoder that is causing the problem. The EncoderButton lib uses Paul Stoffregen's Encoder library for the encoder and Thomas Fredericks' Bounce2 library for the button - both are well established libraries (hence why I used them).

See also the notes on interrupt pins here: https://www.pjrc.com/teensy/td_libs_Encoder.html

frher commented 2 years ago

Hi Phil.

Attached is a script which shows my problem. If run with out-commented EncoderButton lines the display looks like this: _"setup done

myPos: 0 myClickCnt: 0"_

If only the constructor of encBut is activated display shows: _"setup done

0 0"_ It seem's that the simple String operations will fail. It might also be that the global variables like "myPos" are set in an improper way. I don't know. If additionally the encoder handler ist activated the 0 will disappear too.

I've tested with only encoder and with only button functionality. It doesn't change anything. If I'm using Serial.print of the IDE everything works as expected.

err_example.ino.zip

Greetings. Frank

Stutchbury commented 2 years ago

Hi Frank

I will try to find a display to test this but first thing I noticed is you're updating the display every time in the loop() - you probably need to reduce the refresh rate to around 10 times/sec to give other things a chance to run. Don't use delay() - this is an example: https://github.com/Stutchbury/DisplayUtils/tree/main/examples/BasicDisplayArea - set displayRefreshMs to 100.

frher commented 2 years ago

Hi Phil,

Thanks for your idea. I've tried it. The screen is now as expected, but the values of gMyPos and gMyClick stay at 0 (as initialized). I tried to debug it with Serial output. But if Serial Monitor is active, the OLED screen only shows "setup done". Very strange!!! The values on Serial Monitor are not '0' but 'null'. It looks like that the event handler don't pass the global variables correct to the main.

frher commented 2 years ago

Hi Phil,

sorry for the inconvenience, but I did a mistake! There was the encBut.update() as commented line left. The values at the screen OLED are updated now. It works now! Many thanks. But the conflict with the Serial Monitor is still present. It's not really a problem at the moment.

Thanks again. Have a nice weekend!

Stutchbury commented 2 years ago

Hi Frank - excellent! I'm not really qualified to help with Serial Monitor, so I'll close this now!