Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 20 of 20

Thread: Teensy4.1 Encoder-Problems

  1. #1
    Junior Member
    Join Date
    Jan 2021
    Posts
    9

    Teensy4.1 Encoder-Problems

    Hi everybody and especially Paul,

    let me say first that Im totally impressed of your work. Since Corona gives me enough time, Im learning to work with arduinos. In my first steps I build a keyboard-controller using an arduino nano. This is my very first post in your forum and Im looking foreward to get some help.

    Now I try to build a controller with teensy4.1, 4 pots, 4 knobs, a ILI9341-Display without touch-function, USB-host and 1 encoder.
    I have a problem with the encoder, so I tried to run Pauls Basic-example with my pins 31/32, later 8/9.
    Code:
    ********************************************************
    /* Encoder Library - Basic Example
     * http://www.pjrc.com/teensy/td_libs_Encoder.html
     *
     * This example code is in the public domain.
     */
    
    #include <Encoder.h>
    
    // Change these two numbers to the pins connected to your encoder.
    //   Best Performance: both pins have interrupt capability
    //   Good Performance: only the first pin has interrupt capability
    //   Low Performance:  neither pin has interrupt capability
    Encoder myEnc(8, 9);                         // Edit-Box-Anpassung
    //   avoid using pins with LEDs attached
    
    void setup() {
    //  pinMode(8, INPUT);           // Encoder Eingang Pin 1
    //  pinMode(9, INPUT);           // Encoder Eingang Pin 2
      Serial.begin(9600);
      Serial.println("Basic Encoder Test:");
    }
    
    long oldPosition  = -999;
    
    void loop() {
      long newPosition = myEnc.read();
      if (newPosition != oldPosition) {
        oldPosition = newPosition;
        Serial.println(newPosition);
      }
    }
    This is my pinout:****************************************
    Click image for larger version. 

Name:	pinout teensy.jpg 
Views:	14 
Size:	118.9 KB 
ID:	23415
    Click image for larger version. 

Name:	pinout ILI9341.jpg 
Views:	16 
Size:	51.9 KB 
ID:	23416

    ************************************************** ****

    You see, Ive tried pins 31/32 for encoder DT and CLK, later pins 8/9.
    In both cases I got the following comment:


    "Arduino: 1.8.13 (Windows 10), TD: 1.53, Board: "Teensy 4.1, Serial, 600 MHz, Faster, German
    G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\arduino-builder -dump-prefs -logger=machine -hardware G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\hardware -tools G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\tools-builder -tools G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\hardware\tools\avr -built-in-libraries G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\libraries -libraries G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\libraries -fqbn=teensy:avr:teensy41:usb=serial,speed=600,opt= o2std,keys=de-de -ide-version=10813 -build-path C:\Users\Micki\AppData\Local\Temp\arduino_build_39 3323 -warnings=none -build-cache C:\Users\Micki\AppData\Local\Temp\arduino_cache_57 5043 -verbose G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\Encoder_Stoffregen\Enco der_Stoffregen.ino

    G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\arduino-builder -compile -logger=machine -hardware G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\hardware -tools G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\tools-builder -tools G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\hardware\tools\avr -built-in-libraries G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\libraries -libraries G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\libraries -fqbn=teensy:avr:teensy41:usb=serial,speed=600,opt= o2std,keys=de-de -ide-version=10813 -build-path C:\Users\Micki\AppData\Local\Temp\arduino_build_39 3323 -warnings=none -build-cache C:\Users\Micki\AppData\Local\Temp\arduino_cache_57 5043 -verbose G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\Encoder_Stoffregen\Enco der_Stoffregen.ino

    Using board 'teensy41' from platform in folder: G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\hardware\teensy\avr

    Using core 'teensy4' from platform in folder: G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\hardware\teensy\avr

    Detecting libraries used...

    "G:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_GERMAN "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy\\avr\\cores\\teensy4" "C:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323\\sketch\\Encoder_Stoffregen.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

    Alternatives for Encoder.h: [Encoder@1.4.1 Encoder@1.4.1]

    ResolveLibrary(Encoder.h)

    -> candidates: [Encoder@1.4.1 Encoder@1.4.1]

    "G:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_GERMAN "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy\\avr\\cores\\teensy4" "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\portable\\sketchbook\\libraries\\Encoder" "C:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323\\sketch\\Encoder_Stoffregen.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

    "G:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_GERMAN "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy\\avr\\cores\\teensy4" "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\portable\\sketchbook\\libraries\\Encoder" "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\portable\\sketchbook\\libraries\\Encoder\\ utility" "G:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\portable\\sketchbook\\libraries\\Encoder\\ Encoder.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

    Generating function prototypes...

    "G:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_GERMAN "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy\\avr\\cores\\teensy4" "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\portable\\sketchbook\\libraries\\Encoder" "C:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323\\sketch\\Encoder_Stoffregen.ino.cpp" -o "C:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323\\preproc\\ctags_target_for_gcc_minus_e .cpp" -DARDUINO_LIB_DISCOVERY_PHASE

    "G:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323\\preproc\\ctags_target_for_gcc_minus_e .cpp"

    Sketch wird kompiliert...

    "G:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy/../tools/precompile_helper" "G:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy\\avr/cores/teensy4" "C:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323" "G:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -x c++-header -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_GERMAN "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy\\avr/cores/teensy4" "C:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323/pch/Arduino.h" -o "C:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323/pch/Arduino.h.gch"

    Using previously compiled file: C:\Users\Micki\AppData\Local\Temp\arduino_build_39 3323\pch\Arduino.h.gch

    "G:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_GERMAN "-IC:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323/pch" "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\hardware\\teensy\\avr\\cores\\teensy4" "-IG:\\Einplatinen Computer\\Arduino IDE ZIP\\arduino-1.8.13-windows\\arduino-1.8.13\\portable\\sketchbook\\libraries\\Encoder" "C:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323\\sketch\\Encoder_Stoffregen.ino.cpp" -o "C:\\Users\\Micki\\AppData\\Local\\Temp\\arduino_b uild_393323\\sketch\\Encoder_Stoffregen.ino.cpp.o"

    In file included from G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\Encoder_Stoffregen\Enco der_Stoffregen.ino:7:0:

    G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\libraries\Encoder/Encoder.h: In constructor 'Encoder::Encoder(uint8_t, uint8_t)':

    G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\libraries\Encoder/Encoder.h:82:25: error: cannot convert 'volatile uint32_t* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment

    encoder.pin1_register = PIN_TO_BASEREG(pin1);

    ^

    G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\libraries\Encoder/Encoder.h:84:25: error: cannot convert 'volatile uint32_t* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment

    encoder.pin2_register = PIN_TO_BASEREG(pin2);

    ^

    Mehrere Bibliotheken wurden fr "Encoder.h" gefunden

    Benutzt: G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\libraries\Encoder

    Nicht benutzt: G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\hardware\teensy\avr\libraries\Encoder

    Bibliothek Encoder in Version 1.4.1 im Ordner: G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\libraries\Encoder wird verwendet

    Fehler beim Kompilieren fr das Board Teensy 4.1."
    ************************************************** *****************


    Ive read some posts about problems with arduino ide and so I buildt a new one using the portable feature. But I earned the same fault.
    It would be very nice, if you can help me.
    Please excuse my bad english-skills.

    Keep healthy
    Yours
    Micki
    Last edited by Frank B; 01-23-2021 at 02:10 PM. Reason: readability

  2. #2
    Junior Member
    Join Date
    Jan 2021
    Posts
    9
    Sorry for confusion

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,995
    Which problem with the IDE?
    It should work out of the box. Own builds will not work with Teensyduino - it checks the version, on install.
    There are no problems.

    Something is wrong with your installation.

    Do it simple:
    1. Forget all you read. Don't think.
    2. Delete all arduino installations.
    2a) Reboot.
    3. Install Arduino (download the windows-zip from the official page) to c:\Arduino
    4. Install Teensyduino.
    Test, and see: It works

    After that, don't forget to re-enable thinking

  4. #4
    Member KD0RC's Avatar
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    75
    @Micki What kind of encoder do you have? Is it an incremental or absolute? When you show a data and clock line, that implies an absolute position encoder. If it is a mechanical switch type, then it is likely an incremental unit and should work with Paul's Encoder.h library.

    Len

  5. #5
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    6,372
    @Micki - you don't have multiple encoder libraries installed? Like one in your libraries folder and another in the Teensyduino folder. Your sketch compiled fine for me with no issue unlike what you showed in post #1.

  6. #6
    Junior Member
    Join Date
    Jan 2021
    Posts
    9
    Quote Originally Posted by Frank B View Post
    Which problem with the IDE?
    It should work out of the box. Own builds will not work with Teensyduino - it checks the version, on install.
    There are no problems.

    Something is wrong with your installation.

    Do it simple:
    1. Forget all you read. Don't think.
    2. Delete all arduino installations.
    2a) Reboot.
    3. Install Arduino (download the windows-zip from the official page) to c:\Arduino
    4. Install Teensyduino.
    Test, and see: It works

    After that, don't forget to re-enable thinking
    Hi Frank B,
    thats exactly what Ive done. But it doesmt work.

    With my teensy i can run other scatches (playing music etc.) Only the encoderscetch doest work.

    The error-report says:
    "G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\libraries\Encoder/Encoder.h:82:25: error: cannot convert 'volatile uint32_t* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment

    encoder.pin1_register = PIN_TO_BASEREG(pin1);
    ^
    G:\Einplatinen Computer\Arduino IDE ZIP\arduino-1.8.13-windows\arduino-1.8.13\portable\sketchbook\libraries\Encoder/Encoder.h:84:25: error: cannot convert 'volatile uint32_t* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
    encoder.pin2_register = PIN_TO_BASEREG(pin2);
    ^"

    I think, thats the reason why it doesnt work. But I dont know, whats to do.

  7. #7
    Junior Member
    Join Date
    Jan 2021
    Posts
    9
    Hi KDORC,

    its an incremantal mechanical encoder Joy-it KY-040

  8. #8
    Junior Member
    Join Date
    Jan 2021
    Posts
    9
    Quote Originally Posted by mjs513 View Post
    @Micki - you don't have multiple encoder libraries installed? Like one in your libraries folder and another in the Teensyduino folder. Your sketch compiled fine for me with no issue unlike what you showed in post #1.
    Yes, the compiler read the one in the portable-folder an in the zip-folder.
    I deleted the zip folder, but its the same

  9. #9
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,995
    Well, your program compiles fine for other users.
    thats exactly what Ive done.
    Nope.

  10. #10
    Junior Member
    Join Date
    Jan 2021
    Posts
    9
    Quote Originally Posted by Frank B View Post
    Well, your program compiles fine for other users.

    Nope.
    Hi Frank,
    that are not so much words.

    Ive read a post from Paul Stoffregen to create a portable Arduino folder, with
    - deleting the old arduino instance
    - loading the arduino.zip file
    - remembering, where the new arduino.ide is installed.
    - careful installing the teensyduino in that folder.

    So now I have a smart arduino.IDE.

    Ive deconstructed my teensy so that now it is only connected to the audio-shield.
    Than i loadet the first testsketch "blink". - works
    Than i tried to load Pauls encodersketch and I got the same error report.
    i looked into the portable/sketchbook/libraries folder and found the Encoder entry.

    I think its quit normal ....

  11. #11
    Junior Member
    Join Date
    Jan 2021
    Posts
    9
    ***************************************
    Update:

    ive used another LapTop and now I can compile the scetch.
    I will do a new installation asap. ;-)

    But on the serial monitor I only see "0" and "1", not a counting up and down.
    What can I do?

    And a 2nd question:
    Paul writes in the sketch, that we have the possibillity to switch the performance quality.
    How can I do that?

    Thanx for your tips and helping!

    stay healthy

  12. #12
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    6,372
    Think this may help you out: https://www.pjrc.com/teensy/td_libs_Encoder.html in understanding how the encoder library works.

    If all you are getting in 0s and 1s it sounds like you are only registering on 1 of the encoder pins. I would check your wiring to make sure you have the ky040 hooked up correctly.

    Click image for larger version. 

Name:	KY-040-PIC-5.png 
Views:	5 
Size:	6.0 KB 
ID:	23428

    Just make sure you use 3.3v instead of 5v!!!!!! I know those encoders work because I have tested them.

  13. #13
    Junior Member
    Join Date
    Jan 2021
    Posts
    9
    Quote Originally Posted by mjs513 View Post
    Think this may help you out: https://www.pjrc.com/teensy/td_libs_Encoder.html in understanding how the encoder library works.

    If all you are getting in 0s and 1s it sounds like you are only registering on 1 of the encoder pins. I would check your wiring to make sure you have the ky040 hooked up correctly.

    Click image for larger version. 

Name:	KY-040-PIC-5.png 
Views:	5 
Size:	6.0 KB 
ID:	23428

    Just make sure you use 3.3v instead of 5v!!!!!! I know those encoders work because I have tested them.
    Problem nearly solved !

    Hi mjs513,
    today Ive tried the 2 knobs sketch with my pins 8/9 with the same results.
    Than I took Pauls pins 5/6 and it works !!!!

    But, what have I to do, if I want to use other pins?
    I thought, that I only have to change the pinnumbers in line 13/14 ...

    And playing with the sketch I saw that it jumps 2 numbers up or down in the serial monitor when i go one step with the encoder up or down.

    Thanx for helping !!!
    Keep healthy!
    Last edited by Micki; 01-24-2021 at 01:03 PM. Reason: news

  14. #14
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    6,372
    @Micki
    Not sure what line 13/14 is but problem these 2 lines:
    Code:
    Encoder knobLeft(5, 6);
    Encoder knobRight(7, 8);
    If you are using a Teensy 4.x then all digital pins should be able to be used for the encoder pins. If 8,9 is not working for you maybe you should check the soldering on the t4.1 or put a multmeter to see if you have continuity between the breadboard and those pins? Possibly a cold solder joint? Not sure.

  15. #15
    Member KD0RC's Avatar
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    75
    @Micki, you get two value increments per detent click because your encoder is a 2:1 encoder. There are also 4:1 encoders that jump 4 values per click. To solve this problem, I multiply or divide by the number of steps that the encoder uses. In my radio application, I can read any kind of incremental encoder:

    VolAEncSteps is 1 for 1:1. 2 for 2:1, etc. In my application, I take this value in as a parameter in a config file on the SD card. Hopefully this example will make sense.
    Code:
    void ReadVolAEnc()    // called from main loop
    {
      if(VolAEnc.read() % VolAEncSteps != 0)  // don't waste time if not on a detent click
      {
        return;
      }
        
      VolVal[A] = VolAEnc.read() / VolAEncSteps;    // The value kept is multiplied by VolAEncSteps, so needs to be divided out here
      
      if (VolVal[A] != VolValSave[A])    // only process if there was a change in value
      {
        if(VolVal[A] > 100)    // Max value for this encoder is 100
        {
          VolVal[A] = 100;
          VolValSave[A] = 100;
          VolAEnc.write(100 * VolAEncSteps);    // Encoder keeps VolAEncSteps * the value
        }
    
        if(VolVal[A] < 0)    // Min value for this encoder is 0
        {
          VolVal[A] = 0;
          VolValSave[A] = 0;
          VolAEnc.write(0);
        }
        
        fRig.setAudioGain(A,VolVal[A]);    // send new volume value to radio
        VolValSave[A] = VolVal[A];    // Save new volume value for comparison in the next pass thru loop
    //    Serial.println(VolVal[A]);
      }
    } // end ReadAVolEnc
    Len

  16. #16
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,371
    To solve this problem, I multiply or divide by the number of steps that the encoder uses.
    Just a note: That works nicely if your application is not sensitive to bounces. E.g. if you use the encoder for set point applications like a volume control or similar. If you need to trigger stuff whenever the encoder value changes (e.g. for menu applications) you might run into problems with this simple approach.

    The decoding algorithm of the standard Encoder library only guarantees that you end up with a correct value (modulo 2 or 4) if you rotate from one encoder detent to another. Between the detents it might (and will) generate rapid up/down counts if you use a mechanical encoder. The reason why encoders have their detents not at every encoder value is to allow for more elaborate decoding algorithms. Those algorithms can eliminate any "between detent" bouncing completely.
    In case your application needs to be bounce free without rapid up/down counts between detents you can give the EncoderTool a try. In addition to the algorithm the standard encoder library provides, it uses dedicated algorithms for x2 and x4 type encoders.

  17. #17
    Member KD0RC's Avatar
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    75
    Hi luni, Thanks for the information. On the unit that I built, I use 1:1 encoders from Leo Bodnar in England. My buddy built one with Bourns PEC-11 4:1 encoders. No problem with encoder jitter from either encoder. I am indeed using the encoders for things like volume. It is a radio controller with 9 mechanical encoders and two optical encoders, all using Encoder.h.

    Does your EncoderTool allow setting the encoder to a value like Encoder does (Encoder.write(val))? This feature is important in my application because the controls on the connected radio may be changed, necessitating adjusting the encoder accordingly.

    Len

  18. #18
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,371
    Quote Originally Posted by KD0RC View Post
    Does your EncoderTool allow setting the encoder to a value like Encoder does (Encoder.write(val))? This feature is important in my application because the controls on the connected radio may be changed, necessitating adjusting the encoder accordingly.
    Len
    Sure, here the documentation: https://github.com/luni64/EncoderTool/wiki For things like volume control it also provides built in value limiting (cyclic and hard stop). Since you are using 11 encoders you might be interested in the mulitplexing capabilities as well. On the other hand never change a running system...

  19. #19
    Member KD0RC's Avatar
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    75
    Good to know that you support multiplexed encoders. I got that question recently from a guy who is considering replicating my controller. I will pass the EncoderTool information on to him. Thanks again!

    Len

  20. #20
    Junior Member
    Join Date
    Jan 2021
    Posts
    9
    Hallo everybody,

    first let me thank you all. In the last days I made a lot of tests.
    Here is my result:

    1. yes, there were misconnections. Ive used standard female patchcords to connect the t41-pins to the encoder. I will solder this in future.
    2. I was not careful enough to take the right pin numbers. Pin 8 is used by the audio-shield. I did not see that. The missfunction of pins 31/32 was a mal connection.
    3. I have to reinstall my arduino-IDE, because it works not save. In some cases I get the compiler-error, in other cases not. This must be fixed.
    4. And thanx for the info about the 2:1-encoder. I want to use the encoder for Mode-choosing and scrolling thu a directory (later). Theres not time critical issue.

    Im looking foreward to complete my work. Thank you all !!!
    Last edited by Micki; 01-25-2021 at 12:49 PM. Reason: correction

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •