luni64 / EncoderTool

The EncoderTool is a library to manage and read out rotary encoders connected either directly or via multiplexers to ARM based boards. Encoder push buttons are supported. Callback functions can be attached to encoder changes and button presses to allow for event driven applications
MIT License
48 stars 12 forks source link

Issue with TeensyLC #21

Closed bimac closed 2 years ago

bimac commented 2 years ago

Hi luni64,

I have a strange issue with EncoderTool on TeensyLC.

Here's the MWE:

#include <EncoderTool.h>

using namespace EncoderTool;
PolledEncoder enc;

void setup() {
  Serial.begin(9600);
  enc.begin(5, 6, 4, CountMode::half, INPUT_PULLUP);
}

void loop() {
  enc.tick();
  if(enc.valueChanged())
    Serial.println(enc.getValue());
}

On Teensy 3.2 this works perfectly fine: each detent will increment/decrement by 1. On TeensyLC, however, it will keep incrementing like crazy (without turning the encoder) with each iteration of loop() - but only for every other detent. I'm using this encoder. Is there anything that comes to mind?

Cheers!

luni64 commented 2 years ago

This looks weird. Unfortunately I'm currently not at home and don't have a LC with me. I'll have a look on Sunday.

bimac commented 2 years ago

Thanks a lot!

luni64 commented 2 years ago

I can reproduce this. It looks like there is a bug in the direct read code for the T-LC. I'll have a closer look later. As a quick workaround you can do the following:

Change line 46 in the library file cores.h as shown here: image

This disables the direct read code for the T-LC so that it falls back to a standard digitalRead/digitalWrite which works here. Can you please check if this works for you as well?

bimac commented 2 years ago

Thanks for looking into this! I can confirm that the workaround makes the encoder perform as expected.

luni64 commented 2 years ago

Great, I'll look for a permanent solution asap

bimac commented 2 years ago

Thanks for the fix Lutz! It works as expected now.

luni64 commented 2 years ago

Great, let me know if you find something else