• 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.

About

Avatar for Robin @Robin started