• Hi guys!
    I'm trying to use Encoder lib to get rotation direction from my wheels encoders (https://wiki.dfrobot.com/Micro_DC_Motor_­with_Encoder-SJ01_SKU__FIT0450).
    At small speed it's okay and returns correct value. But when I'm trying to rotate wheel a little bit faster Encoder lib starting to print an opposite direction sign.
    What am I doing wrong? Please, help me figure it out.

    const ENCODER = require('Encoder');
    ENCODER.connect(P3,P2,function (direction) {
      print(direction);
    });
    

    Looks like this at slow speed
    1
    1
    1
    1
    1
    1

    And this at higher speed
    -1
    -1
    1
    -1
    1
    -1
    -1
    -1

  • Wed 2019.07.10

    Hi @feanir, While I have no experience with encoders or this module I am unable to provide a definitive answer to what is going on.

    It is possible that pull-up resistors are required, it could be the choice of encoder you have is not compatible with the code module.

    But, looking at the Encoder module code, link at top of reference page,

    http://www.espruino.com/Encoder

    http://www.espruino.com/modules/Encoder.­js

    there is only one function. As a suggestion, simply copy-n-paste that function into your code, removing the module require statement, add a liberal amount of console.log("The output of pin a is: ", a); lines and modify until you get the results you want.

  • Rotary encoders for whatever reason seem to be problematic on the ESP32 and ESP8266. Maybe because "setWatch" uses polling instead of interrupts? I'm not sure. At least your setup is not crashing as it did for me.

    http://forum.espruino.com/conversations/­332965/#comment14722654

    You could try different pins. This could at least improve the situation.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Rotary encoder wrong direction sign at high speed rotation (STM32F405RG)

Posted by Avatar for feanir @feanir

Actions